|
|
|
@ -22,11 +22,9 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = File.OpenRead(sourceFile))
|
|
|
|
|
{
|
|
|
|
|
using var fileStream = File.OpenRead(sourceFile);
|
|
|
|
|
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extracts all.
|
|
|
|
@ -36,10 +34,11 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = ReaderFactory.Open(source))
|
|
|
|
|
using var reader = ReaderFactory.Open(source);
|
|
|
|
|
var options = new ExtractionOptions
|
|
|
|
|
{
|
|
|
|
|
var options = new ExtractionOptions();
|
|
|
|
|
options.ExtractFullPath = true;
|
|
|
|
|
ExtractFullPath = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
@ -48,44 +47,37 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
|
|
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void ExtractAllFromZip(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = ZipReader.Open(source))
|
|
|
|
|
{
|
|
|
|
|
var options = new ExtractionOptions();
|
|
|
|
|
options.ExtractFullPath = true;
|
|
|
|
|
|
|
|
|
|
if (overwriteExistingFiles)
|
|
|
|
|
using var reader = ZipReader.Open(source);
|
|
|
|
|
var options = new ExtractionOptions
|
|
|
|
|
{
|
|
|
|
|
options.Overwrite = true;
|
|
|
|
|
}
|
|
|
|
|
ExtractFullPath = true,
|
|
|
|
|
Overwrite = overwriteExistingFiles
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void ExtractAllFromGz(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GZipReader.Open(source))
|
|
|
|
|
using var reader = GZipReader.Open(source);
|
|
|
|
|
var options = new ExtractionOptions
|
|
|
|
|
{
|
|
|
|
|
var options = new ExtractionOptions();
|
|
|
|
|
options.ExtractFullPath = true;
|
|
|
|
|
|
|
|
|
|
if (overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
options.Overwrite = true;
|
|
|
|
|
}
|
|
|
|
|
ExtractFullPath = true,
|
|
|
|
|
Overwrite = overwriteExistingFiles
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void ExtractFirstFileFromGz(Stream source, string targetPath, string defaultFileName)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GZipReader.Open(source))
|
|
|
|
|
{
|
|
|
|
|
using var reader = GZipReader.Open(source);
|
|
|
|
|
if (reader.MoveToNextEntry())
|
|
|
|
|
{
|
|
|
|
|
var entry = reader.Entry;
|
|
|
|
@ -95,10 +87,10 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
{
|
|
|
|
|
filename = defaultFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reader.WriteEntryToFile(Path.Combine(targetPath, filename));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extracts all from7z.
|
|
|
|
@ -108,11 +100,9 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = File.OpenRead(sourceFile))
|
|
|
|
|
{
|
|
|
|
|
using var fileStream = File.OpenRead(sourceFile);
|
|
|
|
|
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extracts all from7z.
|
|
|
|
@ -122,22 +112,16 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var archive = SevenZipArchive.Open(source))
|
|
|
|
|
{
|
|
|
|
|
using (var reader = archive.ExtractAllEntries())
|
|
|
|
|
{
|
|
|
|
|
var options = new ExtractionOptions();
|
|
|
|
|
options.ExtractFullPath = true;
|
|
|
|
|
|
|
|
|
|
if (overwriteExistingFiles)
|
|
|
|
|
using var archive = SevenZipArchive.Open(source);
|
|
|
|
|
using var reader = archive.ExtractAllEntries();
|
|
|
|
|
var options = new ExtractionOptions
|
|
|
|
|
{
|
|
|
|
|
options.Overwrite = true;
|
|
|
|
|
}
|
|
|
|
|
ExtractFullPath = true,
|
|
|
|
|
Overwrite = overwriteExistingFiles
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extracts all from tar.
|
|
|
|
@ -147,11 +131,9 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = File.OpenRead(sourceFile))
|
|
|
|
|
{
|
|
|
|
|
using var fileStream = File.OpenRead(sourceFile);
|
|
|
|
|
ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extracts all from tar.
|
|
|
|
@ -161,21 +143,15 @@ namespace Emby.Server.Implementations.Archiving
|
|
|
|
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
|
|
|
|
public void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
using (var archive = TarArchive.Open(source))
|
|
|
|
|
{
|
|
|
|
|
using (var reader = archive.ExtractAllEntries())
|
|
|
|
|
using var archive = TarArchive.Open(source);
|
|
|
|
|
using var reader = archive.ExtractAllEntries();
|
|
|
|
|
var options = new ExtractionOptions
|
|
|
|
|
{
|
|
|
|
|
var options = new ExtractionOptions();
|
|
|
|
|
options.ExtractFullPath = true;
|
|
|
|
|
|
|
|
|
|
if (overwriteExistingFiles)
|
|
|
|
|
{
|
|
|
|
|
options.Overwrite = true;
|
|
|
|
|
}
|
|
|
|
|
ExtractFullPath = true,
|
|
|
|
|
Overwrite = overwriteExistingFiles
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|