CPatch: New memory management
[TortoiseGit.git] / src / ResText / ResText.cpp
blob9c2b6fca240cab7f6dc4d8ea78000824b2c38e82
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 typedef std::basic_string<TCHAR> tstring;
28 int _tmain(int argc, _TCHAR* argv[])
30 bool bShowHelp = true;
31 bool bQuiet = false;
32 bool bNoUpdate = false;
33 bool bRTL = false;
34 bool bUseHeader = false;
35 bool bAdjustEOLs = false;
36 //parse the command line
37 std::vector<tstring> arguments;
38 std::vector<tstring> switches;
39 for (int i=1; i<argc; ++i)
41 if ((argv[i][0] == '-')||(argv[i][0] == '/'))
43 tstring str = tstring(&argv[i][1]);
44 switches.push_back(str);
46 else
48 tstring str = tstring(&argv[i][0]);
49 arguments.push_back(str);
53 for (auto I = switches.cbegin(); I != switches.cend(); ++I)
55 if (wcscmp(I->c_str(), L"?")==0)
56 bShowHelp = true;
57 if (wcscmp(I->c_str(), L"help")==0)
58 bShowHelp = true;
59 if (wcscmp(I->c_str(), L"quiet")==0)
60 bQuiet = true;
61 if (wcscmp(I->c_str(), L"noupdate")==0)
62 bNoUpdate = true;
63 if (wcscmp(I->c_str(), L"rtl")==0)
64 bRTL = true;
65 if (wcscmp(I->c_str(), L"useheaderfile")==0)
66 bUseHeader = true;
67 if (wcscmp(I->c_str(), L"adjusteols")==0)
68 bAdjustEOLs = true;
70 auto arg = arguments.cbegin();
72 if (arg != arguments.cend())
74 if (wcscmp(arg->c_str(), L"extract")==0)
76 tstring sPoFile;
77 tstring sHeaderFile;
78 ++arg;
80 std::vector<std::wstring> filelist = arguments;
81 filelist.erase(filelist.begin());
82 sPoFile = tstring((--filelist.end())->c_str());
83 filelist.erase(--filelist.end());
84 if (bUseHeader)
86 sHeaderFile = tstring((--filelist.end())->c_str());
87 filelist.erase(--filelist.end());
90 CResModule module;
91 module.SetQuiet(bQuiet);
92 if (!module.ExtractResources(filelist, sPoFile.c_str(), bNoUpdate, sHeaderFile.c_str()))
93 return -1;
94 bShowHelp = false;
96 else if (wcscmp(arg->c_str(), L"apply")==0)
98 tstring sSrcDllFile;
99 tstring sDstDllFile;
100 tstring sPoFile;
101 WORD wLang = 0;
102 ++arg;
103 if (!PathFileExists(arg->c_str()))
105 _ftprintf(stderr, L"the resource dll <%s> does not exist!\n", arg->c_str());
106 return -1;
108 sSrcDllFile = tstring(arg->c_str());
109 ++arg;
110 sDstDllFile = tstring(arg->c_str());
111 ++arg;
112 if (!PathFileExists(arg->c_str()))
114 _ftprintf(stderr, L"the po-file <%s> does not exist!\n", arg->c_str());
115 return -1;
117 sPoFile = tstring(arg->c_str());
118 ++arg;
119 if (arg != arguments.end())
121 wLang = (WORD)_wtoi(arg->c_str());
123 CResModule module;
124 module.SetQuiet(bQuiet);
125 module.SetLanguage(wLang);
126 module.SetRTL(bRTL);
127 module.SetAdjustEOLs(bAdjustEOLs);
128 if (!module.CreateTranslatedResources(sSrcDllFile.c_str(), sDstDllFile.c_str(), sPoFile.c_str()))
129 return -1;
130 bShowHelp = false;
134 if (bShowHelp)
136 _ftprintf(stdout, L"usage:\n");
137 _ftprintf(stdout, L"\n");
138 _ftprintf(stdout, L"ResText extract <resource.dll> [<resource.dll> ...] [-useheaderfile <headerfile>] <po-file> [-quiet] [-noupdate]\n");
139 _ftprintf(stdout, L"Extracts all strings from the resource dll and writes them to the po-file\n");
140 _ftprintf(stdout, L"-useheaderfile: the content of the header file instead of a default header\n");
141 _ftprintf(stdout, L"-quiet: don't print progress messages\n");
142 _ftprintf(stdout, L"-noupdate: overwrite the po-file\n");
143 _ftprintf(stdout, L"\n");
144 _ftprintf(stdout, L"ResText apply <src resource.dll> <dst resource.dll> <po-file> [langID] [-quiet][-rtl]\n");
145 _ftprintf(stdout, L"Replaces all strings in the dst resource.dll with the po-file translations\n");
146 _ftprintf(stdout, L"-quiet: don't print progress messages\n");
147 _ftprintf(stdout, L"-rtl : change the controls to RTL reading\n");
148 _ftprintf(stdout, L"-adjusteols : if the msgid string has \\r\\n eols, enforce those for the translation too.\n");
149 _ftprintf(stdout, L"\n");
150 _ftprintf(stdout, L"Note: when extracting resources, C-resource header files can be specified\n");
151 _ftprintf(stdout, L"like this: <resource.dll>*<resource.h>*<resource.h>*...\n");
152 _ftprintf(stdout, L"If a resource header file is specified, the defines are used in the po file\n");
153 _ftprintf(stdout, L"as hints instead of the plain control ID number.\n");
156 return 0;