Beispiel #1
0
        public byte[] Merge(List <TranslateUnit> newTus)
        {
            if (_datasubs == null || _datasubs.Count == 0)
            {
                return(new byte[0]);
            }

            List <Byte>   bytes = new List <Byte>();
            TranslateUnit oriTU = null;

            if (_tus != null && _tus.Count > 0)
            {
                oriTU = _tus[0];
                string category      = oriTU.Category;
                string categoryIndex = oriTU.Index;

                int tuIndex = 0;
                for (int i = 0; i < _datasubs.Count; i++)
                {
                    DataSub sub = _datasubs[i];

                    if (sub.extracted)
                    {
                        tuIndex = tuIndex + 1;
                        oriTU   = _tus[tuIndex - 1];
                        TranslateUnit tu         = TranslateUnitUtil.GetTranslateUnit(newTus, category, categoryIndex, "" + tuIndex);
                        string        newContent = tu.SourceContent;
                        string        oriContent = oriTU.SourceContent;

                        if (oriContent.Contains("\n") && !oriContent.Contains("\r\n"))
                        {
                            newContent = newContent.Replace("\r\n", "\n");
                        }

                        bytes.AddRange(Encoding.Unicode.GetBytes(newContent));
                    }
                    else
                    {
                        bytes.AddRange(sub.data);
                    }
                }
            }
            else
            {
                if (Data != null)
                {
                    return(Data);
                }

                foreach (DataSub sub in _datasubs)
                {
                    bytes.AddRange(sub.data);
                }
            }
            return(bytes.ToArray());
        }
Beispiel #2
0
        /*
         *
         * */

        unsafe public static void UpdateResource(string peFile, List <TranslateUnit> units,
                                                 ushort wLanguage, string lpType, string category, string id)
        {
            IntPtr newV = IntPtr.Zero;

            try
            {
                TranslateUnit tu = TranslateUnitUtil.GetTranslateUnit(units, category, id);

                IntPtr hResource = WinAPI.BeginUpdateResource(peFile, true);
                if (hResource.ToInt32() == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                newV = Marshal.StringToHGlobalUni(tu.SourceContent);
                uint cbData = (uint)Encoding.Unicode.GetBytes(tu.SourceContent).Length;

                if (WinAPI.UpdateResource(hResource, lpType, id, wLanguage, newV, cbData) == false)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                if (WinAPI.EndUpdateResource(hResource, false) == false)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                if (newV != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(newV);
                }
            }
        }
Beispiel #3
0
        private static string UpdateVersionValue(string oriVersionInfor, List <TranslateUnit> units, string category, string id)
        {
            TranslateUnit tu = TranslateUnitUtil.GetTranslateUnit(units, category, id);

            return(oriVersionInfor);
        }
Beispiel #4
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;
                }
            }
        }