Allow multiple !finalize commands

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6153 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2011-06-09 20:05:18 +00:00
parent 041a8a9881
commit 96af71d0d1
3 changed files with 53 additions and 18 deletions

View file

@ -92,6 +92,13 @@ CEXEBuild::~CEXEBuild()
for (int i = 0; i < nlt; i++) { for (int i = 0; i < nlt; i++) {
DeleteLangTable(nla+i); DeleteLangTable(nla+i);
} }
for (;postbuild_cmds;)
{
struct postbuild_cmd * tmp = postbuild_cmds;
postbuild_cmds = postbuild_cmds->next;
delete [] tmp;
}
} }
CEXEBuild::CEXEBuild() : CEXEBuild::CEXEBuild() :
@ -172,7 +179,8 @@ CEXEBuild::CEXEBuild() :
build_cursection_isfunc=0; build_cursection_isfunc=0;
build_cursection=NULL; build_cursection=NULL;
// init public data. // 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 // Added by ramon 23 May 2003
build_allowskipfiles=1; build_allowskipfiles=1;
@ -2906,23 +2914,39 @@ int CEXEBuild::write_output(void)
ftell(fp),total_usize,pc/10,pc%10); ftell(fp),total_usize,pc/10,pc%10);
} }
fclose(fp); fclose(fp);
if (postbuild_cmd[0]) if (postbuild_cmds)
{ {
LPTSTR arg = _tcsstr(postbuild_cmd, _T("%1")); for (struct postbuild_cmd *cmd=postbuild_cmds; cmd; cmd = cmd->next)
if (arg) // if found, replace %1 by build_output_filename
{ {
memmove(arg+_tcslen(build_output_filename), arg+2, (_tcslen(arg+2)+1)*sizeof(TCHAR)); LPTSTR cmdstr = cmd->cmd, cmdstrbuf = NULL;
memmove(arg, build_output_filename, _tcslen(build_output_filename)*sizeof(TCHAR)); LPTSTR arg = _tcsstr(cmdstr, _T("%1"));
} if (arg) // if found, replace %1 by build_output_filename
SCRIPT_MSG(_T("\nFinalize command: %s\n"),postbuild_cmd); {
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 #ifdef _WIN32
int ret=sane_system(postbuild_cmd); int ret=sane_system(cmdstr);
#else #else
PATH_CONVERT(postbuild_cmd); PATH_CONVERT(cmdstr);
int ret=system(postbuild_cmd); int ret=system(cmdstr);
#endif #endif
if (ret != 0) if (ret != 0)
INFO_MSG(_T("Finalize command returned %d\n"),ret); INFO_MSG(_T("Finalize command returned %d\n"),ret);
free(cmdstrbuf);
}
} }
print_warnings(); print_warnings();
return PS_OK; return PS_OK;

View file

@ -403,8 +403,13 @@ class CEXEBuild {
bool has_called_write_output; 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 build_packname[1024], build_packcmd[1024];
TCHAR postbuild_cmd[1024];
int build_overwrite, build_last_overwrite, build_crcchk, int build_overwrite, build_last_overwrite, build_crcchk,
build_datesave, build_optimize_datablock, build_datesave, build_optimize_datablock,
build_allowskipfiles; // Added by ramon 23 May 2003 build_allowskipfiles; // Added by ramon 23 May 2003

View file

@ -2983,10 +2983,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
build_packname, build_packcmd); build_packname, build_packcmd);
return PS_OK; return PS_OK;
case TOK_P_FINALIZE: case TOK_P_FINALIZE:
if (postbuild_cmd[0]) {
warning_fl(_T("Several !finalize instructions encountered. Only last one was executed")); TCHAR* cmdstr=line.gettoken_str(1);
_tcsnccpy(postbuild_cmd,line.gettoken_str(1),COUNTOF(postbuild_cmd)-1); struct postbuild_cmd *newcmd, *prevcmd;
SCRIPT_MSG(_T("!finalize: \"%s\"\n"),postbuild_cmd); 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; return PS_OK;
case TOK_P_SYSTEMEXEC: case TOK_P_SYSTEMEXEC:
{ {