-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAssetStore.cs
More file actions
72 lines (63 loc) · 2.64 KB
/
Copy pathUserAssetStore.cs
File metadata and controls
72 lines (63 loc) · 2.64 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.IO;
namespace STAGE
{
internal static class UserAssetStore
{
public static string DirectoryPath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"STAGE",
"UserAssets");
public static string Preserve(
string sourcePath,
string storedName,
string displayName,
params string[] allowedExtensions)
{
if (string.IsNullOrWhiteSpace(sourcePath))
return "";
string source = Path.GetFullPath(sourcePath);
if (!File.Exists(source))
throw new FileNotFoundException(
$"The configured {displayName} file could not be found:\n{source}",
source);
string extension = Path.GetExtension(source);
if (allowedExtensions.Length > 0 &&
!Array.Exists(allowedExtensions, allowed =>
string.Equals(allowed, extension, StringComparison.OrdinalIgnoreCase)))
{
throw new InvalidDataException(
$"{storedName} must use one of these file types: " +
string.Join(", ", allowedExtensions));
}
Directory.CreateDirectory(DirectoryPath);
string destination = Path.Combine(DirectoryPath, storedName + extension.ToLowerInvariant());
if (string.Equals(source, destination, StringComparison.OrdinalIgnoreCase))
return destination;
string temporary = destination + ".stage-writing";
File.Copy(source, temporary, overwrite: true);
File.Move(temporary, destination, overwrite: true);
return destination;
}
public static void MigrateConfiguredAssets()
{
string background = Settings.BackgroundImagePath;
if (File.Exists(background))
{
Settings.BackgroundImagePath = Preserve(
background,
"background",
"background image",
".png", ".jpg", ".jpeg", ".bmp", ".gif");
}
string donorScd = Settings.DefaultScdTemplateSourcePath;
if (File.Exists(donorScd))
Settings.DefaultScdTemplateSourcePath = Preserve(
donorScd, "donor", "donor SCD", ".scd");
string donorPap = Settings.DefaultDonorPapPath;
if (File.Exists(donorPap))
Settings.DefaultDonorPapPath = Preserve(
donorPap, "donor", "donor PAP", ".pap");
}
}
}