added !tempfile and !delfile

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4307 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2005-10-07 13:08:44 +00:00
parent a546017631
commit 03a887ba35
4 changed files with 91 additions and 2 deletions

View file

@ -41,6 +41,16 @@ This command will change the compiler to the new directory, new_path. new_path c
\c !cd ..\more-scripts\new
\S1{delfile} !delfile
\c file
This command deletes a file.
\c !tempfile FILE
\c !delfile "${FILE}"
\c !undef FILE
\S1{echo} !echo
\c message
@ -90,6 +100,23 @@ This command will execute 'command' using a call to system(), and if the return
\c !echo "something is defined"
\c !endif
\S1{tempfile} !tempfile
\c symbol
This command creates a temporary file. It puts its path into a define, named \e{symbol}.
\c !tempfile PACKHDRTEMP
\c !packhdr "${PACKHDRTEMP}" '"C:\Program Files\UPX\upx.exe" "${PACKHDRTEMP}"'
\c !tempfile FILE
\c !define /date DATE "%H:%M:%S %d %b, %Y"
\c !system 'echo built on ${DATE} > "${FILE}"'
\c File /oname=build.txt "${FILE}"
\c !delfile "${FILE}"
\c !undef FILE
\c !undef DATE
\S1{warning} !warning
\c [message]

View file

@ -19,9 +19,11 @@ using namespace std;
#ifdef _WIN32
# include <direct.h> // for chdir
#else
# include <sys/stat.h>
# include <sys/stat.h> // for stat and umask
# include <sys/types.h> // for mode_t
# include <fcntl.h> // for O_RDONLY
# include <unistd.h>
# include <stdlib.h> // for mkstemp
#endif
#define MAX_INCLUDEDEPTH 10
@ -1011,8 +1013,62 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
SCRIPT_MSG("!insertmacro: end of %s\n",line.gettoken_str(1));
}
return PS_OK;
// preprocessor files fun
///////////////////////////////////////////////////////////////////////////////
case TOK_P_TEMPFILE:
{
char *symbol = line.gettoken_str(1);
char *fpath;
#ifdef _WIN32
char buf[MAX_PATH], buf2[MAX_PATH];
GetTempPath(MAX_PATH, buf);
if (!GetTempFileName(buf, "nst", 0, buf2))
{
ERROR_MSG("!tempfile: unable to create temporary file.\n");
return PS_ERROR;
}
fpath = buf2;
#else
char t[] = "/tmp/makensisXXXXXX";
mode_t old_umask = umask(0600);
int fd = mkstemp(t);
if (fd == -1) {
ERROR_MSG("!tempfile: unable to create temporary file.\n");
return PS_ERROR;
}
close(fd);
umask(old_umask);
fpath = t;
#endif
if (definedlist.add(symbol, fpath))
{
ERROR_MSG("!tempfile: \"%s\" already defined!\n", symbol);
return PS_ERROR;
}
SCRIPT_MSG("!tempfile: \"%s\"=\"%s\"\n", symbol, fpath);
}
return PS_OK;
case TOK_P_DELFILE:
if (unlink(line.gettoken_str(1)) == -1) {
ERROR_MSG("!delfile: \"%s\" couldn't be deleted.\n", line.gettoken_str(1));
return PS_ERROR;
}
SCRIPT_MSG("!delfile: \"%s\"\n", line.gettoken_str(1));
return PS_OK;
// page ordering shit
///////////////////////////////////////////////////////////////////////////////
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT

View file

@ -242,6 +242,9 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_P_IFMACRODEF,"!ifmacrodef",1,-1,"macro [| macro2 [& macro3 [...]]]",TP_ALL},
{TOK_P_IFMACRONDEF,"!ifmacrondef",1,-1,"macro [| macro2 [& macro3 [...]]]",TP_ALL},
{TOK_P_TEMPFILE,"!tempfile",1,0,"symbol",TP_ALL},
{TOK_P_DELFILE,"!delfile",1,0,"file",TP_ALL},
{TOK_MISCBUTTONTEXT,"MiscButtonText",0,4,"[back button text] [next button text] [cancel button text] [close button text]",TP_GLOBAL},
{TOK_DETAILSBUTTONTEXT,"DetailsButtonText",0,1,"[details button text]",TP_PG},
{TOK_UNINSTBUTTONTEXT,"UninstallButtonText",0,1,"[uninstall button text]",TP_GLOBAL},

View file

@ -95,6 +95,9 @@ enum
TOK_P_IFMACRODEF,
TOK_P_IFMACRONDEF,
TOK_P_TEMPFILE,
TOK_P_DELFILE,
// section/function shit
TOK_SECTION,
TOK_SECTIONEND,