From 7b010ef96d209199908b3719e90bd2af0c900b21 Mon Sep 17 00:00:00 2001 From: Matt Pannella Date: Sun, 1 Dec 2024 21:12:05 -0500 Subject: [PATCH] New "one time" archives and 7z support (#362) * wip * this seems to be working * annoying * .net 9 * update dotnet * beta --- .github/workflows/build.yaml | 2 +- .github/workflows/dotnet.yml | 2 +- .vscode/launch.json | 2 +- pupdate.csproj | 6 ++++-- src/helpers/SevenZipHelper.cs | 13 +++++++++++++ src/models/Settings/Archive.cs | 10 ++++++++++ src/services/ArchiveService.cs | 15 +++++++++++++++ src/services/CoresService.Download.cs | 11 ++++++++++- 8 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/helpers/SevenZipHelper.cs diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3dba9723..2013a941 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,7 +31,7 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.302 + dotnet-version: 9.0.100 - name: Build shell: bash diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 243ad373..fadd4bd6 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.302 + dotnet-version: 9.0.100 - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.vscode/launch.json b/.vscode/launch.json index bf70844b..5827a86a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net7.0/pupdate.dll", + "program": "${workspaceFolder}/bin/Debug/net9.0/pupdate.dll", "args": ["-p", "/Users/mattpannella/pocket-test"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/pupdate.csproj b/pupdate.csproj index c21521aa..21e9b211 100644 --- a/pupdate.csproj +++ b/pupdate.csproj @@ -3,16 +3,17 @@ true Exe true - net7.0 + net9.0 enable disable - 3.20.0 + 4.0.0-beta Keep your Analogue Pocket up to date 2024 Matt Pannella Matt Pannella Pupdate https://github.com/mattpannella/pupdate Pannella + NU1605 @@ -21,6 +22,7 @@ + diff --git a/src/helpers/SevenZipHelper.cs b/src/helpers/SevenZipHelper.cs new file mode 100644 index 00000000..ea3e91a2 --- /dev/null +++ b/src/helpers/SevenZipHelper.cs @@ -0,0 +1,13 @@ +using Aspose.Zip.SevenZip; + +namespace Pannella.Helpers; + +public class SevenZipHelper +{ + public static void ExtractToDirectory(string zipFile, string destination) + { + SevenZipArchive sevenzip = new SevenZipArchive(zipFile); + Console.WriteLine("Extracting..."); + sevenzip.ExtractToDirectory(destination); + } +} \ No newline at end of file diff --git a/src/models/Settings/Archive.cs b/src/models/Settings/Archive.cs index 041dd320..6462bd9f 100644 --- a/src/models/Settings/Archive.cs +++ b/src/models/Settings/Archive.cs @@ -40,4 +40,14 @@ public class Archive /// This setting only applies to Core Specific Archives /// public bool enabled { get; set; } + + /// + /// This setting only applies to Core Specific Archives + /// + public bool one_time { get; set; } + + /// + /// This setting only applies to Core Specific Archives + /// + public bool complete { get; set; } } diff --git a/src/services/ArchiveService.cs b/src/services/ArchiveService.cs index bd27c76f..aeacaf22 100644 --- a/src/services/ArchiveService.cs +++ b/src/services/ArchiveService.cs @@ -152,6 +152,21 @@ public bool DownloadArchiveFile(SettingsArchive archive, ArchiveFile archiveFile count++; } while (count < 3 && !ValidateChecksum(destinationFileName, archiveFile)); + + if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".zip") + { + //extract + ZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName), true); + //delete + File.Delete(destinationFileName); + } + else if (File.Exists(destinationFileName) && Path.GetExtension(destinationFileName) == ".7z") + { + //extract + SevenZipHelper.ExtractToDirectory(destinationFileName, Path.GetDirectoryName(destinationFileName)); + //delete + File.Delete(destinationFileName); + } } catch (HttpRequestException e) { diff --git a/src/services/CoresService.Download.cs b/src/services/CoresService.Download.cs index 2f0f68bb..b8f31eca 100644 --- a/src/services/CoresService.Download.cs +++ b/src/services/CoresService.Download.cs @@ -191,9 +191,12 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet } } - if ((archive.type == ArchiveType.core_specific_archive || archive.type == ArchiveType.core_specific_custom_archive) && archive.enabled && !archive.has_instance_jsons) + if ((archive.type == ArchiveType.core_specific_archive || archive.type == ArchiveType.core_specific_custom_archive) + && archive.enabled && !archive.has_instance_jsons + && ((archive.one_time && !archive.complete) || !archive.one_time)) { var files = this.archiveService.GetArchiveFiles(archive); + bool allSucceeded = true; string commonPath = Path.Combine(platformPath, "common"); @@ -222,9 +225,15 @@ public Dictionary DownloadAssets(Core core, bool ignoreGlobalSet { WriteMessage($"Not found: {file.name}"); skipped.Add(filePath.Replace(this.installPath, string.Empty)); + allSucceeded = false; } } } + if (archive.one_time && allSucceeded) + { + archive.complete = true; + this.settingsService.Save(); + } } // These cores have instance json files and the roms are not in the default archive.