PersonalPath.cfg path moved from %localappdata%\ShareX to Documents\ShareX and gonna be automatically migrated

This commit is contained in:
Jaex 2017-04-25 01:26:01 +03:00
parent 59397b8b98
commit 1c325dfb9c

View file

@ -116,10 +116,15 @@ private static string PersonalPathConfigFilePath
return oldPath; return oldPath;
} }
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName, PersonalPathConfigFileName); return CurrentPersonalPathConfigFilePath;
} }
} }
private static readonly string CurrentPersonalPathConfigFilePath = Path.Combine(DefaultPersonalFolder, PersonalPathConfigFileName);
private static readonly string PreviousPersonalPathConfigFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
AppName, PersonalPathConfigFileName);
private static readonly string PortableCheckFilePath = Helpers.GetAbsolutePath("Portable"); private static readonly string PortableCheckFilePath = Helpers.GetAbsolutePath("Portable");
private static readonly string PortableAppsCheckFilePath = Helpers.GetAbsolutePath("PortableApps"); private static readonly string PortableAppsCheckFilePath = Helpers.GetAbsolutePath("PortableApps");
public static readonly string NativeMessagingHostFilePath = Helpers.GetAbsolutePath("ShareX_NativeMessagingHost.exe"); public static readonly string NativeMessagingHostFilePath = Helpers.GetAbsolutePath("ShareX_NativeMessagingHost.exe");
@ -379,6 +384,8 @@ private static void UpdatePersonalPath()
private static void CheckPersonalPathConfig() private static void CheckPersonalPathConfig()
{ {
MigratePersonalPathConfig();
string customPersonalPath = ReadPersonalPathConfig(); string customPersonalPath = ReadPersonalPathConfig();
if (!string.IsNullOrEmpty(customPersonalPath)) if (!string.IsNullOrEmpty(customPersonalPath))
@ -396,6 +403,24 @@ private static void CheckPersonalPathConfig()
} }
} }
private static void MigratePersonalPathConfig()
{
if (File.Exists(PreviousPersonalPathConfigFilePath))
{
try
{
Helpers.CreateDirectoryFromFilePath(CurrentPersonalPathConfigFilePath);
File.Move(PreviousPersonalPathConfigFilePath, CurrentPersonalPathConfigFilePath);
File.Delete(PreviousPersonalPathConfigFilePath);
Directory.Delete(Path.GetDirectoryName(PreviousPersonalPathConfigFilePath));
}
catch (Exception e)
{
e.ShowError();
}
}
}
public static string ReadPersonalPathConfig() public static string ReadPersonalPathConfig()
{ {
if (File.Exists(PersonalPathConfigFilePath)) if (File.Exists(PersonalPathConfigFilePath))