private InstallationStatus ReplaceFile(string replacementFile, string targetFile, GameModification mod) { if (ModCollisionTracker.HasReplaceCollision(mod, targetFile, replacementFile, modifications, out var collision)) { return(HandleCollision(collision)); } if (!File.Exists(targetFile)) { throw new Exception($"Unable to find target path: {targetFile}"); } CopyFile_Internal(replacementFile, targetFile, mod); return(InstallationStatus.Success); }
private InstallationStatus WriteToFile(ModAction <WriteToFileAction> modAction) { foreach (var content in modAction.action.Content) { var physicalTargetPath = ResolvePath(modAction.action.TargetFile, modAction.mod, configuration); string filePath = null; if (!File.Exists(physicalTargetPath)) { throw new Exception($"Unable to find target path: {physicalTargetPath}"); } if (!string.IsNullOrEmpty(content.DataFilePath)) { filePath = ResolvePath(content.DataFilePath, modAction.mod, configuration); } var dataToWrite = content.Text ?? File.ReadAllText(filePath); if (ModCollisionTracker.HasEditCollision(modAction.mod, physicalTargetPath, content, fileWriter, modifications, out var collision)) { return(HandleCollision(collision)); } if (IsReservedFile(physicalTargetPath)) { modifications.Add(new EditFileModification(physicalTargetPath, true, modAction.mod.Config.ModID)); BackupFile(physicalTargetPath); } else { modifications.Add(new EditFileModification(physicalTargetPath, false, modAction.mod.Config.ModID)); } if (content.EndOffset.HasValue) { fileWriter.WriteToFileRange(physicalTargetPath, dataToWrite, content.StartOffset, content.EndOffset.Value, false); } else { fileWriter.WriteToFile(physicalTargetPath, dataToWrite, content.StartOffset, !content.Replace, false); } } return(InstallationStatus.Success); }
private InstallationStatus CopyFile(string targetFile, string destinationPath, GameModification mod) { if (ModCollisionTracker.HasCopyCollision(mod, targetFile, destinationPath, modifications, out var collision)) { return(HandleCollision(collision)); } if (!File.Exists(targetFile)) { throw new Exception($"Unable to find target path: {targetFile}"); } // Copying files occurs near the start, and should not cause conflicts CopyFile_Internal(targetFile, destinationPath, mod); return(InstallationStatus.Success); }
private InstallationStatus MoveFile(string targetFile, string destinationPath, GameModification mod) { // Have we already moved this file to the exact same destination? if (HasMovedFileToSameDestination(targetFile, destinationPath)) { return(InstallationStatus.Success); } if (ModCollisionTracker.HasMoveCollision(mod, targetFile, destinationPath, modifications, out var collision)) { return(HandleCollision(collision)); } if (!File.Exists(targetFile)) { throw new Exception($"Unable to find target path: {targetFile}"); } MoveFile_Internal(targetFile, destinationPath, mod); return(InstallationStatus.Success); }