-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
143 lines (126 loc) · 3.71 KB
/
Config.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
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace BSPPackStandalone
{
public static class Config
{
public static string ExeDirectory = AppContext.BaseDirectory;
public static string BSPFile { get; set; }
public static string GameFolder { get; set; }
public static string SteamAppsPath { get; set; }
public static string BSPZip { get; private set; }
public static string KeysFolder { get; private set; }
public static string TempFolder { get; private set; }
public static string CopyLocation { get; private set; }
public static string VPK { get; private set; }
public static void InitializeConfig()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
BSPZip = Path.Combine(GameFolder, @"../bin/win64", "bspzip.exe");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
BSPZip = Path.Combine(GameFolder, @"../bin/linux64", "bspzip");
KeysFolder = Path.Combine(Directory.GetCurrentDirectory(), "Keys");
TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "Temp");
CopyLocation = Path.Combine(Directory.GetCurrentDirectory()); //Placeholder
VPK = Path.Combine(Directory.GetCurrentDirectory()); //Placeholder
}
public static void CreateDefaultResourceConfigFile(string filePath)
{
if (File.Exists(filePath))
{
Console.WriteLine("ResourceConfig.ini already exists.");
return;
}
var lines = new List<string>
{
"# One path per line",
"[IncludeFiles]",
"",
"[IncludeFileLists]",
"",
"[IncludeDirs]",
"",
"[IncludeSourceDirectories]",
"",
"[ExcludeFiles]",
"",
"[ExcludeDirs]",
"",
"[ExcludeVpkFiles]",
"",
};
try
{
File.WriteAllLines(filePath, lines);
Console.WriteLine($"Default ResourceConfig.ini file has been created.");
}
catch (Exception ex)
{
Console.WriteLine($"Error creating configuration file: {ex.Message}");
}
}
public static void LoadConfig(string filePath)
{
Console.WriteLine("Loading config.ini...");
if (!File.Exists(filePath))
{
CreateDefaultConfigFile(filePath);
}
bool configLoaded = true;
string currentSection = "";
foreach (var line in File.ReadLines(filePath))
{
if (line.StartsWith("#"))
continue;
if (line.StartsWith("[") && line.EndsWith("]"))
{
currentSection = line.Trim('[', ']');
continue;
}
var trimmedLine = line.Trim().Trim('"');
switch (currentSection)
{
case "GameFolder":
string gameinfo = Path.Combine(trimmedLine, "gameinfo.txt");
if (!File.Exists(gameinfo))
{
Console.WriteLine($"gameinfo.txt not found in provided game directory ( {trimmedLine} ).");
configLoaded = false;
break;
}
Config.GameFolder = trimmedLine;
break;
case "SteamPath":
string steamapps = Path.Combine(trimmedLine, "steamapps");
if (!Directory.Exists(steamapps))
{
Console.WriteLine($"steamapps not found in provided Steam directory ( {trimmedLine} ).");
configLoaded = false;
break;
}
Config.SteamAppsPath = steamapps;
break;
}
}
if(!configLoaded)
Environment.Exit(1);
InitializeConfig();
}
private static void CreateDefaultConfigFile(string filePath)
{
var lines = new List<string>
{
"[GameFolder]",
"#Specify the path to the game folder here ( directory of gameinfo.txt )",
"",
"[SteamPath]",
"#Specify the path to the Steam folder here ( steam installation directory )",
""
};
File.WriteAllLines(filePath, lines);
Console.WriteLine($"Default configuration file created at {filePath}. Please provide paths to game and steam folders.");
Environment.Exit(1);
}
}
}