Skip to content

Commit

Permalink
Updated Project Configuration and Dependencies: Upgraded MahApps.Metr…
Browse files Browse the repository at this point in the history
…o.IconPacks version, adjusted solution build configurations and updated "UpdateHandler" logic

* Details: The updated code aligns the Debug and Release build configurations in the solution file. The MahApps.Metro.IconPacks library used in the project is updated to version 5.0.0. A new method to delete old files and extract RAR archives in the UpdateHandler class has been added. Furthermore, asset retrieval in the update check now searches for ".rar" files instead of ".exe" files.
* Rationale: The changes provide a better structure for builds, ensure the use of up-to-date dependencies and enable more efficient handling of updates within the EasyExtract tool.
  • Loading branch information
HakuSystems committed Jun 9, 2024
1 parent 9b82093 commit 02dd11d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Version>0.9.7</Version>
</PackageReference>
<PackageReference Include="MahApps.Metro.IconPacks">
<Version>4.11.0</Version>
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>7.1.3</Version>
Expand Down
47 changes: 39 additions & 8 deletions EasyExtractUnitypackageRework/EasyExtract/Updater/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Reflection;
using EasyExtract.Config;
using Octokit;
using SharpCompress.Archives;
using SharpCompress.Common;
using FileMode = System.IO.FileMode;

namespace EasyExtract.Updater;
Expand All @@ -12,11 +14,9 @@ public class UpdateHandler
{
private const string RepoName = "EasyExtractUnitypackage";
private const string RepoOwner = "HakuSystems";

private ConfigModel Config { get; } = new();
private string CurrentVersion => Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "0.0.0";


public async Task<bool> IsUpToDate()
{
var latestRelease = await GetLatestReleaseAsync();
Expand All @@ -36,12 +36,20 @@ public async Task<bool> Update()
var latestRelease = await GetLatestReleaseAsync();
if (latestRelease != null)
{
var asset = latestRelease.Assets.FirstOrDefault(a => a.Name.EndsWith(".exe"));
var asset = latestRelease.Assets.FirstOrDefault(a => a.Name.EndsWith(".rar"));
if (asset != null)
{
var exePath = await DownloadAssetAsync(asset.BrowserDownloadUrl);
Process.Start(exePath);
Environment.Exit(0);
var rarPath = await DownloadAssetAsync(asset.BrowserDownloadUrl);
var exePath = ExtractRar(rarPath);
if (exePath != null)
{
Process.Start(exePath);
Environment.Exit(0);
}
else
{
return false;
}
}
else
{
Expand All @@ -65,8 +73,8 @@ private async Task<string> DownloadAssetAsync(string url)
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
var filePath = Path.Combine(currentDirectory, fileName);

if (File.Exists(filePath))
File.Delete(filePath);
DeleteOldFiles(currentDirectory);

using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
await response.Content.CopyToAsync(fs);
Expand All @@ -75,6 +83,29 @@ private async Task<string> DownloadAssetAsync(string url)
return filePath;
}

private void DeleteOldFiles(string directory)
{
var rarFiles = Directory.GetFiles(directory, "*.rar");
var extractedFiles = Directory.GetFiles(directory, "*.*").Where(f => !f.EndsWith(".rar")).ToArray();

foreach (var file in rarFiles) File.Delete(file);

foreach (var file in extractedFiles) File.Delete(file);
}

private string ExtractRar(string rarPath)
{
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
using (var archive = ArchiveFactory.Open(rarPath))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
entry.WriteToDirectory(currentDirectory,
new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
}

var exeFile = Directory.GetFiles(currentDirectory, "*.exe").FirstOrDefault();
return exeFile;
}

private async Task<Release> GetLatestReleaseAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{956326DB-F441-4870-818F-F722788A88D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{956326DB-F441-4870-818F-F722788A88D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{956326DB-F441-4870-818F-F722788A88D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{956326DB-F441-4870-818F-F722788A88D6}.Release|Any CPU.Build.0 = Release|Any CPU
{956326DB-F441-4870-818F-F722788A88D6}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{956326DB-F441-4870-818F-F722788A88D6}.Debug|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 7 additions & 0 deletions EasyExtractUnitypackageRework/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
}

0 comments on commit 02dd11d

Please sign in to comment.