-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXCom2Browser.cs
70 lines (65 loc) · 3.13 KB
/
XCom2Browser.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
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
namespace XCom2ModTool
{
internal class XCom2Browser
{
private static readonly string EditorName = "editor";
private static readonly string[] EditorArguments = new[] { "editor", "-noscriptcompile", "-nogadwarning" };
public static (string name, Func<XCom2Edition, string> describe, Func<XCom2Edition, string> getPath, string[] arguments)[] GetFolders()
{
return new (string, Func<XCom2Edition, string>, Func<XCom2Edition, string>, string[])[]
{
("xcom2", x => $"The {x.DisplayName} folder", x => x.Path, null),
("mods", x => $"The {x.DisplayName} mods folder", x => x.ModsPath, null),
("sdk", x => $"The {x.SdkDisplayName} folder", x => x.SdkPath, null),
("sdk-mods", x => $"The {x.SdkDisplayName} mods folder", x => x.SdkModsPath, null),
("sdk-src", x => $"The {x.SdkDisplayName} source folder", x => x.SdkSourceCodeClassesPath, null),
("config", x => $"The current user's {x.DisplayName} config folder", x => x.UserConfigPath, null),
("log", x => $"The current user's {x.DisplayName} log file", x => x.UserLogPath, null),
("save", x => $"The current user's {x.DisplayName} save folder", x => x.UserSavePath, null),
("int", x => $"The {x.DisplayName} INT localization folder", x => x.IntPath, null),
(EditorName, x => $"The {x.DisplayName} Editor", x => x.EditorPath, EditorArguments),
};
}
public static void Browse(string name, XCom2Edition edition)
{
var folder = GetFolders().FirstOrDefault(x => string.Equals(name, x.name, StringComparison.OrdinalIgnoreCase));
if (folder.name == null)
{
throw new ArgumentOutOfRangeException(nameof(name));
}
PrepareToBrowse(folder.name, edition);
var path = folder.getPath(edition);
if (folder.arguments?.Length > 0)
{
Report.Verbose($"> \"{path}\" {PathHelper.EscapeAndJoinArguments(folder.arguments)}");
Process.Start(path, PathHelper.EscapeAndJoinArguments(folder.arguments));
}
else
{
Report.Verbose($"> \"{path}\"");
Process.Start(path);
}
}
private static void PrepareToBrowse(string name, XCom2Edition edition)
{
if (name == EditorName)
{
Report.Verbose($"Deleting {edition.SdkDisplayName} mods");
DirectoryHelper.DeleteDirectoryContents(edition.SdkModsPath);
}
}
public static void CopyToClipboard(string name, XCom2Edition edition)
{
var folder = GetFolders().FirstOrDefault(x => string.Equals(name, x.name, StringComparison.OrdinalIgnoreCase));
if (folder.name == null)
{
throw new ArgumentOutOfRangeException(nameof(name));
}
Clipboard.SetText(folder.getPath(edition));
}
}
}