private int[] internal_ReadFileHeader(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS) { int fileSize = internal_ReadFileRaw(stream, file, buffers, flags); if (fileSize == -1) { return(new int[0]); } int referenceNum = BitConverter.ToInt32(buffers[fileSize], 0); if (referenceNum * 4 >= fileSize) { log.Error("referenceNum * 4 > fileSize\n{0}>{1}", referenceNum, fileSize); return(new int[0]); } int[] header = new int[referenceNum]; for (int i = 0; i < referenceNum; i++) { header[i] = BitConverter.ToInt32(buffers[fileSize], (i * 4) + 4); } return(header); }
private int internal_ReadFileData(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS) { int fileSize = internal_ReadFileRaw(stream, file, buffers, flags); if (fileSize == -1) { return(-1); } int referenceNum = BitConverter.ToInt32(buffers[fileSize], 0); if (referenceNum * 4 >= fileSize) { log.Error("referenceNum * 4 > fileSize\n{0}>{1}", referenceNum, fileSize); return(-1); } int dataSize = fileSize - (referenceNum + 1) * 4; byte[] dataBuffer = buffers[dataSize]; byte[] fileBuffer = buffers[fileSize]; for (int i = 0; i < dataSize; i++) { dataBuffer[i] = fileBuffer[i + (referenceNum + 1) * 4]; } return(dataSize); }
public override IEnumerable <int> ReadAllData(BigFileFile[] filesToRead, IOBuffers buffers, BigFileFlags flags) { for (int i = 0; i < filesToRead.Length; i++) { yield return(ReadFileData(filesToRead[i], buffers, flags)); } }
public override int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags) { int[] header; using (FileStream fs = File.OpenRead(packedBigFile.MetadataFileInfo.FullName)) { header = internal_ReadFileHeader(fs, file, buffers, flags); } return(header); }
public override IEnumerable <int> ReadAllData(BigFileFile[] filesToRead, IOBuffers buffers, BigFileFlags flags) { using (FileStream fs = File.OpenRead(packedBigFile.MetadataFileInfo.FullName)) { for (int i = 0; i < filesToRead.Length; i++) { yield return(internal_ReadFileData(fs, filesToRead[i], buffers, flags)); } } }
public override int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags) { int size = -1; using (FileStream fs = File.OpenRead(packedBigFile.MetadataFileInfo.FullName)) { size = internal_ReadFileData(fs, file, buffers, flags); } return(size); }
public override int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags) { string fileName = unpackedBigFile.Directory.FullName + "\\" + BigFileConst.UNPACK_DIR + unpackedBigFile.RenamedMapping[file.FileInfo.Key].FileName + BigFileConst.UNPACKED_HEADER_FILE_EXTENSION; int fileSize = -1; byte[] buffer; using (FileStream fs = File.OpenRead(fileName)) { fileSize = (int)fs.Length; buffer = buffers[fileSize]; fs.Read(buffer, 0, fileSize); } if (fileSize == 0) { return(new int[0]); } int referenceNum = BitConverter.ToInt32(buffer, 0); if (referenceNum * 4 + 4 > fileSize) { throw new Exception("referenceNum * 4 + 4 > fileSize"); } if (referenceNum <= 0) { return(new int[0]); } int[] header = new int[referenceNum]; for (int i = 1; i <= referenceNum; i++) { header[i - 1] = BitConverter.ToInt32(buffer, i * 4); } return(header); }
public override int ReadFileRaw(BigFileFile file, IOBuffers buffers, BigFileFlags flags) { int[] header = ReadFileHeader(file, buffers, flags); int dataSize = ReadFileData(file, buffers, flags); int headerSize = header.Length * 4 + 4; byte[] dataBuffer = buffers[dataSize]; byte[] buffer = buffers[dataSize + headerSize]; for (int i = dataSize - 1; i >= 0; i--) { buffer[i + headerSize] = dataBuffer[i]; } header.Length.ToByteArray(buffer, 0); for (int i = 0; i < header.Length; i++) { header[i].ToByteArray(buffer, i * 4 + 4); } return(dataSize + headerSize); }
public override int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags) { string fullFileName = unpackedBigFile.Directory.FullName + "\\" + BigFileConst.UNPACK_DIR + unpackedBigFile.RenamedMapping[file.FileInfo.Key].FileName; int size = -1; byte[] buffer = buffers[4]; using (FileStream fs = File.OpenRead(fullFileName)) { size = (int)fs.Length; buffer = buffers[size]; fs.Read(buffer, 0, size); } if (size == 0) { size = -1; } return(size); }
private int internal_ReadFileRaw(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS) { log.Debug("Reading file: " + file.Name); int bytesSize = GetBytesSizeAndSeekToStartOfFileData(stream, file, flags); if (bytesSize == -1) { log.Error("There was an error reading the file!"); return(-1); } byte[] buffer = buffers[bytesSize]; log.Debug(string.Format(" > [ZIP: {0}] [flags: {1}] [size: {2}]", file.FileInfo.ZIP, flags, bytesSize)); if (file.FileInfo.ZIP == 0) { stream.Read(buffer, 0, bytesSize); } else { if ((flags & BigFileFlags.Decompress) != 0) { using (ZlibStream zs = new ZlibStream(stream, Ionic.Zlib.CompressionMode.Decompress, true)) { zs.Read(buffer, 0, bytesSize); } } else { stream.Read(buffer, 0, bytesSize); } } return(bytesSize); }
static void CompareAllFiles() { LogManager.GlobalLogFlags = LogFlags.Error | LogFlags.Info; Console.Write("Bigfile 1: "); string path1 = Console.ReadLine(); Console.Write("Bigfile 2: "); string path2 = Console.ReadLine(); IOBuffers buffer1 = new IOBuffers(); IOBuffers buffer2 = new IOBuffers(); BigFile file1 = BigFile.OpenBigFile(path1); BigFile file2 = BigFile.OpenBigFile(path2); if (file1 == null) { Console.WriteLine("file 1 null"); Console.ReadLine(); Environment.Exit(911); } if (file2 == null) { Console.WriteLine("file 2 null"); Console.ReadLine(); Environment.Exit(911); } file1.LoadFromDisk(); Console.Write("Press enter..."); Console.ReadLine(); file2.LoadFromDisk(); Console.Write("Press enter..."); Console.ReadLine(); Console.Clear(); int missingFiles = 0; if (file1.FileMap.FilesList.Length != file2.FileMap.FilesList.Length) { Console.WriteLine("Files count don't match!"); foreach (BigFileFile file1file in file1.FileMap.FilesList) { if (file2.FileMap[file1file.FileInfo.Key] == null) { missingFiles++; Console.WriteLine("Found file {0} (key: {1:X8}) that appears in the first bigfile but not the second!", file1file.Name, file1file.FileInfo.Key); } } Console.ReadLine(); foreach (BigFileFile file2file in file2.FileMap.FilesList) { if (file1.FileMap[file2file.FileInfo.Key] == null) { missingFiles++; Console.WriteLine("Found file {0} (key: {1:X8}) that appears in the second bigfile but not the first!", file2file.Name, file2file.FileInfo.Key); } } Console.ReadLine(); } Console.WriteLine(""); Console.WriteLine("Found {0} file discrepancies between the two bigfiles", missingFiles); Console.Write("Would you like to continue? "); Console.ReadLine(); Console.Clear(); IEnumerator <int[]> headers1 = file1.FileReader.ReadAllHeaders(file1.FileMap.FilesList, buffer1, file1.FileReader.DefaultFlags).GetEnumerator(); IEnumerator <int[]> headers2 = file2.FileReader.ReadAllHeaders(file2.FileMap.FilesList, buffer1, file2.FileReader.DefaultFlags).GetEnumerator(); void CompareHeaders(BigFileFile file1file, BigFileFile file2file, int[] a, int[] b) { bool foundError = a.Length != b.Length; if (!foundError) { for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { foundError = true; break; } } } if (foundError) { Console.WriteLine("File {0} has a header discrepancy!"); Console.WriteLine("File 1 header length: {0}", a.Length); Console.WriteLine("File 2 header length: {1}", b.Length); for (int i = 0; i < a.Length; i++) { Console.Write("{0:X8} ", a[i]); } for (int i = 0; i < b.Length; i++) { Console.Write("{0:X8} ", b[i]); } } } }
static void CompareFiles() { LogManager.GlobalLogFlags = LogFlags.Error | LogFlags.Info; Console.Write("Bigfile 1: "); string path1 = Console.ReadLine(); Console.Write("Bigfile 2: "); string path2 = Console.ReadLine(); IOBuffers buffer1 = new IOBuffers(); IOBuffers buffer2 = new IOBuffers(); Console.Write("File key: "); int key = 0; key = Convert.ToInt32(Console.ReadLine(), 16); if (key == 0) { Environment.Exit(420); } BigFile file1 = BigFile.OpenBigFile(path1); BigFile file2 = BigFile.OpenBigFile(path2); if (file1 == null) { Console.WriteLine("file 1 null"); Console.ReadLine(); Environment.Exit(911); } if (file2 == null) { Console.WriteLine("file 2 null"); Console.ReadLine(); Environment.Exit(911); } file1.LoadFromDisk(); Console.Write("Press enter..."); Console.ReadLine(); file2.LoadFromDisk(); Console.Write("Press enter..."); Console.ReadLine(); BigFileFile bigFileFile1 = file1.FileMap[key]; BigFileFile bigFileFile2 = file2.FileMap[key]; int[] header1 = file1.FileReader.ReadFileHeader(bigFileFile1, buffer1, file1.FileReader.DefaultFlags); int[] header2 = file2.FileReader.ReadFileHeader(bigFileFile2, buffer2, file2.FileReader.DefaultFlags); int size1 = file1.FileReader.ReadFileRaw(bigFileFile1, buffer1, file1.FileReader.DefaultFlags); int size2 = file2.FileReader.ReadFileRaw(bigFileFile2, buffer2, file2.FileReader.DefaultFlags); int chksum1 = 0; int chksum2 = 0; for (int i = 0; i < size1; i++) { chksum1 += buffer1[size1][i]; } for (int i = 0; i < size2; i++) { chksum2 += buffer2[size2][i]; } Console.Clear(); Console.WriteLine("Size 1: " + size1); Console.WriteLine("Checksum 1: " + chksum1); Console.WriteLine("Size 2: " + size2); Console.WriteLine("Checksum 2: " + chksum2); Console.Write("Header 1, length: {0} : ", header1.Length); for (int i = 0; i < header1.Length; i++) { Console.Write("{0:X8} ", header1[i]); } Console.Write("\nHeader 2, length: {0} : ", header2.Length); for (int i = 0; i < header2.Length; i++) { Console.Write("{0:X8} ", header2[i]); } Console.WriteLine(""); LogManager.GlobalLogFlags = LogFlags.All; bigFileFile1.FileInfo.DebugLog(log); bigFileFile2.FileInfo.DebugLog(log); Console.ReadLine(); }
public abstract IEnumerable <int> ReadAllData(BigFileFile[] filesToRead, IOBuffers buffers, BigFileFlags flags);
public abstract int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags);
public abstract int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags);