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.
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
45 } DLGITEMINFO
, * LPDLGITEMINFO
;
48 typedef struct tagDialogInfo
66 } DIALOGINFO
, * LPDIALOGINFO
;
68 typedef struct tagMenuEntry
71 std::wstring reference
;
73 } MENUENTRY
, * LPMENUENTRY
;
77 * Class to handle a resource module (*.exe or *.dll file).
79 * Provides methods to extract and apply resource strings.
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
;}
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
);
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
;
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
;