mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 11:14:45 +00:00
Add support for uncompressed repository.
This commit is contained in:
@@ -412,7 +412,26 @@ public class Vfs(ILoggerFactory loggerFactory) : IDisposable
|
||||
sha384B32[4].ToString(),
|
||||
sha384B32 + ".zst");
|
||||
|
||||
if(!File.Exists(repoPath)) return -1;
|
||||
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);
|
||||
|
||||
if(!File.Exists(repoPath)) return -1;
|
||||
|
||||
_lastHandle++;
|
||||
handle = _lastHandle;
|
||||
|
||||
_streamsCache[handle] = Stream.Synchronized(new FileStream(repoPath, FileMode.Open, FileAccess.Read));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
_lastHandle++;
|
||||
handle = _lastHandle;
|
||||
|
||||
@@ -53,14 +53,25 @@ public sealed class Compression
|
||||
|
||||
Stream zStream;
|
||||
|
||||
if(Settings.Settings.Current.Compression == CompressionType.Zstd)
|
||||
switch(Settings.Settings.Current.Compression)
|
||||
{
|
||||
var zstdStream = new CompressionStream(outFs, 15);
|
||||
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
|
||||
zStream = zstdStream;
|
||||
case CompressionType.Zstd:
|
||||
{
|
||||
var zstdStream = new CompressionStream(outFs, 15);
|
||||
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
|
||||
zStream = zstdStream;
|
||||
|
||||
break;
|
||||
}
|
||||
case CompressionType.None:
|
||||
zStream = outFs;
|
||||
|
||||
break;
|
||||
default:
|
||||
zStream = new LZipStream(outFs, CompressionMode.Compress);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
zStream = new LZipStream(outFs, CompressionMode.Compress);
|
||||
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
@@ -110,6 +121,8 @@ public sealed class Compression
|
||||
zStream = new DecompressionStream(inFs);
|
||||
else if(Path.GetExtension(source) == ".lz")
|
||||
zStream = new LZipStream(inFs, CompressionMode.Decompress);
|
||||
else if(string.IsNullOrWhiteSpace(Path.GetExtension(source)))
|
||||
zStream = inFs;
|
||||
else
|
||||
throw new ArgumentException($"Invalid compression extension {Path.GetExtension(source)}");
|
||||
|
||||
|
||||
@@ -605,7 +605,21 @@ public class FileExporter(long romSetId, string outPath, ILoggerFactory loggerFa
|
||||
sha384B32 + ".zst");
|
||||
|
||||
if(!File.Exists(repoPath))
|
||||
throw new ArgumentException(string.Format(Localization.CannotFindHashInRepository, file.Sha256));
|
||||
{
|
||||
repoPath = Path.Combine(Settings.Settings.Current.RepositoryPath,
|
||||
"files",
|
||||
sha384B32[0].ToString(),
|
||||
sha384B32[1].ToString(),
|
||||
sha384B32[2].ToString(),
|
||||
sha384B32[3].ToString(),
|
||||
sha384B32[4].ToString(),
|
||||
sha384B32);
|
||||
|
||||
return !File.Exists(repoPath)
|
||||
? throw new ArgumentException(string.Format(Localization.CannotFindHashInRepository,
|
||||
file.Sha256))
|
||||
: new FileStream(repoPath, FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
|
||||
inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
|
||||
|
||||
|
||||
@@ -554,9 +554,12 @@ public sealed class FileImporter
|
||||
|
||||
if(!Directory.Exists(repoPath)) Directory.CreateDirectory(repoPath);
|
||||
|
||||
repoPath = Settings.Settings.Current.Compression == CompressionType.Zstd
|
||||
? Path.Combine(repoPath, sha384B32 + ".zst")
|
||||
: Path.Combine(repoPath, sha384B32 + ".lz");
|
||||
repoPath = Settings.Settings.Current.Compression switch
|
||||
{
|
||||
CompressionType.Zstd => Path.Combine(repoPath, sha384B32 + ".zst"),
|
||||
CompressionType.None => Path.Combine(repoPath, sha384B32),
|
||||
_ => Path.Combine(repoPath, sha384B32 + ".lz")
|
||||
};
|
||||
|
||||
if(dbFile.Crc32 == null)
|
||||
{
|
||||
@@ -614,14 +617,25 @@ public sealed class FileImporter
|
||||
|
||||
Stream zStream;
|
||||
|
||||
if(Settings.Settings.Current.Compression == CompressionType.Zstd)
|
||||
switch(Settings.Settings.Current.Compression)
|
||||
{
|
||||
var zstdStream = new CompressionStream(outFs, 15);
|
||||
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
|
||||
zStream = zstdStream;
|
||||
case CompressionType.Zstd:
|
||||
{
|
||||
var zstdStream = new CompressionStream(outFs, 15);
|
||||
zstdStream.SetParameter(ZSTD_cParameter.ZSTD_c_nbWorkers, Environment.ProcessorCount);
|
||||
zStream = zstdStream;
|
||||
|
||||
break;
|
||||
}
|
||||
case CompressionType.None:
|
||||
zStream = outFs;
|
||||
|
||||
break;
|
||||
default:
|
||||
zStream = new LZipStream(outFs, CompressionMode.Compress);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
zStream = new LZipStream(outFs, CompressionMode.Compress);
|
||||
|
||||
SetProgressBounds2?.Invoke(this,
|
||||
new ProgressBoundsEventArgs
|
||||
|
||||
@@ -36,7 +36,8 @@ namespace RomRepoMgr.Settings;
|
||||
public enum CompressionType
|
||||
{
|
||||
Lzip = 0,
|
||||
Zstd
|
||||
Zstd,
|
||||
None
|
||||
}
|
||||
|
||||
public sealed class SetSettings
|
||||
|
||||
Reference in New Issue
Block a user