Small space-saving optimisations

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@693 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
eccles 2002-08-19 21:24:44 +00:00
parent 1ee06159ec
commit 7a2cf3e5b8
5 changed files with 104 additions and 96 deletions

View file

@ -147,14 +147,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
if (cmdline[0] == 'D' && cmdline[1] == '=') if (cmdline[0] == 'D' && cmdline[1] == '=')
{ {
cmdline[-2]=0; // keep this from being passed to uninstaller if necessary cmdline[-2]=0; // keep this from being passed to uninstaller if necessary
lstrcpy(state_install_directory,cmdline+2); mystrcpy(state_install_directory,cmdline+2);
cmdline+=lstrlen(cmdline); cmdline+=mystrlen(cmdline);
} }
else while (*cmdline && *cmdline != ' ') cmdline=CharNext(cmdline); else while (*cmdline && *cmdline != ' ') cmdline=CharNext(cmdline);
} }
while (*cmdline); while (*cmdline);
lstrcpy(g_caption,_LANG_GENERIC_ERROR); mystrcpy(g_caption,_LANG_GENERIC_ERROR);
g_hInstance=GetModuleHandle(NULL); g_hInstance=GetModuleHandle(NULL);
GetModuleFileName(g_hInstance,state_exe_directory,NSIS_MAX_STRLEN); GetModuleFileName(g_hInstance,state_exe_directory,NSIS_MAX_STRLEN);
@ -285,8 +285,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
cmdline+=2; cmdline+=2;
if (is_valid_instpath(cmdline)) if (is_valid_instpath(cmdline))
{ {
lstrcpy(state_install_directory,cmdline); mystrcpy(state_install_directory,cmdline);
lstrcpy(state_output_directory,cmdline); mystrcpy(state_output_directory,cmdline);
} }
else else
{ {
@ -324,7 +324,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
#ifdef NSIS_SUPPORT_MOVEONREBOOT #ifdef NSIS_SUPPORT_MOVEONREBOOT
MoveFileOnReboot(buf2+1,NULL); MoveFileOnReboot(buf2+1,NULL);
#endif #endif
if (state_install_directory[0]) lstrcpy(ibuf,state_install_directory); if (state_install_directory[0]) mystrcpy(ibuf,state_install_directory);
else trimslashtoend(ibuf); else trimslashtoend(ibuf);
if (!is_valid_instpath(ibuf)) break; if (!is_valid_instpath(ibuf)) break;
done++; done++;

View file

@ -104,24 +104,24 @@ HWND m_curwnd;
static int m_whichcfg; static int m_whichcfg;
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
BOOL SetDlgItemTextFromLang(HWND dlg, WORD id, langid_t lid) { static BOOL SetDlgItemTextFromLang(HWND dlg, WORD id, langid_t lid) {
return SetDlgItemText(dlg,id,STR(GetLangString(lid))); return SetDlgItemText(dlg,id,STR(GetLangString(lid)));
} }
BOOL SetUITextFromLang(HWND defhw, WORD def, WORD custom, langid_t lid) { static BOOL SetUITextFromLang(HWND defhw, WORD def, WORD custom, langid_t lid) {
return SetDlgItemTextFromLang(custom?g_hwnd:defhw,custom?custom:def,lid); return SetDlgItemTextFromLang(custom?g_hwnd:defhw,custom?custom:def,lid);
} }
// no tab // no tab
BOOL SetUITextNT(HWND defhw, WORD def, WORD custom, const char *text) { static BOOL SetUITextNT(HWND defhw, WORD def, WORD custom, const char *text) {
return SetDlgItemText(custom?g_hwnd:defhw,custom?custom:def,text); return SetDlgItemText(custom?g_hwnd:defhw,custom?custom:def,text);
} }
UINT GetUIText(WORD def, WORD custom, char *str, int max_size) { static UINT GetUIText(WORD def, WORD custom, char *str, int max_size) {
return GetDlgItemText(custom?g_hwnd:m_curwnd,custom?custom:def,str,max_size); return GetDlgItemText(custom?g_hwnd:m_curwnd,custom?custom:def,str,max_size);
} }
HWND GetUIItem(HWND defhw, WORD def, WORD custom) { static HWND GetUIItem(HWND defhw, WORD def, WORD custom) {
return GetDlgItem(custom?g_hwnd:defhw,custom?custom:def); return GetDlgItem(custom?g_hwnd:defhw,custom?custom:def);
} }
#endif #endif
@ -129,8 +129,7 @@ HWND GetUIItem(HWND defhw, WORD def, WORD custom) {
#ifdef NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_LOG
static void build_g_logfile() static void build_g_logfile()
{ {
lstrcpy(g_log_file,state_install_directory); addtrailingslash(mystrcpy(g_log_file,state_install_directory));
addtrailingslash(g_log_file);
lstrcat(g_log_file,"install.log"); lstrcat(g_log_file,"install.log");
} }
#endif #endif
@ -259,7 +258,7 @@ int ui_doinstall(void)
} }
// p is the path now, check for .exe extension // p is the path now, check for .exe extension
e=p+lstrlen(p)-4; e=p+mystrlen(p)-4;
if (e > p) if (e > p)
{ {
// if filename ends in .exe, and is not a directory, remove the filename // if filename ends in .exe, and is not a directory, remove the filename
@ -275,7 +274,7 @@ int ui_doinstall(void)
} }
} }
lstrcpy(state_install_directory,p); mystrcpy(state_install_directory,p);
} }
} }
} }
@ -296,7 +295,6 @@ int ui_doinstall(void)
{ {
// Added by Amir Szekely 3rd August 2002 // Added by Amir Szekely 3rd August 2002
// Multilingual support // Multilingual support
char pa=0;
int num=g_inst_header->common.str_tables_num; int num=g_inst_header->common.str_tables_num;
LANGID user_lang=GetUserDefaultLangID(), lang_mask=~(LANGID)0; LANGID user_lang=GetUserDefaultLangID(), lang_mask=~(LANGID)0;
int size=num*sizeof(common_strings); int size=num*sizeof(common_strings);
@ -320,13 +318,11 @@ lang_again:
else else
#endif #endif
(installer_strings *)cur_install_strings_table+=size; (installer_strings *)cur_install_strings_table+=size;
pa++;
break; break;
} }
} }
if (!pa) { if ((size < num) && (lang_mask == ~(LANGID)0)) {
lang_mask=0x3ff; // primary lang lang_mask=0x3ff; // primary lang
pa++;
goto lang_again; goto lang_again;
} }
} }
@ -441,19 +437,19 @@ static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (g_is_uninstaller) if (g_is_uninstaller)
{ {
islp=LANG_UNINST_TEXT>=0; islp = (LANG_UNINST_TEXT>=0);
iscp++; iscp++;
} }
else else
#endif//NSIS_CONFIG_UNINSTALL_SUPPORT #endif//NSIS_CONFIG_UNINSTALL_SUPPORT
{ {
#ifdef NSIS_CONFIG_LICENSEPAGE #ifdef NSIS_CONFIG_LICENSEPAGE
if (LANG_LICENSE_DATA>=0) islp++; islp = (LANG_LICENSE_DATA>=0);
#endif//NSIS_CONFIG_LICENSEPAGE #endif//NSIS_CONFIG_LICENSEPAGE
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (LANG_COMP_TEXT>=0) iscp++; iscp = (LANG_COMP_TEXT>=0);
#endif//NSIS_CONFIG_COMPONENTPAGE #endif//NSIS_CONFIG_COMPONENTPAGE
if (LANG_DIR_TEXT>=0) ispotentiallydp++; ispotentiallydp = (LANG_DIR_TEXT>=0);
if (ispotentiallydp && if (ispotentiallydp &&
!((g_inst_cmnheader->misc_flags&2) && !((g_inst_cmnheader->misc_flags&2) &&
is_valid_instpath(state_install_directory) is_valid_instpath(state_install_directory)
@ -512,8 +508,8 @@ static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
(m_page == 2 || (m_page == 1 && !isdp)) ? LANGID_BTN_INSTALL : (m_page == 2 || (m_page == 1 && !isdp)) ? LANGID_BTN_INSTALL :
LANGID_BTN_NEXT LANGID_BTN_NEXT
); );
lstrcpy(g_tmp,g_caption); mystrcpy(g_tmp,g_caption);
process_string_from_lang(g_tmp+lstrlen(g_tmp),LANGID_SUBCAPTION(m_page)); process_string_from_lang(g_tmp+mystrlen(g_tmp),LANGID_SUBCAPTION(m_page));
SetWindowText(hwndDlg,g_tmp); SetWindowText(hwndDlg,g_tmp);
@ -647,7 +643,7 @@ static BOOL CALLBACK UninstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
static void inttosizestr(int kb, char *str) static void inttosizestr(int kb, char *str)
{ {
while (*str) str++; str += mystrlen(str);
if (kb < 1024) wsprintf(str,"%dKB",kb); if (kb < 1024) wsprintf(str,"%dKB",kb);
else if (kb < 1024*1024) wsprintf(str,"%d.%dMB",kb>>10,((kb*10)>>10)%10); else if (kb < 1024*1024) wsprintf(str,"%d.%dMB",kb>>10,((kb*10)>>10)%10);
else wsprintf(str,"%d.%dGB%s",kb>>20,((kb*10)>>20)%10,(GetVersion()&0x80000000) ? "+":""); else wsprintf(str,"%d.%dGB%s",kb>>20,((kb*10)>>20)%10,(GetVersion()&0x80000000) ? "+":"");
@ -722,7 +718,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
if (p >= post_str && *++p) if (p >= post_str && *++p)
{ {
post_str=p; post_str=p;
p=name+lstrlen(name)-lstrlen(post_str); p=name+mystrlen(name)-mystrlen(post_str);
if (p <= name || *CharPrev(name,p)!='\\' || lstrcmpi(p,post_str)) if (p <= name || *CharPrev(name,p)!='\\' || lstrcmpi(p,post_str))
{ {
addtrailingslash(name); addtrailingslash(name);
@ -773,13 +769,11 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
// Added by Amir Szekely 24th July 2002 // Added by Amir Szekely 24th July 2002
// Allows 'SpaceTexts none' // Allows 'SpaceTexts none'
if (LANG_SPACE_REQ >= 0) { if (LANG_SPACE_REQ >= 0) {
lstrcpy(s,STR(LANG_SPACE_REQ)); inttosizestr(total,mystrcpy(s,STR(LANG_SPACE_REQ)));
inttosizestr(total,s);
SetUITextNT(hwndDlg,IDC_SPACEREQUIRED,g_inst_header->space_req_id,s); SetUITextNT(hwndDlg,IDC_SPACEREQUIRED,g_inst_header->space_req_id,s);
if (available != -1) if (available != -1)
{ {
lstrcpy(s,STR(LANG_SPACE_AVAIL)); inttosizestr(available,mystrcpy(s,STR(LANG_SPACE_AVAIL)));
inttosizestr(available,s);
SetUITextNT(hwndDlg,IDC_SPACEAVAILABLE,g_inst_header->space_avail_id,s); SetUITextNT(hwndDlg,IDC_SPACEAVAILABLE,g_inst_header->space_avail_id,s);
} }
else else
@ -1124,8 +1118,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
if (g_inst_section[x].default_state&DFS_SET) if (g_inst_section[x].default_state&DFS_SET)
total+=g_inst_section[x].size_kb; total+=g_inst_section[x].size_kb;
} }
lstrcpy(s,STR(LANG_SPACE_REQ)); inttosizestr(total,mystrcpy(s,STR(LANG_SPACE_REQ)));
inttosizestr(total,s);
SetUITextNT(hwndDlg,IDC_SPACEREQUIRED,g_inst_header->space_req_id,s); SetUITextNT(hwndDlg,IDC_SPACEREQUIRED,g_inst_header->space_req_id,s);
} }
} }
@ -1148,7 +1141,7 @@ void update_status_text(const char *text1, const char *text2)
RECT r; RECT r;
if (insthwnd) if (insthwnd)
{ {
if (lstrlen(text1)+lstrlen(text2) >= sizeof(ps_tmpbuf)) return; if (mystrlen(text1)+mystrlen(text2) >= sizeof(ps_tmpbuf)) return;
wsprintf(ps_tmpbuf,"%s%s",text1,text2); wsprintf(ps_tmpbuf,"%s%s",text1,text2);
if ((ui_st_updateflag&1)) if ((ui_st_updateflag&1))
{ {
@ -1281,8 +1274,8 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!g_autoclose) if (!g_autoclose)
{ {
ShowWindow(g_hwnd,SW_SHOWNA); ShowWindow(g_hwnd,SW_SHOWNA);
lstrcpy(g_tmp,g_caption); mystrcpy(g_tmp,g_caption);
process_string_from_lang(g_tmp+lstrlen(g_caption),LANGID_SUBCAPTION(g_max_page+1)); process_string_from_lang(g_tmp+mystrlen(g_tmp),LANGID_SUBCAPTION(g_max_page+1));
update_status_text_from_lang(LANGID_COMPLETED,""); update_status_text_from_lang(LANGID_COMPLETED,"");
SetWindowText(g_hwnd,g_tmp); SetWindowText(g_hwnd,g_tmp);
SetFocus(h); SetFocus(h);

View file

@ -62,6 +62,7 @@ static LONG myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyifempty)
int retval=RegOpenKeyEx(thiskey,lpSubKey,0,KEY_ALL_ACCESS,&key); int retval=RegOpenKeyEx(thiskey,lpSubKey,0,KEY_ALL_ACCESS,&key);
if (retval==ERROR_SUCCESS) if (retval==ERROR_SUCCESS)
{ {
// NB - don't change this to static (recursive function)
char buffer[MAX_PATH+1]; char buffer[MAX_PATH+1];
while (RegEnumKey(key,0,buffer,MAX_PATH+1)==ERROR_SUCCESS) while (RegEnumKey(key,0,buffer,MAX_PATH+1)==ERROR_SUCCESS)
{ {
@ -113,7 +114,7 @@ int ExecuteCodeSegment(entry *entries, int pos, HWND hwndProgress)
{ {
extern int progress_bar_pos, progress_bar_len; extern int progress_bar_pos, progress_bar_len;
progress_bar_pos+=rv; progress_bar_pos+=rv;
if (!progress_bar_len) progress_bar_len++; progress_bar_len+=(!progress_bar_len);
SendMessage(hwndProgress,PBM_SETPOS,MulDiv(progress_bar_pos,30000,progress_bar_len),0); SendMessage(hwndProgress,PBM_SETPOS,MulDiv(progress_bar_pos,30000,progress_bar_len),0);
} }
} }
@ -201,7 +202,7 @@ static int ExecuteEntry(entry *entries, int pos)
if (parms[1]) if (parms[1])
{ {
update_status_text_from_lang(LANGID_OUTPUTDIR,buf2); update_status_text_from_lang(LANGID_OUTPUTDIR,buf2);
lstrcpy(state_output_directory,buf2); mystrcpy(state_output_directory,buf2);
} }
else update_status_text_from_lang(LANGID_CREATEDIR,buf2); else update_status_text_from_lang(LANGID_CREATEDIR,buf2);
recursive_create_directory(buf2); recursive_create_directory(buf2);
@ -230,8 +231,8 @@ static int ExecuteEntry(entry *entries, int pos)
{ {
process_string_fromtab(buf,parms[0]); process_string_fromtab(buf,parms[0]);
process_string_fromtab(buf2,parms[1]); process_string_fromtab(buf2,parms[1]);
lstrcpy(buf4,buf); mystrcpy(buf4,buf);
if (lstrlen(buf)+lstrlen(buf2) < NSIS_MAX_STRLEN-3) if (mystrlen(buf)+mystrlen(buf2) < NSIS_MAX_STRLEN-3)
{ {
lstrcat(buf4,"->"); lstrcat(buf4,"->");
lstrcat(buf4,buf2); lstrcat(buf4,buf2);
@ -279,7 +280,7 @@ static int ExecuteEntry(entry *entries, int pos)
WIN32_FIND_DATA *fd=file_exists(buf); WIN32_FIND_DATA *fd=file_exists(buf);
if (fd) if (fd)
{ {
lstrcpy(fp,fd->cFileName); mystrcpy(fp,fd->cFileName);
} }
else else
{ {
@ -319,14 +320,13 @@ static int ExecuteEntry(entry *entries, int pos)
HANDLE hOut; HANDLE hOut;
int ret; int ret;
int overwriteflag=parms[0]; int overwriteflag=parms[0];
lstrcpy(buf,state_output_directory); addtrailingslash(mystrcpy(buf,state_output_directory));
addtrailingslash(buf);
process_string_fromtab(buf4,parms[1]); process_string_fromtab(buf4,parms[1]);
log_printf3("File: overwriteflag=%d, name=\"%s\"",overwriteflag,buf4); log_printf3("File: overwriteflag=%d, name=\"%s\"",overwriteflag,buf4);
if (validpathspec(buf4)) if (validpathspec(buf4))
{ {
lstrcpy(buf,buf4); mystrcpy(buf,buf4);
} }
else lstrcat(buf,buf4); else lstrcat(buf,buf4);
_tryagain: _tryagain:
@ -356,11 +356,11 @@ static int ExecuteEntry(entry *entries, int pos)
return 0; return 0;
} }
log_printf2("File: error creating \"%s\"",buf); log_printf2("File: error creating \"%s\"",buf);
lstrcpy(buf3,g_usrvars[0]);//save $0 mystrcpy(buf3,g_usrvars[0]);//save $0
lstrcpy(g_usrvars[0],buf); mystrcpy(g_usrvars[0],buf);
process_string_from_lang(buf2,LANGID_FILEERR); process_string_from_lang(buf2,LANGID_FILEERR);
lstrcpy(g_usrvars[0],buf3); // restore $0 mystrcpy(g_usrvars[0],buf3); // restore $0
switch (my_MessageBox(buf2,MB_ABORTRETRYIGNORE|MB_ICONSTOP)) switch (my_MessageBox(buf2,MB_ABORTRETRYIGNORE|MB_ICONSTOP))
{ {
@ -396,7 +396,7 @@ static int ExecuteEntry(entry *entries, int pos)
} }
else else
{ {
lstrcpy(buf,STR(LANG_ERRORDECOMPRESSING)); mystrcpy(buf,STR(LANG_ERRORDECOMPRESSING));
} }
log_printf2("%s",buf); log_printf2("%s",buf);
my_MessageBox(buf,MB_OK|MB_ICONSTOP); my_MessageBox(buf,MB_OK|MB_ICONSTOP);
@ -411,7 +411,7 @@ static int ExecuteEntry(entry *entries, int pos)
HANDLE h; HANDLE h;
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
process_string_fromtab(buf2,parms[0]); process_string_fromtab(buf2,parms[0]);
lstrcpy(buf,buf2); mystrcpy(buf,buf2);
log_printf2("Delete: \"%s\"",buf); log_printf2("Delete: \"%s\"",buf);
trimslashtoend(buf); trimslashtoend(buf);
h=FindFirstFile(buf2,&fd); h=FindFirstFile(buf2,&fd);
@ -492,7 +492,7 @@ static int ExecuteEntry(entry *entries, int pos)
#ifdef NSIS_SUPPORT_STROPTS #ifdef NSIS_SUPPORT_STROPTS
case EW_STRLEN: case EW_STRLEN:
process_string_fromtab(buf,parms[1]); process_string_fromtab(buf,parms[1]);
myitoa(g_usrvars[parms[0]],lstrlen(buf)); myitoa(g_usrvars[parms[0]],mystrlen(buf));
return 0; return 0;
case EW_ASSIGNVAR: case EW_ASSIGNVAR:
{ {
@ -504,16 +504,16 @@ static int ExecuteEntry(entry *entries, int pos)
*p=0; *p=0;
if (parms[2] < 0 || newlen) if (parms[2] < 0 || newlen)
{ {
l=lstrlen(buf); l=mystrlen(buf);
if (start<0) start=l+start; if (start<0) start=l+start;
if (start>=0) if (start>=0)
{ {
if (start>l) start=l; if (start>l) start=l;
lstrcpy(p,buf+start); mystrcpy(p,buf+start);
if (newlen) if (newlen)
{ {
if (newlen<0) newlen=lstrlen(p)+newlen; if (newlen<0) newlen=mystrlen(p)+newlen;
if (newlen<0) newlen=0; if (newlen<0) newlen=0;
if (newlen < NSIS_MAX_STRLEN) p[newlen]=0; if (newlen < NSIS_MAX_STRLEN) p[newlen]=0;
} }
@ -611,9 +611,9 @@ static int ExecuteEntry(entry *entries, int pos)
log_printf2("Exch: stack < %d elements",parms[2]); log_printf2("Exch: stack < %d elements",parms[2]);
break; break;
} }
lstrcpy(buf,s->text); mystrcpy(buf,s->text);
lstrcpy(s->text,g_st->text); mystrcpy(s->text,g_st->text);
lstrcpy(g_st->text,buf); mystrcpy(g_st->text,buf);
} }
else if (parms[1]) else if (parms[1])
{ {
@ -623,7 +623,7 @@ static int ExecuteEntry(entry *entries, int pos)
exec_errorflag++; exec_errorflag++;
return 0; return 0;
} }
lstrcpy(g_usrvars[parms[0]],s->text); mystrcpy(g_usrvars[parms[0]],s->text);
g_st=s->next; g_st=s->next;
GlobalFree((HGLOBAL)s); GlobalFree((HGLOBAL)s);
} }
@ -870,8 +870,8 @@ static int ExecuteEntry(entry *entries, int pos)
log_printf3("CopyFiles \"%s\"->\"%s\"",buf,buf2); log_printf3("CopyFiles \"%s\"->\"%s\"",buf,buf2);
op.hwnd=g_hwnd; op.hwnd=g_hwnd;
op.wFunc=FO_COPY; op.wFunc=FO_COPY;
buf[lstrlen(buf)+1]=0; buf[mystrlen(buf)+1]=0;
buf2[lstrlen(buf2)+1]=0; buf2[mystrlen(buf2)+1]=0;
wsprintf(buf3,"%s%s",STR(LANG_COPYTO),buf2); wsprintf(buf3,"%s%s",STR(LANG_COPYTO),buf2);
@ -933,8 +933,8 @@ static int ExecuteEntry(entry *entries, int pos)
char *sec, *ent; char *sec, *ent;
sec=ent=0; sec=ent=0;
#ifdef NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_LOG
lstrcpy(buf2,"<RM>"); mystrcpy(buf2,"<RM>");
lstrcpy(buf3,buf2); mystrcpy(buf3,buf2);
#endif #endif
process_string_fromtab(buf,parms[0]); process_string_fromtab(buf,parms[0]);
if (parms[1]>=0) if (parms[1]>=0)
@ -1005,7 +1005,7 @@ static int ExecuteEntry(entry *entries, int pos)
if (type <= 1) if (type <= 1)
{ {
process_string_fromtab(buf3,parms[3]); process_string_fromtab(buf3,parms[3]);
if (RegSetValueEx(hKey,buf2,0,type==1?REG_SZ:REG_EXPAND_SZ,buf3,lstrlen(buf3)+1) == ERROR_SUCCESS) exec_errorflag--; if (RegSetValueEx(hKey,buf2,0,type==1?REG_SZ:REG_EXPAND_SZ,buf3,mystrlen(buf3)+1) == ERROR_SUCCESS) exec_errorflag--;
log_printf5("WriteRegStr: set %d\\%s\\%s to %s",rootkey,buf4,buf2,buf3); log_printf5("WriteRegStr: set %d\\%s\\%s to %s",rootkey,buf4,buf2,buf3);
} }
else if (type == 2) else if (type == 2)
@ -1120,7 +1120,7 @@ static int ExecuteEntry(entry *entries, int pos)
else else
{ {
process_string_fromtab(buf2,parms[1]); process_string_fromtab(buf2,parms[1]);
l=lstrlen(buf2); l=mystrlen(buf2);
} }
if (!*t || !WriteFile((HANDLE)myatoi(t),buf2,l,&dw,NULL)) if (!*t || !WriteFile((HANDLE)myatoi(t),buf2,l,&dw,NULL))
{ {
@ -1195,7 +1195,7 @@ static int ExecuteEntry(entry *entries, int pos)
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
if (*t && FindNextFile((HANDLE)myatoi(t),&fd)) if (*t && FindNextFile((HANDLE)myatoi(t),&fd))
{ {
lstrcpy(textout,fd.cFileName); mystrcpy(textout,fd.cFileName);
} }
else else
{ {
@ -1222,7 +1222,7 @@ static int ExecuteEntry(entry *entries, int pos)
else else
{ {
myitoa(handleout,(int)h); myitoa(handleout,(int)h);
lstrcpy(textout,fd.cFileName); mystrcpy(textout,fd.cFileName);
} }
} }
return 0; return 0;
@ -1236,12 +1236,11 @@ static int ExecuteEntry(entry *entries, int pos)
if (validpathspec(buf)) if (validpathspec(buf))
{ {
lstrcpy(buf2,buf); mystrcpy(buf2,buf);
} }
else else
{ {
lstrcpy(buf2,state_install_directory); addtrailingslash(mystrcpy(buf2,state_install_directory));
addtrailingslash(buf2);
lstrcat(buf2,buf); lstrcat(buf2,buf);
} }
@ -1384,7 +1383,7 @@ static int ExecuteEntry(entry *entries, int pos)
case EW_PLUGINCOMMANDPREP: case EW_PLUGINCOMMANDPREP:
// parms[0] = dll name // parms[0] = dll name
if (!*plugins_temp_dir) lstrcpy(plugins_temp_dir,g_usrvars[0]); if (!*plugins_temp_dir) mystrcpy(plugins_temp_dir,g_usrvars[0]);
return 0; return 0;
#endif // NSIS_CONFIG_PLUGIN_SUPPORT #endif // NSIS_CONFIG_PLUGIN_SUPPORT
} }

View file

@ -39,7 +39,7 @@ void doRMDir(char *buf, int recurse)
{ {
if (recurse && is_valid_instpath(buf)) if (recurse && is_valid_instpath(buf))
{ {
int i=lstrlen(buf); int i=mystrlen(buf);
HANDLE h; HANDLE h;
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
lstrcat(buf,"\\*.*"); lstrcat(buf,"\\*.*");
@ -51,7 +51,7 @@ void doRMDir(char *buf, int recurse)
if (fd.cFileName[0] != '.' || if (fd.cFileName[0] != '.' ||
(fd.cFileName[1] != '.' && fd.cFileName[1])) (fd.cFileName[1] != '.' && fd.cFileName[1]))
{ {
lstrcpy(buf+i+1,fd.cFileName); mystrcpy(buf+i+1,fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf,recurse); if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf,recurse);
else else
{ {
@ -79,7 +79,7 @@ void addtrailingslash(char *str)
char lastchar(const char *str) char lastchar(const char *str)
{ {
return *CharPrev(str,str+lstrlen(str)); return *CharPrev(str,str+mystrlen(str));
} }
void trimslashtoend(char *buf) void trimslashtoend(char *buf)
@ -92,7 +92,7 @@ void trimslashtoend(char *buf)
char *scanendslash(const char *str) char *scanendslash(const char *str)
{ {
char *s=CharPrev(str,str+lstrlen(str)); char *s=CharPrev(str,str+mystrlen(str));
if (!*str) return (char*)str-1; if (!*str) return (char*)str-1;
for (;;) for (;;)
{ {
@ -145,8 +145,8 @@ int is_valid_instpath(char *s)
static char *findinmem(char *a, char *b, int len_of_a) static char *findinmem(char *a, char *b, int len_of_a)
{ {
if (len_of_a<0) len_of_a=lstrlen(a); if (len_of_a<0) len_of_a=mystrlen(a);
len_of_a -= lstrlen(b); len_of_a -= mystrlen(b);
while (*a && len_of_a >= 0) while (*a && len_of_a >= 0)
{ {
char *t=a,*u=b; char *t=a,*u=b;
@ -235,7 +235,7 @@ BOOL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
LPSTR pszRenameSecInFile = findinmem(pszWinInit, szRenameSec,-1); LPSTR pszRenameSecInFile = findinmem(pszWinInit, szRenameSec,-1);
if (pszRenameSecInFile == NULL) if (pszRenameSecInFile == NULL)
{ {
lstrcpy(pszWinInit+dwFileSize, szRenameSec); mystrcpy(pszWinInit+dwFileSize, szRenameSec);
dwFileSize += 10; dwFileSize += 10;
dwRenameLinePos = dwFileSize; dwRenameLinePos = dwFileSize;
do_write++; do_write++;
@ -369,6 +369,7 @@ int GetLangString(langid_t id)
} }
void myitoa(char *s, int d) { wsprintf(s,"%d",d); } void myitoa(char *s, int d) { wsprintf(s,"%d",d); }
int myatoi(char *s) int myatoi(char *s)
{ {
unsigned int v=0; unsigned int v=0;
@ -414,6 +415,19 @@ int myatoi(char *s)
return (int)v; return (int)v;
} }
// Straight copies of selected shell functions. Calling local functions
// requires less code than DLL functions. For the savings to outweigh the cost
// of a new function there should be about a couple of dozen or so calls.
char *mystrcpy(char *out, const char *in)
{
return lstrcpy(out, in);
}
int mystrlen(const char *in)
{
return lstrlen(in);
}
int process_string_fromtab_toint(int offs) int process_string_fromtab_toint(int offs)
{ {
@ -468,13 +482,13 @@ void process_string(char *out, const char *in)
case VAR_CODES_START + 22: // INSTDIR case VAR_CODES_START + 22: // INSTDIR
case VAR_CODES_START + 23: // OUTDIR case VAR_CODES_START + 23: // OUTDIR
case VAR_CODES_START + 24: // EXEDIR case VAR_CODES_START + 24: // EXEDIR
lstrcpy(out, g_usrvars[nVarIdx - (VAR_CODES_START + 1)]); mystrcpy(out, g_usrvars[nVarIdx - (VAR_CODES_START + 1)]);
break; break;
case VAR_CODES_START + 25: // PROGRAMFILES case VAR_CODES_START + 25: // PROGRAMFILES
myRegGetStr(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir", out); myRegGetStr(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir", out);
if (!*out) if (!*out)
lstrcpy(out, "C:\\Program Files"); mystrcpy(out, "C:\\Program Files");
break; break;
case VAR_CODES_START + 26: // SMPROGRAMS case VAR_CODES_START + 26: // SMPROGRAMS
@ -516,7 +530,7 @@ void process_string(char *out, const char *in)
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
case VAR_CODES_START + 35: // PLUGINSDIR case VAR_CODES_START + 35: // PLUGINSDIR
lstrcpy(out, plugins_temp_dir); mystrcpy(out, plugins_temp_dir);
break; break;
#if VAR_CODES_START + 35 >= 255 #if VAR_CODES_START + 35 >= 255
@ -558,7 +572,7 @@ void log_write(int close)
{ {
if (g_log_file[0] && fp==INVALID_HANDLE_VALUE) if (g_log_file[0] && fp==INVALID_HANDLE_VALUE)
{ {
fp = CreateFile(g_log_file,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL); fp = myOpenFile(g_log_file,GENERIC_WRITE,OPEN_ALWAYS);
if (fp!=INVALID_HANDLE_VALUE) if (fp!=INVALID_HANDLE_VALUE)
SetFilePointer(fp,0,NULL,FILE_END); SetFilePointer(fp,0,NULL,FILE_END);
} }
@ -566,7 +580,7 @@ void log_write(int close)
{ {
DWORD d; DWORD d;
lstrcat(log_text,"\r\n"); lstrcat(log_text,"\r\n");
WriteFile(fp,log_text,lstrlen(log_text),&d,NULL); WriteFile(fp,log_text,mystrlen(log_text),&d,NULL);
} }
} }
} }

View file

@ -12,6 +12,8 @@ int process_string_fromtab_toint(int offs);
void myRegGetStr(HKEY root, const char *sub, const char *name, char *out); void myRegGetStr(HKEY root, const char *sub, const char *name, char *out);
int myatoi(char *s); int myatoi(char *s);
void myitoa(char *s, int d); void myitoa(char *s, int d);
char *mystrcpy(char *out, const char *in);
int mystrlen(const char *in);
#ifdef NSIS_CONFIG_LOG #ifdef NSIS_CONFIG_LOG
extern char log_text[NSIS_MAX_STRLEN*4]; extern char log_text[NSIS_MAX_STRLEN*4];