1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*************************************************************************/
/* Copyright (c) 2015 dx, http://kaimi.ru */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following conditions: */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <sstream>
#include <iomanip>
#include "version_info_types.h"
#include "version_info_editor.h"
#include "version_info_viewer.h"
namespace pe_bliss
{
//Default constructor
//strings - version info strings with charsets
//translations - version info translations map
version_info_editor::version_info_editor(lang_string_values_map& strings, translation_values_map& translations)
:version_info_viewer(strings, translations),
strings_edit_(strings),
translations_edit_(translations)
{}
//Below functions have parameter translation
//If it's empty, the default language translation will be taken
//If there's no default language translation, the first one will be taken
//Sets company name
void version_info_editor::set_company_name(const std::wstring& value, const std::wstring& translation)
{
set_property(L"CompanyName", value, translation);
}
//Sets file description
void version_info_editor::set_file_description(const std::wstring& value, const std::wstring& translation)
{
set_property(L"FileDescription", value, translation);
}
//Sets file version
void version_info_editor::set_file_version(const std::wstring& value, const std::wstring& translation)
{
set_property(L"FileVersion", value, translation);
}
//Sets internal file name
void version_info_editor::set_internal_name(const std::wstring& value, const std::wstring& translation)
{
set_property(L"InternalName", value, translation);
}
//Sets legal copyright
void version_info_editor::set_legal_copyright(const std::wstring& value, const std::wstring& translation)
{
set_property(L"LegalCopyright", value, translation);
}
//Sets original file name
void version_info_editor::set_original_filename(const std::wstring& value, const std::wstring& translation)
{
set_property(L"OriginalFilename", value, translation);
}
//Sets product name
void version_info_editor::set_product_name(const std::wstring& value, const std::wstring& translation)
{
set_property(L"ProductName", value, translation);
}
//Sets product version
void version_info_editor::set_product_version(const std::wstring& value, const std::wstring& translation)
{
set_property(L"ProductVersion", value, translation);
}
//Sets version info property value
//property_name - property name
//value - property value
//If translation does not exist, it will be added
//If property does not exist, it will be added
void version_info_editor::set_property(const std::wstring& property_name, const std::wstring& value, const std::wstring& translation)
{
lang_string_values_map::iterator it = strings_edit_.begin();
if(translation.empty())
{
//If no translation was specified
it = strings_edit_.find(default_language_translation); //Find default translation table
if(it == strings_edit_.end()) //If there's no default translation table, take the first one
{
it = strings_edit_.begin();
if(it == strings_edit_.end()) //If there's no any translation table, add default one
{
it = strings_edit_.insert(std::make_pair(default_language_translation, string_values_map())).first;
//Also add it to translations list
add_translation(default_language_translation);
}
}
}
else
{
it = strings_edit_.find(translation); //Find specified translation table
if(it == strings_edit_.end()) //If there's no translation, add it
{
it = strings_edit_.insert(std::make_pair(translation, string_values_map())).first;
//Also add it to translations list
add_translation(translation);
}
}
//Change value of the required property
((*it).second)[property_name] = value;
}
//Adds translation to translation list
void version_info_editor::add_translation(const std::wstring& translation)
{
std::pair<uint16_t, uint16_t> translation_ids(translation_from_string(translation));
add_translation(translation_ids.first, translation_ids.second);
}
void version_info_editor::add_translation(uint16_t language_id, uint16_t codepage_id)
{
std::pair<translation_values_map::const_iterator, translation_values_map::const_iterator>
range(translations_edit_.equal_range(language_id));
//If translation already exists
for(translation_values_map::const_iterator it = range.first; it != range.second; ++it)
{
if((*it).second == codepage_id)
return;
}
translations_edit_.insert(std::make_pair(language_id, codepage_id));
}
//Removes translation from translations and strings lists
void version_info_editor::remove_translation(const std::wstring& translation)
{
std::pair<uint16_t, uint16_t> translation_ids(translation_from_string(translation));
remove_translation(translation_ids.first, translation_ids.second);
}
void version_info_editor::remove_translation(uint16_t language_id, uint16_t codepage_id)
{
{
//Erase string table (if exists)
std::wstringstream ss;
ss << std::hex
<< std::setw(4) << std::setfill(L'0') << language_id
<< std::setw(4) << std::setfill(L'0') << codepage_id;
strings_edit_.erase(ss.str());
}
//Find and erase translation from translations table
std::pair<translation_values_map::iterator, translation_values_map::iterator>
it_pair = translations_edit_.equal_range(language_id);
for(translation_values_map::iterator it = it_pair.first; it != it_pair.second; ++it)
{
if((*it).second == codepage_id)
{
translations_edit_.erase(it);
break;
}
}
}
}
|