mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SimpleSort] Add header support, fix scan levels
This commit is contained in:
@@ -19,31 +19,67 @@ namespace SabreTools.Helper
|
||||
/// <param name="output">Output directory to build to</param>
|
||||
/// <param name="archiveType">Type of archive to attempt to write to</param>
|
||||
/// <param name="rom">RomData representing the new information</param>
|
||||
public static void WriteArchiveOrFile(string input, string output, ArchiveType archiveType, RomData rom)
|
||||
public static void WriteFileToArchive(string input, string output, ArchiveType archiveType, RomData rom)
|
||||
{
|
||||
string archiveFileName = output + Path.DirectorySeparatorChar + rom.Game + ".zip";
|
||||
string singleFileName = output + Path.DirectorySeparatorChar + rom.Game + Path.DirectorySeparatorChar + rom.Name;
|
||||
|
||||
IWriter outarchive = null;
|
||||
FileStream fs = null;
|
||||
IWritableArchive outarchive = null;
|
||||
try
|
||||
{
|
||||
fs = File.OpenWrite(archiveFileName);
|
||||
outarchive = WriterFactory.Open(fs, ArchiveType.Zip, CompressionType.Deflate);
|
||||
outarchive.Write(rom.Name, input);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (!File.Exists(singleFileName))
|
||||
if (!File.Exists(archiveFileName))
|
||||
{
|
||||
File.Copy(input, singleFileName);
|
||||
outarchive = ArchiveFactory.Create(archiveType) as IWritableArchive;
|
||||
}
|
||||
else
|
||||
{
|
||||
outarchive = ArchiveFactory.Open(archiveFileName, Options.LookForHeader) as IWritableArchive;
|
||||
}
|
||||
outarchive.AddEntry(rom.Name, input);
|
||||
outarchive.SaveTo(archiveFileName, new CompressionInfo { Type = CompressionType.Deflate });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
outarchive?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy a file either to an output archive or to an output folder
|
||||
/// </summary>
|
||||
/// <param name="input">Input filename to be moved</param>
|
||||
/// <param name="output">Output directory to build to</param>
|
||||
/// <param name="archiveType">Type of archive to attempt to write to</param>
|
||||
/// <param name="rom">RomData representing the new information</param>
|
||||
public static void WriteFolderToArchive(string input, string output, ArchiveType archiveType)
|
||||
{
|
||||
string archiveFileName = output + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(input) + ".zip";
|
||||
|
||||
IWritableArchive outarchive = null;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(archiveFileName))
|
||||
{
|
||||
outarchive = ArchiveFactory.Create(archiveType) as IWritableArchive;
|
||||
}
|
||||
else
|
||||
{
|
||||
outarchive = ArchiveFactory.Open(archiveFileName, Options.LookForHeader) as IWritableArchive;
|
||||
}
|
||||
outarchive.AddAllFromDirectory(input, "*", SearchOption.AllDirectories);
|
||||
outarchive.SaveTo(archiveFileName, new CompressionInfo { Type = CompressionType.Deflate });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
outarchive?.Dispose();
|
||||
fs?.Close();
|
||||
fs?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -608,7 +608,7 @@ namespace SabreTools.Helper
|
||||
long adjustedLength = br.BaseStream.Length - bytesToRemoveFromTail;
|
||||
|
||||
// Seek to the correct position
|
||||
br.BaseStream.Seek(bytesToRemoveFromHead, SeekOrigin.Begin);
|
||||
br.BaseStream.Seek((bytesToRemoveFromHead < 0 ? 0 : bytesToRemoveFromHead), SeekOrigin.Begin);
|
||||
|
||||
// Now read the file in chunks and write out
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
@@ -695,5 +695,22 @@ namespace SabreTools.Helper
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy a file to a new location, creating directories as needed
|
||||
/// </summary>
|
||||
/// <param name="input">Input filename</param>
|
||||
/// <param name="output">Output filename</param>
|
||||
public static void CopyFileToNewLocation(string input, string output)
|
||||
{
|
||||
if (File.Exists(input) && !File.Exists(output))
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(output)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(output));
|
||||
}
|
||||
File.Copy(input, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="noMD5">True if MD5 hashes should not be calculated, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should not be calcluated, false otherwise</param>
|
||||
/// <returns>Populated RomData object if success, empty one on error</returns>
|
||||
/// <remarks>Add read-offset for hash info</remarks>
|
||||
public static RomData GetSingleFileInfo(string input, bool noMD5 = false, bool noSHA1 = false)
|
||||
{
|
||||
RomData rom = new RomData
|
||||
|
||||
Reference in New Issue
Block a user