Cleanup
[TortoiseGit.git] / src / ResText / ResModule.h
blobf44942cd2acd568ad2275c68bc29a485497f794c
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(LPCTSTR lpszType);
99 BOOL ExtractDialog(LPCTSTR lpszType);
100 BOOL ExtractMenu(LPCTSTR lpszType);
101 BOOL ExtractRibbon(LPCTSTR lpszType);
102 BOOL ReplaceString(LPCTSTR lpszType, WORD wLanguage);
103 BOOL ReplaceDialog(LPCTSTR lpszType, WORD wLanguage);
104 BOOL ReplaceMenu(LPCTSTR lpszType, WORD wLanguage);
105 BOOL ExtractAccelerator(LPCTSTR lpszType);
106 BOOL ReplaceAccelerator(LPCTSTR lpszType, WORD wLanguage);
107 BOOL ReplaceRibbon(LPCTSTR lpszType, WORD wLanguage);
109 const WORD* ParseMenuResource(const WORD * res);
110 const WORD* CountMemReplaceMenuResource(const WORD * res, size_t * wordcount, WORD * newMenu);
111 const WORD* ParseMenuExResource(const WORD * res);
112 const WORD* CountMemReplaceMenuExResource(const WORD * res, size_t * wordcount, WORD * newMenu);
113 const WORD* GetControlInfo(const WORD* p, LPDLGITEMINFO lpDlgItemInfo, BOOL dialogEx, LPBOOL bIsID);
114 const WORD* GetDialogInfo(const WORD * pTemplate, LPDIALOGINFO lpDlgInfo);
115 const WORD* CountMemReplaceDialogResource(const WORD * res, size_t * wordcount, WORD * newMenu);
116 const WORD* ReplaceControlInfo(const WORD * res, size_t * wordcount, WORD * newDialog, BOOL bEx);
118 void ReplaceStr(LPCWSTR src, WORD * dest, size_t * count, int * translated, int * def);
120 HMODULE m_hResDll;
121 HANDLE m_hUpdateRes;
122 CPOFile m_StringEntries;
123 std::map<WORD, MENUENTRY> m_MenuEntries;
124 std::map<WORD, MENUENTRY>::iterator pME_iter;
125 std::wstring sDestFile;
126 BOOL m_bQuiet;
128 bool m_bRTL;
129 bool m_bAdjustEOLs;
131 int m_bTranslatedStrings;
132 int m_bDefaultStrings;
133 int m_bTranslatedDialogStrings;
134 int m_bDefaultDialogStrings;
135 int m_bTranslatedMenuStrings;
136 int m_bDefaultMenuStrings;
137 int m_bTranslatedAcceleratorStrings;
138 int m_bDefaultAcceleratorStrings;
139 int m_bTranslatedRibbonTexts;
140 int m_bDefaultRibbonTexts;
142 WORD m_wTargetLang;