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