mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[FileTools, ZipFile] Fix a couple things
This commit is contained in:
@@ -397,17 +397,14 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now try to open the file for reading
|
// Now try to open the file for reading
|
||||||
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
_zipstream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||||
int errorcode = fs.Read(new byte[1], 0, 1);
|
int read = _zipstream.Read(new byte[1], 0, 1);
|
||||||
if (errorcode != 0)
|
if (read != 1)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
if (errorcode == 32)
|
|
||||||
{
|
|
||||||
return ZipReturn.ZipFileLocked;
|
|
||||||
}
|
|
||||||
return ZipReturn.ZipErrorOpeningFile;
|
return ZipReturn.ZipErrorOpeningFile;
|
||||||
}
|
}
|
||||||
|
_zipstream.Position = 0;
|
||||||
}
|
}
|
||||||
catch (PathTooLongException)
|
catch (PathTooLongException)
|
||||||
{
|
{
|
||||||
@@ -420,7 +417,7 @@ namespace SabreTools.Helper
|
|||||||
return ZipReturn.ZipErrorOpeningFile;
|
return ZipReturn.ZipErrorOpeningFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we succedded, set the flag for read
|
// If we succeeded, set the flag for read
|
||||||
_zipOpen = ZipOpenType.OpenRead;
|
_zipOpen = ZipOpenType.OpenRead;
|
||||||
|
|
||||||
// If we're not reading the headers, return
|
// If we're not reading the headers, return
|
||||||
@@ -618,13 +615,7 @@ namespace SabreTools.Helper
|
|||||||
_zipFileInfo = new FileInfo(filename);
|
_zipFileInfo = new FileInfo(filename);
|
||||||
|
|
||||||
// Now try to open the file
|
// Now try to open the file
|
||||||
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
_zipstream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite);
|
||||||
int errorcode = fs.Read(new byte[1], 0, 1);
|
|
||||||
if (errorcode != 0)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
return ZipReturn.ZipErrorOpeningFile;
|
|
||||||
}
|
|
||||||
ZipOpen = ZipOpenType.OpenWrite;
|
ZipOpen = ZipOpenType.OpenWrite;
|
||||||
return ZipReturn.ZipGood;
|
return ZipReturn.ZipGood;
|
||||||
}
|
}
|
||||||
@@ -838,7 +829,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the entry stream based on the current position
|
// Open the entry stream based on the current position
|
||||||
ZipFileEntry zfe = new ZipFileEntry(_zipstream, filename);
|
ZipFileEntry zfe = new ZipFileEntry(_zipstream, filename, true);
|
||||||
ZipReturn zr = zfe.OpenWriteStream(raw, torrentZip, uncompressedSize, compressionMethod, out stream);
|
ZipReturn zr = zfe.OpenWriteStream(raw, torrentZip, uncompressedSize, compressionMethod, out stream);
|
||||||
_entries.Add(zfe);
|
_entries.Add(zfe);
|
||||||
|
|
||||||
|
|||||||
@@ -130,21 +130,30 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
readStream = File.OpenRead(inputFile);
|
readStream = File.OpenRead(inputFile);
|
||||||
|
ulong streamSize = (ulong)(new FileInfo(inputFile).Length);
|
||||||
|
|
||||||
// If the archive doesn't exist, create it
|
// Open or create the archive
|
||||||
if (!File.Exists(archiveFileName))
|
if (!File.Exists(archiveFileName))
|
||||||
{
|
{
|
||||||
zipReturn = zipFile.Create(archiveFileName);
|
zipReturn = zipFile.Create(archiveFileName);
|
||||||
}
|
}
|
||||||
// Otherwise, open the archive
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zipReturn = zipFile.Open(archiveFileName, new FileInfo(archiveFileName).LastWriteTime.Ticks, true);
|
zipReturn = zipFile.Open(archiveFileName, new FileInfo(archiveFileName).LastWriteTime.Ticks, false);
|
||||||
|
zipFile.ZipOpen = ZipOpenType.OpenWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
zipReturn = zipFile.OpenWriteStream(false, true, inputFile, (ulong)(new FileInfo(inputFile).Length), CompressionMethod.Deflated, out writeStream);
|
|
||||||
if (zipReturn != ZipReturn.ZipGood)
|
if (zipReturn != ZipReturn.ZipGood)
|
||||||
{
|
{
|
||||||
|
zipFile.Dispose();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the stream for writing
|
||||||
|
zipReturn = zipFile.OpenWriteStream(false, true, rom.Name, streamSize, CompressionMethod.Deflated, out writeStream);
|
||||||
|
if (zipReturn != ZipReturn.ZipGood)
|
||||||
|
{
|
||||||
|
zipFile.Dispose();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +174,7 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
zipFile.Close();
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user