Exemple #1
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (_fileIndex != null)
            {
                _fileIndex.Close();
                _fileIndex = null;
            }
        }
Exemple #2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            _fileIndex.Close();
        }
Exemple #3
0
        private void PatchFile(string idxPath, string mulPath, string newIdxPath, string newMulPath, List <Patch> patches)
        {
            File.Copy(idxPath, newIdxPath, true);
            File.Copy(mulPath, newMulPath, true);

            FileInfo  idxFileInfo = new FileInfo(newIdxPath);
            FileIndex index       = new FileIndex(Path.GetFileName(idxPath), Path.GetFileName(mulPath), (int)(idxFileInfo.Length / 12));

            BinaryWriter idx = new BinaryWriter(new FileStream(newIdxPath, FileMode.Open));
            BinaryWriter mul = new BinaryWriter(new FileStream(newMulPath, FileMode.Open));

            int oldPercent = 0;

            for (int p = 0; p < patches.Count; p++)
            {
                Patch patch = patches[p];
                //int a = 0;
                //if (patch.BlockID == 0xEEEE)
                //    a = 4;

                /*
                 * int pos;
                 *
                 * if (index[patch.BlockID].length > patch.Length)
                 *  pos = index[patch.BlockID].lookup;
                 * else
                 */
                int pos = Convert.ToInt32(mul.BaseStream.Length);

                idx.Seek(patch.BlockID * 12, SeekOrigin.Begin);

                idx.Write(pos);
                idx.Write(patch.Length);
                idx.Write(patch.Extra);

                if (patch.Length >= 0)
                {
                    mul.Seek(pos, SeekOrigin.Begin);
                    mul.Write(patch.Data, 0, patch.Length);
                }

                int percent = (p * 100) / patches.Count;

                if (percent != oldPercent)
                {
                    OnProgressChanged(this, new PatcherProgressChangeEventArgs(percent));
                    oldPercent = percent;
                }
            }

            index.Close();

            if (idx != null)
            {
                idx.Close();
            }
            if (mul != null)
            {
                mul.Close();
            }

            if (File.Exists(newIdxPath.Substring(0, newIdxPath.Length - 4)))
            {
                File.Delete(newIdxPath.Substring(0, newIdxPath.Length - 4));
            }

            File.Move(newIdxPath, newIdxPath.Substring(0, newIdxPath.Length - 4));

            if (File.Exists(newMulPath.Substring(0, newMulPath.Length - 4)))
            {
                File.Delete(newMulPath.Substring(0, newMulPath.Length - 4));
            }

            File.Move(newMulPath, newMulPath.Substring(0, newMulPath.Length - 4));

            File.Delete(newIdxPath);
            File.Delete(newMulPath);
        }