public static void OpenProcess(string cmd, String parems, ShowString dialogRes, bool waiteToEnd) { System.Diagnostics.Process myProcess = new Process(); //设置外部程序名 myProcess.StartInfo.FileName = cmd; //设置外部程序的启动参数(命令行参数)为test.txt myProcess.StartInfo.Arguments = parems; //设置外部程序工作目录为 C:\ myProcess.StartInfo.WorkingDirectory = "C:\\"; myProcess.StartInfo.UseShellExecute = false; //此处必须为false否则引发异常 myProcess.StartInfo.RedirectStandardInput = dialogRes != null; //标准输入 myProcess.StartInfo.RedirectStandardOutput = dialogRes != null; //标准输出 myProcess.StartInfo.RedirectStandardError = dialogRes != null; //重定向错误输出 //不显示命令行窗口界面 myProcess.StartInfo.CreateNoWindow = true; myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //声明一个程序类 try { myProcess.Start(); if (dialogRes != null) { dialogRes.showString(myProcess.StandardOutput.ReadToEnd()); } if (waiteToEnd) { myProcess.WaitForExit(); } myProcess.Close(); } catch (System.ComponentModel.Win32Exception e) { if (dialogRes != null) { dialogRes.showString("系统找不到指定的程序文件。\n" + e.Message); } } }
//压缩图片 public static void packFiles(ShowString dialog, String srcPath, String searchPatten, int maxPack, bool deleteOld) { //清除包裹文件 dialog.showString("==>清除旧包裹文件"); String[] files = Directory.GetFiles(srcPath, "*.*"); for (int i = 0; i < files.Length; i++) { int pos = files[i].LastIndexOf('\\'); String name = files[i].Substring(pos + 1, files[i].Length - (pos + 1)); if (name.IndexOf("filePacks") >= 0 || name.IndexOf("aep") >= 0) { File.Delete(files[i]); } } //开始转换 files = IOUtil.listFiles(srcPath, searchPatten); dialog.showString("==>共发现" + files.Length + "个文件"); ArrayList filePackList = new ArrayList(); FilePack filePack = new FilePack(); filePackList.Add(filePack); int addUpSize = 0; for (int i = 0; i < files.Length; i++) { int pos = files[i].LastIndexOf('\\'); String name = files[i].Substring(pos + 1, files[i].Length - (pos + 1)); byte[] data = IOUtil.ReadFile(files[i]); addUpSize += data.Length; if (i == 0)//第一个包,则将当前文件压入这个包 { filePack.addFile(name, data); if (addUpSize >= maxPack) { filePack = new FilePack(); filePackList.Add(filePack); addUpSize = data.Length; } } else//不是第一个包,则将当前文件压入后一个包 { if (addUpSize >= maxPack) { filePack = new FilePack(); filePackList.Add(filePack); addUpSize = data.Length; } filePack.addFile(name, data); } } //开始输出 String dictionFile = srcPath + "\\" + Consts.exportFileName + "_filePacks.bin"; FileStream fsDictionary = new FileStream(dictionFile, FileMode.Create); IOUtil.writeShort(fsDictionary, (short)filePackList.Count); IOUtil.writeShort(fsDictionary, (short)files.Length); dialog.showString("==>即将输出" + (filePackList.Count) + "个包裹"); int outputFiles = 0; for (int i = 0; i < filePackList.Count; i++) { FilePack pack = (FilePack)filePackList[i]; IOUtil.writeShort(fsDictionary, (short)pack.fileNames.Count); String strPack = srcPath + "\\" + Consts.exportFileName + "_" + i + ".aep"; FileStream fsPackI = new FileStream(strPack, FileMode.Create); int dataPos = 0; dialog.showString("-->开始输出第" + (i + 1) + "个包裹,共" + pack.fileNames.Count + "个文件"); for (int j = 0; j < pack.fileNames.Count; j++) { String fileName = (String)(pack.fileNames[j]); byte[] data = (byte[])pack.fileDatas[j]; IOUtil.writeString(fsDictionary, fileName); IOUtil.writeInt(fsDictionary, dataPos); IOUtil.writeInt(fsDictionary, data.Length); IOUtil.writeData(fsPackI, data); dataPos += data.Length; dialog.showString("->加入第" + (j + 1) + "个文件[" + fileName + "],长度[" + data.Length + "],当前包裹大小[" + dataPos + "]"); if (deleteOld) { File.Delete(srcPath + "\\" + fileName); } outputFiles++; dialog.setStep(outputFiles, files.Length); } fsPackI.Flush(); fsPackI.Close(); dialog.showString("->完成输出第" + (i + 1) + "个包裹"); } fsDictionary.Flush(); fsDictionary.Close(); }
//编译全部脚本文件 public void compileScripts(ShowString shower) { String scriptSuffix = ".c2ds";//脚本代码文件后缀名 String scriptFilePath = ""; bool lostKssExe = false; if (FileTypeRegister.FileTypeRegistered(scriptSuffix)) { FileTypeRegInfo regInfo = FileTypeRegister.GetFileTypeRegInfo(scriptSuffix); String exePath = regInfo.ExePath; if (File.Exists(exePath)) { for (int i = 0; i < mapsManagerForExport.listExpScriptFiles.Count; i++) { String file = (String)mapsManagerForExport.listExpScriptFiles[i]; scriptFilePath = Consts.PATH_PROJECT_FOLDER + Consts.SUBPARH_KSS + file; if (File.Exists(scriptFilePath)) { if (shower != null) { shower.showString("开始编译脚本文件[" + scriptFilePath + "]"); } IOUtil.OpenProcess(exePath, "-CF " + scriptFilePath, null, true); String kseFilePath = scriptFilePath.Replace(".c2ds", ".bin"); String kseFileName = kseFilePath.Substring(kseFilePath.LastIndexOf('\\') + 1, kseFilePath.Length - (kseFilePath.LastIndexOf('\\') + 1)); if (File.Exists(kseFilePath)) { File.Copy(kseFilePath, Consts.exportC2DBinFolder + kseFileName, true); File.Delete(kseFilePath); } else { if (shower != null) { shower.showString("编译脚本文件[" + scriptFilePath + "]过程中发生问题"); } } } else { if (shower != null) { shower.showString("丢失脚本文件[" + scriptFilePath + "],因此无法汇编此脚本"); } } } } else { lostKssExe = true; } } else { lostKssExe = true; } if (lostKssExe) { MessageBox.Show("没有找到被注册的\"CycloneScriptEditor.exe\",请在任意位置打开一次,它将自动被注册。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//压缩图片 public static void packFiles(ShowString dialog,String srcPath, String searchPatten, int maxPack,bool deleteOld) { //清除包裹文件 dialog.showString("==>清除旧包裹文件"); String[] files = Directory.GetFiles(srcPath, "*.*"); for (int i = 0; i < files.Length; i++) { int pos = files[i].LastIndexOf('\\'); String name = files[i].Substring(pos + 1, files[i].Length - (pos + 1)); if (name.IndexOf("filePacks")>=0 || name.IndexOf("aep")>=0) { File.Delete(files[i]); } } //开始转换 files = IOUtil.listFiles(srcPath, searchPatten); dialog.showString("==>共发现" + files.Length + "个文件"); ArrayList filePackList = new ArrayList(); FilePack filePack = new FilePack(); filePackList.Add(filePack); int addUpSize = 0; for (int i = 0; i < files.Length; i++) { int pos = files[i].LastIndexOf('\\'); String name = files[i].Substring(pos + 1, files[i].Length - (pos + 1)); byte[] data = IOUtil.ReadFile(files[i]); addUpSize += data.Length; if (i == 0)//第一个包,则将当前文件压入这个包 { filePack.addFile(name, data); if (addUpSize >= maxPack) { filePack = new FilePack(); filePackList.Add(filePack); addUpSize = data.Length; } } else//不是第一个包,则将当前文件压入后一个包 { if (addUpSize >= maxPack) { filePack = new FilePack(); filePackList.Add(filePack); addUpSize = data.Length; } filePack.addFile(name, data); } } //开始输出 String dictionFile = srcPath + "\\" + Consts.exportFileName + "_filePacks.bin"; FileStream fsDictionary = new FileStream(dictionFile, FileMode.Create); IOUtil.writeShort(fsDictionary, (short)filePackList.Count); IOUtil.writeShort(fsDictionary, (short)files.Length); dialog.showString("==>即将输出" + (filePackList.Count) + "个包裹"); int outputFiles = 0; for (int i = 0; i < filePackList.Count; i++) { FilePack pack = (FilePack)filePackList[i]; IOUtil.writeShort(fsDictionary, (short)pack.fileNames.Count); String strPack = srcPath + "\\" + Consts.exportFileName + "_" + i + ".aep"; FileStream fsPackI = new FileStream(strPack, FileMode.Create); int dataPos = 0; dialog.showString("-->开始输出第" + (i + 1) + "个包裹,共" + pack.fileNames.Count + "个文件"); for (int j = 0; j < pack.fileNames.Count; j++) { String fileName = (String)(pack.fileNames[j]); byte[] data = (byte[])pack.fileDatas[j]; IOUtil.writeString(fsDictionary, fileName); IOUtil.writeInt(fsDictionary, dataPos); IOUtil.writeInt(fsDictionary, data.Length); IOUtil.writeData(fsPackI, data); dataPos += data.Length; dialog.showString("->加入第" + (j + 1) + "个文件[" + fileName + "],长度[" + data.Length + "],当前包裹大小[" + dataPos + "]"); if (deleteOld) { File.Delete(srcPath+"\\"+fileName); } outputFiles++; dialog.setStep(outputFiles, files.Length); } fsPackI.Flush(); fsPackI.Close(); dialog.showString("->完成输出第" + (i + 1) + "个包裹"); } fsDictionary.Flush(); fsDictionary.Close(); }