Use CAutoGeneralHandle
[TortoiseGit.git] / src / ResText / ResModule.h
blob0bd66f067f47851c54191f29317db0d242f5ecbe
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007, 2011-2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #pragma once
19 #include <vector>
20 #include <string>
21 #include <map>
22 #include "POFile.h"
24 #define GET_WORD(ptr) (*(WORD *)(ptr))
25 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
26 #define ALIGN_DWORD(type, p) ((type)(((DWORD)p + 3) & ~3))
28 #define MAX_STRING_LENGTH (32*1024)
30 // DIALOG CONTROL INFORMATION
31 typedef struct tagDlgItemInfo
33 DWORD style;
34 DWORD exStyle;
35 DWORD helpId;
36 short x;
37 short y;
38 short cx;
39 short cy;
40 WORD id;
41 LPCTSTR className;
42 LPCTSTR windowName;
43 LPVOID data;
44 } DLGITEMINFO, * LPDLGITEMINFO;
46 // DIALOG TEMPLATE
47 typedef struct tagDialogInfo
49 DWORD style;
50 DWORD exStyle;
51 DWORD helpId;
52 WORD nbItems;
53 short x;
54 short y;
55 short cx;
56 short cy;
57 LPCTSTR menuName;
58 LPCTSTR className;
59 LPCTSTR caption;
60 WORD pointSize;
61 WORD weight;
62 BOOL italic;
63 LPCTSTR faceName;
64 BOOL dialogEx;
65 } DIALOGINFO, * LPDIALOGINFO;
66 // MENU resource
67 typedef struct tagMenuEntry
69 WORD wID;
70 std::wstring reference;
71 std::wstring msgstr;
72 } MENUENTRY, * LPMENUENTRY;
74 /**
75 * \ingroup ResText
76 * Class to handle a resource module (*.exe or *.dll file).
78 * Provides methods to extract and apply resource strings.
80 class CResModule
82 public:
83 CResModule(void);
84 ~CResModule(void);
86 BOOL ExtractResources(LPCTSTR lpszSrcLangDllPath, LPCTSTR lpszPOFilePath, BOOL bNoUpdate, LPCTSTR lpszHeaderFile);
87 BOOL ExtractResources(std::vector<std::wstring> filelist, LPCTSTR lpszPOFilePath, BOOL bNoUpdate, LPCTSTR lpszHeaderFile);
88 BOOL CreateTranslatedResources(LPCTSTR lpszSrcLangDllPath, LPCTSTR lpszDestLangDllPath, LPCTSTR lpszPOFilePath);
89 void SetQuiet(BOOL bQuiet = TRUE) {m_bQuiet = bQuiet; m_StringEntries.SetQuiet(bQuiet);}
90 void SetLanguage(WORD wLangID) {m_wTargetLang = wLangID;}
91 void SetRTL(bool bRTL = true) {m_bRTL = bRTL;}
92 void SetAdjustEOLs(bool bAdjustEOLs = true) {m_bAdjustEOLs = bAdjustEOLs;}
94 private:
95 static BOOL CALLBACK EnumResNameCallback(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam);
96 static BOOL CALLBACK EnumResNameWriteCallback(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam);
97 static BOOL CALLBACK EnumResWriteLangCallback(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, WORD wLanguage, LONG_PTR lParam);
98 BOOL ExtractString(UINT nID);
99 BOOL ExtractDialog(UINT nID);
100 BOOL ExtractMenu(UINT nID);
101 BOOL ReplaceString(UINT nID, WORD wLanguage);
102 BOOL ReplaceDialog(UINT nID, WORD wLanguage);
103 BOOL ReplaceMenu(UINT nID, WORD wLanguage);
104 BOOL ExtractAccelerator(UINT nID);
105 BOOL ReplaceAccelerator(UINT nID, WORD wLanguage);
107 const WORD* ParseMenuResource(const WORD * res);
108 const WORD* CountMemReplaceMenuResource(const WORD * res, size_t * wordcount, WORD * newMenu);
109 const WORD* ParseMenuExResource(const WORD * res);
110 const WORD* CountMemReplaceMenuExResource(const WORD * res, size_t * wordcount, WORD * newMenu);
111 const WORD* GetControlInfo(const WORD* p, LPDLGITEMINFO lpDlgItemInfo, BOOL dialogEx, LPBOOL bIsID);
112 const WORD* GetDialogInfo(const WORD * pTemplate, LPDIALOGINFO lpDlgInfo);
113 const WORD* CountMemReplaceDialogResource(const WORD * res, size_t * wordcount, WORD * newMenu);
114 const WORD* ReplaceControlInfo(const WORD * res, size_t * wordcount, WORD * newDialog, BOOL bEx);
116 void ReplaceStr(LPCWSTR src, WORD * dest, size_t * count, int * translated, int * def);
118 HMODULE m_hResDll;
119 HANDLE m_hUpdateRes;
120 CPOFile m_StringEntries;
121 std::map<WORD, MENUENTRY> m_MenuEntries;
122 std::map<WORD, MENUENTRY>::iterator pME_iter;
123 std::wstring sDestFile;
124 BOOL m_bQuiet;
126 bool m_bRTL;
127 bool m_bAdjustEOLs;
129 int m_bTranslatedStrings;
130 int m_bDefaultStrings;
131 int m_bTranslatedDialogStrings;
132 int m_bDefaultDialogStrings;
133 int m_bTranslatedMenuStrings;
134 int m_bDefaultMenuStrings;
135 int m_bTranslatedAcceleratorStrings;
136 int m_bDefaultAcceleratorStrings;
138 WORD m_wTargetLang;