public void ShouldCreateJunctionPoint() { var path = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Path.GetRandomFileName()); Directory.CreateDirectory(path); var file = Path.Combine(path, "file.txt"); using (File.Create(file)) { } var junctionPath = string.Format("{0}+junction", path); JunctionPoint.Create(junctionPath, path, true); var junctionFiles = Directory.GetFiles(junctionPath); Assert.That(junctionFiles.Length, Is.EqualTo(1)); Assert.That(junctionFiles[0], Is.EqualTo(Path.Combine(junctionPath, "file.txt"))); JunctionPoint.Delete(junctionPath); Assert.That(Directory.Exists(junctionPath), Is.False); Assert.That(File.Exists(file), Is.True); }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { var targetFolder = this.tempFolder.Combine("ADirectory"); var junctionPoint = this.tempFolder.Combine("SymLink"); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Target path does not exist or is not a directory."); }
public static bool MoveSourceToStorage(Assignment prof, IProgress <long> sizeFromHell, object _lock, CancellationToken ct) { string sourceDir = prof.Source.FullName; string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name; Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " started"); bool returnStatus = false; try { returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); if (returnStatus == false) { return(returnStatus); } else { DirectoryInfo deletableDirInfo = prof.Source; deletableDirInfo.Delete(true); Console.WriteLine("Deleted " + sourceDir); if (!AnalyzeFolders.ExistsAsDirectory(sourceDir)) { JunctionPoint.Create(@sourceDir, @targetDir, false); Console.WriteLine("Created Link"); } } } catch (Exception exp) { MessageBox.Show(exp.Message); } Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " finished with " + returnStatus); return(returnStatus); }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); JunctionPoint.Create(junctionPoint, targetFolder, false); }
private void createButton_Click(object sender, EventArgs e) { string origin = junctionTextBox.Text; string target = targetTextBox.Text; if (origin.Length == 0) { ActiveControl = junctionTextBox; System.Media.SystemSounds.Exclamation.Play(); return; } else if (target.Length == 0) { ActiveControl = targetTextBox; System.Media.SystemSounds.Exclamation.Play(); return; } if (!Directory.Exists(target)) { DialogResult recursionCaution = MessageBox.Show("There is no folder at " + target + ", please select a folder that the junction can target", "Folder doesn't exist", MessageBoxButtons.OK); } DialogResult confirmDialog = MessageBox.Show("Are you sure you want to create a junction at " + origin + " that links to " + target + "?", "Confirmation", MessageBoxButtons.YesNo); if (confirmDialog == DialogResult.No) { return; } JunctionPoint.Create(origin, target, true); SQLiteManager.AddJunction(origin, target); }
public void TestDeleteDirectory_JunctionPoint() { var targetFolder = rootTestDir.Combine("ADirectory"); var junctionPoint = rootTestDir.Combine("SymLink"); targetFolder.CreateDirectory(); try { var targetFile = targetFolder.Combine("AFile"); File.Create(targetFile).Close(); try { JunctionPoint.Create(junctionPoint, targetFolder, overwrite: false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsTrue(File.Exists(junctionPoint.Combine("AFile")), "File should be accessible via the junction point."); Directory.Delete(junctionPoint, false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point should not exist now."); Assert.IsTrue(!File.Exists(junctionPoint.Combine("AFile")), "File should not be accessible via the junction point."); } finally { File.Delete(targetFile); } } finally { Directory.Delete(targetFolder); } }
public static bool LinkStorageToSource(Assignment prof) { bool returnStatus = false; try { string sourceDir = prof.Source.FullName; string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name; if (!AnalyzeFolders.ExistsAsDirectory(targetDir)) { JunctionPoint.Create(@targetDir, @sourceDir, false); returnStatus = true; } else { returnStatus = false; } } catch (Exception exp) { MessageBox.Show(exp.Message); returnStatus = false; } return(returnStatus); }
protected override void ProcessRecord() { if (ShouldProcess("Creating link from {0} to {1}")) { JunctionPoint.Create(sourcePath, destinationPath, overwrite); } }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Target path does not exist or is not a directory."); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(junctionPoint); JunctionPoint.Create(junctionPoint, targetFolder, false); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { var targetFolder = this.tempFolder.Combine("ADirectory"); var junctionPoint = this.tempFolder.Combine("SymLink"); junctionPoint.CreateDirectory(); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Directory already exists and overwrite parameter is false."); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(junctionPoint); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Directory already exists and overwrite parameter is false."); }
public override Directory LinkTo(Path path) { if (!Exists()) { throw new System.IO.IOException("Source path does not exist or is not a directory."); } JunctionPoint.Create(GetDirectory(path.FullPath), Path.FullPath, true); return(new Win32Directory(path)); }
public void ShouldGetTargetPathForJunction() { var path = IOPath.Combine(Environment.GetEnvironmentVariable("TEMP"), IOPath.GetRandomFileName()); Directory.CreateDirectory(path); var junctionPath = string.Format("{0}+junction", path); JunctionPoint.Create(junctionPath, path, true); Assert.That(ReparsePoint.GetTarget(junctionPath), Is.EqualTo(path)); }
public static bool CreateDirectory(string target, string source) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { JunctionPoint.Create(target, source, true); } else { LostTech.IO.Links.Symlink.CreateForDirectory(source, target); } return(Directory.Exists(target)); }
public void Create_OverwritesIfSpecifiedAndDirectoryExists() { var targetFolder = this.tempFolder.Combine("ADirectory"); var junctionPoint = this.tempFolder.Combine("SymLink"); junctionPoint.CreateDirectory(); targetFolder.CreateDirectory(); JunctionPoint.Create(junctionPoint, targetFolder, true); Assert.AreEqual(targetFolder, JunctionPoint.GetTarget(junctionPoint)); }
public static void MoveWithJunction(string origin, string target) { //Copy folder and delete the original folder (essentially a move" Program.CopyFolder(origin, target); Directory.Delete(origin, true); Program.Log("INFO: Moved " + origin + " to " + target); //Create a junction at the original location pointing to the new location JunctionPoint.Create(origin, target, true); //Update the SQLite database with the new junction created SQLiteManager.AddJunction(origin, target); }
public void Create_OverwritesIfSpecifiedAndDirectoryExists() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(junctionPoint); Directory.CreateDirectory(targetFolder); JunctionPoint.Create(junctionPoint, targetFolder, true); Assert.AreEqual(targetFolder, JunctionPoint.GetTarget(junctionPoint)); }
public void CreateHardLink(string existingPath, string newPath) { if (Directory.Exists(newPath)) { if (Directory.GetFiles(newPath, "*.*").Length > 0) { throw new ArgumentOutOfRangeException("newPath", "Folder still has files in it!"); } Directory.Delete(newPath, false); } JunctionPoint.Create(newPath, existingPath, false); }
/// <summary> /// Makes a junction point that links the target path to the target directory. /// </summary> /// <param name="SourceDirectory">Source directory to target.</param> /// <param name="TargetDirectory">Target directory which should link to source.</param> /// <returns>True on success.</returns> public static bool CreateJunction(string SourceDirectory, string TargetDirectory) { Logger.Log(LogLevel.Info, LogCategory.Script, "Creating symlink from '{0}' to '{1}'.", SourceDirectory, TargetDirectory); try { JunctionPoint.Create(TargetDirectory, SourceDirectory, true); } catch (Exception Ex) { Logger.Log(LogLevel.Error, LogCategory.Script, "Failed to create symlink with error: {0}", Ex.Message.ToString()); return(false); } return(true); }
public void Create_VerifyExists_GetTarget_Delete() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(targetFolder); try { File.Create(Path.Combine(targetFolder, "AFile")).Close(); try { // Verify behavior before junction point created. Assert.IsFalse(File.Exists(Path.Combine(junctionPoint, "AFile")), "File should not be located until junction point created."); Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point not created yet."); // Create junction point and confirm its properties. JunctionPoint.Create(junctionPoint, targetFolder, overwrite: false); Assert.IsTrue(JunctionPoint.Exists(junctionPoint), "Junction point exists now."); Assert.AreEqual(targetFolder, JunctionPoint.GetTarget(junctionPoint)); Assert.IsTrue(File.Exists(Path.Combine(junctionPoint, "AFile")), "File should be accessible via the junction point."); // Delete junction point. JunctionPoint.Delete(junctionPoint); Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point should not exist now."); Assert.IsFalse(File.Exists(Path.Combine(junctionPoint, "AFile")), "File should not be located after junction point deleted."); Assert.IsFalse(Directory.Exists(junctionPoint), "Ensure directory was deleted too."); } finally { File.Delete(Path.Combine(targetFolder, "AFile")); } } finally { Directory.Delete(targetFolder); } }
public static (DirectoryInfo root, DirectoryInfo source, DirectoryInfo destination) SetupTestData(DirectoryInfo rootDirectoryInfo) { rootDirectoryInfo.Create(); var sourceDirectory = rootDirectoryInfo.CreateSubdirectory("Source"); var destinationDirectory = rootDirectoryInfo.CreateSubdirectory("Destination"); sourceDirectory.GetDirectories().Select(info => info.FullName).ForEach(DeleteDirectoryRecursive); destinationDirectory.GetDirectories().Select(info => info.FullName).ForEach(DeleteDirectoryRecursive); foreach (var capitalLetter in CapitalLetters) { sourceDirectory.CreateSubdirectory(capitalLetter); var name = capitalLetter + capitalLetter; JunctionPoint.Create(sourceDirectory.CreateSubdirectory("1" + name), destinationDirectory.CreateSubdirectory(name), true); } return(rootDirectoryInfo, sourceDirectory, destinationDirectory); }
public void GetTarget() { Helper.DemandTestDriveAvailable(TestDrive); //Helper.DemandElevated(); var testFolder = Helper.GetTestFolder(TestDrive, "WriteTests", this); _fixture = new Fixture(() => Directory.Delete(testFolder, true)); Directory.CreateDirectory(testFolder); var originalFolder = Path.Combine(testFolder, "original"); Directory.CreateDirectory(originalFolder); var junction = Path.Combine(testFolder, "junction"); JunctionPoint.Create(junction, originalFolder, true); Assert.IsTrue(Directory.Exists(junction)); Assert.AreEqual(originalFolder, JunctionPoint.GetTarget(junction)); }
static void InitTestApp() { var testAppPath = Path.Combine(_binPath, "DebugApp"); var testAppAssemblyPath = Path.Combine(_binPath, "DebugApp", TestAppExeName); var versionText = FileVersionInfo.GetVersionInfo(testAppAssemblyPath).FileVersion; var appDeploymentPath = Path.Combine(_stagingPath, "v" + versionText); Directory.CreateDirectory(appDeploymentPath); foreach (var file in Directory.GetFiles(testAppPath)) { var targetFile = Path.Combine(appDeploymentPath, Path.GetFileName(file)); File.Copy(file, targetFile); } if (!JunctionPoint.Exists(_currentAppPath)) { JunctionPoint.Create(_currentAppPath, appDeploymentPath); } Assert.That(Directory.Exists(_currentAppPath)); }
private static void RepairUpdateFolder(Model.Model model, InstalledVersion v) { InstalledVersion dlcSource = GetLatestDlcVersion(model); if (v.VersionNumber < 1110 || model.Settings.MlcFolder == "") { if (!v.HasDlc) { if (dlcSource != null) { try { JunctionPoint.Create(Path.Combine(dlcSource.Folder, "mlc01", "usr", "title"), Path.Combine(v.Folder, "mlc01", "usr", "title"), true); } catch (Exception) { // No code } } } } }
public void CreateTest() { Helper.DemandTestDriveAvailable(TestDrive); //Helper.DemandElevated(); var testFolder = Helper.GetTestFolder(TestDrive, "WriteTests", this); _fixture = new Fixture(() => Directory.Delete(testFolder, true)); Directory.CreateDirectory(testFolder); var originalFolder = Path.Combine(testFolder, "original"); Directory.CreateDirectory(originalFolder); var originalFile = Path.Combine(originalFolder, "original.txt"); File.WriteAllText(originalFile, "Original"); var junction = Path.Combine(testFolder, "junction"); JunctionPoint.Create(junction, originalFolder, true); Assert.AreEqual("Original", File.ReadAllText(Path.Combine(junction, "original.txt"))); }
public void Paste() { var paths = Clipboard.GetFileDropList(); foreach (string path in paths) { DirectoryInfo dir = new DirectoryInfo(path); DirectoryInfo ddir = new DirectoryInfo(Environment.CurrentDirectory + "\\" + dir.Name); // 获取path的原始路径 string cur = path; string next = path; do { cur = next; next = JunctionPoint.GetTarget(next); } while (next != null); if (cur != path) { dir = new DirectoryInfo(cur); } if (dir.Exists) { if (ddir.Exists) { if (MessageBox.Show(dir.Name + "已经存在,是否覆盖?", "提问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != DialogResult.Yes) { continue; } ddir.Delete(true); } JunctionPoint.Create(ddir.FullName, dir.FullName, true); } } }
public static void TestCreateJunctionPoint() { var rootDir = Environment.CurrentDirectory; var folderToJunction = Path.Combine(rootDir, "TestFolder"); var junctionFolder = Path.Combine(rootDir, "TestJunctionFolder"); if (Directory.Exists(folderToJunction)) { Directory.Delete(folderToJunction, true); } if (Directory.Exists(junctionFolder)) { Directory.Delete(junctionFolder); } Directory.CreateDirectory(folderToJunction); File.WriteAllText(Path.Combine(folderToJunction, "TestFile.txt"), "Test file"); JunctionPoint.Create(junctionFolder, folderToJunction); Assert.That(Directory.Exists(junctionFolder), "Junction not created"); Assert.That(File.Exists(Path.Combine(junctionFolder, "TestFile.txt")), "File not found in junction"); }
static int Main(string[] args) { string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().FullName); string mappingsFile = Path.Combine(currentDirectory, "mappings.txt"); string lastGameModeFile = Path.Combine(currentDirectory, "lastGameMode.bin"); // create missing files if (!File.Exists(mappingsFile)) { using (var writer = File.CreateText(mappingsFile)) { writer.Write(@"################################################################################################################ # whitespace characters (space, tab, ...) and equal sign (=) all count as separators. # 1st word is the name of folder (usually gamemode prefix) containing paks for this gamemode. # all other words in the line are names for this gamemode (case insensitive). # all names have to be unique. if not, they are ignored. # whitespace in gamemode's name entered from input or as argument in UTPreparePaks.exe is not accounted for # # example: you enter ""CaP t ure the fLA G, bt"" it will be changed to ""CaPturethefLAG, bt"" # this string will then be compared to all names in this file (case insensitive) # and then junctions to CTF and BT directory will be created in target directory ################################################################################################################ # lastGameMode.bin contains which gamemodes were last set for every target directory # file is litle bit encrypted so that users wouldnt edit its content and potentially # make it so that some unwanted junctions would not be deleted when no longer needed ################################################################################################################ AS = AS Assault BR = BR BombingRun BT = BT BunnyTrack CTF = CTF CaptureTheFlag CaptureFlag DM = DM Deathmatch Duel = Duel 1v1 pvp Elim = Elim Elimination FR = FR FlagRun Blitz KO = KO Knockout" ); } } if (!File.Exists(lastGameModeFile)) { File.Create(lastGameModeFile).Close(); } // get target directory and gameModePrefix string targetDirectory = null; List <string> selectedGameModeNames = null; if (args.Length > 0) { targetDirectory = Path.GetFullPath(args[0]); if (args.Length > 1) { selectedGameModeNames = new List <string>(args[1].Replace(" ", "").ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } else { Console.Write("Enter one or more gamemode names (comma separated): "); selectedGameModeNames = new List <string>(Console.ReadLine().Replace(" ", "").ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } var lastGameModeTargets = ParseLastGameModesFile(lastGameModeFile); var mappings = ParseMappingsFile(mappingsFile); var selectedGameModes = new List <string>(); // get selected gamemodes foreach (var selectedGameModeName in selectedGameModeNames) { if (mappings.TryGetValue(selectedGameModeName, out string selectedGameMode)) { selectedGameModes.Add(selectedGameMode); } else { Console.WriteLine($"No mapping defined for '{selectedGameModeName}'. skipped."); } } // get games modes used last time if (lastGameModeTargets.TryGetValue(targetDirectory, out List <string> lastGameModes)) { // go through every gamemode from last time foreach (var lastGameMode in lastGameModes) { string lastJunctionDestination = Path.Combine(targetDirectory, lastGameMode); if (!selectedGameModes.Contains(lastGameMode) && JunctionPoint.Exists(lastJunctionDestination)) // if supposed to delete and exists { JunctionPoint.Delete(lastJunctionDestination); // delete } } } // go through every selected gamemode foreach (var selectedGameMode in selectedGameModes) { string junctionSource = Path.Combine(currentDirectory, selectedGameMode); string junctionDestination = Path.Combine(targetDirectory, selectedGameMode); if (!Directory.Exists(junctionSource)) // directory on which junction will point doesnt exist yet { Directory.CreateDirectory(junctionSource); // make that directory } JunctionPoint.Create(junctionDestination, junctionSource, true); // finally create junction from targetDirectory to out gamemode directory } lastGameModeTargets[targetDirectory] = selectedGameModes; // sets which gamemodes were set this time WriteLastGameModes(lastGameModeFile, lastGameModeTargets); // save used gamemodes } else { Console.WriteLine("UTPreparePaks <TargetDirectory> [GameModeName]"); return(1); } return(0); }
private void buttonOK_Click(object sender, EventArgs e) { if (radioHardLink.Checked) { FileInfo fiToHL = new FileInfo(textLinkTo.Text); DirectoryInfo diFmHL = new DirectoryInfo(textLinkFrom.Text); FileInfo fiFmHL = new FileInfo(textLinkFrom.Text); if (!fiToHL.Exists) { MessageBox.Show(I18N.GetString("Target file not exist!")); return; } if (diFmHL.Exists) { MessageBox.Show(I18N.GetString("Only file can create hard link!")); return; } if (fiFmHL.Exists) { MessageBox.Show(I18N.GetString(diFmHL.Name + " exist!")); return; } if (fiFmHL.Directory.Root.Name.ToLower().Equals(fiToHL.Directory.Root.Name.ToLower())) { bool success = CreateHardLink(fiFmHL.FullName, fiToHL.FullName, IntPtr.Zero); if (!success) { MessageBox.Show(I18N.GetString("Create Failed!")); return; } } else { MessageBox.Show(I18N.GetString("Must create hard link in same drive!")); return; } } else if (radioSymbolLink.Checked) { FileInfo fiToSL = new FileInfo(textLinkTo.Text); DirectoryInfo diFmSL = new DirectoryInfo(textLinkFrom.Text); FileInfo fiFmSL = new FileInfo(textLinkFrom.Text); if (!fiToSL.Exists) { MessageBox.Show(I18N.GetString("Target file not exist!")); return; } if (diFmSL.Exists) { MessageBox.Show(I18N.GetString("Only file can create hard link!")); return; } if (fiFmSL.Exists) { MessageBox.Show(I18N.GetString(diFmSL.Name + " exist!")); return; } //TODO: How to process UAC to create symboliclink bool success = CreateSymbolicLink(fiFmSL.FullName, fiToSL.FullName, 0); if (!success) { MessageBox.Show(I18N.GetString("Create Failed!")); return; } } else if (radioDirSymbolLink.Checked) { DirectoryInfo diToDSL = new DirectoryInfo(textLinkTo.Text); FileInfo fiFmDSL = new FileInfo(textLinkFrom.Text); DirectoryInfo diFmDSL = new DirectoryInfo(textLinkFrom.Text); if (!diToDSL.Exists) { MessageBox.Show(I18N.GetString("Target directory not exist!")); return; } if (fiFmDSL.Exists) { MessageBox.Show(I18N.GetString("Only directory can create directory symbol link!")); return; } if (diFmDSL.Exists) { MessageBox.Show(I18N.GetString(diFmDSL.Name + " exist!")); return; } //TODO: How to process UAC to create symboliclink bool success = CreateSymbolicLink(diFmDSL.FullName, diToDSL.FullName, 1);//1:dir,0:file if (!success) { MessageBox.Show(I18N.GetString("Create Failed!")); return; } } else if (radioDirJunction.Checked) { DirectoryInfo diToDJ = new DirectoryInfo(textLinkTo.Text); FileInfo fiFmDJ = new FileInfo(textLinkFrom.Text); DirectoryInfo diFmDJ = new DirectoryInfo(textLinkFrom.Text); if (!diToDJ.Exists) { MessageBox.Show(I18N.GetString("Target directory not exist!")); return; } if (fiFmDJ.Exists) { MessageBox.Show(I18N.GetString("Only directory can create directory symbol link!")); return; } if (diFmDJ.Exists) { MessageBox.Show(string.Format(I18N.GetString("{0} exist!")), diFmDJ.Name); return; } bool success = JunctionPoint.Create(diFmDJ.FullName, diToDJ.FullName); if (!success) { MessageBox.Show(I18N.GetString("Create Failed!")); return; } } else { MessageBox.Show(I18N.GetString("Must select one link mode!")); } Dispose(true); }