예제 #1
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);
        }
예제 #2
0
        private void PatchFile(string idxPath, string mulPath, string newIdxPath, string newMulPath, List <Patch> patches)
        {
            if (StatusChange != null)
            {
                StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)...")));
            }

            File.Copy(idxPath, newIdxPath, true);
            File.Copy(mulPath, newMulPath, true);

            if (StatusChange != null)
            {
                StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath))));
            }

            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);
                }

                if (p != 0 && ProgressChange != null)
                {
                    int percent = (p * 100) / patches.Count;

                    if (percent != oldPercent)
                    {
                        ProgressChange.Invoke(this, new ProgressChangeEventArgs(percent, p, patches.Count));
                        oldPercent = percent;
                    }
                }
            }

            index.Close();

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

            if (StatusChange != null)
            {
                StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)...")));
            }

            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));

            if (this.StatusChange != null)
            {
                this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0])));
            }

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

            #region Meh for now

            /*
             * if (StatusChange != null)
             *      StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)...")));
             *
             * FileInfo info = new FileInfo(idxPath);
             * FileIndex oldIndex = new FileIndex(Path.GetFileName(idxPath), Path.GetFileName(mulPath), (int)(info.Length / ((long)12)));
             *
             * BinaryWriter idx = new BinaryWriter(new FileStream(newIdxPath, FileMode.Create));
             * idx.Seek((int)new FileInfo(idxPath).Length, SeekOrigin.Begin);
             *
             * BinaryWriter mul = new BinaryWriter(new FileStream(newMulPath, FileMode.Create));
             * mul.Seek((int)new FileInfo(mulPath).Length, SeekOrigin.Begin);
             *
             * idx.Seek(0, SeekOrigin.Begin);
             * mul.Seek(0, SeekOrigin.Begin);
             *
             * if (StatusChange != null)
             *      StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath))));
             *
             * int patchIndex = 0;
             * int oldPercent = 0;
             *
             * int offset = 0;
             *
             * for (int i = 0; i < oldIndex.IndexCount; i++)
             * {
             *      if (patchIndex < patches.Count && patches[patchIndex].BlockID == i)//Write the patch
             *      {
             *              if (StatusChange != null)
             *                      StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i)));
             *
             *              Patch patch = patches[patchIndex];
             *
             *              idx.Write((int)mul.BaseStream.Position);
             *              idx.Write(patch.Length);
             *              idx.Write(patch.Extra);
             *
             *              if (patch.Length > 0)
             *                      mul.Write(patch.Data, 0, patch.Length);
             *
             *              patchIndex++;
             *      }
             *      else//Write the regular data
             *      {
             *              if (StatusChange != null && (i % 200 == 0))
             *                      StatusChange(this, new StatusChangeEventArgs(String.Format("Writing index: {0}...", i)));
             *
             *              idx.Write((int)mul.BaseStream.Position);
             *              idx.Write(oldIndex[i].length);
             *              idx.Write(oldIndex[i].extra);
             *
             *              if (oldIndex[i].length > 0)
             *              {
             *                      BinaryReader reader = new BinaryReader(oldIndex.Seek(i));
             *                      mul.Write(reader.ReadBytes(oldIndex[i].length), 0, oldIndex[i].length);
             *              }
             *      }
             *
             *      if (i != 0 && ProgressChange != null)
             *      {
             *              int percent = (i * 100) / oldIndex.IndexCount;
             *
             *              if (percent != oldPercent)
             *              {
             *                      ProgressChange(this, new ProgressChangeEventArgs(percent, i, oldIndex.IndexCount));
             *                      oldPercent = percent;
             *              }
             *      }
             * }
             *
             * //Patches out of idx range? Is this possible?
             * if (patchIndex < patches.Count - 1)
             * {
             *      if (StatusChange != null)
             *              StatusChange(this, new StatusChangeEventArgs(String.Format("Applying left over patches...")));
             *
             *      int count = (patches.Count - 1) - patchIndex;
             *      int i = 0;
             *      while (i < count)
             *      {
             *              if (StatusChange != null)
             *                      StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i)));
             *
             *              Patch patch = patches[patchIndex];
             *
             *              idx.Write((int)mul.BaseStream.Position);
             *              idx.Write(patch.Length);
             *              idx.Write(patch.Extra);
             *
             *              if (patch.Length >= 0)
             *                      mul.Write(patch.Data, 0, patch.Length);
             *
             *              if (i != 0 && ProgressChange != null)
             *              {
             *                      int percent = (i * 100) / count;
             *
             *                      if (percent != oldPercent)
             *                      {
             *                              ProgressChange(this, new ProgressChangeEventArgs(percent, i, count));
             *                              oldPercent = percent;
             *                      }
             *              }
             *
             *              patchIndex++;
             *              i++;
             *      }
             * }
             *
             * oldIndex.Close();
             *
             * if (idx != null)
             *      idx.Close();
             * if (mul != null)
             *      mul.Close();
             *
             * if (StatusChange != null)
             *      StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)...")));
             *
             * 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));
             *
             * if (this.StatusChange != null)
             *      this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0])));
             *
             * File.Delete(newIdxPath);
             * File.Delete(newMulPath);*/
            #endregion
        }
예제 #3
0
        private void InternalCompare()
        {
            if (_usesIdx)
            {
                    byte[] buffOne = new byte[0xFFFF];
                    byte[] buffTwo = new byte[0xFFFF];

                    FileInfo infoOne = new FileInfo(_pathOneIdx);
                    FileInfo infoTwo = new FileInfo(_pathTwoIdx);

                    long lengthOne = infoOne.Length;
                    long lengthTwo = infoTwo.Length;

                    int maxIndexes = (int)Math.Min(lengthOne / 12, lengthTwo / 12);

                    FileIndex indexOne = new FileIndex(Path.GetDirectoryName(_pathOneMul), Path.GetFileName(_pathOneIdx), Path.GetFileName(_pathOneMul), maxIndexes);
                    FileIndex indexTwo = new FileIndex(Path.GetDirectoryName(_pathTwoMul), Path.GetFileName(_pathTwoIdx), Path.GetFileName(_pathTwoMul), maxIndexes);

                    for (int i = 0; i < maxIndexes; i++)
                    {
                        Stream streamOne = indexOne.Seek(i);
                        Stream streamTwo = indexTwo.Seek(i);
                        BinaryReader readerOne = null;
                        BinaryReader readerTwo = null;

                        if (streamOne == null && streamTwo == null)
                            continue;

                        if (streamOne != null)
                            readerOne = new BinaryReader(streamOne);

                        if (streamTwo != null)
                            readerTwo = new BinaryReader(streamTwo);

                        if (readerOne != null && readerTwo == null)
                            CreatePatchFromIdxMul(readerOne, indexOne.Index[i]);
                        else if (readerOne == null && readerTwo != null)
                            CreatePatchFromIdxMul(readerTwo, indexTwo.Index[i]);
                        else
                        {
                            Entry3D entryOne = indexOne.Index[i];
                            Entry3D entryTwo = indexTwo.Index[i];

                            if (entryOne.length != entryTwo.length)
                            {
                                CreatePatchFromIdxMul(readerOne, entryOne);
                                CreatePatchFromIdxMul(readerTwo, entryTwo);
                            }
                            else
                            {
                                while (readerOne.BaseStream.Position != readerOne.BaseStream.Length)
                                {
                                    int toRead = Math.Min(buffOne.Length, (int)(readerOne.BaseStream.Length - readerOne.BaseStream.Position));

                                    readerOne.Read(buffOne, 0, toRead);
                                    readerTwo.Read(buffTwo, 0, toRead);

                                    bool match = true;

                                    for (int a = 0; a < buffOne.Length; a++)
                                        if (buffOne[a] != buffTwo[a])
                                        {
                                            match = false;
                                            break;
                                        }

                                    if (!match)
                                    {
                                        CreatePatchFromIdxMul(readerOne, entryOne);
                                        CreatePatchFromIdxMul(readerTwo, entryTwo);
                                    }
                                }
                            }
                        }
                    }

            }
            else
            {

            }
        }
예제 #4
0
        private void PatchFile(string idxPath, string mulPath, string newIdxPath, string newMulPath, List<Patch> patches)
        {
            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)...")));

            File.Copy(idxPath, newIdxPath, true);
            File.Copy(mulPath, newMulPath, true);

            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath))));

            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);
                }

                if (p != 0 && ProgressChange != null)
                {
                    int percent = (p * 100) / patches.Count;

                    if (percent != oldPercent)
                    {
                        ProgressChange.Invoke(this, new ProgressChangeEventArgs(percent, p, patches.Count));
                        oldPercent = percent;
                    }
                }
            }

            index.Close();

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

            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)...")));

            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));

            if (this.StatusChange != null)
                this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0])));

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

            #region Meh for now
            /*
            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Creating temp mul/idx file(s)...")));

            FileInfo info = new FileInfo(idxPath);
            FileIndex oldIndex = new FileIndex(Path.GetFileName(idxPath), Path.GetFileName(mulPath), (int)(info.Length / ((long)12)));

            BinaryWriter idx = new BinaryWriter(new FileStream(newIdxPath, FileMode.Create));
            idx.Seek((int)new FileInfo(idxPath).Length, SeekOrigin.Begin);

            BinaryWriter mul = new BinaryWriter(new FileStream(newMulPath, FileMode.Create));
            mul.Seek((int)new FileInfo(mulPath).Length, SeekOrigin.Begin);

            idx.Seek(0, SeekOrigin.Begin);
            mul.Seek(0, SeekOrigin.Begin);

            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Applying {0} patches to {1}...", patches.Count, Path.GetFileName(newMulPath))));

            int patchIndex = 0;
            int oldPercent = 0;

            int offset = 0;

            for (int i = 0; i < oldIndex.IndexCount; i++)
            {
                if (patchIndex < patches.Count && patches[patchIndex].BlockID == i)//Write the patch
                {
                    if (StatusChange != null)
                        StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i)));

                    Patch patch = patches[patchIndex];

                    idx.Write((int)mul.BaseStream.Position);
                    idx.Write(patch.Length);
                    idx.Write(patch.Extra);

                    if (patch.Length > 0)
                        mul.Write(patch.Data, 0, patch.Length);

                    patchIndex++;
                }
                else//Write the regular data
                {
                    if (StatusChange != null && (i % 200 == 0))
                        StatusChange(this, new StatusChangeEventArgs(String.Format("Writing index: {0}...", i)));

                    idx.Write((int)mul.BaseStream.Position);
                    idx.Write(oldIndex[i].length);
                    idx.Write(oldIndex[i].extra);

                    if (oldIndex[i].length > 0)
                    {
                        BinaryReader reader = new BinaryReader(oldIndex.Seek(i));
                        mul.Write(reader.ReadBytes(oldIndex[i].length), 0, oldIndex[i].length);
                    }
                }

                if (i != 0 && ProgressChange != null)
                {
                    int percent = (i * 100) / oldIndex.IndexCount;

                    if (percent != oldPercent)
                    {
                        ProgressChange(this, new ProgressChangeEventArgs(percent, i, oldIndex.IndexCount));
                        oldPercent = percent;
                    }
                }
            }

            //Patches out of idx range? Is this possible?
            if (patchIndex < patches.Count - 1)
            {
                if (StatusChange != null)
                    StatusChange(this, new StatusChangeEventArgs(String.Format("Applying left over patches...")));

                int count = (patches.Count - 1) - patchIndex;
                int i = 0;
                while (i < count)
                {
                    if (StatusChange != null)
                        StatusChange(this, new StatusChangeEventArgs(String.Format("Applying patch id: {0}...", i)));

                    Patch patch = patches[patchIndex];

                    idx.Write((int)mul.BaseStream.Position);
                    idx.Write(patch.Length);
                    idx.Write(patch.Extra);

                    if (patch.Length >= 0)
                        mul.Write(patch.Data, 0, patch.Length);

                    if (i != 0 && ProgressChange != null)
                    {
                        int percent = (i * 100) / count;

                        if (percent != oldPercent)
                        {
                            ProgressChange(this, new ProgressChangeEventArgs(percent, i, count));
                            oldPercent = percent;
                        }
                    }

                    patchIndex++;
                    i++;
                }
            }

            oldIndex.Close();

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

            if (StatusChange != null)
                StatusChange(this, new StatusChangeEventArgs(String.Format("Moving temp mul/idx file(s)...")));

            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));

            if (this.StatusChange != null)
                this.StatusChange(this, new StatusChangeEventArgs(string.Format("Cleaning up...", new object[0])));

            File.Delete(newIdxPath);
            File.Delete(newMulPath);*/
            #endregion
        }