//复制文件夹 public static void Copy(this DirectoryInfo source, DirectoryInfo target, Action <FileInfo> callback = null) { if (source == null || !source.Exists) { return; } if (!target.Exists) { target.Create(); } DirectoryInfo subDirInfo; FileInfo subFileInfo; foreach (FileSystemInfo sysInfo in source.GetFileSystemInfos()) { if ((subDirInfo = sysInfo as DirectoryInfo) != null) { Copy(subDirInfo, new DirectoryInfo(FilePathHelper.GetAbsolutePath(subDirInfo.Name, target.FullName)), callback); } else if ((subFileInfo = sysInfo as FileInfo) != null) { try { subFileInfo.CopyTo(FilePathHelper.GetAbsolutePath(subFileInfo.Name, target.FullName), true); if (callback != null) { callback(subFileInfo); } } catch (Exception exp) { Console.WriteLine(exp.Message); } } } }
public OpenChineseConverter() { FilePathHelper helper = new FilePathHelper(); // Get File Absolute Path string filePath = helper.GetAbsolutePath(DictionaryPath); // Load Dictionary LoadDictionary(filePath); }
public OpenChineseConverter(string dictionaryPath) { string filePath = dictionaryPath; if (string.IsNullOrEmpty(filePath)) { FilePathHelper helper = new FilePathHelper(); // Get File Absolute Path filePath = helper.GetAbsolutePath(DictionaryPath); } // Load Dictionary LoadDictionary(filePath); }
//翻译器-替换富友资源 public static StringBuilder TranslatorReplaceResourceWfy(TranslatorConfig config) { StringBuilder result = new StringBuilder(); if (config.WorkFolder.IsNullOrEmpty()) { return(result); } using (MemoryStream ms = new MemoryStream(Resources.resource)) { using (IArchive archive = ArchiveFactory.Open(ms)) { //创建临时目录 string tempDir = FilePathHelper.GetAbsolutePath(Guid.NewGuid().ToStringEx(), config.WorkFolder); Directory.CreateDirectory(tempDir); //解压到临时目录 foreach (var entry in archive.Entries) { if (!entry.IsDirectory) { entry.WriteToDirectory(tempDir, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } } //复制wfy 到工作目录 new DirectoryInfo(FilePathHelper.GetAbsolutePath(".\\wfy", tempDir)).Copy(new DirectoryInfo(config.WorkFolder)); //删除临时目录 try { Directory.Delete(tempDir, true); } catch { } } } //存在显式文件夹则复制 DirectoryInfo dirInfoWfy = new DirectoryInfo(FilePathHelper.GetAbsolutePath(".\\resources\\wfy")); if (dirInfoWfy.Exists) { dirInfoWfy.Copy(new DirectoryInfo(config.WorkFolder)); } //根据配置提交 GitHelper.GitAdd(config); GitHelper.GitCommit(config, "【富友资源】替换富友资源"); result.AppendLine("已替换富友资源"); return(result); }
private static readonly char[] CHARS_DIRECTORY_END = new char[] { '/', '\\' };//目录结束符 //签出文件 public static void CheckOut(this Config config, FileInfo fileInfo) { if (!config.Enabled) { return; } //签出参数 string relative = FilePathHelper.GetDirectoryName(fileInfo.FullName).Trim(CHARS_DIRECTORY_END).Substring(config.WorkDir.Trim(CHARS_DIRECTORY_END).Length).Trim(CHARS_DIRECTORY_END).Replace("\\", "/"); StringBuilder args = new StringBuilder(); args.Append(" CheckOutFile");//签出 args.Append(" -server ").Append(config.Server); args.Append(" -port ").Append(config.Port); args.Append(" -username ").Append(config.UserName); args.Append(" -pwd ").Append(config.Pwd); args.Append(" -alias ").Append(config.Alias); args.Append(" -prj ").Append(config.Prj.Trim(CHARS_DIRECTORY_END).Replace("\\", "/")).Append(relative.Length > 0 ? "/" : string.Empty).Append(relative); args.Append(" -workdir ").Append(config.WorkDir.Trim(CHARS_DIRECTORY_END).Replace("\\", "/")).Append(relative.Length > 0 ? "/" : string.Empty).Append(relative); args.Append(" -file ").Append(fileInfo.Name); args.Append(" -replace"); //尝试三次签出 for (int i = 0; i < 3; i++) { ProcessStartInfo startInfo = new ProcessStartInfo { FileName = FilePathHelper.GetAbsolutePath("SAWVCmd.exe"), Arguments = args.ToStringEx(), WindowStyle = ProcessWindowStyle.Hidden, }; Process process = Process.Start(startInfo); process.WaitForExit(); //签出成功返回 fileInfo.Refresh(); if (!fileInfo.IsReadOnly) { return; } } }
public static List <IGitHelperExtensionFile> GetExtensionFiles(List <string> extensionPaths, bool showWariningIfFileIsNotFound = false) { var extensions = new List <IGitHelperExtensionFile>(); if (Utility.IsNullOrEmpty(extensionPaths)) { return(extensions); } var currentPath = FilePathHelper.GetCurrentDirectory(); var showedErrorMessage = new List <string>(); foreach (var f in extensionPaths) { var filePath = f; var useRelativePath = !FilePathHelper.IsFullPath(filePath); if (useRelativePath) { filePath = FilePathHelper.GetAbsolutePath(filePath, currentPath); } if (!File.Exists(filePath)) { if (showWariningIfFileIsNotFound) { MessageBox.Show($"Cannot find file \"{filePath}\""); } continue; } try { IGitHelperExtensionFile extension = null; var ext = Path.GetExtension(filePath)?.ToLower(); switch (ext) { case ".bat": extension = new GitHelperScriptFile(filePath); break; } if (extension != null) { if (extension.IsValid(out var extensionError)) { if (useRelativePath) { extension.ToRelatvePath(); } extensions.Add(extension); } else { MessageBox.Show(string.Join(", ", extensionError)); } } } catch (Exception e) { if (!showedErrorMessage.Contains(e.Message)) { showedErrorMessage.Add(e.Message); MessageBox.Show(e.Message); } } } return(extensions); }