Skip to content

Commit

Permalink
Merge pull request #74 from malept/better-icon-errors
Browse files Browse the repository at this point in the history
Give more specific errors when rcedit cannot set an icon
  • Loading branch information
zcbenz authored May 7, 2018
2 parents 452c0c3 + 5c4845e commit fc54d9f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/rescle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,26 +586,36 @@ bool ResourceUpdater::SetIcon(const WCHAR* path, const LANGID& langId,
DWORD bytes;

ScopedFile file(path);
if (file == INVALID_HANDLE_VALUE)
if (file == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Cannot open icon file '%s'\n", path);
return false;
}

IconsValue::ICONHEADER& header = icon.header;
if (!ReadFile(file, &header, 3 * sizeof(WORD), &bytes, NULL))
if (!ReadFile(file, &header, 3 * sizeof(WORD), &bytes, NULL)) {
fprintf(stderr, "Cannot read icon header for '%s'\n", path);
return false;
}

if (header.reserved != 0 || header.type != 1)
if (header.reserved != 0 || header.type != 1) {
fprintf(stderr, "Reserved header is not 0 or image type is not icon for '%s'\n", path);
return false;
}

header.entries.resize(header.count);
if (!ReadFile(file, header.entries.data(), header.count * sizeof(IconsValue::ICONENTRY), &bytes, NULL))
if (!ReadFile(file, header.entries.data(), header.count * sizeof(IconsValue::ICONENTRY), &bytes, NULL)) {
fprintf(stderr, "Cannot read icon metadata for '%s'\n", path);
return false;
}

icon.images.resize(header.count);
for (size_t i = 0; i < header.count; ++i) {
icon.images[i].resize(header.entries[i].bytesInRes);
SetFilePointer(file, header.entries[i].imageOffset, NULL, FILE_BEGIN);
if (!ReadFile(file, icon.images[i].data(), icon.images[i].size(), &bytes, NULL))
if (!ReadFile(file, icon.images[i].data(), icon.images[i].size(), &bytes, NULL)) {
fprintf(stderr, "Cannot read icon data for '%s'\n", path);
return false;
}
}

icon.grpHeader.resize(3 * sizeof(WORD) + header.count * sizeof(GRPICONENTRY));
Expand Down

0 comments on commit fc54d9f

Please sign in to comment.