Skip to content

Commit

Permalink
New "one time" archives and 7z support (#362)
Browse files Browse the repository at this point in the history
* wip

* this seems to be working

* annoying

* .net 9

* update dotnet

* beta
  • Loading branch information
mattpannella authored Dec 2, 2024
1 parent f6cc1c4 commit 7b010ef
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pupdate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
<PublishTrimmed>true</PublishTrimmed>
<OutputType>Exe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Version>3.20.0</Version>
<Version>4.0.0-beta</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2024 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
<Product>Pupdate</Product>
<RepositoryUrl>https://github.com/mattpannella/pupdate</RepositoryUrl>
<RootNamespace>Pannella</RootNamespace>
<NoWarn>NU1605</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
Expand All @@ -21,6 +22,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="UrlCombine" Version="2.0.0" />
<PackageReference Include="Aspose.Zip" Version="24.11.0" />
</ItemGroup>
<ItemGroup>
<EditorConfigFiles Remove=".editorconfig" />
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/SevenZipHelper.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions src/models/Settings/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ public class Archive
/// This setting only applies to Core Specific Archives
/// </summary>
public bool enabled { get; set; }

/// <summary>
/// This setting only applies to Core Specific Archives
/// </summary>
public bool one_time { get; set; }

/// <summary>
/// This setting only applies to Core Specific Archives
/// </summary>
public bool complete { get; set; }
}
15 changes: 15 additions & 0 deletions src/services/ArchiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 10 additions & 1 deletion src/services/CoresService.Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@ public Dictionary<string, object> 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");

Expand Down Expand Up @@ -222,9 +225,15 @@ public Dictionary<string, object> 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.
Expand Down

0 comments on commit 7b010ef

Please sign in to comment.