diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 9f663635..d3ef8b84 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -74,11 +74,11 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd void ResetInputScript() { - if(g_sdata.input_script) { - g_sdata.script_alloced = true; - g_sdata.script = (char *)GlobalAlloc(GPTR, (lstrlen(g_sdata.input_script)+3)*sizeof(char)); - wsprintf(g_sdata.script,"\"%s\"",g_sdata.input_script); - } + if(g_sdata.input_script) { + g_sdata.script_alloced = true; + g_sdata.script = (char *)GlobalAlloc(GPTR, (lstrlen(g_sdata.input_script)+3)*sizeof(char)); + wsprintf(g_sdata.script,"\"%s\"",g_sdata.input_script); + } } BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -87,8 +87,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { - int argc; - char **argv; + int argc; + char **argv; int i, j; int argSpaceSize; bool chooseCompressor = false; @@ -120,7 +120,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int n; g_sdata.script_alloced = true; - g_sdata.script = (char *)GlobalAlloc(GPTR,argSpaceSize + 2*(argc-1)*sizeof(char)+1); + g_sdata.script = (char *) GlobalAlloc(GPTR,argSpaceSize+2*(argc-1)*sizeof(char)+1); lstrcpy(g_sdata.script,""); for(i=1; i 0) { g_sdata.defines = (char **)GlobalAlloc(GPTR, (n+1)*sizeof(char *)); - for(int i=0; i= (int)COMPRESSOR_SCRIPT && n <= (int)COMPRESSOR_BEST) { + if (n >= (int)COMPRESSOR_SCRIPT && n <= (int)COMPRESSOR_BEST) { g_sdata.default_compressor = (NCOMPRESSOR)n; } else { @@ -879,53 +881,53 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) } } break; - case IDLEFT: - { - int index = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETCURSEL, 0, 0); - if(index != LB_ERR) { - int n = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETTEXTLEN, (WPARAM)index, 0); - if(n > 0) { - char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char)); - SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETTEXT, (WPARAM)index, (LPARAM)buf); - char *p = my_strstr(buf,"="); - if(p) { - SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1)); - *p=0; + case IDLEFT: + { + int index = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETCURSEL, 0, 0); + if(index != LB_ERR) { + int n = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETTEXTLEN, (WPARAM)index, 0); + if(n > 0) { + char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char)); + SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETTEXT, (WPARAM)index, (LPARAM)buf); + char *p = my_strstr(buf,"="); + if(p) { + SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1)); + *p=0; + } + SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, (LPARAM)buf); + GlobalFree(buf); + SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_DELETESTRING, (WPARAM)index, (LPARAM)buf); + EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE); } - SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, (LPARAM)buf); - GlobalFree(buf); - SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_DELETESTRING, (WPARAM)index, (LPARAM)buf); - EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE); } } - } + break; + case IDC_SYMBOL: + if(HIWORD(wParam) == EN_CHANGE) + { + int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0); + if(n > 0) { + EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), TRUE); + } + else { + EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), FALSE); + } + } + break; + case IDC_DEFINES: + if(HIWORD(wParam) == LBN_SELCHANGE) + { + int n = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETCURSEL, 0, 0); + if(n != LB_ERR) { + EnableWindow(GetDlgItem(hwndDlg, IDLEFT), TRUE); + } + else { + EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE); + } + } + break; + } break; - case IDC_SYMBOL: - if(HIWORD(wParam) == EN_CHANGE) - { - int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0); - if(n > 0) { - EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), TRUE); - } - else { - EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), FALSE); - } - } - break; - case IDC_DEFINES: - if(HIWORD(wParam) == LBN_SELCHANGE) - { - int n = SendDlgItemMessage(hwndDlg, IDC_DEFINES, LB_GETCURSEL, 0, 0); - if(n != LB_ERR) { - EnableWindow(GetDlgItem(hwndDlg, IDLEFT), TRUE); - } - else { - EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE); - } - } - break; - } - break; } } return FALSE; diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index b7016a80..fcb8778e 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -35,79 +35,82 @@ extern char *compressor_names[]; int SetArgv(char *cmdLine, int *argc, char ***argv) { - char *p, *arg, *argSpace; - int size, argSpaceSize, inquote, copy, slashes; + char *p, *arg, *argSpace; + int size, argSpaceSize, inquote, copy, slashes; - size = 2; - for (p = cmdLine; *p != '\0'; p++) { - if ((*p == ' ') || (*p == '\t')) { - size++; - while ((*p == ' ') || (*p == '\t')) { - p++; - } - if (*p == '\0') { - break; - } - } - } + size = 2; + for (p = cmdLine; *p != '\0'; p++) { + if ((*p == ' ') || (*p == '\t')) { + size++; + while ((*p == ' ') || (*p == '\t')) { + p++; + } + if (*p == '\0') { + break; + } + } + } argSpaceSize = size * sizeof(char *) + lstrlen(cmdLine) + 1; - argSpace = (char *) LocalAlloc(GMEM_FIXED, argSpaceSize); - *argv = (char **) argSpace; - argSpace += size * sizeof(char *); - size--; + argSpace = (char *) GlobalAlloc(GMEM_FIXED, argSpaceSize); + if (!argSpace) + return 0; - p = cmdLine; - for (*argc = 0; *argc < size; (*argc)++) { - (*argv)[*argc] = arg = argSpace; - while ((*p == ' ') || (*p == '\t')) { - p++; - } - if (*p == '\0') { - break; - } + *argv = (char **) argSpace; + argSpace += size * sizeof(char *); + size--; - inquote = 0; - slashes = 0; - while (1) { - copy = 1; - while (*p == '\\') { - slashes++; - p++; - } - if (*p == '"') { - if ((slashes & 1) == 0) { - copy = 0; - if ((inquote) && (p[1] == '"')) { - p++; - copy = 1; - } - else { - inquote = !inquote; - } - } - slashes >>= 1; - } + p = cmdLine; + for (*argc = 0; *argc < size; (*argc)++) { + (*argv)[*argc] = arg = argSpace; + while ((*p == ' ') || (*p == '\t')) { + p++; + } + if (*p == '\0') { + break; + } - while (slashes) { - *arg = '\\'; - arg++; - slashes--; - } + inquote = 0; + slashes = 0; + while (1) { + copy = 1; + while (*p == '\\') { + slashes++; + p++; + } + if (*p == '"') { + if ((slashes & 1) == 0) { + copy = 0; + if ((inquote) && (p[1] == '"')) { + p++; + copy = 1; + } + else { + inquote = !inquote; + } + } + slashes >>= 1; + } - if ((*p == '\0') || (!inquote && ((*p == ' ') || (*p == '\t')))) { - break; - } - if (copy != 0) { - *arg = *p; - arg++; - } - p++; - } - *arg = '\0'; - argSpace = arg + 1; - } - (*argv)[*argc] = NULL; + while (slashes) { + *arg = '\\'; + arg++; + slashes--; + } + + if ((*p == '\0') || (!inquote && ((*p == ' ') || (*p == '\t')))) { + break; + } + if (copy != 0) { + *arg = *p; + arg++; + } + p++; + } + *arg = '\0'; + argSpace = arg + 1; + } + (*argv)[*argc] = NULL; return argSpaceSize; } @@ -321,56 +324,62 @@ void SaveWindowPos(HWND hwnd) { void RestoreDefines() { - HKEY hKey; - HKEY hSubKey; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { - int n = 0; - DWORD l = sizeof(n); - DWORD t; - if ((RegQueryValueEx(hKey,REGDEFCOUNT,NULL,&t,(unsigned char*)&n,&l)==ERROR_SUCCESS)&&(t == REG_DWORD)&&(l==sizeof(n))) { - if(n > 0) { - if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; - g_sdata.defines = (char **)GlobalAlloc(GPTR, (n+1)*sizeof(char *)); - for(int i=0; i 0) { + if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) { + char buf[8]; + g_sdata.defines = (char **)GlobalAlloc(GPTR, (n+1)*sizeof(char *)); + if (g_sdata.defines) + { + for(int i = 0; i < n; i++) { + wsprintf(buf,"%d",i); + l = 0; + if ((RegQueryValueEx(hSubKey,buf,NULL,&t,NULL,&l)==ERROR_SUCCESS)&&(t == REG_SZ)) { + l++; + g_sdata.defines[i] = (char *)GlobalAlloc(GPTR, l*sizeof(char)); + if (g_sdata.defines[i]) + RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)g_sdata.defines[i],&l); + else + break; + } } + g_sdata.defines[n] = NULL; + } + RegCloseKey(hSubKey); } - RegCloseKey(hKey); + } } + RegCloseKey(hKey); + } } void SaveDefines() { - HKEY hKey; - HKEY hSubKey; - int n = 0; - if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { - RegDeleteKey(hKey,REGDEFSUBKEY); - if(g_sdata.defines) { - if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; - while(g_sdata.defines[n]) { - wsprintf(buf,"%d",n); - RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)g_sdata.defines[n],lstrlen(g_sdata.defines[n])); - n++; - } - RegCloseKey(hSubKey); - } + HKEY hKey; + HKEY hSubKey; + int n = 0; + if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { + RegDeleteKey(hKey,REGDEFSUBKEY); + if(g_sdata.defines) { + if (RegCreateKey(hKey,REGDEFSUBKEY,&hSubKey) == ERROR_SUCCESS) { + char buf[8]; + while(g_sdata.defines[n]) { + wsprintf(buf,"%d",n); + RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)g_sdata.defines[n],lstrlen(g_sdata.defines[n])+1); + n++; } - RegSetValueEx(hKey,REGDEFCOUNT,0,REG_DWORD,(CONST BYTE *)&n,sizeof(n)); - RegCloseKey(hKey); + RegCloseKey(hSubKey); + } } + RegSetValueEx(hKey,REGDEFCOUNT,0,REG_DWORD,(CONST BYTE *)&n,sizeof(n)); + RegCloseKey(hKey); + } } void ResetObjects() { @@ -382,7 +391,7 @@ void ResetObjects() { void ResetDefines() { if(g_sdata.defines) { - int i=0; + int i = 0; while(g_sdata.defines[i]) { GlobalFree(g_sdata.defines[i]); i++; @@ -520,7 +529,7 @@ char* BuildDefines() } else { buf = (char *)GlobalAlloc(GPTR, sizeof(char)); - lstrcpy(buf,""); + buf[0] = NULL; } return buf; @@ -694,49 +703,49 @@ void LoadMRUFile(int position) void RestoreMRUList() { - HKEY hKey; - HKEY hSubKey; - int n = 0; - int i; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { - if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) { - char buf[8]; - DWORD l; - for(int i=0; i