-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtils.cs
More file actions
75 lines (67 loc) · 2.39 KB
/
Copy pathFileUtils.cs
File metadata and controls
75 lines (67 loc) · 2.39 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
73
74
75
namespace VModLoader
{
/// <summary>
/// A static class containing various file utilities.
/// </summary>
internal static class FileUtils
{
/// <summary>
/// The path seperator character.
/// </summary>
static readonly string C = Path.DirectorySeparatorChar.ToString();
/// <summary>
/// The filepath of the main runtime data folder.
/// </summary>
static readonly string MAIN_RUNTIME_FOLDER = "data" + C;
/// <summary>
/// The name referring to the runtime data folder.
/// </summary>
public static readonly string MAIN_RUNTIME_FOLDER_NAME = nameof(MAIN_RUNTIME_FOLDER);
/// <summary>
/// The mod data file path.
/// </summary>
static readonly string MOD_DATA = MAIN_RUNTIME_FOLDER + "moddata.vml";
/// <summary>
/// The name referring to the mod data file.
/// </summary>
public static readonly string MOD_DATA_NAME = nameof(MOD_DATA);
/// <summary>
/// Gets the filepath of a required file by name.
/// </summary>
/// <param name="name">The name of the file.</param>
/// <returns>The filepath, or null if none.</returns>
internal static string? GetRequiredFile(string name)
{
REQUIRED_FILENAMES.TryGetValue(name, out string? r);
return r;
}
/// <summary>
/// A dictionary of required filenames.
/// </summary>
static readonly Dictionary<string, string> REQUIRED_FILENAMES = new()
{
{ MAIN_RUNTIME_FOLDER_NAME, MAIN_RUNTIME_FOLDER },
{ MOD_DATA_NAME, MOD_DATA },
};
/// <summary>
/// Initializes the program with all required filepaths.
/// </summary>
internal static void Initialize()
{
foreach (KeyValuePair<string, string> file in REQUIRED_FILENAMES)
{
string path = file.Value;
if (Path.EndsInDirectorySeparator(path))
{
// Is directory, treat it as such.
Directory.CreateDirectory(path);
} else
{
// Is file, treat it as such.
if (!File.Exists(path))
File.Create(path).Close();
}
}
}
}
}