示例#1
0
        private void DoMerge(string[] lines, List <TranslateUnit3RD> units, TranslateUnitType type, bool addChar, string specialChar)
        {
            if (lines == null || lines.Length == 0 || units == null || units.Count == 0)
            {
                return;
            }

            for (int i = 0; i < lines.Length; i++)
            {
                string line       = lines[i];
                int    lineNumber = i + 1;
                string lineTrimed = line.Trim();

                switch (type)
                {
                case TranslateUnitType.MenuType:
                    if (lineTrimed.StartsWith("POPUP") || lineTrimed.StartsWith("MENUITEM"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "menu", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.StringType:
                    if (lineTrimed.Contains(startChar) && lineTrimed.Contains(endChar))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "string", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.DialogType:
                    if (lineTrimed.StartsWith("CAPTION") || lineTrimed.StartsWith("CONTROL"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "dialog", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.VersionType:
                    if (lineTrimed.StartsWith("VALUE"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 3);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "version", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;
                }
            }
        }
示例#2
0
        private void DoExtract(List <TranslateUnit3RD> result, string[] lines, TranslateUnitType type, List <TranslateUnit> resultSelf)
        {
            if (lines == null || lines.Length == 0)
            {
                return;
            }

            for (int i = 0; i < lines.Length; i++)
            {
                string line       = lines[i];
                int    lineNumber = i + 1;
                string lineTrimed = line.Trim();

                switch (type)
                {
                case TranslateUnitType.MenuType:
                    if (lineTrimed.StartsWith("POPUP") || lineTrimed.StartsWith("MENUITEM"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "menu", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.StringType:
                    if (lineTrimed.Contains(startChar) && lineTrimed.Contains(endChar))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "string", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.DialogType:
                    if (lineTrimed.StartsWith("CAPTION") || lineTrimed.StartsWith("CONTROL"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "dialog", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.VersionType:
                    if (lineTrimed.StartsWith("VALUE"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 3);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "version", si.content, si.content);

                            // set id for version
                            StringIndex siID = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);
                            if (siID != null && siID.content != null && siID.content.Length > 0)
                            {
                                tu.Id = siID.content;

                                TranslateUnit tuSelf = TranslateUnitUtil.GetTranslateUnit(resultSelf, "RT_VERSION", tu.Id);
                                if (tuSelf != null)
                                {
                                    tu.SourceContent = tuSelf.SourceContent;
                                    tu.TargetContent = tuSelf.SourceContent;
                                }
                            }

                            result.Add(tu);
                        }
                    }
                    break;
                }
            }
        }
示例#3
0
        private void MergeOneFile(CommandUtil comUtil, List <TranslateUnit3RD> units, string rcFile, string resFile, TranslateUnitType tuType, string oriFile, String newFile)
        {
            string[] menulines = ReadAllLinesForRCFile(rcFile, tuType);

            if (menulines.Length != 0)
            {
                for (int i = 0; i < menulines.Length; i++)
                {
                    string line = menulines[i];

                    while (line.StartsWith("\0"))
                    {
                        line = line.Substring(1);
                    }

                    menulines[i] = line;
                }

                DoMerge(menulines, units, tuType, false, null);

                File.WriteAllLines(rcFile, menulines, Encoding.Unicode);
                comUtil.Compile(rcFile, resFile);
                DebugCompile(Encoding.Unicode, resFile);

                if (!File.Exists(resFile) || File.ReadAllBytes(resFile).Length == 32)
                {
                    File.WriteAllLines(rcFile, menulines, Encoding.Default);
                    comUtil.Compile(rcFile, resFile);
                    DebugCompile(Encoding.Default, resFile);
                }

                if (!File.Exists(resFile) || File.ReadAllBytes(resFile).Length == 32)
                {
                    String specalChar = "\x2063";

                    switch (tuType)
                    {
                    case TranslateUnitType.StringType: specalChar = " "; break;

                    case TranslateUnitType.DialogType: specalChar = "\x2063"; break;

                    case TranslateUnitType.MenuType: specalChar = "\x2063"; break;

                    case TranslateUnitType.VersionType: specalChar = " "; break;
                    }

                    DoMerge(menulines, units, tuType, true, specalChar);

                    File.WriteAllLines(rcFile, menulines, Encoding.Unicode);
                    comUtil.Compile(rcFile, resFile);
                    DebugCompile(Encoding.Unicode, resFile);

                    if (!File.Exists(resFile) || File.ReadAllBytes(resFile).Length == 32)
                    {
                        File.WriteAllLines(rcFile, menulines, Encoding.Default);
                        comUtil.Compile(rcFile, resFile);
                        DebugCompile(Encoding.Default, resFile);
                    }
                }

                if (!File.Exists(resFile) || File.ReadAllBytes(resFile).Length == 32)
                {
                    string log = comUtil.GetLog();
                    if (log.Contains("Error compiling script at line"))
                    {
                        StringIndex si = StringUtil.GetBetween(log, "Error compiling script at line", ":", 0, 1);

                        if (si != null && si.content != null)
                        {
                            string line = si.content.Trim();
                            //TODO: fix this line
                        }
                    }

                    m_log.Debug(log);
                }

                comUtil.Modify(oriFile, newFile, resFile);
            }

            if (!File.Exists(newFile))
            {
                File.Copy(oriFile, newFile);
            }
        }