Special section of data for user vars, whitch allow compiler to assign the right size and no code needed in exehead for mem allocs. Warnings for unreferenced user vars. (758773) Error, if temp file not available, now directory is created if not exist.

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2673 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
ramon18 2003-06-23 22:40:11 +00:00
parent 2077919dc5
commit 054db45f63
12 changed files with 227 additions and 105 deletions

View file

@ -108,7 +108,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
InitCommonControls();
GetTempPath(sizeof(temp_directory), temp_directory);
GetTempPath(sizeof(state_temp_dir), state_temp_dir);
CreateDirectory(state_temp_dir,NULL);
lstrcpyn(state_command_line,GetCommandLine(),NSIS_MAX_STRLEN);
@ -308,7 +309,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
static char ibuf[NSIS_MAX_STRLEN];
buf2[0]='\"';
mystrcpy(buf2+1,temp_directory);
mystrcpy(buf2+1,state_temp_dir);
lstrcat(buf2,s);
DeleteFile(buf2+1); // clean up after all the other ones if they are there
@ -334,7 +335,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
lstrcat(buf2,realcmds);
lstrcat(buf2," _?=");
lstrcat(buf2,ibuf);
hProc=myCreateProcess(buf2,temp_directory);
hProc=myCreateProcess(buf2,state_temp_dir);
if (hProc) CloseHandle(hProc);
else m_Err = g_errorcopyinginstall;
}

View file

@ -26,16 +26,6 @@
// really a big deal, but not usually needed).
#define NSIS_MAX_STRLEN 1024
#define USER_VARS_COUNT 26
typedef char NSIS_STRING[NSIS_MAX_STRLEN];
// MAX_NAMED_USER_VARS defines the maximum of named user variables
// the complier also use this value to abort if exceded
// The real maximum is (0x0FFF - USER_VARS_COUNT) = 4069
// But 500 variables are a more than enough (and only consume more 512kb of memory)
#define MAX_NAMED_USER_VARS 500
// NSIS_MAX_INST_TYPES specified the maximum install types.
// note that this should not exceed 32, ever.
#define NSIS_MAX_INST_TYPES 32
@ -364,6 +354,26 @@ typedef char NSIS_STRING[NSIS_MAX_STRLEN];
#define NSIS_SUPPORT_STANDARD_PREDEFINES
#endif
// This is the old static var count that occupies memory
// From $0 to $PLUGINSDIR
#define USER_VARS_COUNT 26
#ifdef NSIS_SUPPORT_NAMED_USERVARS
// This is the total number of old static var
// From $0 to $HWNDPARENT
#define TOTAL_COMPATIBLE_STATIC_VARS_COUNT 36
#define VARS_SECTION_NAME ".ndata"
typedef char NSIS_STRING[NSIS_MAX_STRLEN];
// MAX_NAMED_USER_VARS defines the maximum of named user variables
// the complier also use this value to abort if exceded
// The real maximum is (0x0FFF - USER_VARS_COUNT) = 4068
#define MAX_NAMED_USER_VARS (0x0FFF - USER_VARS_COUNT)
#endif //NSIS_SUPPORT_NAMED_USERVARS
#endif//!APSTUDIO_INVOKED
#endif // NSIS_CONFIG_H

View file

@ -367,7 +367,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
int n=100;
while (n--)
{
if (GetTempFileName(temp_directory,"nst",0,textout))
if (GetTempFileName(state_temp_dir,"nst",0,textout))
return 0;
}
g_flags.exec_error++;
@ -1443,7 +1443,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
filebuf=(unsigned char *)my_GlobalAlloc(g_filehdrsize);
if (filebuf)
{
int fixoffs=0;
//int fixoffs=0;
DWORD lout;
SetSelfFilePointer(0,FILE_BEGIN);
ReadSelfFile((char*)filebuf,g_filehdrsize);

View file

@ -52,17 +52,7 @@ int NSISCALL isheader(firstheader *h)
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
static z_stream g_inflate_stream;
#endif
/*
void DEBUG(const char* Frm, ...)
{
char Buf[1024];
va_list va;
va_start(va, Frm);
wvsprintf(Buf, Frm, va);
MessageBox(0, Buf, 0, 0);
va_end(va);
}
*/
const char * NSISCALL loadHeaders(void)
{
void *data;
@ -70,13 +60,7 @@ const char * NSISCALL loadHeaders(void)
if (!ReadSelfFile((LPVOID)&h,sizeof(h)) || !isheader(&h)) return _LANG_INVALIDCRC;
#ifdef NSIS_SUPPORT_NAMED_USERVARS
//DEBUG("Needed size is : %i", h.length_of_header + h.length_of_uservars);
g_usrvars = (NSIS_STRING*)GlobalReAlloc(g_usrvars, h.length_of_header + h.length_of_uservars, GMEM_MOVEABLE);
data = (void*)(g_usrvars[0]+h.length_of_uservars);
#else
data=(void*)my_GlobalAlloc(h.length_of_header);
#endif
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
inflateInit(&g_inflate_stream);
@ -86,7 +70,7 @@ const char * NSISCALL loadHeaders(void)
{
char fno[MAX_PATH];
GetTempFileName(temp_directory,"nst",0,fno);
GetTempFileName(state_temp_dir,"nst",0,fno);
dbd_hFile=CreateFile(fno,GENERIC_WRITE|GENERIC_READ,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE,NULL);
if (dbd_hFile == INVALID_HANDLE_VALUE)
{

View file

@ -204,10 +204,6 @@ typedef struct
// these point to the header+sections+entries+stringtable in the datablock
int length_of_header;
#ifdef NSIS_SUPPORT_NAMED_USERVARS
// this store the sized needed to store all user vars
int length_of_uservars;
#endif
// this specifies the length of all the data (including the firstheader and CRC)
int length_of_all_following_data;

View file

@ -1,15 +1,16 @@
extern char temp_directory[NSIS_MAX_STRLEN];
#ifdef NSIS_SUPPORT_NAMED_USERVARS
extern NSIS_STRING *g_usrvars;
#define state_command_line g_usrvars[20]
#define state_install_directory g_usrvars[21]
#define state_output_directory g_usrvars[22]
#define state_exe_directory g_usrvars[23]
#define state_language g_usrvars[24]
extern NSIS_STRING g_usrvars[TOTAL_COMPATIBLE_STATIC_VARS_COUNT];
#define state_command_line g_usrvars[20]
#define state_install_directory g_usrvars[21]
#define state_output_directory g_usrvars[22]
#define state_exe_directory g_usrvars[23]
#define state_language g_usrvars[24]
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#define state_plugins_dir g_usrvars[25]
#define state_plugins_dir g_usrvars[25]
#endif
#define state_temp_dir g_usrvars[32]
#else
extern char temp_directory[NSIS_MAX_STRLEN];
extern char g_usrvars[USER_VARS_COUNT][NSIS_MAX_STRLEN];
extern char *state_command_line;
extern char *state_install_directory;
@ -19,6 +20,7 @@ extern char temp_directory[NSIS_MAX_STRLEN];
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
extern char *state_plugins_dir;
#endif
#define state_temp_dir temp_directory
#endif
extern char g_caption[NSIS_MAX_STRLEN*2];

View file

@ -14,10 +14,20 @@
char g_log_file[1024];
#endif
char temp_directory[NSIS_MAX_STRLEN];
#ifdef NSIS_SUPPORT_NAMED_USERVARS
NSIS_STRING *g_usrvars;
// *** DO NOT DECLARE MORE VARIABLES INSIDE THIS PRAGMAS ***
// This will produce a special section called ".ndata" (stands for nsis data)
// this way makensis during build time, can search for this section by name
// and change the virtual size of this section
// which result in extra memory for extra variables without code to do allocation :)
// nsis then removes the "DISCARDABLE" style from section (for safe)
#pragma bss_seg( VARS_SECTION_NAME )
NSIS_STRING g_usrvars[TOTAL_COMPATIBLE_STATIC_VARS_COUNT];
#pragma bss_seg()
#define SECTION_VARS_RWD "/section:" ## VARS_SECTION_NAME ## ",rwd"
#pragma comment(linker, SECTION_VARS_RWD)
#else
char temp_directory[NSIS_MAX_STRLEN];
char g_usrvars[USER_VARS_COUNT][NSIS_MAX_STRLEN];
char *state_command_line=g_usrvars[20];
char *state_install_directory=g_usrvars[21];
@ -580,7 +590,7 @@ char * NSISCALL process_string(const char *in)
{
f=0; goto again;
}
mystrcpy(out,temp_directory);
mystrcpy(out,state_temp_dir);
}
if (nVarIdx == 31) {
@ -592,10 +602,6 @@ char * NSISCALL process_string(const char *in)
else break;
}
case 32: // TEMP
mystrcpy(out,temp_directory);
break;
case 33: // WINDIR
GetWindowsDirectory(out, NSIS_MAX_STRLEN);
break;
@ -612,7 +618,7 @@ char * NSISCALL process_string(const char *in)
mystrcpy(out, g_usrvars[nVarIdx]);
} // switch
// validate the directory name
if (nVarIdx > 21 && nVarIdx < 36 ) { // only if not $0 to $R9, $CMDLINE, or $HWNDPARENT and not great than $SYSDIR
if (nVarIdx > 21 && nVarIdx < TOTAL_COMPATIBLE_STATIC_VARS_COUNT ) { // only if not $0 to $R9, $CMDLINE, or $HWNDPARENT and not great than $SYSDIR
// ($LANGUAGE can't have trailing backslash anyway...)
validate_filename(out);
}