-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDataPaths.cs
More file actions
49 lines (42 loc) · 1.55 KB
/
Copy pathAppDataPaths.cs
File metadata and controls
49 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace MarkdownThing
{
internal static class AppDataPaths
{
public const string AppFolderName = "MarkdownThing";
private const string LegacyFolderName = "MDConvert";
private static string AppDataRoot =>
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
public static string AppFolder =>
Path.Combine(AppDataRoot, AppFolderName);
public static string SettingsFile =>
Path.Combine(AppFolder, "settings.json");
public static string RecentFilesFile =>
Path.Combine(AppFolder, "recentfiles.txt");
public static string WebView2Folder =>
Path.Combine(AppFolder, "WebView2");
public static void MigrateLegacyData()
{
var legacyFolder = Path.Combine(AppDataRoot, LegacyFolderName);
if (!Directory.Exists(legacyFolder) || Directory.Exists(AppFolder))
return;
try
{
Directory.CreateDirectory(Path.GetDirectoryName(AppFolder)!);
Directory.Move(legacyFolder, AppFolder);
}
catch
{
try
{
Directory.CreateDirectory(AppFolder);
foreach (var file in Directory.GetFiles(legacyFolder))
File.Copy(file, Path.Combine(AppFolder, Path.GetFileName(file)), overwrite: false);
}
catch
{
// non-fatal
}
}
}
}
}