From a94a7b67e3734622c4f744f43c7c502c245eeb7f Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 27 Jan 2006 15:57:56 +0000 Subject: [PATCH] fixed bug #1174742 - Icon error message is uninformative git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4508 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/script.cpp | 13 +++---------- Source/util.cpp | 28 +++++++++------------------- Source/util.h | 2 +- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/Source/script.cpp b/Source/script.cpp index 356c5c4a..06e3134a 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1518,13 +1518,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SCRIPT_MSG("Icon: \"%s\"\n",line.gettoken_str(1)); try { init_res_editor(); - if (replace_icon(res_editor, IDI_ICON2, line.gettoken_str(1)) < 0) { - ERROR_MSG("Error: File doesn't exist or is an invalid icon file\n"); - return PS_ERROR; - } + replace_icon(res_editor, IDI_ICON2, line.gettoken_str(1)); } catch (exception& err) { - ERROR_MSG("Error while replacing icon: %s\n", err.what()); + ERROR_MSG("Error while setting icon to \"%s\": %s\n", line.gettoken_str(1), err.what()); return PS_ERROR; } return PS_OK; @@ -2929,13 +2926,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) try { free(m_unicon_data); m_unicon_data = generate_uninstall_icon_data(line.gettoken_str(1), m_unicon_size); - if (!m_unicon_data) { - ERROR_MSG("Error: File doesn't exist or is an invalid icon file\n"); - return PS_ERROR; - } } catch (exception& err) { - ERROR_MSG("Error while replacing icon: %s\n", err.what()); + ERROR_MSG("Error while setting icon to \"%s\": %s\n", line.gettoken_str(1), err.what()); return PS_ERROR; } return PS_OK; diff --git a/Source/util.cpp b/Source/util.cpp index fe4a4886..8f2868ae 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -133,20 +133,16 @@ typedef struct { #define SIZEOF_RSRC_ICON_GROUP_ENTRY 14 -// Added by Amir Szekely 8th July 2002 // replace_icon, must get an initialized resource editor -// return values: -// 0 - All OK -// -1 - Bad icon file -int replace_icon(CResourceEditor* re, WORD wIconId, const char* filename) +void replace_icon(CResourceEditor* re, WORD wIconId, const char* filename) { FILE* f = FOPEN(filename, "rb"); - if (!f) return -1; + if (!f) throw exception("can't open file"); IconGroupHeader igh; - fread(&igh, sizeof(IconGroupHeader), 1, f); + if (!fread(&igh, sizeof(IconGroupHeader), 1, f)) throw exception("unable to read file"); - if (igh.wIsIcon != 1 && igh.wReserved != 0) return -1; + if (igh.wIsIcon != 1 && igh.wReserved != 0) throw exception("invalid icon file"); BYTE* rsrcIconGroup = (BYTE*)malloc(sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY); if (!rsrcIconGroup) throw bad_alloc(); @@ -174,7 +170,7 @@ int replace_icon(CResourceEditor* re, WORD wIconId, const char* filename) if (fseek(f, dwOffset, SEEK_SET)) { free(rsrcIconGroup); - return -1; + throw exception("corrupted icon file, too small"); } BYTE* iconData = (BYTE*)malloc(ige->dwRawSize); if (!iconData) { @@ -200,27 +196,21 @@ int replace_icon(CResourceEditor* re, WORD wIconId, const char* filename) re->UpdateResource(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, rsrcIconGroup, sizeof(IconGroupHeader) + igh.wCount*SIZEOF_RSRC_ICON_GROUP_ENTRY); free(rsrcIconGroup); - - return 0; } -// Added by Amir Szekely 8th July 2002 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT // returns the data of the uninstaller icon that should replace the installer icon data -// return values: -// 0 - Bad icon file -// Anything else - Pointer to the uninstaller icon data unsigned char* generate_uninstall_icon_data(const char* filename, size_t &size) { int i; FILE* f = FOPEN(filename, "rb"); - if (!f) return 0; + if (!f) throw exception("can't open file"); IconGroupHeader igh; - if (!fread(&igh, sizeof(IconGroupHeader), 1, f)) return 0; + if (!fread(&igh, sizeof(IconGroupHeader), 1, f)) throw exception("unable to read file"); - if (igh.wIsIcon != 1 && igh.wReserved != 0) return 0; + if (igh.wIsIcon != 1 && igh.wReserved != 0) throw exception("invalid icon file"); int iNewIconSize = 0; FileIconGroupEntry ige; @@ -230,7 +220,7 @@ unsigned char* generate_uninstall_icon_data(const char* filename, size_t &size) if (!offsets || !rawSizes) throw bad_alloc(); for (i = 0; i < igh.wCount; i++) { - if (!fread(&ige, sizeof(FileIconGroupEntry), 1, f)) return 0; + if (!fread(&ige, sizeof(FileIconGroupEntry), 1, f)) throw exception("unable to read file"); offsets[i] = ige.dwImageOffset; rawSizes[i] = ige.dwRawSize; iNewIconSize += ige.dwRawSize; diff --git a/Source/util.h b/Source/util.h index 94b2f305..f85f1314 100644 --- a/Source/util.h +++ b/Source/util.h @@ -22,7 +22,7 @@ extern void dopause(void); int update_bitmap(CResourceEditor* re, WORD id, const char* filename, int width=0, int height=0, int maxbpp=0); // reads icon file filename and places its icons in the resource wIconId using resource editor re -int replace_icon(CResourceEditor* re, WORD wIconId, const char* filename); +void replace_icon(CResourceEditor* re, WORD wIconId, const char* filename); #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT // returns the data of the uninstaller icon (inside filename) that should replace the installer icon data