Skip to content

Commit

Permalink
Merge pull request #71 from barkingfoodog/add-get-resource-string
Browse files Browse the repository at this point in the history
Added --get-resource-string
  • Loading branch information
zcbenz authored Feb 12, 2018
2 parents 502218f + 9ac081b commit 452c0c3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ And you can change multiple things in one command:
```bash
$ rcedit "path-to-exe-or-dll" --set-icon "path-to-ico" --set-file-version "10.7"
```

Get version string:

```bash
$ rcedit "path-to-exe-or-dll" --get-version-string "property"
```

Use the same properties as `--set-version-string`. Use `"FileVersion"` to get the results of `--set-file-version` and `"ProductVersion"` to get the results of `--get-product-version`.

Get resource string:

```bash
$ rcedit "path-to-exe-or-dll" --get-resource-string id_number
```
22 changes: 20 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.

Expand All @@ -22,7 +22,8 @@ void print_help() {
" --set-icon <path-to-icon> Set file icon\n"
" --set-requested-execution-level <level> Pass nothing to see usage\n"
" --application-manifest <path-to-file> Set manifest file\n"
" --set-resource-string <key> <value> Set resource string\n");
" --set-resource-string <key> <value> Set resource string\n"
" --get-resource-string <key> Get resource string\n");
}

bool print_error(const char* message) {
Expand Down Expand Up @@ -153,6 +154,23 @@ int wmain(int argc, const wchar_t* argv[]) {
if (!updater.ChangeString(key_id, value))
return print_error("Unable to change string");

} else if (wcscmp(argv[i], L"--get-resource-string") == 0 ||
wcscmp(argv[i], L"-grs") == 0) {
if (argc - i < 2)
return print_error("--get-resource-string requires int 'Key'");

const wchar_t* key = argv[++i];
unsigned int key_id = 0;
if (swscanf_s(key, L"%d", &key_id) != 1)
return print_error("Unable to parse id");

const wchar_t* result = updater.GetString(key_id);
if (!result)
return print_error("Unable to get resource string");

fwprintf(stdout, L"%s", result);
return 0; // no changes made

} else {
if (loaded) {
fprintf(stderr, "Unrecognized argument: \"%ls\"\n", argv[i]);
Expand Down
25 changes: 24 additions & 1 deletion src/rescle.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
//
Expand Down Expand Up @@ -553,6 +553,29 @@ bool ResourceUpdater::ChangeString(UINT id, const WCHAR* value) {
return ChangeString(langId, id, value);
}

const WCHAR* ResourceUpdater::GetString(WORD languageId, UINT id) {
StringTable& table = stringTableMap_[languageId];

UINT blockId = id / 16;
if (table.find(blockId) == table.end()) {
// Fill the table until we reach the block.
for (size_t i = table.size(); i <= blockId; ++i) {
table[i] = std::vector<std::wstring>(16);
}
}

assert(table[blockId].size() == 16);
UINT blockIndex = id % 16;

return table[blockId][blockIndex].c_str();
}

const WCHAR* ResourceUpdater::GetString(UINT id) {
LANGID langId = stringTableMap_.empty() ? kLangEnUs
: stringTableMap_.begin()->first;
return GetString(langId, id);
}

bool ResourceUpdater::SetIcon(const WCHAR* path, const LANGID& langId,
UINT iconBundle) {
std::unique_ptr<IconsValue>& pIcon = iconBundleMap_[langId].iconBundles[iconBundle];
Expand Down
4 changes: 3 additions & 1 deletion src/rescle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
//
Expand Down Expand Up @@ -131,6 +131,8 @@ class ResourceUpdater {
bool SetFileVersion(unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4);
bool ChangeString(WORD languageId, UINT id, const WCHAR* value);
bool ChangeString(UINT id, const WCHAR* value);
const WCHAR* GetString(WORD languageId, UINT id);
const WCHAR* GetString(UINT id);
bool SetIcon(const WCHAR* path, const LANGID& langId, UINT iconBundle);
bool SetIcon(const WCHAR* path, const LANGID& langId);
bool SetIcon(const WCHAR* path);
Expand Down

0 comments on commit 452c0c3

Please sign in to comment.