From 96af71d0d17203eac05516ac47ae9b02fed923a8 Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 9 Jun 2011 20:05:18 +0000 Subject: [PATCH] Allow multiple !finalize commands git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6153 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 50 +++++++++++++++++++++++++++++++++++------------ Source/build.h | 7 ++++++- Source/script.cpp | 14 +++++++++---- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index 52a917c8..098725ea 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -92,6 +92,13 @@ CEXEBuild::~CEXEBuild() for (int i = 0; i < nlt; i++) { DeleteLangTable(nla+i); } + + for (;postbuild_cmds;) + { + struct postbuild_cmd * tmp = postbuild_cmds; + postbuild_cmds = postbuild_cmds->next; + delete [] tmp; + } } CEXEBuild::CEXEBuild() : @@ -172,7 +179,8 @@ CEXEBuild::CEXEBuild() : build_cursection_isfunc=0; build_cursection=NULL; // init public data. - build_packname[0]=build_packcmd[0]=build_output_filename[0]=postbuild_cmd[0]=0; + build_packname[0]=build_packcmd[0]=build_output_filename[0]=0; + postbuild_cmds=NULL; // Added by ramon 23 May 2003 build_allowskipfiles=1; @@ -2906,23 +2914,39 @@ int CEXEBuild::write_output(void) ftell(fp),total_usize,pc/10,pc%10); } fclose(fp); - if (postbuild_cmd[0]) + if (postbuild_cmds) { - LPTSTR arg = _tcsstr(postbuild_cmd, _T("%1")); - if (arg) // if found, replace %1 by build_output_filename + for (struct postbuild_cmd *cmd=postbuild_cmds; cmd; cmd = cmd->next) { - memmove(arg+_tcslen(build_output_filename), arg+2, (_tcslen(arg+2)+1)*sizeof(TCHAR)); - memmove(arg, build_output_filename, _tcslen(build_output_filename)*sizeof(TCHAR)); - } - SCRIPT_MSG(_T("\nFinalize command: %s\n"),postbuild_cmd); + LPTSTR cmdstr = cmd->cmd, cmdstrbuf = NULL; + LPTSTR arg = _tcsstr(cmdstr, _T("%1")); + if (arg) // if found, replace %1 by build_output_filename + { + const UINT cchbldoutfile = _tcslen(build_output_filename); + cmdstrbuf = (LPTSTR) malloc( (_tcslen(cmdstr) + cchbldoutfile + 1)*sizeof(TCHAR) ); + if (!cmdstrbuf) + { + ERROR_MSG(_T("Error: can't allocate memory for finalize command\n")); + return PS_ERROR; + } + arg -= (UINT_PTR)cmdstr, arg += (UINT_PTR)cmdstrbuf; + _tcscpy(cmdstrbuf,cmdstr); + cmdstr = cmdstrbuf; + memmove(arg+cchbldoutfile, arg+2, (_tcslen(arg+2)+1)*sizeof(TCHAR)); + memmove(arg, build_output_filename, cchbldoutfile*sizeof(TCHAR)); + } + + SCRIPT_MSG(_T("\nFinalize command: %s\n"),cmdstr); #ifdef _WIN32 - int ret=sane_system(postbuild_cmd); + int ret=sane_system(cmdstr); #else - PATH_CONVERT(postbuild_cmd); - int ret=system(postbuild_cmd); + PATH_CONVERT(cmdstr); + int ret=system(cmdstr); #endif - if (ret != 0) - INFO_MSG(_T("Finalize command returned %d\n"),ret); + if (ret != 0) + INFO_MSG(_T("Finalize command returned %d\n"),ret); + free(cmdstrbuf); + } } print_warnings(); return PS_OK; diff --git a/Source/build.h b/Source/build.h index 2a9db775..738a4d10 100644 --- a/Source/build.h +++ b/Source/build.h @@ -403,8 +403,13 @@ class CEXEBuild { bool has_called_write_output; + struct postbuild_cmd + { + struct postbuild_cmd*next; + TCHAR cmd[1]; + } *postbuild_cmds; + TCHAR build_packname[1024], build_packcmd[1024]; - TCHAR postbuild_cmd[1024]; int build_overwrite, build_last_overwrite, build_crcchk, build_datesave, build_optimize_datablock, build_allowskipfiles; // Added by ramon 23 May 2003 diff --git a/Source/script.cpp b/Source/script.cpp index 5395dfc6..83ab18b4 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2983,10 +2983,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) build_packname, build_packcmd); return PS_OK; case TOK_P_FINALIZE: - if (postbuild_cmd[0]) - warning_fl(_T("Several !finalize instructions encountered. Only last one was executed")); - _tcsnccpy(postbuild_cmd,line.gettoken_str(1),COUNTOF(postbuild_cmd)-1); - SCRIPT_MSG(_T("!finalize: \"%s\"\n"),postbuild_cmd); + { + TCHAR* cmdstr=line.gettoken_str(1); + struct postbuild_cmd *newcmd, *prevcmd; + newcmd = (struct postbuild_cmd*) new BYTE[FIELD_OFFSET(struct postbuild_cmd,cmd[_tcsclen(cmdstr)+1])]; + newcmd->next=NULL; + _tcscpy(newcmd->cmd,cmdstr); + for (prevcmd=postbuild_cmds; prevcmd && prevcmd->next;) prevcmd = prevcmd->next; + if (prevcmd) prevcmd->next = newcmd; else postbuild_cmds = newcmd; + SCRIPT_MSG(_T("!finalize: \"%s\"\n"),cmdstr); + } return PS_OK; case TOK_P_SYSTEMEXEC: {