예제 #1
0
 private void TriggleErrorEvent(string errorInfo)
 {
     if (OnFilePathError != null)
     {
         FileInfoEventArgs args = new FileInfoEventArgs();
         args.Desc = errorInfo;
         OnFilePathError(this, args);
     }
 }
예제 #2
0
        public void StartCovertCN()
        {
            this.SetPathInfo();

            #region 源文件解压缩/参考文件解压缩
            CfgInfo cfg = this.GetCfgInfo();
            if (!File.Exists(cfg.Source))
            {
                this.TriggleErrorEvent("要汉化的英文资源文件不存在\r\n请在【设置】中正确设置,之后再操作");
                return;
            }
            if (!File.Exists(Path.Combine(appStartPath, this.refSourceName)))
            {
                this.TriggleErrorEvent("参考的中文资源文件不存在\r\n请确定在当前文件夹中存在【" + this.refSourceName + "】,之后再操作");
                return;
            }

            //创建操作所用的临时目录
            this.CreateOperateFileDirectory();

            //解压缩文件
            //生成要解压文件列表
            string fileLstName = "fileList.lst";
            File.WriteAllText(fileLstName, @"messages\*.*");
            UnPressSourceFile(this.cmdSourcePara, cfg.Source, sourcePath);
            UnPressSourceFile(this.cmdRefPara, refSourceName, refPath);
            File.Delete(fileLstName);

            #endregion

            #region 文件夹及文件是否存在判定
            string sName          = "源";
            string sDesc          = "(即将要汉化的)";
            string refName        = "参照";
            string refDesc        = "(即已汉化过的)";
            string DirNoSave      = "{0}文件文件夹不存在";
            string DirNoSaveAlert = @"请确认{0}文件夹在 {1} 下,或通过【设置】设置文件路径";
            if (!Directory.Exists(sourcePath))
            {
                OutErrorInfo(string.Format(DirNoSave, sName + sDesc), string.Format(DirNoSaveAlert, sName, sourcePath));
                return;
            }
            if (!Directory.Exists(refPath))
            {
                OutErrorInfo(string.Format(DirNoSave, refName + refDesc), string.Format(DirNoSaveAlert, refName, refPath));
                return;
            }
            string fileNoSave      = "{0}文件不存在";
            string fileNoSaveAlert = @"请复制{0}文件到 {1} 下,或通过【设置】设置文件路径";
            if (GetFileName(sourcePath) == null || GetFileName(sourcePath).Length < 1)
            {
                OutErrorInfo(string.Format(fileNoSave, sName + sDesc), string.Format(fileNoSaveAlert, sName, sourcePath));
                return;
            }
            if (GetFileName(refPath) == null || GetFileName(refPath).Length < 1)
            {
                OutErrorInfo(string.Format(fileNoSave, refName + refDesc), string.Format(fileNoSaveAlert, refName, refPath));
                return;
            }
            #endregion

            var     sFileList = GetFileName(sourcePath);
            int     fileCount = sFileList.Length;
            decimal index     = 1m;
            if (sFileList != null && sFileList.Length > 0)
            {
                foreach (var file in sFileList)
                {
                    string fileInfo = string.Format("处理文件:{0} ...", Path.GetFileName(file));
                    if (OnFileOperate != null)
                    {
                        OnFileOperate(this, new FileInfoEventArgs {
                            Desc = fileInfo, Rate = index / fileCount
                        });
                    }
                    ReplaceInfoByReferenceInfo(file, refPath, distPath);
                    index++;
                    System.Threading.Thread.Sleep(200);
                }
            }
            List <string> error = new List <string>();
            error.Add("");
            error.Add("文件处理完...");
            error.Add("");
            error.Add("");
            error.Add("请用Beyond Compare之类软件进行比较修正");
            error.Add("以获得更好的效果");

            error.Add("");
            string errorInfo = string.Join("\r\n", error.ToArray());
            if (OnFileOperateComplete != null)
            {
                FileInfoEventArgs args = new FileInfoEventArgs();
                args.Desc = errorInfo;
                OnFileOperateComplete(this, args);
                return;
            }
        }