/// <summary> /// 文件重编码。根据文件的编码格式读取文件内容,输出为指定的编码格式,可指定仅修改指定后缀的文件 /// </summary> public static void ReCode(String[] filePaths, Encoding encoding = null, String[] Endwith = null) { foreach (String filePath in filePaths) { RecodeTool.ReCode(filePath, encoding, Endwith); } }
/// <summary> /// 压缩工程src为Resources资源 /// </summary> private static void zipSrcToResources(string slnDir, string srcName) { string Resources = getRsourcesDir(slnDir); // 获取Resources目录 string newZipFile = Resources + "\\" + srcName; String[] ignores = new String[] { "\\bin\\", "\\obj\\", "\\" + srcName }; // 复制到缓存目录进行重编码、压缩 string slnDirTmp = slnDir + "_src"; if (Directory.Exists(slnDirTmp)) { Directory.Delete(slnDirTmp, true); } FileTool.CopyFolderTo(slnDir, slnDirTmp, true); // 复制目录文件 RecodeTool.Main(new String[] { slnDirTmp }); // 重编码 bool ziped = ZipTool.zip(slnDirTmp, null, ignores); // 压缩为zip,压缩时忽略bin和obj目录 if (Directory.Exists(slnDirTmp)) { Directory.Delete(slnDirTmp, true); } string zipFile = slnDirTmp + ".zip"; if (File.Exists(newZipFile)) { File.Delete(newZipFile); // 删除原有文件 } if (ziped) { File.Move(zipFile, newZipFile); } }
/// <summary> /// 重编码载入的所有文件 /// </summary> private void button_Click(object sender, EventArgs e) { if (checkBox.Checked) { RenameTool.ReName(files); } RecodeTool.ReCode(files, encode); MessageBox.Show("重编码完成"); }
/// <summary> /// 文件重编码示例入口 /// </summary> public static void Main(String[] args) { if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ReCode_Form()); } else { String[] files = DragDropTool.GetSubFiles(args); // 载入文件信息 String[] Endwith = new String[] { ".java", ".cs", ".txt", ".xml" }; RenameTool.ReName(files, Endwith); // 重命名 RecodeTool.ReCode(files, Encoding.UTF8, Endwith); // 重编码所有文件 } }