Beispiel #1
0
        } //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
Beispiel #2
0
        } //end CreateIndexRecords

        public static IndexRecord[] RebuildPak(string pakFileName, List <PakFile> files, bool isPackFileProtected)
        {
            var pakIndex = PakTools.CreateIndexRecords(PakTools.LoadIndexData(pakFileName.Replace(".pak", ".idx")), true);

            var fileStream = File.OpenWrite(pakFileName);

            foreach (var pakFile in files)
            {
                var bytes = Encoding.Default.GetBytes(pakFile.Content);
                bytes = PakTools.Encode(bytes, 0);

                var num = pakFile.Id - 1;
                pakIndex[num].Offset = (int)fileStream.Seek((long)0, SeekOrigin.End);
                fileStream.Write(bytes, 0, (int)bytes.Length);
            }

            fileStream.Close();

            return(pakIndex);
        } //end RebuildPak