OSDN Git Service

Improve log speed.
[tortoisegit/TortoiseGitJp.git] / src / ResText / ResText.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006 - Stefan Kueng\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 #include "stdafx.h"\r
19 #include "ResModule.h"\r
20 \r
21 #include <string>\r
22 #include <vector>\r
23 #include "shlwapi.h"\r
24 #pragma comment(lib, "shlwapi.lib")\r
25 \r
26 typedef std::basic_string<wchar_t> wstring;\r
27 #ifdef UNICODE\r
28 #       define stdstring wstring\r
29 #else\r
30 #       define stdstring std::string\r
31 #endif\r
32 \r
33 int _tmain(int argc, _TCHAR* argv[])\r
34 {\r
35         bool bShowHelp = true;\r
36         bool bQuiet = false;\r
37         bool bNoUpdate = false;\r
38         bool bRTL = false;\r
39         //parse the command line\r
40         std::vector<stdstring> arguments;\r
41         std::vector<stdstring> switches;\r
42         for (int i=1; i<argc; ++i)\r
43         {\r
44                 if ((argv[i][0] == '-')||(argv[i][0] == '/'))\r
45                 {\r
46                         stdstring str = stdstring(&argv[i][1]);\r
47                         switches.push_back(str);\r
48                 }\r
49                 else\r
50                 {\r
51                         stdstring str = stdstring(&argv[i][0]);\r
52                         arguments.push_back(str);\r
53                 }\r
54         }\r
55 \r
56         for (std::vector<stdstring>::iterator I = switches.begin(); I != switches.end(); ++I)\r
57         {\r
58                 if (_tcscmp(I->c_str(), _T("?"))==0)\r
59                         bShowHelp = true;\r
60                 if (_tcscmp(I->c_str(), _T("help"))==0)\r
61                         bShowHelp = true;\r
62                 if (_tcscmp(I->c_str(), _T("quiet"))==0)\r
63                         bQuiet = true;\r
64                 if (_tcscmp(I->c_str(), _T("noupdate"))==0)\r
65                         bNoUpdate = true;\r
66                 if (_tcscmp(I->c_str(), _T("rtl"))==0)\r
67                         bRTL = true;\r
68         }\r
69         std::vector<stdstring>::iterator arg = arguments.begin();\r
70 \r
71         if (arg != arguments.end())\r
72         {\r
73                 if (_tcscmp(arg->c_str(), _T("extract"))==0)\r
74                 {\r
75                         stdstring sDllFile;\r
76                         stdstring sPoFile;\r
77                         ++arg;\r
78                         \r
79                         std::vector<std::wstring> filelist = arguments;\r
80                         filelist.erase(filelist.begin());\r
81                         sPoFile = stdstring((--filelist.end())->c_str());\r
82                         filelist.erase(--filelist.end());\r
83                         \r
84                         CResModule module;\r
85                         module.SetQuiet(bQuiet);\r
86                         if (!module.ExtractResources(filelist, sPoFile.c_str(), bNoUpdate))\r
87                                 return -1;\r
88                         bShowHelp = false;\r
89                 }\r
90                 else if (_tcscmp(arg->c_str(), _T("apply"))==0)\r
91                 {\r
92                         stdstring sSrcDllFile;\r
93                         stdstring sDstDllFile;\r
94                         stdstring sPoFile;\r
95                         WORD wLang = 0;\r
96                         ++arg;\r
97                         if (!PathFileExists(arg->c_str()))\r
98                         {\r
99                                 _ftprintf(stderr, _T("the resource dll <%s> does not exist!\n"), arg->c_str());\r
100                                 return -1;\r
101                         }\r
102                         sSrcDllFile = stdstring(arg->c_str());\r
103                         ++arg;\r
104                         sDstDllFile = stdstring(arg->c_str());\r
105                         ++arg;\r
106                         if (!PathFileExists(arg->c_str()))\r
107                         {\r
108                                 _ftprintf(stderr, _T("the po-file <%s> does not exist!\n"), arg->c_str());\r
109                                 return -1;\r
110                         }\r
111                         sPoFile = stdstring(arg->c_str());\r
112                         ++arg;\r
113                         if (arg != arguments.end())\r
114                         {\r
115                                 wLang = (WORD)_ttoi(arg->c_str());\r
116                         }\r
117                         CResModule module;\r
118                         module.SetQuiet(bQuiet);\r
119                         module.SetLanguage(wLang);\r
120                         module.SetRTL(bRTL);\r
121                         if (!module.CreateTranslatedResources(sSrcDllFile.c_str(), sDstDllFile.c_str(), sPoFile.c_str()))\r
122                                 return -1;\r
123                         bShowHelp = false;\r
124                 }\r
125         }\r
126 \r
127         if (bShowHelp)\r
128         {\r
129                 _ftprintf(stdout, _T("usage:\n"));\r
130                 _ftprintf(stdout, _T("\n"));\r
131                 _ftprintf(stdout, _T("ResText extract <resource.dll> [<resource.dll> ...] <po-file> [-quiet] [-noupdate]\n"));\r
132                 _ftprintf(stdout, _T("Extracts all strings from the resource dll and writes them to the po-file\n"));\r
133                 _ftprintf(stdout, _T("-quiet: don't print progress messages\n"));\r
134                 _ftprintf(stdout, _T("-noupdate: overwrite the po-file\n"));\r
135                 _ftprintf(stdout, _T("\n"));\r
136                 _ftprintf(stdout, _T("ResText apply <src resource.dll> <dst resource.dll> <po-file> [langID] [-quiet][-rtl]\n"));\r
137                 _ftprintf(stdout, _T("Replaces all strings in the dst resource.dll with the po-file translations\n"));\r
138                 _ftprintf(stdout, _T("-quiet: don't print progress messages\n"));\r
139                 _ftprintf(stdout, _T("-rtl  : change the controls to RTL reading\n"));\r
140                 _ftprintf(stdout, _T("\n"));\r
141         }\r
142 \r
143         return 0;\r
144 }\r
145 \r