mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ArchiveTools] Further fixes to tzip for multiple file support
This commit is contained in:
@@ -870,7 +870,7 @@ namespace SabreTools.Helper
|
|||||||
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < inputFiles.Count; i++)
|
||||||
{
|
{
|
||||||
inputIndexMap.Add(inputFiles[i], i);
|
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the keys in TZIP order
|
// Sort the keys in TZIP order
|
||||||
@@ -880,27 +880,23 @@ namespace SabreTools.Helper
|
|||||||
// Now add all of the files in order
|
// Now add all of the files in order
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
string inputFile = key;
|
// Get the index mapped to the key
|
||||||
Rom rom = roms[inputIndexMap[key]];
|
int index = inputIndexMap[key];
|
||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream fs = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(inputFiles[index], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||||
ulong streamSize = (ulong)(new FileInfo(inputFile).Length);
|
zipFile.OpenWriteStream(false, true, roms[index].Name.Replace('\\', '/'), istreamSize, CompressionMethod.Deflated, out writeStream);
|
||||||
zipReturn = zipFile.OpenWriteStream(false, true, rom.Name, streamSize, CompressionMethod.Deflated, out writeStream);
|
|
||||||
|
|
||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
byte[] buffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
int len;
|
int ilen;
|
||||||
while ((len = fs.Read(buffer, 0, _bufferSize)) > 0)
|
while ((ilen = freadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||||
{
|
{
|
||||||
writeStream.Write(buffer, 0, len);
|
writeStream.Write(ibuffer, 0, ilen);
|
||||||
}
|
}
|
||||||
writeStream.Flush();
|
freadStream.Dispose();
|
||||||
zipFile.CloseWriteStream(Convert.ToUInt32(rom.CRC, 16));
|
zipFile.CloseWriteStream(Convert.ToUInt32(roms[index].CRC, 16));
|
||||||
|
|
||||||
//Dispose of the file stream
|
|
||||||
fs.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -915,12 +911,12 @@ namespace SabreTools.Helper
|
|||||||
for (int i = 0; i < inputFiles.Count; i++)
|
for (int i = 0; i < inputFiles.Count; i++)
|
||||||
{
|
{
|
||||||
// If the old one contains the new file, then just skip out
|
// If the old one contains the new file, then just skip out
|
||||||
if (oldZipFile.Contains(roms[i].Name))
|
if (oldZipFile.Contains(roms[i].Name.Replace('\\', '/')))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputIndexMap.Add(inputFiles[i], -(i + 1));
|
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), -(i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then add all of the old entries to it too
|
// Then add all of the old entries to it too
|
||||||
@@ -946,16 +942,16 @@ namespace SabreTools.Helper
|
|||||||
// Copy over all files to the new archive
|
// Copy over all files to the new archive
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
// Get the index mapped to they key
|
// Get the index mapped to the key
|
||||||
int index = inputIndexMap[key];
|
int index = inputIndexMap[key];
|
||||||
|
|
||||||
// If we have the input file, add it now
|
// If we have the input file, add it now
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
Stream freadStream = File.Open(key, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
Stream freadStream = File.Open(inputFiles[-index - 1], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
ulong istreamSize = (ulong)(new FileInfo(key).Length);
|
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||||
zipFile.OpenWriteStream(false, true, roms[-index - 1].Name, istreamSize, CompressionMethod.Deflated, out writeStream);
|
zipFile.OpenWriteStream(false, true, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, CompressionMethod.Deflated, out writeStream);
|
||||||
|
|
||||||
// Copy the input stream to the output
|
// Copy the input stream to the output
|
||||||
byte[] ibuffer = new byte[_bufferSize];
|
byte[] ibuffer = new byte[_bufferSize];
|
||||||
|
|||||||
Reference in New Issue
Block a user