public void CreateFile() { var pathOfFileToCreate = "file.jpg"; File.Delete(pathOfFileToCreate); #region CreateFile AllFiles.CreateFile(pathOfFileToCreate); #endregion Assert.True(File.Exists(pathOfFileToCreate)); File.Delete(pathOfFileToCreate); AllFiles.CreateFile("foo.txt", true); Assert.True(File.Exists("foo.txt")); File.Delete("foo.txt"); Assert.True(AllFiles.TryCreateFile(pathOfFileToCreate)); Assert.True(File.Exists(pathOfFileToCreate)); File.Delete(pathOfFileToCreate); Assert.False(AllFiles.TryCreateFile("foo.txt")); Assert.False(File.Exists("foo.txt")); File.Delete("foo.txt"); Assert.True(AllFiles.TryCreateFile("foo.txt", true)); Assert.True(File.Exists("foo.txt")); File.Delete("foo.txt"); }
public void Unknown_extension() { Assert.Throws <Exception>(() => AllFiles.GetPathFor("txt")); Assert.False(AllFiles.TryGetPathFor("txt", out var result)); Assert.Null(result); Assert.False(AllFiles.TryGetPathFor(".txt", out result)); Assert.Null(result); Assert.False(AllFiles.TryCreateFile("foo.txt")); Assert.Null(result); Assert.Throws <Exception>(() => AllFiles.GetPathFor(".txt")); Assert.Throws <Exception>(() => AllFiles.CreateFile("foo.txt")); }
static bool TryCreate(ResolvedTool tool, string targetFile) { var targetExists = File.Exists(targetFile); if (tool.RequiresTarget && !targetExists) { if (!AllFiles.TryCreateFile(targetFile, useEmptyStringForTextFiles: true)) { return(false); } } return(true); }
public static Task <LaunchResult> Launch(ResolvedTool tool, string tempFile, string targetFile) { GuardFiles(tempFile, targetFile); Guard.AgainstNull(tool, nameof(tool)); if (Disabled) { return(Task.FromResult(LaunchResult.Disabled)); } var targetExists = File.Exists(targetFile); if (tool.RequiresTarget && !targetExists) { if (!AllFiles.TryCreateFile(targetFile, useEmptyStringForTextFiles: true)) { return(Task.FromResult(LaunchResult.NoEmptyFileForExtension)); } } return(InnerLaunch(tool, tempFile, targetFile)); }
/// <summary> /// Launch a diff tool for the given paths. /// </summary> public static void Launch(string path1, string path2) { Guard.AgainstNullOrEmpty(path1, nameof(path1)); Guard.AgainstNullOrEmpty(path2, nameof(path2)); var extension = Extensions.GetExtension(path1); if (launchedInstances >= maxInstancesToLaunch) { return; } if (!DiffTools.TryFind(extension, out var diffTool)) { return; } //TODO: throw if both dont exist if (!File.Exists(path1)) { if (!AllFiles.TryCreateFile(path1, true)) { return; } } if (!File.Exists(path2)) { if (!AllFiles.TryCreateFile(path2, true)) { return; } } launchedInstances++; Launch(diffTool, path1, path2); }