39 lines
1.1 KiB
C#
Raw Normal View History

using SevenZip;
2023-05-11 23:11:39 -04:00
using SPTInstaller.Models;
2022-05-13 22:41:15 +01:00
namespace SPTInstaller.Helpers;
public static class ZipHelper
2022-05-13 22:41:15 +01:00
{
2024-05-01 10:31:55 -04:00
public static Result Decompress(FileInfo archiveFile, DirectoryInfo outputDirectory,
IProgress<double> progress = null)
2022-05-13 22:41:15 +01:00
{
try
2022-05-13 22:41:15 +01:00
{
using var archiveStream = archiveFile.OpenRead();
2024-05-01 10:31:55 -04:00
var dllPath = Path.Join(DownloadCacheHelper.CachePath, "7z.dll");
SevenZipBase.SetLibraryPath(dllPath);
2024-05-01 10:31:55 -04:00
var extractor = new SevenZipExtractor(archiveStream);
2024-05-01 10:31:55 -04:00
extractor.Extracting += (_, args) => { progress.Report(args.PercentDone); };
extractor.ExtractArchive(outputDirectory.FullName);
2024-05-01 10:31:55 -04:00
outputDirectory.Refresh();
2024-05-01 10:31:55 -04:00
if (!outputDirectory.Exists)
2022-07-09 13:08:41 -04:00
{
return Result.FromError($"Failed to extract files: {archiveFile.Name}");
2022-07-09 13:08:41 -04:00
}
2024-05-01 10:31:55 -04:00
return Result.FromSuccess();
}
catch (Exception ex)
{
return Result.FromError(ex.Message);
2022-05-13 22:41:15 +01:00
}
}
}