public void MoveFileFailsWhenUsedByAnotherProcess() { var destinationPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId(), DestinationDirectory = destinationPath }; var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var createdFileStream = File.Create(sourcePath); Assert.IsTrue(File.Exists(sourcePath)); var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, sourcePath)); var result = moveFileAction.Execute(args); Assert.IsNotNull(result); Assert.IsFalse(result.Result); Assert.IsTrue(File.Exists(sourcePath)); createdFileStream.Close(); // Cleanup File.Delete(sourcePath); Assert.IsFalse(File.Exists(sourcePath)); }
public void MoveFileTestSuccess() { var destinationPath = Path.Combine(Path.GetTempPath()); var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId(), DestinationDirectory = destinationPath, DestinationPrefix = "RENAMED" }; var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); using (var file = File.Create(sourcePath)) { } Assert.IsTrue(File.Exists(sourcePath)); Assert.IsFalse(File.Exists(destinationPath)); var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, new List <string>() { sourcePath })); var result = moveFileAction.Execute(args); Assert.IsNotNull(result); Assert.IsTrue(result.Result); Assert.IsFalse(File.Exists(sourcePath)); destinationPath = Path.Combine(destinationPath, $"RENAMED{Path.GetFileName(sourcePath)}"); Assert.IsTrue(File.Exists(destinationPath)); // CleanUp File.Delete(destinationPath); }
public void MoveFileFailsWhenDestinationFileAlreadyExist() { var destinationPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId(), DestinationDirectory = destinationPath }; var filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); using (var sourceFile = File.Create(filePath)) { } using (var destinationFile = File.Create(destinationPath)) { } var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, filePath) ); var result = moveFileAction.Execute(args); Assert.IsNotNull(result); Assert.IsFalse(result.Result); // Clean up File.Delete(filePath); File.Delete(destinationPath); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jObject = JObject.Load(reader); string actionType = (string)jObject["Action"] ?? string.Empty; ModInstallAction item = null; if (actionType.Equals("MoveFile", StringComparison.InvariantCultureIgnoreCase)) { item = new MoveFileAction(); } else if (actionType.Equals("MoveFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new MoveFilesAction(); } else if (actionType.Equals("DeleteFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new DeleteFilesAction(); } else if (actionType.Equals("ReplaceFile", StringComparison.InvariantCultureIgnoreCase)) { item = new ReplaceFileAction(); } else if (actionType.Equals("ReplaceFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new ReplaceFilesAction(); } else if (actionType.Equals("CopyFile", StringComparison.InvariantCultureIgnoreCase)) { item = new CopyFileAction(); } else if (actionType.Equals("CopyFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new CopyFilesAction(); } else if (actionType.Equals("WriteToFile", StringComparison.InvariantCultureIgnoreCase)) { item = new WriteToFileAction(); } else if (actionType.Equals("QuickBMSExtract", StringComparison.InvariantCultureIgnoreCase)) { item = new QuickBMSExtractAction(); } else if (actionType.Equals("UnluacDecompile", StringComparison.InvariantCultureIgnoreCase)) { item = new UnluacDecompileAction(); } else { item = new ModInstallAction(); } serializer.Populate(jObject.CreateReader(), item); return(item); }
public void MoveFileFailsWhenArgumentsNull() { var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId() }; var result = moveFileAction.Execute(null); Assert.IsNotNull(result); Assert.IsFalse(result.Result); }
public void MoveFileFailsWhenMissingArgumentSourcePath() { var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId(), DestinationDirectory = null }; var result = moveFileAction.Execute(null); Assert.IsNotNull(result); Assert.IsFalse(result.Result); }
public void MoveFileFailsWhenMissingArgumentDestinationPath() { var moveFileAction = new MoveFileAction() { Id = PluginUtilities.GetUniqueId() }; var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, "")); var result = moveFileAction.Execute(args); Assert.IsNotNull(result); Assert.IsFalse(result.Result); }
static bool CheckFileMoveAction(MoveFileAction action, List <string> loadErrors) { // Files can only be moved into the game folder if (!ValidGameFilePath(action.DestinationPath)) { loadErrors.Add($"FileMove - {nameof(action.DestinationPath)}: Provided path must be in the [GAME] folder"); return(false); } // Files can only be moved from the game folder if (!ValidGameFilePath(action.TargetFile)) { loadErrors.Add($"FileMove - {nameof(action.TargetFile)}: Provided path must be in the [GAME] folder"); return(false); } return(!string.IsNullOrWhiteSpace(action.TargetFile) && !string.IsNullOrWhiteSpace(action.DestinationPath)); }