Exemple #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
Exemple #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
Exemple #3
0
        } //end RebuildPak

        public static void RebuildIndex(string indexFile, IndexRecord[] indexRecords, bool isPackFileProtected)
        {
            var numArray = new byte[4 + indexRecords.Length * 28];

            Array.Copy(BitConverter.GetBytes(indexRecords.Length), 0, numArray, 0, 4);

            for (var i = 0; i < indexRecords.Length; i++)
            {
                var num = 4 + i * 28;
                Array.Copy(BitConverter.GetBytes(indexRecords[i].Offset), 0, numArray, num, 4);
                Encoding.Default.GetBytes(indexRecords[i].FileName, 0, indexRecords[i].FileName.Length, numArray, num + 4);
                Array.Copy(BitConverter.GetBytes(indexRecords[i].FileSize), 0, numArray, num + 24, 4);
            }

            if (isPackFileProtected)
            {
                Array.Copy(PakTools.Encode(numArray, 4), 0, numArray, 4, (int)numArray.Length - 4);
            }

            File.WriteAllBytes(indexFile, numArray);
        } //end RebuildIndex