From 82af101f9c46f1b2c83aba006c523139cbbf7ec1 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Thu, 23 Jan 2025 21:43:54 -0600 Subject: [PATCH] feat: pathing --- src/CLI/CLI.csproj | 4 ++++ src/CLI/Functions/DLC.cs | 27 +++++++++++++++++++++++++++ src/CLI/Models/Arguments.cs | 19 +++++++++++++++++++ src/CLI/Models/LocalManifest.cs | 4 ++-- src/CLI/Program.cs | 22 ++++++++-------------- 5 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 src/CLI/Functions/DLC.cs create mode 100644 src/CLI/Models/Arguments.cs diff --git a/src/CLI/CLI.csproj b/src/CLI/CLI.csproj index fd4bd08da..767d236a6 100644 --- a/src/CLI/CLI.csproj +++ b/src/CLI/CLI.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/src/CLI/Functions/DLC.cs b/src/CLI/Functions/DLC.cs new file mode 100644 index 000000000..273a3489e --- /dev/null +++ b/src/CLI/Functions/DLC.cs @@ -0,0 +1,27 @@ +using CLI.Models; + +namespace CLI.Functions +{ + class DLC + { + public static void Run(Arguments args) + { + if (args.raw.Length < 2) + { + throw new ArgumentException("No directory provided"); + } + + string dlcPaksDirectory = args.raw[1]; + + if (args.sanitize && Directory.Exists(dlcPaksDirectory)) + { + Directory.Delete(dlcPaksDirectory, true); + } + + Directory.CreateDirectory(dlcPaksDirectory); + + string testFilePath = Path.Combine(dlcPaksDirectory, "test.txt"); + File.WriteAllText(testFilePath, "test"); + } + } +} diff --git a/src/CLI/Models/Arguments.cs b/src/CLI/Models/Arguments.cs new file mode 100644 index 000000000..33f8fe8cd --- /dev/null +++ b/src/CLI/Models/Arguments.cs @@ -0,0 +1,19 @@ +namespace CLI.Models +{ + public class Arguments + { + public string[] raw; + public bool sanitize; + + public Arguments(string[] args) + { + raw = args; + sanitize = args.Contains("--sanitize"); + + if (args.Length < 1) + { + throw new ArgumentException("No arguments provided"); + } + } + } +} diff --git a/src/CLI/Models/LocalManifest.cs b/src/CLI/Models/LocalManifest.cs index 5c1372f89..1af4ef6d4 100644 --- a/src/CLI/Models/LocalManifest.cs +++ b/src/CLI/Models/LocalManifest.cs @@ -1,6 +1,6 @@ namespace CLI.Models { - public class PakFile + public class LocalManifestPakFile { public long FileSize { get; set; } public required string FileHash { get; set; } @@ -8,6 +8,6 @@ namespace CLI.Models public class LocalManifest { - public required Dictionary PakFiles { get; set; } + public required Dictionary PakFiles { get; set; } } } diff --git a/src/CLI/Program.cs b/src/CLI/Program.cs index 0dc368bbc..fa17e4c5d 100644 --- a/src/CLI/Program.cs +++ b/src/CLI/Program.cs @@ -1,27 +1,21 @@ -using System.Text.Json; +using CLI.Functions; using CLI.Models; namespace CLI { class Program { - static readonly JsonSerializerOptions options = new() { PropertyNameCaseInsensitive = true }; - static void Main(string[] args) { - string RootDir = @"C:\Users\coola\AppData\Local\Blitz"; - string paksPath = Path.Combine(RootDir, @"Saved\PersistentDownloadDir\Dlc\PakCache"); - string localManifestPath = Path.Combine(paksPath, "LocalManifest.json"); - string localManifestContent = File.ReadAllText(localManifestPath); + Arguments arguments = new(args); - LocalManifest localManifest = - JsonSerializer.Deserialize(localManifestContent, options) - ?? throw new Exception("Failed to deserialize LocalManifest"); - - foreach (var pakFile in localManifest.PakFiles) + switch (args[0]) { - string pakFilePath = Path.Combine(paksPath, pakFile.Key); - Console.WriteLine($"({pakFile.Value.FileSize}) {pakFilePath}"); + case "dlc": + { + DLC.Run(arguments); + break; + } } } }