Ejemplo n.º 1
0
        private void Merge(CommandUtil comUtil, List <TranslateUnit3RD> units)
        {
            string[] filenames = comUtil.Extract(m_peFileName);
            string   menurc = null, stringrc = null, dialogrc = null, versionrc = null;
            string   menures = null, stringres = null, dialogres = null, versionres = null;

            try
            {
                // menu.rc
                menurc  = filenames[0];
                menures = menurc.Substring(0, menurc.LastIndexOf(".")) + ".res";
                MergeOneFile(comUtil, units, menurc, menures, TranslateUnitType.MenuType, m_peFileName, m_newFileName0);

                // string.rc
                stringrc  = filenames[1];
                stringres = stringrc.Substring(0, stringrc.LastIndexOf(".")) + ".res";
                MergeOneFile(comUtil, units, stringrc, stringres, TranslateUnitType.StringType, m_newFileName0, m_newFileName1);

                // dialog.rc
                dialogrc  = filenames[2];
                dialogres = dialogrc.Substring(0, dialogrc.LastIndexOf(".")) + ".res";
                MergeOneFile(comUtil, units, dialogrc, dialogres, TranslateUnitType.DialogType, m_newFileName1, m_newFileName2);

                // version.rc
                versionrc  = filenames[3];
                versionres = versionrc.Substring(0, versionrc.LastIndexOf(".")) + ".res";
                MergeOneFile(comUtil, units, versionrc, versionres, TranslateUnitType.VersionType, m_newFileName2, m_newFileName3);

                File.Copy(m_newFileName3, m_peFileName, true);
            }
            finally
            {
                if (!AppConfig.KeepTempFiles)
                {
                    DeleteFile(menurc);
                    DeleteFile(stringrc);
                    DeleteFile(dialogrc);
                    DeleteFile(versionrc);

                    DeleteFile(menures);
                    DeleteFile(stringres);
                    DeleteFile(dialogres);
                    DeleteFile(versionres);

                    DeleteFile(m_newFileName0);
                    DeleteFile(m_newFileName1);
                    DeleteFile(m_newFileName2);
                    DeleteFile(m_newFileName3);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the file from one format to another.
        /// </summary>
        /// <param name="p_filename">The command file
        /// (.im_command, .ex_command)</param>
        /// <param name="p_language">the language of the directory
        /// the file was written in</param>
        public void Convert(string p_fileName, string p_language)
        {
            try
            {
                ResetState();
                m_statusFileName = p_fileName.Substring(
                    0, p_fileName.Length - FILE_EXT_LEN) + "status";
                DetermineConversionValues(p_fileName);
                FileInfo      file = new FileInfo(p_fileName);
                DirectoryInfo dir  = file.Directory;

                m_log.Log("Processing file " + m_originalFileName);

                CommandUtil comUtil = new CommandUtil();

                // process files
                if (!m_isConvertBack)
                {
                    List <TranslateUnit3RD> units = Extract(comUtil);
                    String xml = XmlUtil3RD.OutputTranslateUnits(units);
                    XmlUtil3RD.WriteXml(xml, m_xmlFileName, "UTF-8");
                }
                else
                {
                    String xml = XmlUtil3RD.ReadFile(m_xmlFileName, "UTF-8");
                    List <TranslateUnit3RD> units = XmlUtil3RD.ParseTranslateUnits(xml);
                    int c = units.Count;
                    Merge(comUtil, units);
                }

                StatusFile.WriteSuccessStatus(m_statusFileName,
                                              m_originalFileName + " was converted successfully.");

                m_log.Log("Converted successfully to " + m_newFileName);
            }
            catch (Exception e)
            {
                Logger.LogError(m_log, "Windows Portable Executable Conversion Failed", e);
                StatusFile.WriteErrorStatus(m_statusFileName, e, (int)1);
            }
            finally
            {
                DeleteInputFile(p_fileName);
            }
        }
Ejemplo n.º 3
0
        private List <TranslateUnit3RD> Extract(CommandUtil comUtil)
        {
            List <TranslateUnit> resultSelf = ParsePEFile();

            string[] filenames = comUtil.Extract(m_peFileName);
            List <TranslateUnit3RD> result = new List <TranslateUnit3RD>();
            string menurc = null, stringrc = null, dialogrc = null, versionrc = null;

            try
            {
                // menu.rc
                menurc = filenames[0];
                ExtractOneFile(result, menurc, TranslateUnitType.MenuType, resultSelf);

                // string.rc
                stringrc = filenames[1];
                ExtractOneFile(result, stringrc, TranslateUnitType.StringType, resultSelf);

                // dialog.rc
                dialogrc = filenames[2];
                ExtractOneFile(result, dialogrc, TranslateUnitType.DialogType, resultSelf);

                // version.rc
                versionrc = filenames[3];
                ExtractOneFile(result, versionrc, TranslateUnitType.VersionType, resultSelf);
            }
            finally
            {
                if (!AppConfig.KeepTempFiles)
                {
                    DeleteFile(menurc);
                    DeleteFile(stringrc);
                    DeleteFile(dialogrc);
                    DeleteFile(versionrc);
                }
            }

            return(result);
        }
Ejemplo n.º 4
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);
            }
        }