示例#1
0
        public CfgInfo GetDefaultCfgInfo()
        {
            string wsPath = this.GetWebStormPath();
            string source = Path.Combine(wsPath == "" ? appStartPath : wsPath, sourceJarName);
            string dist   = Path.Combine(appStartPath);
            //先赋默认值
            CfgInfo cfg = new CfgInfo
            {
                Source = source,
                Dist   = dist
            };

            return(cfg);
        }
示例#2
0
        public CfgInfo GetCfgInfo()
        {
            CfgInfo cfg     = null;
            string  cfgFile = Path.Combine(appStartPath, "FilePath.cfg");
            bool    noCfg   = false;

            //如果有配置文件且内容不为空(对应的各项)
            if (File.Exists(cfgFile))
            {
                XDocument doc = XDocument.Load(cfgFile);

                var cfgItem = doc.Element("path");
                if (cfgItem != null)
                {
                    string source = cfgItem.Element("sourceDirName").Value ?? "";
                    string dist   = cfgItem.Element("distDirName").Value ?? "";

                    if (!(string.IsNullOrWhiteSpace(source) && string.IsNullOrWhiteSpace(dist)))
                    {
                        cfg = new CfgInfo
                        {
                            Source = source,
                            Dist   = dist
                        };
                    }
                }
                else
                {
                    noCfg = true;
                }
            }
            else
            {
                noCfg = true;
            }
            if (noCfg)//无配置文件,取默认的值
            {
                cfg = this.GetDefaultCfgInfo();
            }
            return(cfg);
        }
示例#3
0
        public bool SaveCfgInfo(CfgInfo info)
        {
            bool isOk = true;

            try
            {
                string    cfgFile = Path.Combine(appStartPath, "FilePath.cfg");
                XDocument doc     = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                                  new XElement("path",
                                                               new XComment("英文资源文件"),
                                                               new XElement("sourceDirName", info.Source),
                                                               new XComment("最终生成文件的文件夹"),
                                                               new XElement("distDirName", info.Dist)
                                                               ));
                //doc.Save(Console.Out);
                doc.Save(cfgFile);
            }
            catch
            {
                isOk = false;
            }
            return(isOk);
        }
示例#4
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;
            }
        }