Skip to content

Commit 24f64b5

Browse files
committed
Add command line argument support for running KSP. Remove SHA checking, replacing files is faster.
1 parent 83d79c6 commit 24f64b5

2 files changed

Lines changed: 23 additions & 52 deletions

File tree

DMPModpackUpdater/Program.cs

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Reflection;
6-
using System.Security.Cryptography;
7-
using System.Text;
86

97
namespace DMPModpackUpdater
108
{
@@ -18,11 +16,10 @@ class MainClass
1816
private static string serverIndex;
1917
private static string cachePath;
2018
private static string gamedataPath;
21-
private static bool useCurrentDirectory = false;
2219
private static bool enableDelete = false;
2320
private static bool enableRun = true;
2421
private static bool enableStock = false;
25-
private static bool skipSha = false;
22+
private static string kspArgs = "";
2623
private static string runFile = null;
2724

2825
public static void Main(string[] args)
@@ -52,10 +49,6 @@ public static void Main(string[] args)
5249
{
5350
enableRun = false;
5451
}
55-
if (arg == "--no-check")
56-
{
57-
skipSha = true;
58-
}
5952
if (arg.StartsWith("--run=", StringComparison.Ordinal))
6053
{
6154
runFile = arg.Substring("--run=".Length);
@@ -64,6 +57,10 @@ public static void Main(string[] args)
6457
{
6558
kspPath = arg.Substring("--ksp-path=".Length);
6659
}
60+
if (arg.StartsWith("--ksp-args=", StringComparison.Ordinal))
61+
{
62+
kspArgs = arg.Substring("--ksp-args=".Length);
63+
}
6764
}
6865
if (kspPath == null)
6966
{
@@ -121,9 +118,9 @@ private static void ShowHelp()
121118
Console.WriteLine("--stock: Reverts GameData to stock, implies --delete");
122119
Console.WriteLine("--delete: Delete mods that are not on the server, instead of only updating or adding");
123120
Console.WriteLine("--no-run: Do not attempt to start KSP");
124-
Console.WriteLine("--no-check: Do not compare hashes against server (only adds missing files)");
125-
Console.WriteLine("--ksp-path=[path]: Run in specified folder, rather than the program location");
126121
Console.WriteLine("--run=[ProgramName.exe]: Runs this program instead of trying to find and start KSP.");
122+
Console.WriteLine("--ksp-path=[path]: Run in specified folder, rather than the program location");
123+
Console.WriteLine("--ksp-args=\"args\": Run KSP with these arguments, example: --ksp-args=\"-force-d3d11 -popupwindow -dmp dmp://localhost:6702\"");
127124
Console.WriteLine("--help: Displays this message");
128125
Console.WriteLine();
129126
Console.WriteLine("Press any key to exit");
@@ -271,32 +268,21 @@ private static void AddMissingToGameData()
271268
{
272269
string fileCachePath = Path.Combine(cachePath, kvp.Value + ".bin");
273270
string filePath = Path.Combine(gamedataPath, kvp.Key);
271+
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
272+
bool isUpdate = false;
274273
if (File.Exists(filePath))
275274
{
276-
if (!skipSha)
277-
{
278-
byte[] testBytes = File.ReadAllBytes(filePath);
279-
string testSha256Sum = CalculateSHA256Hash(testBytes);
280-
if (testSha256Sum != kvp.Value)
281-
{
282-
Console.WriteLine("Updated " + kvp.Key);
283-
File.Copy(fileCachePath, filePath, true);
284-
}
285-
else
286-
{
287-
Console.WriteLine("Checked " + kvp.Key);
288-
}
289-
}
290-
else
291-
{
292-
Console.WriteLine("Skipped checking " + kvp.Key);
293-
}
275+
isUpdate = true;
276+
File.Delete(filePath);
277+
}
278+
File.Copy(fileCachePath, filePath);
279+
if (isUpdate)
280+
{
281+
Console.WriteLine("Updated/Checked " + kvp.Key);
294282
}
295283
else
296284
{
297285
Console.WriteLine("Added " + kvp.Key);
298-
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
299-
File.Copy(fileCachePath, filePath);
300286
}
301287
}
302288
}
@@ -308,7 +294,7 @@ private static void RunKSP()
308294
string filePath = Path.Combine(kspPath, runFile);
309295
if (File.Exists(filePath))
310296
{
311-
StartProcess(filePath);
297+
StartProcess(filePath, kspArgs);
312298
}
313299
else
314300
{
@@ -323,32 +309,17 @@ private static void RunKSP()
323309
if (File.Exists(filePath))
324310
{
325311
Console.WriteLine("Starting:" + testFile);
326-
StartProcess(filePath);
312+
StartProcess(filePath, kspArgs);
327313
return;
328314
}
329315
Console.WriteLine("KSP executable not found");
330316
}
331317
}
332318
}
333319

334-
private static void StartProcess(string fileName)
335-
{
336-
Process.Start(fileName);
337-
}
338-
339-
private static string CalculateSHA256Hash(byte[] fileData)
320+
private static void StartProcess(string fileName, string args)
340321
{
341-
StringBuilder sb = new StringBuilder();
342-
using (SHA256Managed sha = new SHA256Managed())
343-
{
344-
byte[] fileHashData = sha.ComputeHash(fileData);
345-
//Byte[] to string conversion adapted from MSDN...
346-
for (int i = 0; i < fileHashData.Length; i++)
347-
{
348-
sb.Append(fileHashData[i].ToString("x2"));
349-
}
350-
}
351-
return sb.ToString();
322+
Process.Start(fileName, args);
352323
}
353324
}
354325
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# DMPModpackUpdater
1+
DMPModpackUpdater
22

33
Place next to KSP and run. It will setup your GameData and automatically start KSP.
44

55
Command line arguments:
66
--stock: Reverts GameData to stock, implies --delete
77
--delete: Delete mods that are not on the server, instead of only updating or adding
88
--no-run: Do not attempt to start KSP
9-
--no-check: Do not compare hashes against server (only adds missing files)
10-
--ksp-path=[path]: Run in specified folder, rather than the program location
119
--run=[ProgramName.exe]: Runs this program instead of trying to find and start KSP.
10+
--ksp-path=[path]: Run in specified folder, rather than the program location
11+
--ksp-args=\"args\": Run KSP with these arguments, example: --ksp-args="-force-d3d11 -popupwindow -dmp dmp://localhost:6702"
1212
--help: Displays this message

0 commit comments

Comments
 (0)