From 05d910c2898b03b7ca7abea5b98864df8f152fe5 Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 3 Mar 2007 14:18:49 +0000 Subject: [PATCH] size optimization - use GetNSISString to do complicated stirng processing git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4971 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 24 ++++++++++++++++++++++++ Source/build.h | 1 + Source/exehead/Main.c | 35 ++++++++++++++++------------------- Source/exehead/fileform.h | 8 ++++++++ Source/exehead/util.c | 3 +-- Source/fileform.cpp | 8 ++++++++ 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index 8d05255f..3f739e8b 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -2083,6 +2083,20 @@ void CEXEBuild::PrepareInstTypes() } #endif +void CEXEBuild::AddStandardStrings() +{ +#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT + if (uninstall_mode) + { + cur_header->str_uninstchild = add_string("$TEMP\\$1"); + cur_header->str_uninstcmd = add_string("\"$TEMP\\$1\" $0 _?=$INSTDIR\\"); + } +#endif//NSIS_CONFIG_UNINSTALL_SUPPORT +#ifdef NSIS_SUPPORT_MOVEONREBOOT + cur_header->str_wininit = add_string("$WINDIR\\wininit.ini"); +#endif//NSIS_SUPPORT_MOVEONREBOOT +} + void CEXEBuild::PrepareHeaders(IGrowBuf *hdrbuf) { GrowBuf blocks_buf; @@ -2236,13 +2250,20 @@ int CEXEBuild::prepare_uninstaller() { build_uninst.flags|=build_header.flags&(CH_FLAGS_PROGRESS_COLORED|CH_FLAGS_NO_ROOT_DIR); set_uninstall_mode(1); + DefineInnerLangString(NLF_UCAPTION); + if (resolve_coderefs("uninstall")) return PS_ERROR; + #ifdef NSIS_CONFIG_COMPONENTPAGE // set sections to the first insttype PrepareInstTypes(); #endif + + // Add standard strings to string table + AddStandardStrings(); + set_uninstall_mode(0); } else if (uninstaller_writes_used) @@ -2332,6 +2353,9 @@ int CEXEBuild::write_output(void) // Set XML manifest RET_UNLESS_OK( SetManifest() ); + // Add standard strings to string table + AddStandardStrings(); + try { // Save all changes to the exe header close_res_editor(); diff --git a/Source/build.h b/Source/build.h index 13b97d7e..cb0ab3e1 100644 --- a/Source/build.h +++ b/Source/build.h @@ -244,6 +244,7 @@ class CEXEBuild { int AddVersionInfo(); int ProcessPages(); void PrepareInstTypes(); + void AddStandardStrings(); void PrepareHeaders(IGrowBuf *hdrbuf); int SetVarsSection(); int SetManifest(); diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index ec4c2224..5073a7b4 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -197,45 +197,42 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, else { int x; + char s[] = "Au_.exe"; - mystrcat(state_temp_dir,"~nsu.tmp\\"); + mystrcat(state_temp_dir,"~nsu.tmp"); CreateDirectory(state_temp_dir,NULL); + if (!state_install_directory[0]) + mystrcpy(state_install_directory,state_exe_directory); + + mystrcpy(g_usrvars[0], realcmds); + mystrcpy(g_usrvars[1], s); + for (x = 0; x < 26; x ++) { - static char s[]="Au_.exe"; - static char buf2[NSIS_MAX_STRLEN*2]; + static char buf2[NSIS_MAX_STRLEN]; static char ibuf[NSIS_MAX_STRLEN]; - *(LPWORD)buf2=CHAR2_TO_WORD('\"',0); - mystrcat(buf2,state_temp_dir); - mystrcat(buf2,s); + GetNSISString(buf2,g_header->str_uninstchild); // $TEMP\$1 - DeleteFile(buf2+1); // clean up after all the other ones if they are there + DeleteFile(buf2); // clean up after all the other ones if they are there if (m_Err) // not done yet { // get current name int l=GetModuleFileName(NULL,ibuf,sizeof(ibuf)); - // check if it is ?Au_.exe - if so, fuck it + // check if it is ?u_.exe - if so, fuck it if (!lstrcmpi(ibuf+l-(sizeof(s)-2),s+1)) break; // copy file - if (CopyFile(ibuf,buf2+1,TRUE)) + if (CopyFile(ibuf,buf2,TRUE)) { HANDLE hProc; #ifdef NSIS_SUPPORT_MOVEONREBOOT - MoveFileOnReboot(buf2+1,NULL); + MoveFileOnReboot(buf2,NULL); MoveFileOnReboot(state_temp_dir,NULL); #endif - if (state_install_directory[0]) mystrcpy(ibuf,state_install_directory); - else trimslashtoend(ibuf); - mystrcat(buf2,"\" "); - mystrcat(buf2,realcmds); - mystrcat(buf2," _?="); - mystrcat(buf2,ibuf); - // add a trailing backslash to make sure is_valid_instpath will not fail when it shouldn't - addtrailingslash(buf2); + GetNSISString(buf2,g_header->str_uninstcmd); // "$TEMP\$1" $0 _?=$INSTDIR\ hProc=myCreateProcess(buf2,state_temp_dir); if (hProc) { @@ -245,7 +242,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, } } } - s[0]++; + g_usrvars[1][0]++; } goto end; } diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index 5be16d3c..00cc8357 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -329,6 +329,14 @@ typedef struct int install_directory_ptr; // default install dir. int install_directory_auto_append; // auto append part + +#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT + int str_uninstchild; + int str_uninstcmd; +#endif//NSIS_CONFIG_UNINSTALL_SUPPORT +#ifdef NSIS_SUPPORT_MOVEONREBOOT + int str_wininit; +#endif//NSIS_SUPPORT_MOVEONREBOOT } header; #ifdef NSIS_SUPPORT_CODECALLBACKS diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 5756ac4b..9da46b97 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -448,8 +448,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) return; cchRenameLine = wsprintf(szRenameLine,"%s=%s\r\n",tmpbuf,wininit); - GetWindowsDirectory(wininit, 1024-16); - mystrcat(wininit, "\\wininit.ini"); + GetNSISString(wininit, g_header->str_wininit); hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS); if (hfile != INVALID_HANDLE_VALUE) diff --git a/Source/fileform.cpp b/Source/fileform.cpp index ca2a877e..fddf8668 100644 --- a/Source/fileform.cpp +++ b/Source/fileform.cpp @@ -95,6 +95,14 @@ void header_writer::write(const header *data) m_sink->write_int(data->install_directory_ptr); m_sink->write_int(data->install_directory_auto_append); + +#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT + m_sink->write_int(data->str_uninstchild); + m_sink->write_int(data->str_uninstcmd); +#endif//NSIS_CONFIG_UNINSTALL_SUPPORT +#ifdef NSIS_SUPPORT_MOVEONREBOOT + m_sink->write_int(data->str_wininit); +#endif//NSIS_SUPPORT_MOVEONREBOOT } void section_writer::write(const section *data)