public async Task <CopyDiagnostics> SyncLinkedFile(string fileName, string sourceFilePath) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string sourceDirectoryPath = sourceFilePath.Replace(@"\" + fileName, string.Empty); SymbolicLink symbolicLink = await this.symbolicLinkRepo.FirstOrDefaultAsync(a => a.Source == sourceDirectoryPath); string targetFilePath = Path.Combine(symbolicLink.Target, fileName); string targetDirectoryPath = Path.GetDirectoryName(targetFilePath); if (!Directory.Exists(targetDirectoryPath)) { Directory.CreateDirectory(targetDirectoryPath); } CopyUtility copyUtility = new CopyUtility(); copyUtility.Copy(sourceFilePath, targetFilePath); stopwatch.Stop(); return(new CopyDiagnostics() { SourcePath = sourceFilePath, TargetPath = targetFilePath, ElapsedTime = stopwatch.ElapsedMilliseconds }); }
private void LinkSource() { var packageBuilder = CreatePackageBuilder(); var packageRoot = Path.Combine(BasePath, packageBuilder.Id, packageBuilder.Version.ToNormalizedString()); Directory.CreateDirectory(packageRoot); var packageOutputPath = GetOutputPath(packageBuilder, false, packageBuilder.Version, packageRoot); var archive = BuildPackage(packageBuilder, packageOutputPath); archive?.Dispose(); foreach (var file in packageBuilder.Files) { if (file is PhysicalPackageFile physicalFile) { var target = Path.Combine(packageRoot, file.Path); Directory.CreateDirectory(Path.GetDirectoryName(target)); if (File.Exists(target)) { File.Delete(target); } SymbolicLink.Create(physicalFile.SourcePath, target); } } }
public void Search(List <string> files, IEnumerable <string> paths) { foreach (var path in paths) { //These three games put game files in the support folders if (path.Contains("Heroes of the Storm") || path.Contains("StarCraft")) { continue; } if (path.Contains("Penumbra Overture\\redist")) { continue; } if (path.Contains("Medieval II Total War\\miles")) { continue; } if (!dirRegex.IsMatch(path)) { continue; } var targetPath = path; if (SymbolicLink.IsSymbolic(path) && SymbolicLink.Exists(path)) { targetPath = SymbolicLink.GetTarget(path); } AddFiles(files, targetPath); Search(files, Directory.GetDirectories(targetPath)); } }
public void Parse() { WorkingDirectory = _fileItem.Directory; if ((_fileItem.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) { TargetPath = SymbolicLink.GetRealPath(_fileItem.Path); TargetType = Directory.Exists(TargetPath) ? ItemType.Container : ItemType.Item; } else if (_fileItem.IsLink()) { var link = GetLink(_fileItem); if (link != null) { TargetPath = link.Path; WorkingDirectory = link.WorkingDirectory; } TargetType = Directory.Exists(TargetPath) ? ItemType.Container : ItemType.Item; } else { TargetPath = _fileItem.Path; TargetType = _fileItem.ItemType; } }
public static void CreateSymLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags) { if (!DirectoryUtil.CreateSymbolicLink(lpSymlinkFileName, lpTargetFileName, dwFlags)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
public static void CreateSymbolicLink(string linkName, string target) { SymbolicLink linkType = string.IsNullOrEmpty(Path.GetExtension(linkName)) ? SymbolicLink.Directory : SymbolicLink.File; if (linkType == SymbolicLink.Directory) { var info = new DirectoryInfo(linkName); if (info.Parent != null && !Directory.Exists(info.Parent.FullName)) { Directory.CreateDirectory(info.Parent.FullName); } } else if (linkType == SymbolicLink.File) { var info = new FileInfo(linkName); if (info.Directory != null && !info.Directory.Exists) { Directory.CreateDirectory(info.Directory.FullName); } } try { CreateSymbolicLink(linkName, target, linkType); } catch { } }
public async Task ForceCopy(long symbolicLinkID) { SymbolicLink symbolicLink = await this.symbolicLinkRepo.FirstOrDefaultAsync(a => a.ID == symbolicLinkID); CopyUtility copyUtil = new CopyUtility(); copyUtil.Copy(symbolicLink.Source, symbolicLink.Target); }
public async Task StartWatcher(int watcherID) { bool isTripped = false; Watcher watcher = await this.watcherRepo.FirstOrDefaultAsync(a => a.ID == watcherID); SymbolicLink symbolicLink = await this.symbolicLinkRepo.FirstOrDefaultAsync(a => a.ID == watcher.SymbolicLinkID); System.Tuple <int, int> monitorKey = new System.Tuple <int, int>(watcher.SymbolicLinkID, watcher.ID); if (DirWatcherTransferApp.Monitors.ContainsKey(monitorKey)) { throw new System.Exception("Watcher already has monitor running. Please end the existing monitor before starting a new one."); } FileSystemMonitor fileSystemMonitor = new FileSystemMonitor(); // This actions gets fired when a file changes. fileSystemMonitor.CopyCompletedAction = async(notifyFilter, fileSystemEventArgs) => { // TODO: Implement a better way to check for visual studio temp files. This will fail if the actual file have a "~" in the name. if (!isTripped && fileSystemEventArgs.Name.Contains("~") && !fileSystemEventArgs.Name.EndsWith("~")) { isTripped = true; string fileName = fileSystemEventArgs.Name; string filePath = fileSystemEventArgs.FullPath; if (fileSystemEventArgs.Name.Contains("~") && !fileSystemEventArgs.Name.EndsWith("~")) { // Remove the vs caching name format. fileName = fileSystemEventArgs.Name.Remove(fileSystemEventArgs.Name.LastIndexOf("~")); filePath = fileSystemEventArgs.FullPath.Replace(fileSystemEventArgs.Name, fileName); } // Sync the changed file with the target file and update the SignalR clients of the copied file. CopyDiagnostics copyDiagnostics = await this.SyncLinkedFile(fileName, filePath); await this.fileSystemHubContext.Clients.All.SendAsync("onFileCopied", copyDiagnostics); await LogUtility.WriteToLog(notifyFilter, copyDiagnostics); // Update counts. if (notifyFilter != null) { await this.symbolicLinkRepo.IncrementCount(fileSystemEventArgs.FullPath.Replace(@"\" + fileSystemEventArgs.Name, string.Empty), (NotifyFilters)notifyFilter); await this.watcherRepo.IncrementCount(watcher, (NotifyFilters)notifyFilter); } isTripped = false; } }; fileSystemMonitor.StartWatcher(symbolicLink.Source, DirWatcherTransferApp.ProcessWatcherFiltersAsList(watcher)); DirWatcherTransferApp.Monitors.Add(monitorKey, fileSystemMonitor); }
//CreateSymbolicLink(symbolicLink, fileName, SymbolicLink.File); public static void CheckThenCreate(string FileToLink, string tempSymlinkFile) { if (File.Exists(FileToLink)) { symbolicLink = tempSymlinkFile; fileName = FileToLink; symlinkType = SymLink.SymbolicLink.File; CreateSymbolicLink(symbolicLink, fileName, symlinkType); } }
public static int CreateSymlinkHelper(string source, string dest, SymbolicLink isFile) { var success = CreateSymbolicLink(dest, source, (UInt32)isFile); if (!success) { var errorCode = Marshal.GetLastWin32Error(); return(errorCode == 0x000000B7 ? 0 : errorCode); // File exist } return(0); }
/// <summary> /// /// </summary> /// <param name="source"></param> Source file location /// <param name="dest"></param> Destination file location including file name /// <param name="isFile"></param> is file or folder /// <returns> win32 error code or 0 </returns> public static void CreateSymlink(string source, string dest, SymbolicLink isFile) { var errorCode = CreateSymlinkHelper(source, dest, isFile); if (errorCode != 0) { var error = DecodeErrorCode(errorCode); throw new SymLinkerError( message: $"Failed to create symlink, please check developer mode is turned on or run as administrator. Vitual folder must be located on a local drive.\n\nWin32 Error Message: {error} \nFilename:{source}"); } }
private void ContextItemStartWatchingLink_Click(object sender, EventArgs e) { string _symbolicLinkName = listSymbolicLinks.FocusedItem.Text; SymbolicLink _symbolicLink = DirWatchTransferApp.SymbolicLinks.FirstOrDefault(a => a.Name == _symbolicLinkName); listSymbolicLinks.FocusedItem.SubItems[3].ForeColor = this.ColorSuccess; listSymbolicLinks.FocusedItem.SubItems[3].Text = "Watching..."; this.SymbolicLinkUtil.StartLinkWatcher(_symbolicLink, this.OnCopyCompleted); }
public void DeleteTest() { Helper.DemandTestDriveAvailable(TestDrive); //Helper.DemandElevated(); var symbolicLink = PrepareSymbolicLink(); SymbolicLink.Delete(symbolicLink); Assert.IsFalse(File.Exists(symbolicLink)); }
public static void Create(string fromPath, string toPath) { try { SymbolicLink.create(toPath, fromPath); } catch (Exception e) { throw new SymbolicLinkException(e, "create", fromPath: fromPath, toPath: toPath); } }
public static string Resolve(string toPath) { try { return(SymbolicLink.resolve(toPath)); } catch (Exception e) { throw new SymbolicLinkException(e, "resolve", toPath: toPath); } }
public void GetTarget() { Helper.DemandTestDriveAvailable(TestDrive); //Helper.DemandElevated(); var symbolicLink = PrepareSymbolicLink(); var testFolder = Helper.GetTestFolder(TestDrive, "WriteTests", this); var originalFile = Path.Combine(testFolder, "Original.txt"); Assert.AreEqual(originalFile, SymbolicLink.GetTarget(symbolicLink)); }
private void LinkTarget() { foreach (var fileLink in GetFileLinks(_linkArgs.PackageId)) { if (File.Exists(fileLink.Target)) { File.Delete(fileLink.Target); } Directory.CreateDirectory(Path.GetDirectoryName(fileLink.Target)); SymbolicLink.Create(fileLink.Source, fileLink.Target); } }
public virtual async Task AddAsync(TEntity entity) { try { this.Context.Entry(entity).State = EntityState.Added; await this.Table.AddAsync(entity); await this.Context.SaveChangesAsync(); Type entityType = typeof(TEntity); if (entityType != typeof(ActivityHistory)) { ActivityHistory activityHistory = null; if (typeof(TEntity) == typeof(SymbolicLink)) { SymbolicLink symbolicLink = entity as SymbolicLink; activityHistory = new ActivityHistory() { Title = "Link Created", Description = $"{symbolicLink.Source} now linked with {symbolicLink.Target}", DateAdded = DateTime.Now }; } if (typeof(TEntity) == typeof(Watcher)) { Watcher watcher = entity as Watcher; SymbolicLink symbolicLink = await new SymbolicLinkRepository().FirstOrDefaultAsync(a => a.ID == watcher.SymbolicLinkID); activityHistory = new ActivityHistory() { Title = "Watcher Created", Description = $"Watcher created for ${symbolicLink.Name}", DateAdded = DateTime.Now }; } if (activityHistory != null) { await new ActivityHistoryRepository().AddAsync(activityHistory); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void ShouldCreateFile() { var tempID = System.IO.Path.GetRandomFileName(); var sourceFile = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), string.Format("sourceFile+{0}.txt", tempID)); var destinationFile = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), string.Format("destinationFile+{0}.txt", tempID)); var content = Guid.NewGuid().ToString(); System.IO.File.WriteAllText(sourceFile, content); SymbolicLink.Create(destinationFile, sourceFile, false); Assert.That(System.IO.File.ReadAllText(destinationFile), Is.EqualTo(content)); Assert.That(SymbolicLink.GetTargetPath(destinationFile), Is.EqualTo(sourceFile)); Assert.That(SymbolicLink.IsSymbolicLink(destinationFile), Is.True); }
private static void CreateSymlink(string source, string target, SymbolicLink options) { if (IsWindows()) { CreateSymbolicLink(source, target, options); } #if NETCOREAPP3_1 || NET5_0 || NET6_0 else { Assert.Equal(0, Mono.Unix.Native.Syscall.symlink(target, source)); } #endif }
/// <summary> /// 变更路径为SVN的合法路径 /// </summary> /// <param name="path"></param> /// <returns></returns> public static string ReplacePath(string path) { path = path.Replace('/', '\\'); if (path.Contains("Assets\\Resources")) { var mnn = SymbolicLink.GetRealPath(Application.dataPath + "/Resources/Res.meta"); var mm = SymbolicLink.GetTarget(Application.dataPath + "/Resources"); UnityEngine.Debug.Log(mm); } return(path); }
public async Task <IActionResult> Add([FromBody] SymbolicLink symbolicLink) { try { await this.symbolicLinkRepo.AddAsync(symbolicLink); return(StatusCode(200)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public static void UpdateLocalSVN() { if (Selection.activeObject != null) { var path = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID()); var resourcePath = SymbolicLink.GetTarget(Application.dataPath + "/Resources"); path = ReplacePath(path, resourcePath); if (path.Length > 0) { UpdatePath(path); } } }
public async Task CreateSymbolicLink(SymbolicLink symbolicLink) { symbolicLink.Monitor.CopyCompletedAction = this.OnCopyCompleted; // Adds symbolic link to SQLite and application variable. await this.SymbolicLinkUtil.AddAsync(symbolicLink); // If the watchers drop down item "Start watchers" is disabled make sure to enable it. if (watchersToolStripMenuItem.DropDownItems[0].Enabled == false && DirWatchTransferApp.SymbolicLinks.Count != 0) { watchersToolStripMenuItem.DropDownItems[0].Enabled = true; } // UI methods. this.AddSymbolicLinkToList(symbolicLink.Name, symbolicLink.Source, symbolicLink.Target, "Stopped"); }
public static void UpdateFromSVN() { //更新项目代码 if (string.IsNullOrEmpty(svnProcPath)) { svnProcPath = GetSvnProcPath(); } var dir = new DirectoryInfo(Application.dataPath); var process = UpdatePath(dir.Parent.FullName); process.WaitForExit(); if (process.HasExited) { var path = "Assets/Resources"; var resourcePath = SymbolicLink.GetTarget(Application.dataPath + "/Resources"); path = ReplacePath(path, resourcePath); //更新Resource var dir2 = new DirectoryInfo(path); var process2 = UpdatePath(dir2.FullName); process2.WaitForExit(); if (process2.HasExited) { //var path2 = "Assets/Resources/Config"; var resourcePath2 = SymbolicLink.GetTarget(Application.dataPath + "/Resources/Config"); //path2 = ReplacePath(path2, resourcePath2); //UnityEngine.Debug.Log(path2); //更新Resource var dir3 = new DirectoryInfo(resourcePath2); UpdatePath(dir3.FullName); } } }
public void ShouldCreateDirectory() { var tempID = System.IO.Path.GetRandomFileName(); var sourceDir = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), string.Format("sourceDir+{0}", tempID)); var destinationDir = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), string.Format("destinationDir+{0}", tempID)); System.IO.Directory.CreateDirectory(sourceDir); var childFilePath = System.IO.Path.Combine(sourceDir, "file.txt"); System.IO.File.WriteAllText(childFilePath, ""); SymbolicLink.Create(destinationDir, sourceDir, true); var destChildFilePath = System.IO.Path.Combine(destinationDir, "file.txt"); Assert.That(System.IO.File.Exists(destChildFilePath), Is.True); Assert.That(SymbolicLink.IsSymbolicLink(destinationDir), Is.True); Assert.That(SymbolicLink.GetTargetPath(destinationDir), Is.EqualTo(sourceDir)); }
public static bool CreateSymbolicLink(string lpFileName, string lpExistingFileName) { SymbolicLink type = SymbolicLink.None; if (File.Exists(lpExistingFileName)) { type = SymbolicLink.File; } if (Directory.Exists(lpExistingFileName)) { type = SymbolicLink.Directory; } if (type == SymbolicLink.None) { return(false); } return(CreateSymbolicLink(lpFileName, lpExistingFileName, type)); }
private string PrepareSymbolicLink([CallerMemberName] string testMethod = null) { var testFolder = Helper.GetTestFolder(TestDrive, "WriteTests", this, testMethod); _fixture = new Fixture(() => Helper.RobustDeleteDirectory(testFolder, true)); Directory.CreateDirectory(testFolder); var originalFile = Path.Combine(testFolder, "Original.txt"); File.WriteAllText(originalFile, "Original"); var symbolicLink = Path.Combine(testFolder, "SymbolicLink.txt"); SymbolicLink.Create(symbolicLink, originalFile, true); Assert.IsTrue(File.Exists(symbolicLink), "File 'SymbolicLink.txt' should exist, but does not!"); return(symbolicLink); }
public static void CommitToSVNSpcialSelect() { if (string.IsNullOrEmpty(svnProcPath)) { svnProcPath = GetSvnProcPath(); } var resourcePath = SymbolicLink.GetTarget(Application.dataPath + "/Resources"); //首先需要过滤只提交Assets var selectionObjs = FilterAssetsInProject(Selection.objects); UnityEngine.Debug.Log(Selection.objects.Length + " " + Selection.instanceIDs.Length + " " + selectionObjs.Length); var selectionPaths = new List <string>(); var dependencies = new List <string>(); for (int i = 0; i < selectionObjs.Length; i++) { var path = AssetDatabase.GetAssetPath(selectionObjs[i].GetInstanceID()); var dependenciest = AssetDatabase.GetDependencies(path); dependencies.AddRange(dependenciest); } for (int i = dependencies.Count - 1; i >= 0; i--) { dependencies.Add(dependencies[i] + ".meta"); } string cpath = ""; for (int i = 0; i < dependencies.Count; i++) { cpath += ReplacePath((dependencies[i]) + (i != dependencies.Count - 1 ? "*" : ""), resourcePath); } var param = "/command:commit /path:\"" + cpath; Process.Start(svnProcPath, param); }
public void Setup() { if (!IsWindows) { return; } var sdkPath = AndroidSdkPath; var ndkPath = AndroidNdkPath; var symSdkPath = Path.Combine(SdkWithSpacesPath, "sdk"); var symNdkPath = Path.Combine(SdkWithSpacesPath, "ndk"); SymbolicLink.Create(symSdkPath, sdkPath); SymbolicLink.Create(symNdkPath, ndkPath); Environment.SetEnvironmentVariable("TEST_ANDROID_SDK_PATH", symSdkPath); Environment.SetEnvironmentVariable("TEST_ANDROID_NDK_PATH", symNdkPath); }
public async Task <CopyDiagnostics> SyncLinkedDirectory(string sourcePath) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); SymbolicLink symbolicLink = await this.symbolicLinkRepo.FirstOrDefaultAsync(a => a.Source == sourcePath); CopyUtility copyUtility = new CopyUtility(); copyUtility.CopyDirectory(symbolicLink.Source, symbolicLink.Target); stopwatch.Stop(); return(new CopyDiagnostics() { SourcePath = symbolicLink.Source, TargetPath = symbolicLink.Target, ElapsedTime = stopwatch.ElapsedMilliseconds }); }
protected static void CreateNewPackage() { var filepath = Application.dataPath; if (Selection.activeObject != null && Selection.activeObject != Selection.activeGameObject) { var selectedFile = AssetDatabase.GetAssetPath(Selection.activeObject); filepath = selectedFile.Substring("Assets/".Length); filepath = Path.Combine(Application.dataPath, filepath); } if (!Directory.Exists(filepath) && File.Exists(filepath)) { filepath = Path.GetDirectoryName(filepath); } if (!Directory.Exists(filepath)) { EditorUtility.DisplayDialog("Error", "You must select a valid folder where you want link to the package to be created.", "OK"); return; } var savePath = EditorUtility.SaveFolderPanel("Create and select actual package folder", "", ""); if (string.IsNullOrEmpty(savePath)) { return; } Directory.CreateDirectory(Path.Combine(savePath, "Source")); File.WriteAllText(Path.Combine(savePath, "Readme.md"), "#Package readme"); if (!savePath.StartsWith(Application.dataPath)) { filepath = Path.Combine(filepath, Path.GetFileName(savePath)); SymbolicLink.Create(filepath, savePath); savePath = filepath; } CreateNuspecAndOpenEditor(savePath); }
public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);