} //end CreateIndexRecords public static IndexRecord[] RebuildPak(string pakFileName, List <PakFile> files, bool isPackFileProtected, Action <int> progressUpdate = null) { var indexFile = pakFileName.Replace(".pak", ".idx"); var pakIndex = PakTools.CreateIndexRecords(PakTools.LoadIndexData(indexFile), true); var fileStream1 = File.OpenWrite(pakFileName); for (var x = 0; x < files.Count; x++) { var pakFile = files[x]; var updatedList = new List <PakTools.IndexRecord>(); byte[] numArray = File.ReadAllBytes(pakFile.FileName); numArray = PakTools.Encode(numArray, 0); int offset = (int)fileStream1.Seek(0L, SeekOrigin.End); fileStream1.Write(numArray, 0, numArray.Length); string filename = pakFile.FileName.Substring(pakFile.FileName.LastIndexOf('\\') + 1); var newRecord = new PakTools.IndexRecord(filename, numArray.Length, offset); bool inserted = false; for (int i = 0; i < pakIndex.Length; ++i) { PakTools.IndexRecord oldRecord = pakIndex[i]; if (oldRecord.FileName.Equals(filename)) { updatedList.Add(newRecord); inserted = true; } // if our filename comes before the records filename alphabetically else if (!inserted && string.CompareOrdinal(filename, oldRecord.FileName) < 0) { updatedList.Add(newRecord); updatedList.Add(oldRecord); inserted = true; } else { updatedList.Add(oldRecord); } } Array.Resize <PakTools.IndexRecord>(ref pakIndex, updatedList.Count); pakIndex = updatedList.ToArray(); if (progressUpdate != null) { progressUpdate.Invoke(x + 1); } } fileStream1.Flush(); fileStream1.Close(); PakTools.RebuildIndex(indexFile, pakIndex, true); return(pakIndex); } //end RebuildPak
} //end LoadIndexData public static PakTools.IndexRecord[] CreateIndexRecords(byte[] indexData, bool isPackFileProtected) { if (indexData == null) { return(null); } var num = (isPackFileProtected ? 0 : 4); var length = ((int)indexData.Length - num) / 28; var indexRecord = new PakTools.IndexRecord[length]; for (var i = 0; i < length; i++) { indexRecord[i] = new PakTools.IndexRecord(indexData, num + i * 28); } return(indexRecord); } //end CreateIndexRecords