-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLocations.cs
156 lines (136 loc) · 5.11 KB
/
Locations.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using WECCL.Content;
namespace WECCL;
public static class Locations
{
public static DirectoryInfo Root { get; } = new(Paths.PluginPath); // Not Plugin.PluginPath!
public static DirectoryInfo Export { get; } = new(Path.Combine(Plugin.PluginPath, "Export"));
public static DirectoryInfo DeletedCharacters { get; } = new(Path.Combine(Plugin.PluginPath, "Purgatory"));
public static DirectoryInfo Cache { get; } = new(Path.Combine(Plugin.PersistentDataPath, ".cache"));
public static DirectoryInfo Debug { get; } = new(Path.Combine(Plugin.PluginPath, "Debug"));
public static DirectoryInfo Data { get; } = new(Path.Combine(Plugin.PluginPath, "Data"));
public static DirectoryInfo Meta { get; } = new(Path.Combine(Plugin.PersistentDataPath, "Meta.meta"));
public static FileInfo SaveFileVanilla { get; } = new(Path.Combine(Application.persistentDataPath, "Save.bytes"));
public static FileInfo SaveFile { get; } = new(Path.Combine(Application.persistentDataPath, Plugin.SaveFileName.Value + ".bytes"));
public static DirectoryInfo ContentMappings { get; } =
new(Path.Combine(Plugin.PersistentDataPath, "ContentMappings.mappings"));
public static DirectoryInfo CharacterMappings { get; } =
new(Path.Combine(Plugin.PersistentDataPath, "CharacterMappings.mappings"));
internal static void CreateDirectories()
{
if (Plugin.CacheEnabled.Value && !Cache.Exists)
{
Cache.Create();
}
else if (Plugin.CacheEnabled.Value && Cache.Attributes.HasFlag(FileAttributes.Hidden))
{
Cache.Attributes &= ~FileAttributes.Hidden;
}
else if (!Plugin.CacheEnabled.Value && Cache.Exists)
{
Cache.Delete(true);
}
Debug.Create();
}
internal static void MoveLegacyLocations()
{
LegacyLocations.MoveLegacyLocations();
}
public static void LoadData()
{
var animationController = AssetBundle.LoadFromFile(Path.Combine(Data.FullName, "animationcontroller")).LoadAllAssets<RuntimeAnimatorController>().FirstOrDefault();
if (animationController == null) throw new Exception("Failed to load data. Please make sure you copied the 'Data' folder alongside the plugin if installed manually.");
AO.AnimationController = animationController;
}
}
internal static class LegacyLocations
{
public static DirectoryInfo OldCache { get; } = new(Path.Combine(Plugin.PluginPath, ".cache"));
public static DirectoryInfo OldMetadata { get; } = new(Path.Combine(Plugin.PluginPath, "Meta.meta"));
public static DirectoryInfo OldMappings { get; } = new(Path.Combine(Plugin.PluginPath, "ContentMappings.mappings"));
public static DirectoryInfo OldMetadata2 { get; } =
new(Path.Combine(Plugin.PluginPath, "CustomConfigsSaveFile.json"));
public static DirectoryInfo OldMappings2 { get; } =
new(Path.Combine(Plugin.PluginPath, "CustomContentSaveFile.json"));
public static DirectoryInfo OldMetadata3 { get; } = new(Path.Combine(Plugin.PluginPath, "Meta.json"));
public static DirectoryInfo OldMappings3 { get; } = new(Path.Combine(Plugin.PluginPath, "ContentMappings.json"));
public static void MoveLegacyLocations()
{
if (OldCache.Exists)
{
if (!Locations.Cache.Exists)
{
OldCache.MoveTo(Locations.Cache.FullName);
}
else
{
OldCache.Delete(true);
}
}
if (OldMetadata.Exists)
{
if (!Locations.Meta.Exists)
{
OldMetadata.MoveTo(Locations.Meta.FullName);
}
else
{
OldMetadata.Delete(true);
}
}
if (OldMappings.Exists)
{
if (!Locations.ContentMappings.Exists)
{
OldMappings.MoveTo(Locations.ContentMappings.FullName);
}
else
{
OldMappings.Delete(true);
}
}
if (OldMetadata2.Exists)
{
if (!Locations.Meta.Exists)
{
OldMetadata2.MoveTo(Locations.Meta.FullName);
}
else
{
OldMetadata2.Delete(true);
}
}
if (OldMappings2.Exists)
{
if (!Locations.ContentMappings.Exists)
{
OldMappings2.MoveTo(Locations.ContentMappings.FullName);
}
else
{
OldMappings2.Delete(true);
}
}
if (OldMetadata3.Exists)
{
if (!Locations.Meta.Exists)
{
OldMetadata3.MoveTo(Locations.Meta.FullName);
}
else
{
OldMetadata3.Delete(true);
}
}
if (OldMappings3.Exists)
{
if (!Locations.ContentMappings.Exists)
{
OldMappings3.MoveTo(Locations.ContentMappings.FullName);
}
else
{
OldMappings3.Delete(true);
}
}
}
}