static void ConvertJunction(string dir) { string from = JunctionPoint.GetTarget(dir); if (from != "") { string target = from.TrimEnd('\\'); try { File.Copy(target, dir + "-junction", true); Directory.Delete(dir); File.Move(dir + "-junction", dir); Console.WriteLine("Created " + dir); } catch (ArgumentException ex) { Console.WriteLine(""); Console.WriteLine("Conversion of " + target + " -> " + dir + " failed: " + ex.ToString()); Console.WriteLine(""); } catch (IOException ioex) { Console.WriteLine(""); Console.WriteLine("Conversion of " + target + " -> " + dir + " failed (IO): " + ioex.ToString()); Console.WriteLine(""); } } else { Console.WriteLine("No target for " + dir); } }
public Item(FileSystemInfo info) { Info = info; if (info.IsReparsePoint()) { if (JunctionPoint.Exists(info.FullName)) { Type = ItemType.Junction; var reparse = JunctionPoint.GetTarget(info.FullName); LinkTarget = reparse.SubstituteName; PrintName = reparse.PrintName; } else { Type = info is FileInfo ? ItemType.FileSymlink : info is DirectoryInfo ? ItemType.DirSymlink : throw new Exception("unreachable 27117"); LinkTarget = File.GetLinkTargetInfo(info.FullName).PrintName; // this should throw for reparse points of unknown types (ie neither junction nor symlink) } } else if (info is FileInfo) { Type = ItemType.File; } else if (info is DirectoryInfo) { Type = ItemType.Dir; } else { throw new Exception("unreachable 61374"); } }
public void GetTarget_CalledOnAFile() { File.Create(Path.Combine(tempFolder, "AFile")).Close(); Assert.Throws <IOException>(() => JunctionPoint.GetTarget(Path.Combine(tempFolder, "AFile")), "Path is not a junction point."); }
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 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 GameFolder([NotNull] DirectoryInfo directory, PauseToken pauseToken) { DirectoryInfo = directory; PauseToken = pauseToken; IsJunction = JunctionPoint.Exists(directory); if (IsJunction) { Size = JUNCTION_POINT_SIZE; JunctionTarget = JunctionPoint.GetTarget(directory); } UpdatePropertiesFromSubdirectoriesAsync().Forget(); }
public TransferForm(string arg) { InitializeComponent(); //Select the confirm button by default ActiveControl = confirmButton; origin = arg; //Get any junctions that point to the folder being moved, and save where they were moved from if they exist SQLiteDataReader reader = SQLiteManager.ExecuteSQLiteCommand("SELECT origin, target FROM junctions WHERE target = '" + origin + "';"); string databaseOrigin = null; if (reader.Read()) { databaseOrigin = reader.GetString(reader.GetOrdinal("origin")); } reader.Close(); SQLiteManager.CloseConnection(); if (!JunctionPoint.Exists(origin)) { //If the directory given is not a junction and is registered in the database... if (databaseOrigin != null) { //Hide some elements to just show a message instead of getting input from the user junctionArg = true; destinationInput.Visible = false; browseButton.Visible = false; //Assign the variables their proper values target = origin; origin = databaseOrigin; //Give the user a message that this folder has been moved by this app, and ask if they want to move it back label1.Text = target + " is already moved from " + origin + "! Would you like to move it back?"; } else { //If the directory given is not a junction and isn't registered in the database... //Leave the window in its standard move with junction state, and put the last used location as the default junctionArg = false; destinationInput.Text = Program.GetLastStorage() + "\\" + new DirectoryInfo(origin).Name; } } else { //if the directory given is a junction //Hide some elements to just show a message instead of getting input from the user junctionArg = true; destinationInput.Visible = false; browseButton.Visible = false; //Get the directory the junction is pointing to and ask the user if he would like to move that folder back target = JunctionPoint.GetTarget(origin); label1.Text = "Move " + target + " back to its original location at " + origin + "?"; } }
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 bool DoFoldersPointToSameJunctionPoint(string path1, string path2) { var current = Directory.GetCurrentDirectory(); path1 = Path.Combine(current, path1); path2 = Path.Combine(current, path2); var realPath1 = JunctionPoint.GetTarget(path1); var realPath2 = JunctionPoint.GetTarget(path2); if (realPath1 == null && realPath2 == null) { return(false); } return(path1 == realPath2 || path2 == realPath1); }
private void button2_Click(object sender, EventArgs e) { if (junctionPathBox.Text.Length == 0) { ActiveControl = junctionPathBox; System.Media.SystemSounds.Exclamation.Play(); } else { string origin = junctionPathBox.Text; if (JunctionPoint.Exists(origin)) { string target = JunctionPoint.GetTarget(origin); SQLiteManager.AddJunction(origin, target); Close(); } } }
/// <summary> /// /// </summary> /// <param name="folder"></param> /// <returns></returns> static bool HasDlcInstalled(string folder) { if (Directory.Exists(Path.Combine(new[] { folder, "mlc01", "usr", "title" }))) { string dest = JunctionPoint.GetTarget(Path.Combine(new[] { folder, "mlc01", "usr", "title" })); if (dest != null) { if (!Directory.Exists(dest)) { return(true); } } if (Directory.EnumerateDirectories(Path.Combine(new[] { folder, "mlc01", "usr", "title" })).Any()) { return(true); } } return(false); }
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)); }
/// <summary> /// /// </summary> /// <param name="model"></param> internal static void UpdateFeaturesForInstalledVersions(Model.Model model) { foreach (var version in model.Settings.InstalledVersions) { version.HasFonts = HasFontsInstalled(version.Folder); version.HasOnlineFiles = HasOnlineFiles(version.Folder); version.HasCemuHook = HasCemuHookInstalled(version.Folder); version.HasPatch = HasPatchInstalled(version.Folder); version.HasDlc = HasDlcInstalled(version.Folder); version.HasControllerProfiles = HasControllerProfiles(version.Folder); if (version.HasDlc) { version.DlcSource = JunctionPoint.GetTarget(Path.Combine(version.Folder, "mlc01", "usr", "title")); if (JunctionPoint.Exists(Path.Combine(version.Folder, "mlc01", "usr", "title"))) { if (Directory.Exists(version.DlcSource)) { version.DlcType = 2; } else { version.DlcType = 3; } } else { version.DlcType = 1; } } else { version.DlcType = 0; version.DlcSource = ""; } if (version.Version.StartsWith("cemu")) { version.Version = version.Name.Replace("cemu_", "").Replace("a", "").Replace("b", "").Replace("c", "").Replace("d", "").Replace("e", "").Replace("f", "").Replace("g", ""); } } }
public void GetTargetTest() { TestHelper.Init(); var d = SetFor(LinkType.D); var td = JunctionPoint.GetTarget(d); // target2 - also folder var rd = JunctionPoint.GetTarget(target2); var ed = FS.ExistsDirectory(d); var j = SetFor(LinkType.J); var tj = JunctionPoint.GetTarget(j); //var rj = JunctionPoint.GetTarget(target); var ej = FS.ExistsDirectory(j); SetFor(LinkType.H); var h = SetFor(LinkType.H); var th = JunctionPoint.GetTarget(h); var rh = JunctionPoint.GetTarget(target); var eh = FS.ExistsDirectory(h); }
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); } } }
protected override void ProcessRecord() { WriteObject(JunctionPoint.GetTarget(path)); }
public void GetTarget_NonExistentJunctionPoint() { JunctionPoint.GetTarget(Path.Combine(tempFolder, "SymLink")); }
public void GetTarget_CalledOnADirectoryThatIsNotAJunctionPoint() { JunctionPoint.GetTarget(tempFolder); }
public void GetTarget_CalledOnAFile() { File.Create(Path.Combine(tempFolder, "AFile")).Close(); JunctionPoint.GetTarget(Path.Combine(tempFolder, "AFile")); }
static void MakeJunction(string solution, string junctionsRoot, string path, bool preserveRelative) { string targetPath; string binRelative; if (preserveRelative) { string relativePath = MakeRelativePath(solution, path); targetPath = Path.Combine(junctionsRoot, relativePath); binRelative = null; } else { targetPath = junctionsRoot; //path = ReduceToBinFolder(path, out binRelative); } bool correctJunctionExists = false; if (Directory.Exists(path)) { if (JunctionPoint.Exists(path)) { string existingTarget = JunctionPoint.GetTarget(path); if (existingTarget == targetPath) { correctJunctionExists = true; } else { return; } } else if (IsDirectoryEmpty(path)) { Directory.Delete(path, true); } } string parentPath = Path.GetDirectoryName(path); if (!Directory.Exists(parentPath)) { Directory.CreateDirectory(parentPath); } Directory.CreateDirectory(targetPath); if (correctJunctionExists) { return; } try { JunctionPoint.Create(path, targetPath, false); } catch { Console.WriteLine("FAILED junction:"); Console.WriteLine(" from " + path); Console.WriteLine(" to " + targetPath); } //if (binRelative != null) //MakeJunction(null, targetPath, Path.Combine(targetPath, binRelative), false); }
public string GetLinkTarget(DirectoryInfo directoryInfo) { string result = JunctionPoint.GetTarget(directoryInfo.FullName); return(result); }
public void GetFolderStructure(Profile input) { //numberOfCalls++; LinkedFolders.Clear(); StorableFolders.Clear(); UnlinkedFolders.Clear(); DuplicateFolders.Clear(); List <string> dGFolders = new List <string>(); List <DirectoryInfo> gFolders = new List <DirectoryInfo>(); gFolders.AddRange(input.GameFolder.GetDirectories()); List <DirectoryInfo> sFolders = new List <DirectoryInfo>(); sFolders.AddRange(input.StorageFolder.GetDirectories()); List <DirectoryInfo> _gFolders = new List <DirectoryInfo>(); List <DirectoryInfo> _uFolders = new List <DirectoryInfo>(); List <DirectoryInfo> _lFolders = new List <DirectoryInfo>(); foreach (DirectoryInfo g in gFolders) { try { bool isJunction = JunctionPoint.Exists(@g.FullName); if (isJunction) { this.LinkedFolders.Add(new DirectoryInfo(JunctionPoint.GetTarget(@g.FullName))); } else { this.StorableFolders.Add(new DirectoryInfo(g.FullName)); _gFolders.Add(g); dGFolders.Add(g.Name); } } catch (IOException ex) { MessageBox.Show(ex.Message); } } List <string> dSFolders = new List <string>(); List <DirectoryInfo> tmpList1 = sFolders.Where(n => LinkedFolders.Select(m => m.FullName).Contains(n.FullName) && !JunctionPoint.Exists(@n.FullName)).ToList(); this.LinkedFolders.Clear(); foreach (DirectoryInfo d in tmpList1) { this.LinkedFolders.Add(d); _lFolders.Add(d); dSFolders.Add(d.Name); } List <DirectoryInfo> tmpList = sFolders.Where(n => !LinkedFolders.Select(m => m.FullName).Contains(n.FullName) && !JunctionPoint.Exists(@n.FullName)).ToList(); foreach (DirectoryInfo d in tmpList) { this.UnlinkedFolders.Add(d); _uFolders.Add(d); dSFolders.Add(d.Name); } DuplicateFolders = dGFolders.Intersect(dSFolders).ToList(); _gFolders.RemoveAll(n => DuplicateFolders.Contains(n.Name)); _uFolders.RemoveAll(n => DuplicateFolders.Contains(n.Name)); _lFolders.RemoveAll(n => DuplicateFolders.Contains(n.Name)); this.StorableFolders = _gFolders; this.UnlinkedFolders = _uFolders; this.LinkedFolders = _lFolders; }
private void refreshDataGrid() { SQLiteDataReader reader = SQLiteManager.ExecuteSQLiteCommand("SELECT * FROM junctions;"); List <string> sqlCommandQueue = new List <string>(); while (reader.Read()) { string origin = reader.GetString(reader.GetOrdinal("origin")); string target = reader.GetString(reader.GetOrdinal("target")); if (!JunctionPoint.Exists(origin)) { if (Directory.Exists(origin)) { MessageBox.Show("The junction at " + origin + " that pointed to " + target + " has been replaced by a folder by the same name. If you moved the folder back yourself this is fine, otherwise you might wanna look into this", "Junction is now a folder", MessageBoxButtons.OK); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " replaced by a folder with the same name"); continue; } else { MessageBox.Show("The junction at " + origin + " that pointed to " + target + " is not there, it could have been moved or deleted.", "Missing junction", MessageBoxButtons.OK); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: Junction at " + origin + " that pointed to " + target + " missing"); continue; } } string realTarget = JunctionPoint.GetTarget(origin); if (realTarget != target) { MessageBox.Show("The junction at " + origin + " has changed targets from " + target + " to " + realTarget + ".", "Moved junction target", MessageBoxButtons.OK); sqlCommandQueue.Add("UPDATE junctions SET target = '" + realTarget + "' WHERE origin = '" + origin + "';"); target = realTarget; Program.Log("WARNING: Junction at " + origin + " is now pointing to " + realTarget + ", was pointing to " + target); } if (!Directory.Exists(realTarget)) { MessageBox.Show("The folder at " + target + " is missing, the junction " + origin + " pointed to it.", "Folder missing", MessageBoxButtons.OK); JunctionPoint.Delete(origin); sqlCommandQueue.Add("DELETE FROM junctions WHERE origin = '" + origin + "';"); Program.Log("WARNING: " + target + " is missing, pointed to by junction at " + origin); } } SQLiteManager.CloseConnection(); foreach (string s in sqlCommandQueue) { SQLiteManager.ExecuteSQLiteCommand(s); SQLiteManager.CloseConnection(); } SQLiteManager.CloseConnection(); //Create a DataSet object DataSet dataSet = new DataSet(); //Get the adapter for the grid view, which will contain every junction in the table SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM junctions;", SQLiteManager.GetSQLiteConnection()); dataAdapter.Fill(dataSet); //Fill the view with the dataset dataGridView1.DataSource = dataSet.Tables[0].DefaultView; //Close the connection SQLiteManager.CloseConnection(); if (dataGridView1.Rows.Count == 0) { restoreButton.Enabled = false; moveButton.Enabled = false; } else { restoreButton.Enabled = true; moveButton.Enabled = true; } }
public static bool MoveStorageToSource(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 { /// find a junction, which has a different name, than the folder to be moved List <string> ListOfJunctions = prof.Source.GetDirectories().Select(dir => dir.FullName).ToList().Where(str => JunctionPoint.Exists(@str)).ToList(); List <string> ListOfTargets = ListOfJunctions.Select(str => JunctionPoint.GetTarget(@str)).ToList(); List <Tuple <string, string> > pairsOfJaT = new List <Tuple <string, string> >(); for (int i = 0; i < ListOfJunctions.Count; i++) { string JunctionName = (new DirectoryInfo(ListOfJunctions[i])).Name; string TargetName = (new DirectoryInfo(ListOfTargets[i])).Name; if (JunctionName != TargetName) { pairsOfJaT.Add(new Tuple <string, string>(JunctionName, TargetName)); } } string renamedJunction = null; if (pairsOfJaT.Count > 0) { renamedJunction = pairsOfJaT.FirstOrDefault(str => str.Item2 == prof.Source.Name).Item1; } if (renamedJunction != null) { renamedJunction = prof.Target.Parent + @"\" + renamedJunction; } if (JunctionPoint.Exists(@targetDir)) { JunctionPoint.Delete(@targetDir); returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); } else if (JunctionPoint.Exists(@renamedJunction)) { JunctionPoint.Delete(@renamedJunction); returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); } if (returnStatus == true) { DirectoryInfo deletableDirInfo = prof.Source; deletableDirInfo.Delete(true); } } catch (Exception exp) { MessageBox.Show(exp.Message); } Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " finished with " + returnStatus); return(returnStatus); }
public void GetTarget_NonExistentJunctionPoint() => Assert.Throws <IOException>(() => JunctionPoint.GetTarget(this.tempFolder.Combine("SymLink")), "Unable to open reparse point.");
public void GetTarget_CalledOnADirectoryThatIsNotAJunctionPoint() => Assert.Throws <IOException>(() => JunctionPoint.GetTarget(this.tempFolder), "Path is not a junction point.");