コード例 #1
0
        private async Task BuildFilePatchAction(FilePatchInstruction instruction, string targetFilePath, Action <IFilePatchAction> callback)
        {
            string installedHash = await SHA256.GetFileHashAsync(targetFilePath);

            bool isOld = installedHash == instruction.OldHash;
            bool isNew = installedHash == instruction.NewHash;

            if (!isNew)
            {
                bool needsBackup = !isOld && installedHash != null;
                if (instruction.NewHash == null)
                {
                    callback(new RemoveAction(this, instruction.Path, needsBackup));
                }
                else if (isOld && instruction.HasDelta)
                {
                    string deltaFileName = Path.Combine("delta", instruction.NewHash + "_from_" + instruction.OldHash);
                    callback(new DeltaPatchAction(this, instruction.Path, deltaFileName, instruction.DeltaSize, instruction.DeltaHash));
                }
                else
                {
                    string fullFileName = Path.Combine("full", instruction.NewHash);
                    callback(new FullReplaceAction(this, instruction.Path, fullFileName, needsBackup, instruction.FullReplaceSize, instruction.CompressedHash));
                }
            }

            if (instruction.NewHash != null)
            {
                callback(new ModifiedTimeReplaceAction(this, instruction.Path, instruction.NewLastWriteTime));
            }
        }
コード例 #2
0
        private async Task BuildFilePatchAction(FilePatchInstruction instruction, string targetFilePath, Action <IFilePatchAction> callback)
        {
            string installedHash = await Sha256.GetFileHashAsync(targetFilePath);

            bool isOld = installedHash == instruction.OldHash;

            instruction.isActive = true;

            // Patch file only if it is different from the new version
            if (installedHash != instruction.NewHash)
            {
                // Backup any existing files that don't match the old hash
                bool needsBackup = !isOld && installedHash != null;

                if (instruction.NewHash == null)
                {
                    // File deleted
                    callback(new RemoveAction(this, instruction.Path, needsBackup));
                }
                else if (isOld && instruction.HasDelta)
                {
                    // Incremental update
                    string deltaFileName = Path.Combine("delta", instruction.NewHash + "_from_" + instruction.OldHash);
                    callback(new DeltaPatchAction(this, instruction.Path, deltaFileName, instruction.DeltaSize, instruction.DeltaHash));
                }
                else
                {
                    // Full download
                    string fullFileName = Path.Combine("full", instruction.NewHash);
                    callback(new FullReplaceAction(this, instruction.Path, fullFileName, needsBackup, instruction.FullReplaceSize, instruction.CompressedHash));
                }
            }

            // Update LastWriteTime
            if (instruction.NewHash != null)
            {
                callback(new ModifiedTimeReplaceAction(this, instruction.Path, instruction.NewLastWriteTime));
            }
        }