Skip to content

Commit 08e7664

Browse files
committed
Update Program.cs
1 parent 0b8c40e commit 08e7664

File tree

1 file changed

+19
-55
lines changed

1 file changed

+19
-55
lines changed

UnturnedRedistUpdateTool/Program.cs

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public static async Task<int> Main(string[] args)
1919

2020
AssertPlatformSupported();
2121

22-
string path;
22+
string unturnedPath;
2323
if (args.Length < 3)
2424
{
2525
Console.WriteLine("Wrong usage. Correct usage: UnturnedRedistAutoUpdate.exe <path> <app_id> [args]");
2626
return 1;
2727
}
28-
path = args[0];
28+
unturnedPath = args[0];
2929
AppId = args[1];
3030
Force = !args.Any(x => x.Equals("--force", StringComparison.OrdinalIgnoreCase));
3131

@@ -34,12 +34,12 @@ public static async Task<int> Main(string[] args)
3434
Console.WriteLine("AppId is not specified.");
3535
return 1;
3636
}
37-
if (Path.Exists(path) == false)
37+
if (Path.Exists(unturnedPath) == false)
3838
{
39-
Console.WriteLine($"Path doesn't exists: \"{path}\".");
39+
Console.WriteLine($"Path doesn't exists: \"{unturnedPath}\".");
4040
return 1;
4141
}
42-
var redistPath = Path.Combine(path, "redist");
42+
var redistPath = Path.Combine(unturnedPath, "redist");
4343
if (Path.Exists(redistPath) == false)
4444
{
4545
Console.WriteLine($"Redist path doesn't exists: \"{redistPath}\".");
@@ -59,48 +59,28 @@ public static async Task<int> Main(string[] args)
5959

6060
Console.WriteLine("Preparing to run tool...");
6161

62-
var steamappsDirectory = Path.Combine(path, "steamapps");
62+
var steamappsDirectory = Path.Combine(unturnedPath, "steamapps");
6363
if (Directory.Exists(steamappsDirectory) == false)
6464
{
6565
Console.WriteLine($"steamapps Directory not found: \"{steamappsDirectory}\"");
6666
return 1;
6767
}
6868
Console.WriteLine("steamappsDirectory: " + string.Join(", ", Directory.GetDirectories(steamappsDirectory)));
6969

70-
var commonDirectory = Path.Combine(steamappsDirectory, "common");
71-
if (Directory.Exists(commonDirectory) == false)
72-
{
73-
Console.WriteLine($"common Directory not found: \"{commonDirectory}\"");
74-
return 1;
75-
}
76-
var unturnedDirectory = GetUnturnedDirectory(commonDirectory);
77-
if (unturnedDirectory == null || Directory.Exists(unturnedDirectory) == false)
78-
{
79-
Console.WriteLine($"Unturned Directory not found: \"{unturnedDirectory}\"");
80-
return 1;
81-
}
82-
Console.WriteLine("unturnedDirectory: " + string.Join(", ", Directory.GetDirectories(unturnedDirectory)));
83-
84-
var unturnedDataDirectoryName = GetUnturnedDataDirectoryName();
85-
var unturnedDataPath = Path.Combine(unturnedDirectory, unturnedDataDirectoryName);
86-
if (Directory.Exists(unturnedDataPath) == false)
87-
{
88-
Console.WriteLine($"Unturned Data Directory not found: \"{unturnedDataPath}\"");
89-
return 1;
90-
}
70+
var unturnedDataPath = GetUnturnedDataDirectoryName(unturnedPath);
9171
var managedDirectory = Path.Combine(unturnedDataPath, "Managed");
9272
if (Directory.Exists(managedDirectory) == false)
9373
{
9474
Console.WriteLine($"Unturned Managed Directory not found: \"{managedDirectory}\"");
9575
return 1;
9676
}
9777
const string statusFileName = "Status.json";
98-
var statusFilePath = Path.Combine(unturnedDirectory, statusFileName);
78+
var statusFilePath = Path.Combine(unturnedPath, statusFileName);
9979
if (File.Exists(statusFilePath) == false)
10080
{
10181
throw new FileNotFoundException("Required file is not found", statusFilePath);
10282
}
103-
var (version, buildId) = await GetInfo(unturnedDirectory, steamappsDirectory, AppId);
83+
var (version, buildId) = await GetInfo(unturnedPath, steamappsDirectory, AppId);
10484

10585
Console.WriteLine($"Found Unturned v{version} ({buildId})");
10686

@@ -128,7 +108,7 @@ public static async Task<int> Main(string[] args)
128108

129109
var forcedNote = Force ? " [Forced]" : "";
130110

131-
await File.WriteAllTextAsync(Path.Combine(path, ".commit"),
111+
await File.WriteAllTextAsync(Path.Combine(unturnedPath, ".commit"),
132112
$"{DateTime.UtcNow:dd MMMM yyyy} - Version {version} ({buildId})" + forcedNote);
133113

134114
return 0;
@@ -140,21 +120,6 @@ void AssertPlatformSupported()
140120
throw new PlatformNotSupportedException();
141121
}
142122
}
143-
string GetUnturnedDataDirectoryName()
144-
{
145-
if (linux)
146-
{
147-
return "Unturned_Headless_Data";
148-
}
149-
else if (windows)
150-
{
151-
return "Unturned_Data";
152-
}
153-
else
154-
{
155-
throw new PlatformNotSupportedException();
156-
}
157-
}
158123
void UpdateRedist(string unturnedManagedDirectory)
159124
{
160125
var managedFiles = new DirectoryInfo(unturnedManagedDirectory).GetFiles();
@@ -165,7 +130,7 @@ void UpdateRedist(string unturnedManagedDirectory)
165130

166131
foreach (var fileInfo in managedFiles)
167132
{
168-
var redistFilePath = Path.Combine(path, fileInfo.Name);
133+
var redistFilePath = Path.Combine(unturnedPath, fileInfo.Name);
169134
if (File.Exists(redistFilePath))
170135
{
171136
fileInfo.CopyTo(redistFilePath, true);
@@ -174,21 +139,20 @@ void UpdateRedist(string unturnedManagedDirectory)
174139
}
175140
}
176141

177-
private static string? GetUnturnedDirectory(string commonDirectory)
142+
private static string GetUnturnedDataDirectoryName(string unturnedPath)
178143
{
179-
var unturnedDirectory = Path.Combine(commonDirectory, "Unturned");
180-
if (Directory.Exists(unturnedDirectory))
144+
var headless = Path.Combine(unturnedPath, "Unturned_Headless_Data");
145+
if (Directory.Exists(headless))
181146
{
182-
return unturnedDirectory;
147+
return headless;
183148
}
184-
unturnedDirectory = Path.Combine(commonDirectory, "U3DS");
185-
if (Directory.Exists(unturnedDirectory))
149+
var usual = Path.Combine(unturnedPath, "Unturned_Data");
150+
if (Directory.Exists(usual))
186151
{
187-
return unturnedDirectory;
152+
return usual;
188153
}
189-
return null;
154+
throw new DirectoryNotFoundException("Unturned Data directory cannot be found!");
190155
}
191-
192156
private static async Task<(string version, string buildId)> GetInfo(string unturnedPath, string steamappsPath, string appId)
193157
{
194158
var node = JsonNode.Parse(await File.ReadAllTextAsync(Path.Combine(unturnedPath, "Status.json")))!["Game"]!;

0 commit comments

Comments
 (0)