more clean-up:

* removed ResetInputScript()
 * don't edit g_sdata.script for CreateProcess
 * use SetScript in LoadMRUFile
 * proper and clear allocation of g_sdata.compile_command in CompileNSISScript()


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5047 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2007-04-10 21:07:21 +00:00
parent 3a657559b0
commit 845566790d
3 changed files with 35 additions and 30 deletions

View file

@ -76,7 +76,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
return msg.wParam;
}
void SetScript(const char *script, bool clearArgs = true)
void SetScript(const char *script, bool clearArgs /*= true*/)
{
if (g_sdata.script)
{
@ -85,12 +85,12 @@ void SetScript(const char *script, bool clearArgs = true)
if (clearArgs)
{
if (g_sdata.script_cmd_args);
if (g_sdata.script_cmd_args)
{
GlobalFree(g_sdata.script_cmd_args);
}
g_sdata.script_cmd_args = (char *) GlobalAlloc(GPTR, 1)
g_sdata.script_cmd_args = (char *) GlobalAlloc(GPTR, 1);
}
g_sdata.script = (char *) GlobalAlloc(GPTR, lstrlen(script) + 1);
@ -108,13 +108,6 @@ void AddScriptCmdArgs(const char *arg)
lstrcat(g_sdata.script_cmd_args, "\"");
}
void ResetInputScript()
{
if(g_sdata.input_script) {
SetScript(g_sdata.input_script);
}
}
void ProcessCommandLine()
{
int argc;
@ -309,7 +302,6 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
g_sdata.best_compressor_name = g_sdata.compressor_name;
g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+2];
ResetObjects();
ResetInputScript();
CompileNSISScript();
return TRUE;
@ -360,8 +352,6 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
char buf[1024];
g_sdata.compressor_name = compressor_names[(int)COMPRESSOR_SCRIPT+1];
g_sdata.appended = false;
ResetInputScript();
if(!lstrcmpi(g_sdata.best_compressor_name,compressor_names[this_compressor])) {
wsprintf(buf,COMPRESSOR_MESSAGE,g_sdata.best_compressor_name,thisSize);
@ -374,13 +364,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
LogMessage(g_sdata.hwnd, g_sdata.compressor_stats);
}
DeleteFile(temp_file_name);
ResetInputScript();
lstrcpy(g_sdata.compressor_stats,"");
}
else {
g_sdata.compressor_name = compressor_names[this_compressor+1];
ResetObjects();
ResetInputScript();
CompileNSISScript();
return TRUE;
@ -738,9 +726,9 @@ DWORD WINAPI MakeNSISProc(LPVOID p) {
si.hStdOutput = newstdout;
si.hStdError = newstdout;
si.hStdInput = newstdin;
if (!CreateProcess(NULL,g_sdata.script,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
if (!CreateProcess(NULL,g_sdata.compile_command,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
char buf[MAX_STRING];
wsprintf(buf,"Could not execute:\r\n %s.",g_sdata.script);
wsprintf(buf,"Could not execute:\r\n %s.",g_sdata.compile_command);
ErrorMessage(g_sdata.hwnd,buf);
CloseHandle(newstdout);
CloseHandle(read_stdout);
@ -967,7 +955,6 @@ BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
case IDOK:
{
ResetObjects();
ResetInputScript();
ResetSymbols();
g_sdata.symbols = GetSymbols(hwndDlg);
@ -1300,7 +1287,6 @@ void SetCompressor(NCOMPRESSOR compressor)
}
CheckMenuItem(g_sdata.menu, command, MF_BYCOMMAND | MF_CHECKED);
ResetObjects();
ResetInputScript();
}
}

View file

@ -151,6 +151,7 @@ BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CompressorProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
void SetScript(const char *script, bool clearArgs = true);
void CompileNSISScript();
char* BuildSymbols();
void SetCompressor(NCOMPRESSOR);
@ -165,6 +166,7 @@ void SaveMRUList();
typedef struct NSISScriptData {
char *script;
char *script_cmd_args;
char *compile_command;
char *output_exe;
char *input_script;
char *branding;
@ -174,7 +176,6 @@ typedef struct NSISScriptData {
BOOL userSelectCompressor;
DWORD logLength;
DWORD warnings;
BOOL appended;
HINSTANCE hInstance;
HWND hwnd;
HMENU menu;

View file

@ -268,24 +268,40 @@ void CompileNSISScript() {
DragAcceptFiles(g_sdata.hwnd,TRUE);
return;
}
if (!g_sdata.appended) {
if (!g_sdata.compile_command) {
if (s) GlobalFree(s);
char *symbols = BuildSymbols();
char compressor[40];
if(lstrlen(g_sdata.compressor_name)) {
wsprintf(compressor,"/X\"SetCompressor /FINAL %s\" ",g_sdata.compressor_name);
wsprintf(compressor,"/X\"SetCompressor /FINAL %s\"",g_sdata.compressor_name);
}
else {
lstrcpy(compressor,"");
}
s = (char *)GlobalAlloc(GPTR, lstrlen(g_sdata.script)+lstrlen(symbols)+lstrlen(compressor)+sizeof(EXENAME)+sizeof(" /NOTIFYHWND ")+23);
wsprintf(s,"%s %s%s /NOTIFYHWND %d %s -- \"%s\"",EXENAME,compressor,symbols,g_sdata.hwnd,g_sdata.script_cmd_args,g_sdata.script);
g_sdata.compile_command = (char *) GlobalAlloc(
GPTR,
/* makensis.exe */ sizeof(EXENAME) + /* space */ 1 +
/* script path */ lstrlen(g_sdata.script) + /* space */ 1 +
/* script cmd args */ lstrlen(g_sdata.script_cmd_args) + /* space */ 1 +
/* defines /Dblah=... */ lstrlen(symbols) + /* space */ 1 +
/* /XSetCompressor... */ lstrlen(compressor) + /* space */ 1 +
/* /NOTTIFYHWND + HWND */ sizeof("/NOTIFYHWND -4294967295") + /* space */ 1
);
wsprintf(
g_sdata.compile_command,
"%s %s %s /NOTIFYHWND %d %s -- \"%s\"",
EXENAME,
compressor,
symbols,
g_sdata.hwnd,
g_sdata.script_cmd_args,
g_sdata.script
);
GlobalFree(symbols);
if (g_sdata.script) GlobalFree(g_sdata.script);
g_sdata.script = s;
g_sdata.appended = TRUE;
}
GlobalFree(g_sdata.input_script);
GlobalFree(g_sdata.output_exe);
@ -507,10 +523,13 @@ void SaveSymbolSet(char *name, char **symbols)
}
void ResetObjects() {
g_sdata.appended = FALSE;
if (g_sdata.compile_command)
GlobalFree(g_sdata.compile_command);
g_sdata.warnings = FALSE;
g_sdata.retcode = -1;
g_sdata.thread = NULL;
g_sdata.compile_command = NULL;
}
void ResetSymbols() {
@ -810,8 +829,7 @@ void BuildMRUMenus()
void LoadMRUFile(int position)
{
if (!g_sdata.thread && position >=0 && position < MRU_LIST_SIZE && g_mru_list[position][0]) {
g_sdata.script = (char *)GlobalAlloc(GPTR,lstrlen(g_mru_list[position])+3);
wsprintf(g_sdata.script,"\"%s\"",g_mru_list[position]);
SetScript(g_mru_list[position]);
if(IsValidFile(g_mru_list[position])) {
PushMRUFile(g_mru_list[position]);
}