Apply backgroundcolors.patch
[TortoiseGit.git] / src / ResText / ResModule.h
blob0c3cad3d393c846b96a72b02b27965376575ab9a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2019 - TortoiseGit
4 // Copyright (C) 2003-2007, 2011-2012, 2014-2017 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include "POFile.h"
25 #define GET_WORD(ptr) (*reinterpret_cast<const WORD*>(ptr))
26 #define GET_DWORD(ptr) (*reinterpret_cast<const DWORD*>(ptr))
27 #define ALIGN_DWORD(type, p) reinterpret_cast<type>(reinterpret_cast<DWORD>((p) + 3) & ~3)
29 #define MAX_STRING_LENGTH (32*1024)
31 // DIALOG CONTROL INFORMATION
32 typedef struct tagDlgItemInfo
34 DWORD style;
35 DWORD exStyle;
36 DWORD helpId;
37 short x;
38 short y;
39 short cx;
40 short cy;
41 WORD id;
42 LPCWSTR className;
43 LPCWSTR windowName;
44 LPVOID data;
45 } DLGITEMINFO, * LPDLGITEMINFO;
47 // DIALOG TEMPLATE
48 typedef struct tagDialogInfo
50 DWORD style;
51 DWORD exStyle;
52 DWORD helpId;
53 WORD nbItems;
54 short x;
55 short y;
56 short cx;
57 short cy;
58 LPCWSTR menuName;
59 LPCWSTR className;
60 LPCWSTR caption;
61 WORD pointSize;
62 WORD weight;
63 BOOL italic;
64 LPCWSTR faceName;
65 BOOL dialogEx;
66 } DIALOGINFO, * LPDIALOGINFO;
67 // MENU resource
68 typedef struct tagMenuEntry
70 WORD wID;
71 std::wstring reference;
72 std::wstring msgstr;
73 } MENUENTRY, * LPMENUENTRY;
75 /**
76 * \ingroup ResText
77 * Class to handle a resource module (*.exe or *.dll file).
79 * Provides methods to extract and apply resource strings.
81 class CResModule
83 public:
84 CResModule();
85 ~CResModule();
87 BOOL ExtractResources(LPCWSTR lpszSrcLangDllPath, LPCWSTR lpszPOFilePath, BOOL bNoUpdate, LPCWSTR lpszHeaderFile);
88 BOOL ExtractResources(const std::vector<std::wstring>& filelist, LPCWSTR lpszPOFilePath, BOOL bNoUpdate, LPCWSTR lpszHeaderFile);
89 BOOL CreateTranslatedResources(LPCWSTR lpszSrcLangDllPath, LPCWSTR lpszDestLangDllPath, LPCWSTR lpszPOFilePath);
90 void SetQuiet(BOOL bQuiet = TRUE) {m_bQuiet = bQuiet; m_StringEntries.SetQuiet(bQuiet);}
91 void SetLanguage(WORD wLangID) {m_wTargetLang = wLangID;}
92 void SetRTL(bool bRTL = true) {m_bRTL = bRTL;}
93 void SetAdjustEOLs(bool bAdjustEOLs = true) {m_bAdjustEOLs = bAdjustEOLs;}
95 private:
96 static BOOL CALLBACK EnumResNameCallback(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam);
97 static BOOL CALLBACK EnumResNameWriteCallback(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam);
98 static BOOL CALLBACK EnumResWriteLangCallback(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, WORD wLanguage, LONG_PTR lParam);
99 BOOL ExtractString(LPCWSTR lpszType);
100 BOOL ExtractDialog(LPCWSTR lpszType);
101 BOOL ExtractMenu(LPCWSTR lpszType);
102 BOOL ExtractRibbon(LPCWSTR lpszType);
103 BOOL ReplaceString(LPCWSTR lpszType, WORD wLanguage);
104 BOOL ReplaceDialog(LPCWSTR lpszType, WORD wLanguage);
105 BOOL ReplaceMenu(LPCWSTR lpszType, WORD wLanguage);
106 BOOL ExtractAccelerator(LPCWSTR lpszType);
107 BOOL ReplaceAccelerator(LPCWSTR lpszType, WORD wLanguage);
108 BOOL ReplaceRibbon(LPCWSTR lpszType, WORD wLanguage);
110 template <size_t _Size>
111 inline std::wstring ReplaceWithRegex(WCHAR (&pBuf)[_Size])
113 return ReplaceWithRegex(pBuf, _Size);
115 std::wstring ReplaceWithRegex(WCHAR* pBuf, size_t bufferSize);
116 std::wstring ReplaceWithRegex(std::wstring& s);
118 const WORD* ParseMenuResource(const WORD * res);
119 const WORD* CountMemReplaceMenuResource(const WORD * res, size_t * wordcount, WORD * newMenu);
120 const WORD* ParseMenuExResource(const WORD * res);
121 const WORD* CountMemReplaceMenuExResource(const WORD * res, size_t * wordcount, WORD * newMenu);
122 const WORD* GetControlInfo(const WORD* p, LPDLGITEMINFO lpDlgItemInfo, BOOL dialogEx, LPBOOL bIsID) const;
123 const WORD* GetDialogInfo(const WORD * pTemplate, LPDIALOGINFO lpDlgInfo) const;
124 const WORD* CountMemReplaceDialogResource(const WORD * res, size_t * wordcount, WORD * newMenu);
125 const WORD* ReplaceControlInfo(const WORD * res, size_t * wordcount, WORD * newDialog, BOOL bEx);
127 void ReplaceStr(LPCWSTR src, WORD * dest, size_t * count, int * translated, int * def);
129 size_t ScanHeaderFile(const std::wstring& filepath);
130 void InsertResourceIDs(LPCWSTR lpType, INT_PTR mainId, RESOURCEENTRY& entry, INT_PTR id, LPCWSTR infotext);
131 bool AdjustCheckSum(const std::wstring& resFile);
132 void RemoveSignatures(LPCWSTR lpszDestLangDllPath);
134 HMODULE m_hResDll;
135 HANDLE m_hUpdateRes;
136 CPOFile m_StringEntries;
137 std::map<WORD, MENUENTRY> m_MenuEntries;
138 std::map<WORD, MENUENTRY>::iterator pME_iter;
139 std::wstring sDestFile;
140 std::map<INT_PTR, std::wstring> m_currentHeaderDataDialogs;
141 std::map<INT_PTR, std::wstring> m_currentHeaderDataStrings;
142 std::map<INT_PTR, std::wstring> m_currentHeaderDataMenus;
143 BOOL m_bQuiet;
145 bool m_bRTL;
146 bool m_bAdjustEOLs;
148 int m_bTranslatedStrings;
149 int m_bDefaultStrings;
150 int m_bTranslatedDialogStrings;
151 int m_bDefaultDialogStrings;
152 int m_bTranslatedMenuStrings;
153 int m_bDefaultMenuStrings;
154 int m_bTranslatedAcceleratorStrings;
155 int m_bDefaultAcceleratorStrings;
156 int m_bTranslatedRibbonTexts;
157 int m_bDefaultRibbonTexts;
159 WORD m_wTargetLang;