Add support to compress repository with zstd.

This commit is contained in:
2025-07-25 17:49:36 +01:00
parent bf19439e49
commit 0bda03afee
12 changed files with 224 additions and 71 deletions

View File

@@ -45,6 +45,6 @@
<PackageVersion Include="System.IO.Compression" Version="4.3.0"/> <PackageVersion Include="System.IO.Compression" Version="4.3.0"/>
<PackageVersion Include="SharpCompress" Version="0.38.0"/> <PackageVersion Include="SharpCompress" Version="0.38.0"/>
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0"/> <PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0"/>
<PackageVersion Include="ZstdSharp.Port" Version="0.8.1"/> <PackageVersion Include="ZstdSharp.Port" Version="0.8.6"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -12,6 +12,7 @@ using RomRepoMgr.Database;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
using SharpCompress.Compressors; using SharpCompress.Compressors;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using ZstdSharp;
namespace RomRepoMgr.Core.Filesystem; namespace RomRepoMgr.Core.Filesystem;
@@ -365,9 +366,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
internal long Open(string sha384, long fileSize) internal long Open(string sha384, long fileSize)
{ {
var sha384Bytes = new byte[48]; byte[] sha384Bytes = new byte[48];
for(var i = 0; i < 48; i++) for(int i = 0; i < 48; i++)
{ {
if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39) if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39)
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10); sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10);
@@ -386,19 +387,47 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
string sha384B32 = Base32.ToBase32String(sha384Bytes); string sha384B32 = Base32.ToBase32String(sha384Bytes);
string repoPath = Path.Combine(Settings.Settings.Current.RepositoryPath,
"files",
sha384B32[0].ToString(),
sha384B32[1].ToString(),
sha384B32[2].ToString(),
sha384B32[3].ToString(),
sha384B32[4].ToString(),
sha384B32 + ".lz");
if(!File.Exists(repoPath)) return -1; string repoPath;
repoPath = Path.Combine(Settings.Settings.Current.RepositoryPath,
"files",
sha384B32[0].ToString(),
sha384B32[1].ToString(),
sha384B32[2].ToString(),
sha384B32[3].ToString(),
sha384B32[4].ToString(),
sha384B32 + ".lz");
long handle;
if(!File.Exists(repoPath))
{
repoPath = Path.Combine(Settings.Settings.Current.RepositoryPath,
"files",
sha384B32[0].ToString(),
sha384B32[1].ToString(),
sha384B32[2].ToString(),
sha384B32[3].ToString(),
sha384B32[4].ToString(),
sha384B32 + ".zst");
if(!File.Exists(repoPath)) return -1;
_lastHandle++;
handle = _lastHandle;
_streamsCache[handle] =
Stream.Synchronized(new ForcedSeekStream<DecompressionStream>(fileSize,
new FileStream(repoPath,
FileMode.Open,
FileAccess.Read)));
return handle;
}
_lastHandle++; _lastHandle++;
long handle = _lastHandle; handle = _lastHandle;
_streamsCache[handle] = _streamsCache[handle] =
Stream.Synchronized(new ForcedSeekStream<LZipStream>(fileSize, Stream.Synchronized(new ForcedSeekStream<LZipStream>(fileSize,
@@ -457,9 +486,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
if(sha1 != null) if(sha1 != null)
{ {
var sha1Bytes = new byte[20]; byte[] sha1Bytes = new byte[20];
for(var i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
{ {
if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39) if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39)
sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10); sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10);
@@ -490,9 +519,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
if(md5 != null) if(md5 != null)
{ {
var md5Bytes = new byte[16]; byte[] md5Bytes = new byte[16];
for(var i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39) if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39)
md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10); md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10);
@@ -545,9 +574,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
if(sha256 != null) if(sha256 != null)
{ {
var sha256Bytes = new byte[32]; byte[] sha256Bytes = new byte[32];
for(var i = 0; i < 32; i++) for(int i = 0; i < 32; i++)
{ {
if(sha256[i * 2] >= 0x30 && sha256[i * 2] <= 0x39) if(sha256[i * 2] >= 0x30 && sha256[i * 2] <= 0x39)
sha256Bytes[i] = (byte)((sha256[i * 2] - 0x30) * 0x10); sha256Bytes[i] = (byte)((sha256[i * 2] - 0x30) * 0x10);
@@ -579,9 +608,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
if(sha1 != null) if(sha1 != null)
{ {
var sha1Bytes = new byte[20]; byte[] sha1Bytes = new byte[20];
for(var i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
{ {
if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39) if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39)
sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10); sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10);
@@ -612,9 +641,9 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
if(md5 != null) if(md5 != null)
{ {
var md5Bytes = new byte[16]; byte[] md5Bytes = new byte[16];
for(var i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39) if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39)
md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10); md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup> <ItemGroup>
<PackageReference Include="Aaru.Checksums.Native" /> <PackageReference Include="Aaru.Checksums.Native"/>
<PackageReference Include="DotNetZip"/> <PackageReference Include="DotNetZip"/>
<PackageReference Include="EFCore.BulkExtensions"/> <PackageReference Include="EFCore.BulkExtensions"/>
<PackageReference Include="Mono.Fuse.NETStandard"/> <PackageReference Include="Mono.Fuse.NETStandard"/>
@@ -19,6 +19,7 @@
<PackageReference Include="Roslynator.Formatting.Analyzers"/> <PackageReference Include="Roslynator.Formatting.Analyzers"/>
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer"/> <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer"/>
<PackageReference Include="Text.Analyzers"/> <PackageReference Include="Text.Analyzers"/>
<PackageReference Include="ZstdSharp.Port"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -28,8 +28,11 @@ using System.Diagnostics;
using System.IO; using System.IO;
using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Resources; using RomRepoMgr.Core.Resources;
using RomRepoMgr.Settings;
using SharpCompress.Compressors; using SharpCompress.Compressors;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using ZstdSharp;
using ZstdSharp.Unsafe;
using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs; using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
namespace RomRepoMgr.Core.Workers; namespace RomRepoMgr.Core.Workers;
@@ -45,11 +48,21 @@ public sealed class Compression
public void CompressFile(string source, string destination) public void CompressFile(string source, string destination)
{ {
var inFs = new FileStream(source, FileMode.Open, FileAccess.Read); var inFs = new FileStream(source, FileMode.Open, FileAccess.Read);
var outFs = new FileStream(destination, FileMode.CreateNew, FileAccess.Write); var outFs = new FileStream(destination, FileMode.CreateNew, FileAccess.Write);
Stream zStream = new LZipStream(outFs, CompressionMode.Compress);
var buffer = new byte[BUFFER_SIZE]; Stream zStream;
if(Settings.Settings.Current.Compression == CompressionType.Zstd)
{
var zstdStream = new CompressionStream(outFs, 15);
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
zStream = zstdStream;
}
else
zStream = new LZipStream(outFs, CompressionMode.Compress);
byte[] buffer = new byte[BUFFER_SIZE];
SetProgressBounds?.Invoke(this, SetProgressBounds?.Invoke(this,
new ProgressBoundsEventArgs new ProgressBoundsEventArgs
@@ -89,9 +102,17 @@ public sealed class Compression
public void DecompressFile(string source, string destination) public void DecompressFile(string source, string destination)
{ {
var inFs = new FileStream(source, FileMode.Open, FileAccess.Read); var inFs = new FileStream(source, FileMode.Open, FileAccess.Read);
var outFs = new FileStream(destination, FileMode.Create, FileAccess.Write); var outFs = new FileStream(destination, FileMode.Create, FileAccess.Write);
Stream zStream = new LZipStream(inFs, CompressionMode.Decompress); Stream zStream;
if(Path.GetExtension(source) == ".zst")
zStream = new DecompressionStream(inFs);
else if(Path.GetExtension(source) == ".lz")
zStream = new LZipStream(inFs, CompressionMode.Decompress);
else
throw new ArgumentException($"Invalid compression extension {Path.GetExtension(source)}");
zStream.CopyTo(outFs); zStream.CopyTo(outFs);

View File

@@ -12,6 +12,7 @@ using RomRepoMgr.Core.Resources;
using RomRepoMgr.Database; using RomRepoMgr.Database;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using ZstdSharp;
using CompressionMode = SharpCompress.Compressors.CompressionMode; using CompressionMode = SharpCompress.Compressors.CompressionMode;
namespace RomRepoMgr.Core.Workers; namespace RomRepoMgr.Core.Workers;
@@ -155,10 +156,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
if(media.Sha256 != null) if(media.Sha256 != null)
{ {
var sha256Bytes = new byte[32]; byte[] sha256Bytes = new byte[32];
string sha256 = media.Sha256; string sha256 = media.Sha256;
for(var i = 0; i < 32; i++) for(int i = 0; i < 32; i++)
{ {
if(sha256[i * 2] >= 0x30 && sha256[i * 2] <= 0x39) if(sha256[i * 2] >= 0x30 && sha256[i * 2] <= 0x39)
sha256Bytes[i] = (byte)((sha256[i * 2] - 0x30) * 0x10); sha256Bytes[i] = (byte)((sha256[i * 2] - 0x30) * 0x10);
@@ -190,10 +191,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
if(media.Sha1 != null) if(media.Sha1 != null)
{ {
var sha1Bytes = new byte[20]; byte[] sha1Bytes = new byte[20];
string sha1 = media.Sha1; string sha1 = media.Sha1;
for(var i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
{ {
if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39) if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39)
sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10); sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10);
@@ -225,10 +226,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
if(media.Md5 != null) if(media.Md5 != null)
{ {
var md5Bytes = new byte[16]; byte[] md5Bytes = new byte[16];
string md5 = media.Md5; string md5 = media.Md5;
for(var i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39) if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39)
md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10); md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10);
@@ -286,7 +287,7 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
Maximum = inFs.Length Maximum = inFs.Length
}); });
var buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
while(inFs.Position + BUFFER_SIZE <= inFs.Length) while(inFs.Position + BUFFER_SIZE <= inFs.Length)
{ {
@@ -359,10 +360,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
if(disk.Sha1 != null) if(disk.Sha1 != null)
{ {
var sha1Bytes = new byte[20]; byte[] sha1Bytes = new byte[20];
string sha1 = disk.Sha1; string sha1 = disk.Sha1;
for(var i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
{ {
if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39) if(sha1[i * 2] >= 0x30 && sha1[i * 2] <= 0x39)
sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10); sha1Bytes[i] = (byte)((sha1[i * 2] - 0x30) * 0x10);
@@ -394,10 +395,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
if(disk.Md5 != null) if(disk.Md5 != null)
{ {
var md5Bytes = new byte[16]; byte[] md5Bytes = new byte[16];
string md5 = disk.Md5; string md5 = disk.Md5;
for(var i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39) if(md5[i * 2] >= 0x30 && md5[i * 2] <= 0x39)
md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10); md5Bytes[i] = (byte)((md5[i * 2] - 0x30) * 0x10);
@@ -453,7 +454,7 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
Maximum = inFs.Length Maximum = inFs.Length
}); });
var buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
while(inFs.Position + BUFFER_SIZE <= inFs.Length) while(inFs.Position + BUFFER_SIZE <= inFs.Length)
{ {
@@ -558,10 +559,10 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
// Special case for empty file, as it seems to crash when SharpCompress tries to unLZMA it. // Special case for empty file, as it seems to crash when SharpCompress tries to unLZMA it.
if(file.Size == 0) return new MemoryStream(); if(file.Size == 0) return new MemoryStream();
var sha384Bytes = new byte[48]; byte[] sha384Bytes = new byte[48];
string sha384 = file.Sha384; string sha384 = file.Sha384;
for(var i = 0; i < 48; i++) for(int i = 0; i < 48; i++)
{ {
if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39) if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39)
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10); sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10);
@@ -589,10 +590,29 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
sha384B32[4].ToString(), sha384B32[4].ToString(),
sha384B32 + ".lz"); sha384B32 + ".lz");
if(!File.Exists(repoPath)) FileStream inFs;
throw new ArgumentException(string.Format(Localization.CannotFindHashInRepository, file.Sha256));
var inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read); // Try ZSTD
if(!File.Exists(repoPath))
{
repoPath = Path.Combine(Settings.Settings.Current.RepositoryPath,
"files",
sha384B32[0].ToString(),
sha384B32[1].ToString(),
sha384B32[2].ToString(),
sha384B32[3].ToString(),
sha384B32[4].ToString(),
sha384B32 + ".zst");
if(!File.Exists(repoPath))
throw new ArgumentException(string.Format(Localization.CannotFindHashInRepository, file.Sha256));
inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
return new StreamWithLength(new DecompressionStream(inFs), (long)file.Size);
}
inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
return new StreamWithLength(new LZipStream(inFs, CompressionMode.Decompress), (long)file.Size); return new StreamWithLength(new LZipStream(inFs, CompressionMode.Decompress), (long)file.Size);
} }
@@ -612,11 +632,9 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
Value = _filePosition Value = _filePosition
}); });
if(!_filesByMachine.TryGetValue(e.CurrentEntry.FileName, out FileByMachine fileByMachine)) if(!_filesByMachine.TryGetValue(e.CurrentEntry.FileName, out FileByMachine fileByMachine) &&
{ !_filesByMachine.TryGetValue(e.CurrentEntry.FileName.Replace('/', '\\'), out fileByMachine))
if(!_filesByMachine.TryGetValue(e.CurrentEntry.FileName.Replace('/', '\\'), out fileByMachine)) throw new ArgumentException(Localization.CannotFindZipEntryInDictionary);
throw new ArgumentException(Localization.CannotFindZipEntryInDictionary);
}
DbFile currentFile = fileByMachine.File; DbFile currentFile = fileByMachine.File;

View File

@@ -15,9 +15,12 @@ using RomRepoMgr.Core.Models;
using RomRepoMgr.Core.Resources; using RomRepoMgr.Core.Resources;
using RomRepoMgr.Database; using RomRepoMgr.Database;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
using RomRepoMgr.Settings;
using SabreTools.FileTypes.Aaru; using SabreTools.FileTypes.Aaru;
using SabreTools.FileTypes.CHD; using SabreTools.FileTypes.CHD;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using ZstdSharp;
using ZstdSharp.Unsafe;
using CompressionMode = SharpCompress.Compressors.CompressionMode; using CompressionMode = SharpCompress.Compressors.CompressionMode;
namespace RomRepoMgr.Core.Workers; namespace RomRepoMgr.Core.Workers;
@@ -551,7 +554,9 @@ public sealed class FileImporter
if(!Directory.Exists(repoPath)) Directory.CreateDirectory(repoPath); if(!Directory.Exists(repoPath)) Directory.CreateDirectory(repoPath);
repoPath = Path.Combine(repoPath, sha384B32 + ".lz"); repoPath = Settings.Settings.Current.Compression == CompressionType.Zstd
? Path.Combine(repoPath, sha384B32 + ".zst")
: Path.Combine(repoPath, sha384B32 + ".lz");
if(dbFile.Crc32 == null) if(dbFile.Crc32 == null)
{ {
@@ -605,8 +610,18 @@ public sealed class FileImporter
inFs.Position = 0; inFs.Position = 0;
var outFs = new FileStream(repoPath, FileMode.CreateNew, FileAccess.Write); var outFs = new FileStream(repoPath, FileMode.CreateNew, FileAccess.Write);
Stream zStream = new LZipStream(outFs, CompressionMode.Compress);
Stream zStream;
if(Settings.Settings.Current.Compression == CompressionType.Zstd)
{
var zstdStream = new CompressionStream(outFs, 15);
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
zStream = zstdStream;
}
else
zStream = new LZipStream(outFs, CompressionMode.Compress);
SetProgressBounds2?.Invoke(this, SetProgressBounds2?.Invoke(this,
new ProgressBoundsEventArgs new ProgressBoundsEventArgs

View File

@@ -33,12 +33,19 @@ using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
namespace RomRepoMgr.Settings; namespace RomRepoMgr.Settings;
public enum CompressionType
{
Lzip = 0,
Zstd
}
public sealed class SetSettings public sealed class SetSettings
{ {
public string DatabasePath { get; set; } public string DatabasePath { get; set; }
public string RepositoryPath { get; set; } public string RepositoryPath { get; set; }
public string TemporaryFolder { get; set; } public string TemporaryFolder { get; set; }
public string UnArchiverPath { get; set; } public string UnArchiverPath { get; set; }
public CompressionType Compression { get; set; }
} }
/// <summary>Manages statistics</summary> /// <summary>Manages statistics</summary>
@@ -105,6 +112,11 @@ public static class Settings
? ((NSString)obj).ToString() ? ((NSString)obj).ToString()
: null; : null;
Current.Compression = parsedPreferences.TryGetValue("Compression", out obj)
? (CompressionType)Enum.Parse(typeof(CompressionType),
((NSNumber)obj).ToString())
: CompressionType.Lzip;
prefsFs.Close(); prefsFs.Close();
} }
else else
@@ -150,6 +162,11 @@ public static class Settings
Current.RepositoryPath = key.GetValue("RepositoryPath") as string; Current.RepositoryPath = key.GetValue("RepositoryPath") as string;
Current.TemporaryFolder = key.GetValue("TemporaryFolder") as string; Current.TemporaryFolder = key.GetValue("TemporaryFolder") as string;
Current.UnArchiverPath = key.GetValue("UnArchiverPath") as string; Current.UnArchiverPath = key.GetValue("UnArchiverPath") as string;
if(key.GetValue("Compression") is int compression)
Current.Compression = (CompressionType)compression;
else
Current.Compression = CompressionType.Lzip;
} }
break; break;
@@ -222,6 +239,9 @@ public static class Settings
}, },
{ {
"UnArchiverPath", Current.UnArchiverPath "UnArchiverPath", Current.UnArchiverPath
},
{
"Compression", (NSNumber)(int)Current.Compression
} }
}; };
@@ -256,6 +276,7 @@ public static class Settings
key?.SetValue("RepositoryPath", Current.RepositoryPath); key?.SetValue("RepositoryPath", Current.RepositoryPath);
key?.SetValue("TemporaryFolder", Current.TemporaryFolder); key?.SetValue("TemporaryFolder", Current.TemporaryFolder);
key?.SetValue("UnArchiverPath", Current.UnArchiverPath); key?.SetValue("UnArchiverPath", Current.UnArchiverPath);
key?.SetValue("Compression", (int)Current.Compression);
} }
break; break;
@@ -309,7 +330,8 @@ public static class Settings
{ {
DatabasePath = Path.Combine(dataPath, "romrepo.db"), DatabasePath = Path.Combine(dataPath, "romrepo.db"),
RepositoryPath = Path.Combine(dataPath, "repo"), RepositoryPath = Path.Combine(dataPath, "repo"),
TemporaryFolder = Path.GetTempPath() TemporaryFolder = Path.GetTempPath(),
Compression = CompressionType.Lzip
}; };
} }
} }

View File

@@ -770,5 +770,11 @@ namespace RomRepoMgr.Resources {
return ResourceManager.GetString("ProgressLabel", resourceCulture); return ResourceManager.GetString("ProgressLabel", resourceCulture);
} }
} }
public static string CompressionType {
get {
return ResourceManager.GetString("CompressionType", resourceCulture);
}
}
} }
} }

View File

@@ -381,4 +381,7 @@ Tardará mucho tiempo...</value>
<data name="ProgressLabel" xml:space="preserve"> <data name="ProgressLabel" xml:space="preserve">
<value>Progreso</value> <value>Progreso</value>
</data> </data>
<data name="CompressionType" xml:space="preserve">
<value>Compresión</value>
</data>
</root> </root>

View File

@@ -389,4 +389,7 @@ This will take a long time...</value>
<data name="ProgressLabel" xml:space="preserve"> <data name="ProgressLabel" xml:space="preserve">
<value>Progress</value> <value>Progress</value>
</data> </data>
<data name="CompressionType" xml:space="preserve">
<value>Compression</value>
</data>
</root> </root>

View File

@@ -26,6 +26,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
@@ -39,6 +40,7 @@ using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Core.Workers; using RomRepoMgr.Core.Workers;
using RomRepoMgr.Database; using RomRepoMgr.Database;
using RomRepoMgr.Resources; using RomRepoMgr.Resources;
using RomRepoMgr.Settings;
using RomRepoMgr.Views; using RomRepoMgr.Views;
using Serilog; using Serilog;
using Serilog.Extensions.Logging; using Serilog.Extensions.Logging;
@@ -49,13 +51,16 @@ namespace RomRepoMgr.ViewModels;
public sealed partial class SettingsViewModel : ViewModelBase public sealed partial class SettingsViewModel : ViewModelBase
{ {
readonly SettingsDialog _view; readonly SettingsDialog _view;
bool _databaseChanged;
string _databasePath; CompressionType _compression;
bool _repositoryChanged; bool _compressionChanged;
string _repositoryPath; bool _databaseChanged;
bool _temporaryChanged; string _databasePath;
string _temporaryPath; bool _repositoryChanged;
bool _unArChanged; string _repositoryPath;
bool _temporaryChanged;
string _temporaryPath;
bool _unArChanged;
[ObservableProperty] [ObservableProperty]
string _unArPath; string _unArPath;
[ObservableProperty] [ObservableProperty]
@@ -83,10 +88,14 @@ public sealed partial class SettingsViewModel : ViewModelBase
RepositoryPath = Settings.Settings.Current.RepositoryPath; RepositoryPath = Settings.Settings.Current.RepositoryPath;
TemporaryPath = Settings.Settings.Current.TemporaryFolder; TemporaryPath = Settings.Settings.Current.TemporaryFolder;
UnArPath = Settings.Settings.Current.UnArchiverPath; UnArPath = Settings.Settings.Current.UnArchiverPath;
Compression = Settings.Settings.Current.Compression;
if(!string.IsNullOrWhiteSpace(UnArPath)) CheckUnAr(); if(!string.IsNullOrWhiteSpace(UnArPath)) CheckUnAr();
} }
public List<CompressionType> CompressionTypes { get; } =
Enum.GetValues(typeof(CompressionType)).Cast<CompressionType>().ToList();
public ICommand UnArCommand { get; } public ICommand UnArCommand { get; }
public ICommand TemporaryCommand { get; } public ICommand TemporaryCommand { get; }
public ICommand RepositoryCommand { get; } public ICommand RepositoryCommand { get; }
@@ -126,6 +135,16 @@ public sealed partial class SettingsViewModel : ViewModelBase
} }
} }
public CompressionType Compression
{
get => _compression;
set
{
SetProperty(ref _compression, value);
_compressionChanged = true;
}
}
void CheckUnAr() void CheckUnAr()
{ {
var worker = new Compression(); var worker = new Compression();
@@ -331,7 +350,9 @@ public sealed partial class SettingsViewModel : ViewModelBase
Settings.Settings.UnArUsable = true; Settings.Settings.UnArUsable = true;
} }
if(_databaseChanged || _repositoryChanged || _temporaryChanged || _unArChanged) if(_compressionChanged) Settings.Settings.Current.Compression = Compression;
if(_databaseChanged || _repositoryChanged || _temporaryChanged || _unArChanged || _compressionChanged)
Settings.Settings.SaveSettings(); Settings.Settings.SaveSettings();
_view.Close(); _view.Close();

View File

@@ -41,7 +41,7 @@
<vm:SettingsViewModel /> <vm:SettingsViewModel />
</Design.DataContext> </Design.DataContext>
<Border Padding="15"> <Border Padding="15">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto"> <Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<Grid Grid.Row="0" <Grid Grid.Row="0"
ColumnDefinitions="*,250,Auto"> ColumnDefinitions="*,250,Auto">
<TextBlock Grid.Column="0" <TextBlock Grid.Column="0"
@@ -135,7 +135,21 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{Binding UnArVersion, Mode=OneWay}" Text="{Binding UnArVersion, Mode=OneWay}"
FontWeight="Bold" /> FontWeight="Bold" />
<StackPanel Grid.Row="5" <Grid Grid.Row="5"
ColumnDefinitions="Auto, *">
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Static resources:Localization.CompressionType}"
FontWeight="Bold"
Padding="5" />
<ComboBox Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
SelectedItem="{Binding Compression, Mode=TwoWay}"
ItemsSource="{Binding CompressionTypes, Mode=OneWay}"
Padding="5" />
</Grid>
<StackPanel Grid.Row="6"
Orientation="Horizontal" Orientation="Horizontal"
HorizontalAlignment="Right"> HorizontalAlignment="Right">
<Button HorizontalAlignment="Right" <Button HorizontalAlignment="Right"