Skip to content

Commit d94ad97

Browse files
committed
Migration of legacy user
1 parent 7d56dd1 commit d94ad97

5 files changed

Lines changed: 70 additions & 41 deletions

File tree

gamevault/Helper/ProfileManager.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,35 @@ public static void EnsureRootDirectory()
1919
if (!Directory.Exists(ProfileRootDirectory))
2020
{
2121
Directory.CreateDirectory(ProfileRootDirectory);
22+
MigrateLegacyCache();
2223
MoveLegacyCache();
23-
}
24+
}
25+
}
26+
private static void MigrateLegacyCache()
27+
{
28+
string legacyUserCacheFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GameVault", "config", "user");
29+
if (File.Exists(legacyUserCacheFile))
30+
{
31+
try
32+
{
33+
string username = Preferences.Get("Username", legacyUserCacheFile);
34+
string password = Preferences.Get("Password", legacyUserCacheFile, true);
35+
string serverurl = Preferences.Get("ServerUrl", legacyUserCacheFile, true);
36+
string rootpath = Preferences.Get("RootPath", legacyUserCacheFile);
37+
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(serverurl))
38+
{
39+
UserProfile profile = CreateUserProfile(WebHelper.RemoveSpecialCharactersFromUrl(serverurl));
40+
Preferences.Set(AppConfigKey.ServerUrl, serverurl, profile.UserConfigFile, true);
41+
Preferences.Set(AppConfigKey.Username, username, profile.UserConfigFile);
42+
Preferences.Set(AppConfigKey.Password, password, profile.UserConfigFile, true);
43+
if (Directory.Exists(rootpath))
44+
{
45+
Preferences.Set(AppConfigKey.RootDirectories, rootpath, profile.UserConfigFile);
46+
}
47+
}
48+
}
49+
catch { }
50+
}
2451
}
2552
private static void MoveLegacyCache()
2653
{
@@ -35,20 +62,20 @@ private static void MoveLegacyCache()
3562

3663
if (Directory.Exists(cache))
3764
{
38-
string cacheDestination = Path.Combine(legacyDir, "cache");
39-
Directory.Move(cache, cacheDestination);
65+
string cacheDestination = Path.Combine(legacyDir, "cache");
66+
Directory.Move(cache, cacheDestination);
4067
}
4168

4269
if (Directory.Exists(config))
4370
{
44-
string configDestination = Path.Combine(legacyDir, "config");
45-
Directory.Move(config, configDestination);
71+
string configDestination = Path.Combine(legacyDir, "config");
72+
Directory.Move(config, configDestination);
4673
}
4774

4875
if (Directory.Exists(themes))
4976
{
50-
string themesDestination = Path.Combine(legacyDir, "themes");
51-
Directory.Move(themes, themesDestination);
77+
string themesDestination = Path.Combine(legacyDir, "themes");
78+
Directory.Move(themes, themesDestination);
5279
}
5380
}
5481
catch { }
@@ -89,7 +116,7 @@ public static List<UserProfile> GetUserProfiles()
89116
{
90117
UserProfile userProfile = new UserProfile(userDir, Path.Combine(serverDir, "ImageCache"));
91118
userProfile.Name = Preferences.Get(AppConfigKey.Username, userProfile.UserConfigFile);
92-
userProfile.ServerUrl = Preferences.Get(AppConfigKey.ServerUrl, userProfile.UserConfigFile);
119+
userProfile.ServerUrl = Preferences.Get(AppConfigKey.ServerUrl, userProfile.UserConfigFile, true);
93120
userProfile.UserCacheAvatar = CacheHelper.GetUserProfileAvatarPath(userProfile);
94121
if (string.IsNullOrWhiteSpace(userProfile.ServerUrl) || string.IsNullOrWhiteSpace(userProfile.Name))
95122
{

gamevault/Helper/Web/WebHelper.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ public static async Task<string> UploadFileAsync(string apiUrl, Stream imageStre
160160
return responseContent;
161161
}
162162
}
163+
public static string RemoveSpecialCharactersFromUrl(string url)
164+
{
165+
if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
166+
{
167+
url = url.Substring(7);
168+
}
169+
else if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
170+
{
171+
url = url.Substring(8);
172+
}
173+
174+
StringBuilder sb = new StringBuilder();
175+
foreach (char c in url)
176+
{
177+
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_')
178+
{
179+
sb.Append(c);
180+
}
181+
}
182+
return sb.ToString();
183+
}
163184
}
164185
}
165186

gamevault/ViewModels/SettingsViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public void Init()
7777
{
7878
userConfigFile = LoginManager.Instance.GetUserProfile().UserConfigFile;
7979

80-
UserName = Preferences.Get(AppConfigKey.Username, userConfigFile);
81-
ServerUrl = Preferences.Get(AppConfigKey.ServerUrl, userConfigFile);
80+
UserName = Preferences.Get(AppConfigKey.Username, userConfigFile);
81+
ServerUrl = Preferences.Get(AppConfigKey.ServerUrl, userConfigFile, true);
8282

8383
string rootDirectoriesString = Preferences.Get(AppConfigKey.RootDirectories, userConfigFile);
8484
RootDirectories = string.IsNullOrWhiteSpace(rootDirectoriesString) ? null! : new ObservableCollection<DirectoryEntry>(rootDirectoriesString.Split(';').Select(part => new DirectoryEntry { Uri = part }).ToList());
@@ -127,7 +127,7 @@ public void Init()
127127
usePrimaryCloudSaveManifest = usePrimaryCloudSaveManifestString == "1" || usePrimaryCloudSaveManifestString == "";
128128

129129
string customCloudSaveManifestsString = Preferences.Get(AppConfigKey.CustomCloudSaveManifests, userConfigFile);
130-
customCloudSaveManifests = string.IsNullOrWhiteSpace(customCloudSaveManifestsString) ? null! : new ObservableCollection<DirectoryEntry>(customCloudSaveManifestsString.Split(';').Select(part => new DirectoryEntry { Uri = part }).ToList());
130+
customCloudSaveManifests = string.IsNullOrWhiteSpace(customCloudSaveManifestsString) ? null! : new ObservableCollection<DirectoryEntry>(customCloudSaveManifestsString.Split(';').Select(part => new DirectoryEntry { Uri = part }).ToList());
131131

132132
string mountIsoString = Preferences.Get(AppConfigKey.MountIso, userConfigFile);
133133
mountIso = mountIsoString == "1";
@@ -444,7 +444,7 @@ public async Task<string> SelectDownloadPath()
444444
});
445445
return selectedDirectory;
446446
});
447-
}
447+
}
448448
public string Version
449449
{
450450
get

gamevault/Windows/LoginWindow.xaml.cs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ private void ServerUrlInput_TextChanged(object sender, RoutedEventArgs e)
161161
}
162162
private UserProfile SetupUserProfile(LoginUser user)
163163
{
164-
string cleanedServerUrl = RemoveSpecialCharacters(user.ServerUrl);
164+
string cleanedServerUrl = WebHelper.RemoveSpecialCharactersFromUrl(user.ServerUrl);
165165
UserProfile profile = ProfileManager.CreateUserProfile(cleanedServerUrl);
166166
profile.ServerUrl = user.ServerUrl;
167-
Preferences.Set(AppConfigKey.ServerUrl, user.ServerUrl, profile.UserConfigFile);
167+
Preferences.Set(AppConfigKey.ServerUrl, user.ServerUrl, profile.UserConfigFile, true);
168168
if (!user.IsLoggedInWithSSO)
169169
{
170170
profile.Name = user.Username;
@@ -404,27 +404,7 @@ private void ValidateSignUpData()
404404
}
405405
}
406406
}
407-
private string RemoveSpecialCharacters(string str)
408-
{
409-
if (str.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
410-
{
411-
str = str.Substring(7);
412-
}
413-
else if (str.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
414-
{
415-
str = str.Substring(8);
416-
}
417-
418-
StringBuilder sb = new StringBuilder();
419-
foreach (char c in str)
420-
{
421-
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_')
422-
{
423-
sb.Append(c);
424-
}
425-
}
426-
return sb.ToString();
427-
}
407+
428408

429409
private void UserProfileContextMenu_Click(object sender, RoutedEventArgs e)
430410
{
@@ -477,12 +457,12 @@ private void UserProfileEditSave_Click(object sender, RoutedEventArgs e)
477457
{
478458
ProfileManager.DeleteUserProfile(profileToEdit);
479459
ViewModel.UserProfiles.Remove(profileToEdit);
480-
string cleanedServerUrl = RemoveSpecialCharacters(ViewModel.EditUser.ServerUrl);
460+
string cleanedServerUrl = WebHelper.RemoveSpecialCharactersFromUrl(ViewModel.EditUser.ServerUrl);
481461
UserProfile profile = ProfileManager.CreateUserProfile(cleanedServerUrl);
482462
profile.Name = ViewModel.EditUser.Username;
483463
profile.ServerUrl = ViewModel.EditUser.ServerUrl;
484464
ViewModel.UserProfiles.Add(profile);
485-
Preferences.Set(AppConfigKey.ServerUrl, ViewModel.EditUser.ServerUrl, profile.UserConfigFile);
465+
Preferences.Set(AppConfigKey.ServerUrl, ViewModel.EditUser.ServerUrl, profile.UserConfigFile, true);
486466
Preferences.Set(AppConfigKey.Username, ViewModel.EditUser.Username, profile.UserConfigFile);
487467
Preferences.Set(AppConfigKey.Password, ViewModel.EditUser.Password, profile.UserConfigFile, true);
488468
}
@@ -507,13 +487,13 @@ private void CreateDemoUser()
507487
string demoUsername = "demo";
508488
string demoPassword = "demodemo";
509489

510-
UserProfile demoProfile = ProfileManager.CreateUserProfile(RemoveSpecialCharacters(demoServerUrl));
490+
UserProfile demoProfile = ProfileManager.CreateUserProfile(WebHelper.RemoveSpecialCharactersFromUrl(demoServerUrl));
511491
demoProfile.Name = demoUsername;
512492
demoProfile.ServerUrl = demoServerUrl;
513493

514494
ViewModel.UserProfiles.Add(demoProfile);
515495

516-
Preferences.Set(AppConfigKey.ServerUrl, demoServerUrl, demoProfile.UserConfigFile);
496+
Preferences.Set(AppConfigKey.ServerUrl, demoServerUrl, demoProfile.UserConfigFile, true);
517497
Preferences.Set(AppConfigKey.Username, demoUsername, demoProfile.UserConfigFile);
518498
Preferences.Set(AppConfigKey.Password, demoPassword, demoProfile.UserConfigFile, true);
519499
}
@@ -674,6 +654,6 @@ private async void UserRegistrationTextBox_KeyDown(object sender, System.Windows
674654
await SaveAndSignUp();
675655
}
676656
}
677-
657+
678658
}
679659
}

gamevault/Windows/MainWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private async void MetroWindow_Loaded(object sender, System.Windows.RoutedEventA
111111

112112
uiNewsBadge.Badge = await CheckForNews() ? "!" : "";
113113
InitNewsTimer();
114-
114+
115115
}
116116
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
117117
{
@@ -236,6 +236,7 @@ public void Dispose()
236236
LoginManager.Instance.StopOnlineTimer();
237237
App.Instance.ResetJumpListGames();
238238
PipeServiceHandler.Instance.IsReadyForCommands = false;
239+
MainWindowViewModel.Instance.UserAvatar = null;
239240
this.Close();
240241
}
241242
}

0 commit comments

Comments
 (0)