public static void Install(string file, string source, string destinationBase, bool makeCopy = false, bool ignoreMissingFile = false) { var sourcePath = Path.GetFullPath(Path.Combine(source, file)); var destinationPath = Path.GetFullPath(Path.Combine(destinationBase, file)); Directory.CreateDirectory(Directory.GetParent(destinationPath).FullName); if (!File.Exists(sourcePath)) { if (!ignoreMissingFile) { InfoBox.Write($"File missing: {sourcePath}", InfoBox.Level.Warning); } return; } if (makeCopy) { try { File.Copy(sourcePath, destinationPath, false); } catch (IOException error) { if (error.HResult != -2147024816) // ignore fileExist 0x80070050 { InfoBox.Write($"{file} : {error.Message}", InfoBox.Level.Warning); } } } else { SymLinker.CreateSymlink(sourcePath, destinationPath, SymLinker.SymbolicLink.File); } }
static void CreateFolderSymLink() { DirectoryEntry selectedFolder = EditorIO.OpenFolderPanelV2("Select a folder to link into Assets"); var targetFolder = EditorIO.GetAssetsFolder(); try { targetFolder = EditorIO.GetFolderOfCurrentSelectedObject(); } catch (System.Exception) { } targetFolder = targetFolder.GetChildDir(selectedFolder.Name); SymLinker.CreateSymlink(selectedFolder, targetFolder); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); }
public void ExampleUsage1() { var root = EnvironmentV2.instance.GetOrAddTempFolder("SymLinkTests"); foreach (var dir in root.GetDirectories()) { dir.DeleteV2(); } var f1 = root.CreateSubdirectory("Folder1"); var targetForF1 = root.GetChildDir("TargetForFolder1"); SymLinker.CreateSymlink(f1, targetForF1); const string fileName = "t1.txt"; const string text = "Abc"; f1.GetChild(fileName).SaveAsText(text); // Check that the change in f1 also shows in the symlinked TargetForFolder1 Assert.Equal(text, targetForF1.GetChild(fileName).LoadAs <string>()); }