Fixed issue #3602: Make it possible to select multiple old commit messages from log...
[TortoiseGit.git] / src / ResText / ResText.cpp
blobd99fb0b8ec18671252135e7f04caae92cd728e71
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2009-2012, 2014-2015 - 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 #include "stdafx.h"
19 #include "ResModule.h"
21 #include <string>
22 #include <vector>
23 #include <Shlwapi.h>
24 #pragma comment(lib, "shlwapi.lib")
26 int wmain(int argc, wchar_t* argv[])
28 bool bShowHelp = true;
29 bool bQuiet = false;
30 bool bNoUpdate = false;
31 bool bRTL = false;
32 bool bUseHeader = false;
33 bool bAdjustEOLs = false;
34 //parse the command line
35 std::vector<std::wstring> arguments;
36 std::vector<std::wstring> switches;
37 for (int i=1; i<argc; ++i)
39 if ((argv[i][0] == '-')||(argv[i][0] == '/'))
41 std::wstring str = std::wstring(&argv[i][1]);
42 switches.push_back(str);
44 else
46 std::wstring str = std::wstring(&argv[i][0]);
47 arguments.push_back(str);
51 for (auto I = switches.cbegin(); I != switches.cend(); ++I)
53 if (wcscmp(I->c_str(), L"?")==0)
54 bShowHelp = true;
55 if (wcscmp(I->c_str(), L"help")==0)
56 bShowHelp = true;
57 if (wcscmp(I->c_str(), L"quiet")==0)
58 bQuiet = true;
59 if (wcscmp(I->c_str(), L"noupdate")==0)
60 bNoUpdate = true;
61 if (wcscmp(I->c_str(), L"rtl")==0)
62 bRTL = true;
63 if (wcscmp(I->c_str(), L"useheaderfile")==0)
64 bUseHeader = true;
65 if (wcscmp(I->c_str(), L"adjusteols")==0)
66 bAdjustEOLs = true;
68 auto arg = arguments.cbegin();
70 if (arg != arguments.cend())
72 if (wcscmp(arg->c_str(), L"extract")==0)
74 std::wstring sPoFile;
75 std::wstring sHeaderFile;
76 ++arg;
78 std::vector<std::wstring> filelist = arguments;
79 filelist.erase(filelist.begin());
80 sPoFile = std::wstring((--filelist.end())->c_str());
81 filelist.erase(--filelist.end());
82 if (bUseHeader)
84 sHeaderFile = std::wstring((--filelist.end())->c_str());
85 filelist.erase(--filelist.end());
88 CResModule module;
89 module.SetQuiet(bQuiet);
90 if (!module.ExtractResources(filelist, sPoFile.c_str(), bNoUpdate, sHeaderFile.c_str()))
91 return -1;
92 bShowHelp = false;
94 else if (wcscmp(arg->c_str(), L"apply")==0)
96 std::wstring sSrcDllFile;
97 std::wstring sDstDllFile;
98 std::wstring sPoFile;
99 WORD wLang = 0;
100 ++arg;
101 if (!PathFileExists(arg->c_str()))
103 fwprintf(stderr, L"the resource dll <%s> does not exist!\n", arg->c_str());
104 return -1;
106 sSrcDllFile = std::wstring(arg->c_str());
107 ++arg;
108 sDstDllFile = std::wstring(arg->c_str());
109 ++arg;
110 if (!PathFileExists(arg->c_str()))
112 fwprintf(stderr, L"the po-file <%s> does not exist!\n", arg->c_str());
113 return -1;
115 sPoFile = std::wstring(arg->c_str());
116 ++arg;
117 if (arg != arguments.end())
119 wLang = static_cast<WORD>(_wtoi(arg->c_str()));
121 CResModule module;
122 module.SetQuiet(bQuiet);
123 module.SetLanguage(wLang);
124 module.SetRTL(bRTL);
125 module.SetAdjustEOLs(bAdjustEOLs);
126 if (!module.CreateTranslatedResources(sSrcDllFile.c_str(), sDstDllFile.c_str(), sPoFile.c_str()))
127 return -1;
128 bShowHelp = false;
132 if (bShowHelp)
134 fwprintf(stdout, L"usage:\n");
135 fwprintf(stdout, L"\n");
136 fwprintf(stdout, L"ResText extract <resource.dll> [<resource.dll> ...] [-useheaderfile <headerfile>] <po-file> [-quiet] [-noupdate]\n");
137 fwprintf(stdout, L"Extracts all strings from the resource dll and writes them to the po-file\n");
138 fwprintf(stdout, L"-useheaderfile: the content of the header file instead of a default header\n");
139 fwprintf(stdout, L"-quiet: don't print progress messages\n");
140 fwprintf(stdout, L"-noupdate: overwrite the po-file\n");
141 fwprintf(stdout, L"\n");
142 fwprintf(stdout, L"ResText apply <src resource.dll> <dst resource.dll> <po-file> [langID] [-quiet][-rtl]\n");
143 fwprintf(stdout, L"Replaces all strings in the dst resource.dll with the po-file translations\n");
144 fwprintf(stdout, L"-quiet: don't print progress messages\n");
145 fwprintf(stdout, L"-rtl : change the controls to RTL reading\n");
146 fwprintf(stdout, L"-adjusteols : if the msgid string has \\r\\n eols, enforce those for the translation too.\n");
147 fwprintf(stdout, L"\n");
148 fwprintf(stdout, L"Note: when extracting resources, C-resource header files can be specified\n");
149 fwprintf(stdout, L"like this: <resource.dll>*<resource.h>*<resource.h>*...\n");
150 fwprintf(stdout, L"If a resource header file is specified, the defines are used in the po file\n");
151 fwprintf(stdout, L"as hints instead of the plain control ID number.\n");
154 return 0;