From 03a887ba35c7e3c7a03a0339619dce1901d62f77 Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 7 Oct 2005 13:08:44 +0000 Subject: [PATCH] added !tempfile and !delfile git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4307 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/compiler.but | 27 +++++++++++++++++++ Source/script.cpp | 60 +++++++++++++++++++++++++++++++++++++++++-- Source/tokens.cpp | 3 +++ Source/tokens.h | 3 +++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/Docs/src/compiler.but b/Docs/src/compiler.but index 2ceb221a..9d00cc4b 100644 --- a/Docs/src/compiler.but +++ b/Docs/src/compiler.but @@ -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] diff --git a/Source/script.cpp b/Source/script.cpp index 9dc32076..18335c33 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -19,9 +19,11 @@ using namespace std; #ifdef _WIN32 # include // for chdir #else -# include +# include // for stat and umask +# include // for mode_t # include // for O_RDONLY # include +# include // 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 diff --git a/Source/tokens.cpp b/Source/tokens.cpp index facd99c1..02a64049 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -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}, diff --git a/Source/tokens.h b/Source/tokens.h index 5d8ea9da..9ec243f6 100644 --- a/Source/tokens.h +++ b/Source/tokens.h @@ -95,6 +95,9 @@ enum TOK_P_IFMACRODEF, TOK_P_IFMACRONDEF, + TOK_P_TEMPFILE, + TOK_P_DELFILE, + // section/function shit TOK_SECTION, TOK_SECTIONEND,