/// <summary> /// 文件夹压缩 /// </summary> /// <param name="dir"></param> /// <param name="targetDir"></param> protected void MakeFolder(string dir, string targetDir) { if (dir == null) { return; } bool yes = SystemConsole.ContinueY("是否将文件夹压缩(y/n):"); if (!yes) { return; } string targetMd5Dir; var isHaveMd5Dir = TargetMd5Dir(out targetMd5Dir, dir, targetDir); var dirZip = (!isHaveMd5Dir ? targetDir : targetMd5Dir); string message = Library.Compress.DecompressUtils.MakeZipFile(dirZip); if (string.IsNullOrEmpty(message)) { Console.WriteLine("文件压缩成功!"); } else { Console.WriteLine("文件压缩失败!" + message); } DeleteInfo(dirZip, true); }
private string ExportFile(Dictionary <string, FileDetailInfo> cache) { var yes = SystemConsole.ContinueY("是否导出目标版本号文件(y/n):"); string targetDir = string.Format(Name, folder, startVersion, endVersion); DeleteInfo(targetDir); WriteToTxt(targetDir, cache); //if (yes) //{ // Console.WriteLine("正在导出中..."); // Console.WriteLine("根据项目大时间长短不定,请耐心等待..."); // FileHelper.CreateDirectory(Environment.CurrentDirectory.Replace("\\", "/") + "/" + targetDir); // RunCmd(string.Format("svn export -r {0} {1}@{0} {2}", targetVersion, svnUrl, targetDir), true); // index = 0; // foreach (var s in cache) // { // Console.WriteLine((++index).ToString().PadLeft(5, '0') + "\t" + s.Key); // string fullPath = targetDir + "/" + s.Key; // if (File.Exists(fullPath)) // SetContent(fullPath, s.Value); // } //} //if (yes) //{ // List<string> del = new List<string>(); // cache.ForEach((s, index) => // { // Console.Clear(); // Console.WriteLine("\n正在导出文件..."); // Console.WriteLine("根据项目大小时间长短不定,请耐心等待..."); // Console.WriteLine("正在导出中...{0}", ((float)(++index) / cache.Count).ToString("P")); // Console.WriteLine("is now: {0}", s.Key); // Console.WriteLine(); // string fullPath = Environment.CurrentDirectory.Replace("\\", "/") + "/" + targetDir + "/" + s.Key; // FileHelper.CreateDirectory(fullPath); // //拉取的文件版本号不会小于所在目录版本号,如若小于,说明文件所在目录曾经被移动过 // CmdReadAll(string.Format("svn cat -r {0} \"{1}/{2}@{0}\">\"{3}\"", endVersion, svnUrl, s.Key, // fullPath)); // //RunCmd(string.Format("svn cat -r {0} \"{1}/{2}@{0}\">\"{3}\"", s.Value.version, svnUrl, s.Key, fullPath)); // if (File.Exists(fullPath)) // { // SetContent(fullPath, s.Value); // Console.WriteLine(); // } // else // { // del.Add(s.Key); // } // }); // foreach (string s in del) // cache.Remove(s); //} return(targetDir); }
static void Main(string[] args) { do { SystemConsole.Run(config: new Dictionary <string, Action>() { { "加密", () => { new YueGeEncrypt(); } }, { "解密", () => { new YueGeDencrypt(); } }, { "解密2", () => { new YueGeDencrypt2(); } } }); } while (SystemConsole.ContinueY()); }
/// <summary> /// 每一个文件进行加密 /// </summary> /// <param name="targetDir"></param> /// <param name="cache"></param> protected void MakAESEncrypt(string targetDir, Dictionary <string, FileDetailInfo> cache) { if (!SystemConsole.ContinueY("是否对文件夹内每个文件进行加密(y/n):")) { return; } int index = 0; foreach (var s in cache) { Console.Clear(); Console.WriteLine("\n正在加密文件..."); Console.WriteLine("根据项目大小时间长短不定,请耐心等待..."); Console.WriteLine("正在加密中...{0}", ((float)(++index) / cache.Count).ToString("P")); Console.WriteLine("is now: {0}", s.Key); Console.WriteLine(); string fullPath = targetDir + "/" + s.Key; if (!File.Exists(fullPath)) { continue; } var array = EncryptExclude.Split(',').Where(p => !string.IsNullOrEmpty(p)).ToArray(); if (array.Contains(Path.GetExtension(s.Key))) { continue; } array = EncryptRootDir.Split(',').Where(p => !string.IsNullOrEmpty(p)).ToArray(); if (array.Any(p => s.Key.StartsWith(p))) { continue; } var content = AES.Encrypt(File.ReadAllBytes(fullPath), AESKey); s.Value.encrypt_hash = GetMD5(content); s.Value.encrypt_size = content.Length; File.WriteAllBytes(fullPath, content); } }
public GetLineCount() { do { var folder = SystemConsole.GetInputStr("请拖入文件夹:"); if (!Directory.Exists(folder)) { continue; } var ex = SystemConsole.GetInputStr("请输入文件后缀(如\"cs,cpp\":"); if (string.IsNullOrEmpty(folder)) { continue; } var files = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories).ToList(); var res = new List <string>(); ex.Split(',').ToList().ForEach(s => res.AddRange(files.Where(p => Path.GetExtension(p) == s))); File.WriteAllLines(ex + ".txt", res.ToArray()); Console.WriteLine("总行数:" + res.Sum(p => File.Exists(p) ? File.ReadAllLines(p).Length : 0)); } while (SystemConsole.ContinueY()); }
/// <summary> /// 路径MD5化 /// </summary> /// <param name="dir"></param> /// <param name="targetDir"></param> /// <param name="cache"></param> protected void PathToMd5(string dir, string targetDir, Dictionary <string, FileDetailInfo> cache) { if (!SystemConsole.ContinueY("是否将路径MD5化(y/n):")) { return; } if (dir == null) { return; } string targetMd5Dir; var isHaveMd5Dir = TargetMd5Dir(out targetMd5Dir, dir, targetDir); DeleteInfo(targetMd5Dir); int index = 0; foreach (var s in cache) { Console.WriteLine(); Console.WriteLine("正在转化中...{0}", ((float)(++index) / cache.Count).ToString("P")); Console.WriteLine("is now: {0}", s.Key); Console.WriteLine(); string fullPath = targetDir + "/" + s.Key; string targetFullPath = targetMd5Dir + "/" + GetPathHash(s.Key); if (!File.Exists(fullPath)) { continue; } DirectoryHelper.CreateDirectory(targetFullPath); File.Copy(fullPath, targetFullPath, true); } DeleteInfo(targetDir); WriteToTxt(targetMd5Dir, cache); }
public override void Run() { base.Run(); if (File.Exists(outFile)) { ; } { } Console.Write("请输入目标版本号(输入数字,[{0}-{1}]),然后回车:", lowVersion, highVersion); endVersion = Console.ReadLine().AsInt(); endVersion = Math.Max(endVersion, lowVersion); endVersion = Math.Min(endVersion, highVersion); Console.WriteLine("目标版本号:" + endVersion); Console.WriteLine(); Console.WriteLine("\n正在获取目标版本号文件详细信息..."); Dictionary <string, FileDetailInfo> cache = new Dictionary <string, FileDetailInfo>(); CmdReadAll(string.Format("svn list -r {0} {1}@{0} -R -v", endVersion, svnUrl)) .Where(s => !s.EndsWith("/")) .ToArray() .ForEach((s, index) => { List <string> res = s.Split(' ').Where(s1 => !string.IsNullOrEmpty(s1)).ToList(); var last = res.Skip(6).Join(" ").Replace("\\", "/").Trim(); FileDetailInfo svnFileInfo = new FileDetailInfo() { is_delete = false, version = res.First().Trim().AsLong(), content_size = res.Skip(2).First().Trim().AsLong(), path = last, }; cache[svnFileInfo.path] = svnFileInfo; Console.WriteLine("{0:D5}\t{1}", index, svnFileInfo); }); ExcludeFile(cache); var yes = SystemConsole.ContinueY("是否导出目标版本号文件(y/n):"); string targetDir = string.Format(Name, folder, startVersion, endVersion); DeleteInfo(targetDir); WriteToTxt(targetDir, cache); if (yes) { List <string> del = new List <string>(); cache.ForEach((s, index) => { Console.Clear(); Console.WriteLine("\n正在导出文件..."); Console.WriteLine("根据项目大小时间长短不定,请耐心等待..."); Console.WriteLine("正在导出中...{0}", ((float)(index) / cache.Count).ToString("P")); Console.WriteLine("is now: {0}", s.Key); Console.WriteLine(); string fullPath = Environment.CurrentDirectory.Replace("\\", "/") + "/" + targetDir + "/" + s.Key; DirectoryHelper.CreateDirectory(fullPath); //拉取的文件版本号不会小于所在目录版本号,如若小于,说明文件所在目录曾经被移动过 CmdReadAll(string.Format("svn cat -r {0} \"{1}/{2}@{0}\">\"{3}\"", endVersion, svnUrl, s.Key, fullPath)); //RunCmd(string.Format("svn cat -r {0} \"{1}/{2}@{0}\">\"{3}\"", s.Value.version, svnUrl, s.Key, fullPath)); if (File.Exists(fullPath)) { SetContent(fullPath, s.Value); Console.WriteLine(); } else { del.Add(s.Key); } }); foreach (string s in del) { cache.Remove(s); } } Common(targetDir, cache); }
/// <summary> /// 最后一步形成补丁列表 /// </summary> protected void UpdatePathList() { var array = Directory.GetFileSystemEntries(Environment.CurrentDirectory.Replace("\\", "/") + "/" + SaveDir, "*-*-*-*"); if (array.Length == 0) { return; } var dic = array.ToLookup(Path.GetFileNameWithoutExtension) .ToDictionary(p => p.Key, q => new List <string>(q)); if (dic.Count == 0) { return; } List <FilePatchInfo> svnPatchInfos = new List <FilePatchInfo>(); bool yes = SystemConsole.ContinueY("是否对文件进行加密(y/n),然后回车:"); foreach (KeyValuePair <string, List <string> > pair in dic) { FilePatchInfo filePatchInfo = new FilePatchInfo(); svnPatchInfos.Add(filePatchInfo); filePatchInfo.path = pair.Key; var txt = pair.Value.FirstOrDefault(p => p.EndsWith(".txt")); var zip = pair.Value.FirstOrDefault(p => p.EndsWith(".zip")); if (txt != null && File.Exists(txt)) { filePatchInfo.content_hash = GetMD5(File.ReadAllBytes(txt)); filePatchInfo.content_size = new FileInfo(txt).Length; if (yes) { EncryptFile(txt); } filePatchInfo.encrypt_hash = GetMD5(File.ReadAllBytes(txt)); filePatchInfo.encrypt_size = new FileInfo(txt).Length; } if (zip != null && File.Exists(zip)) { filePatchInfo.zip_hash = GetMD5(File.ReadAllBytes(zip)); filePatchInfo.zip_size = new FileInfo(zip).Length; } var xx = pair.Key.Split('-'); filePatchInfo.group = xx.First(); filePatchInfo.firstVersion = xx.Skip(1).First().AsInt(); filePatchInfo.lastVersion = xx.Skip(2).First().AsInt(); } WriteToTxt(Name, new VersionInfo() { softwareVersion = softwareVersion, pathInfos = svnPatchInfos.OrderBy(p => p.group).ThenBy(p => p.firstVersion).ToList() }); if (yes) { EncryptFile(Name); } }