示例#1
0
        private bool RenameItems(List <PatchRenamedItem> items)
        {
            string rootPath = comms.SelfPatching ? comms.DecompressedFilesPath : comms.RootPath;

            for (int i = 0; i < items.Count; i++)
            {
                if (comms.Cancel)
                {
                    return(false);
                }

                string fromAbsolutePath = rootPath + items[i].BeforePath;
                string toAbsolutePath   = rootPath + items[i].AfterPath;
                if (File.Exists(fromAbsolutePath))
                {
                    PatchUtils.MoveFile(fromAbsolutePath, toAbsolutePath);
                }
                else if (Directory.Exists(fromAbsolutePath))
                {
                    PatchUtils.MoveDirectory(fromAbsolutePath, toAbsolutePath);
                }
            }

            return(true);
        }
示例#2
0
        public static void CalculateDelta(string sourcePath, string targetPath, string deltaPath, int quality = 3, FilePatchProgress progressReporter = null)
        {
            // Try different chunk sizes to find the smallest diff file
            if (quality < 1)
            {
                quality = 1;
            }

            int[] chunkSizes = new int[quality * 2 - 1];
            chunkSizes[0] = SignatureBuilder.DefaultChunkSize;

            int validChunkSizes  = 1;
            int currentChunkSize = chunkSizes[0];

            for (int i = 1; i < quality; i++)
            {
                currentChunkSize /= 2;
                if (currentChunkSize < SignatureBuilder.MinimumChunkSize)
                {
                    break;
                }

                chunkSizes[validChunkSizes++] = currentChunkSize;
            }

            currentChunkSize = chunkSizes[0];
            for (int i = 1; i < quality; i++)
            {
                currentChunkSize *= 2;
                if (currentChunkSize > SignatureBuilder.MaximumChunkSize)
                {
                    break;
                }

                chunkSizes[validChunkSizes++] = currentChunkSize;
            }

            string deltaPathTemp     = deltaPath + ".detmp";
            string signaturePathTemp = deltaPath + ".sgtmp";
            long   deltaSize         = 0L;

            for (int i = 0; i < validChunkSizes; i++)
            {
                if (i == 0)
                {
                    CalculateDeltaInternal(sourcePath, targetPath, deltaPath, signaturePathTemp, chunkSizes[i], progressReporter);
                    deltaSize = new FileInfo(deltaPath).Length;
                }
                else
                {
                    CalculateDeltaInternal(sourcePath, targetPath, deltaPathTemp, signaturePathTemp, chunkSizes[i], progressReporter);

                    long newDeltaSize = new FileInfo(deltaPathTemp).Length;
                    if (newDeltaSize < deltaSize)
                    {
                        PatchUtils.MoveFile(deltaPathTemp, deltaPath);
                        deltaSize = newDeltaSize;
                    }
                }
            }

            File.Delete(deltaPathTemp);
            File.Delete(signaturePathTemp);
        }