Improved Sunjammer's code

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@666 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-08-08 15:04:45 +00:00
parent 8976cc3e61
commit c3c52d4f4c
15 changed files with 178 additions and 206 deletions

View file

@ -33,10 +33,6 @@
#include "ui.h"
#include "lang.h"
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "dllpaths.h"
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
extern unsigned long CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
#if !defined(NSIS_CONFIG_VISIBLE_SUPPORT) && !defined(NSIS_CONFIG_SILENT_SUPPORT)
@ -62,6 +58,10 @@ HWND g_hwnd;
static int m_length;
static int m_pos;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
extern char plugins_temp_dir[NSIS_MAX_STRLEN];
#endif
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
#ifdef NSIS_CONFIG_CRC_SUPPORT
static BOOL CALLBACK verProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -364,7 +364,9 @@ end:
if (m_Err) MessageBox(NULL,m_Err,g_caption,MB_OK|MB_ICONSTOP);
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
DllPathsCleanup();
// Clean up after plug-ins
MessageBox(0, plugins_temp_dir, "delete", MB_OK);
if (plugins_temp_dir[0]) doRMDir(plugins_temp_dir,1);
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
ExitProcess(ret);

View file

@ -40,11 +40,13 @@
// Added by Amir Szekely 3rd August 2002
installer_strings *install_strings_tables;
common_strings *common_strings_tables;
uninstall_strings *uninstall_strings_tables;
installer_strings *cur_install_strings_table;
common_strings *common_strings_tables;
common_strings *cur_common_strings_table;
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
uninstall_strings *uninstall_strings_tables;
uninstall_strings *cur_uninstall_strings_table;
#endif
int g_quit_flag; // set when Quit has been called (meaning bail out ASAP)
@ -304,26 +306,32 @@ int ui_doinstall(void)
// Multilingual support
char c=0;
LANGID user_lang=GetUserDefaultLangID();
int size=g_inst_header->common.str_tables_num*sizeof(common_strings);
int size=g_inst_header->str_tables_num*sizeof(common_strings);
cur_common_strings_table=common_strings_tables=(common_strings*)GlobalAlloc(GPTR,size);
GetCompressedDataFromDataBlockToMemory(g_inst_header->common.str_tables,(char*)common_strings_tables,size);
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
if (!g_is_uninstaller) {
#endif
size=g_inst_header->str_tables_num*sizeof(installer_strings);
cur_install_strings_table=install_strings_tables=(installer_strings*)GlobalAlloc(GPTR,size);
GetCompressedDataFromDataBlockToMemory(g_inst_header->str_tables,(char*)install_strings_tables,size);
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
}
else {
size=g_inst_header->str_tables_num*sizeof(uninstall_strings);
size=g_inst_uninstheader->str_tables_num*sizeof(uninstall_strings);
cur_uninstall_strings_table=uninstall_strings_tables=(uninstall_strings*)GlobalAlloc(GPTR,size);
GetCompressedDataFromDataBlockToMemory(g_inst_header->str_tables,(char*)uninstall_strings_tables,size);
GetCompressedDataFromDataBlockToMemory(g_inst_uninstheader->str_tables,(char*)uninstall_strings_tables,size);
}
#endif
lang_again:
for (size=0; size<g_inst_header->str_tables_num; size++) {
if (user_lang == common_strings_tables[size].lang_id
|| (c && PRIMARYLANGID(user_lang) == PRIMARYLANGID(common_strings_tables[size].lang_id))) {
cur_install_strings_table = &install_strings_tables[size];
cur_common_strings_table = &common_strings_tables[size];
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
cur_uninstall_strings_table = &uninstall_strings_tables[size];
#endif
break;
}
}
@ -373,6 +381,7 @@ int ui_doinstall(void)
#ifdef NSIS_SUPPORT_CODECALLBACKS
ExecuteCodeSegment(g_inst_entry,g_inst_cmnheader->code_onInstSuccess,NULL);
#endif//NSIS_SUPPORT_CODECALLBACKS
return 0;
}
#endif//NSIS_CONFIG_SILENT_SUPPORT
@ -1138,20 +1147,23 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
int ui_st_updateflag=0x3;
void update_status_text_from_tab(int texttab, const char *text2)
{
update_status_text(STR(texttab), text2);
}
void update_status_text(const char *text1, const char *text2)
{
static LVITEM new_item = {LVIF_TEXT,};
static LVITEM new_item = {LVIF_TEXT,0,0,0,0,ps_tmpbuf};
RECT r;
if (insthwnd)
{
if (lstrlen(text1)+lstrlen(text2) >= sizeof(ps_tmpbuf)) return;
lstrcpy(ps_tmpbuf,text1);
lstrcat(ps_tmpbuf,text2);
if ((ui_st_updateflag&1))
{
// Changed by Amir Szekely 26th July 2002
new_item.pszText=ps_tmpbuf;
new_item.iItem=ListView_GetItemCount(insthwnd);
ListView_InsertItem(insthwnd, &new_item);
ListView_EnsureVisible(insthwnd, new_item.iItem, 0);
@ -1288,7 +1300,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
ShowWindow(g_hwnd,SW_SHOWNA);
lstrcpy(g_tmp,g_caption);
process_string_fromtab(g_tmp+lstrlen(g_caption),COMMON_STR(subcaptions[g_max_page+1]));
update_status_text(STR(LANG_COMPLETED),"");
update_status_text_from_tab(LANG_COMPLETED,"");
SetWindowText(h2,g_tmp);
SetFocus(h);
}

View file

@ -9,10 +9,6 @@
#include "lang.h"
#include "resource.h"
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "dllpaths.h"
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
#define EXEC_ERROR 0x7FFFFFFF
#ifdef NSIS_CONFIG_COMPONENTPAGE
@ -37,6 +33,11 @@ static int exec_rebootflag;
HBITMAP g_hBrandingBitmap = 0;
#endif
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
char plugins_temp_dir[NSIS_MAX_STRLEN]="";
char plugin[NSIS_MAX_STRLEN]="";
#endif
extern HWND m_curwnd;
static WIN32_FIND_DATA *file_exists(char *buf)
@ -52,46 +53,6 @@ static WIN32_FIND_DATA *file_exists(char *buf)
return NULL;
}
#ifdef NSIS_SUPPORT_RMDIR
static void doRMDir(char *buf, int recurse)
{
if (recurse && is_valid_instpath(buf))
{
int i=lstrlen(buf);
HANDLE h;
WIN32_FIND_DATA fd;
lstrcat(buf,"\\*.*");
h = FindFirstFile(buf,&fd);
if (h != INVALID_HANDLE_VALUE)
{
do
{
if (fd.cFileName[0] != '.' ||
(fd.cFileName[1] != '.' && fd.cFileName[1]))
{
lstrcpy(buf+i+1,fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf,recurse);
else
{
update_status_text(STR(LANG_DELETEFILE),buf);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
SetFileAttributes(buf,fd.dwFileAttributes^FILE_ATTRIBUTE_READONLY);
DeleteFile(buf);
}
}
} while (FindNextFile(h,&fd));
FindClose(h);
}
buf[i]=0; // fix buffer
}
log_printf2("RMDir: RemoveDirectory(\"%s\")",buf);
update_status_text(STR(LANG_REMOVEDIR),buf);
RemoveDirectory(buf);
}
#endif//NSIS_SUPPORT_RMDIR
#ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS
// based loosely on code from Tim Kosse
// in win9x this isn't necessary (RegDeleteKey() can delete a tree of keys),
@ -240,10 +201,10 @@ static int ExecuteEntry(entry *entries, int pos)
log_printf3("CreateDirectory: \"%s\" (%d)",buf2,parms[1]);
if (parms[1])
{
update_status_text(STR(LANG_OUTPUTDIR),buf2);
update_status_text_from_tab(LANG_OUTPUTDIR,buf2);
lstrcpy(state_output_directory,buf2);
}
else update_status_text(STR(LANG_CREATEDIR),buf2);
else update_status_text_from_tab(LANG_CREATEDIR,buf2);
recursive_create_directory(buf2);
return 0;
case EW_IFFILEEXISTS:
@ -279,7 +240,7 @@ static int ExecuteEntry(entry *entries, int pos)
log_printf2("Rename: %s",buf4);
if (MoveFile(buf,buf2))
{
update_status_text(STR(LANG_RENAME),buf4);
update_status_text_from_tab(LANG_RENAME,buf4);
}
else
{
@ -290,7 +251,7 @@ static int ExecuteEntry(entry *entries, int pos)
exec_rebootflag++;
#endif
MoveFileOnReboot(buf,buf2);
update_status_text(STR(LANG_RENAMEONREBOOT),buf4);
update_status_text_from_tab(LANG_RENAMEONREBOOT,buf4);
log_printf2("Rename on reboot: %s",buf4);
}
else
@ -390,7 +351,7 @@ static int ExecuteEntry(entry *entries, int pos)
{
if (overwriteflag)
{
update_status_text(STR(LANG_SKIPPED),buf4);
update_status_text_from_tab(LANG_SKIPPED,buf4);
if (overwriteflag==2) exec_errorflag++;
log_printf3("File: skipped: \"%s\" (overwriteflag=%d)",buf,overwriteflag);
return 0;
@ -413,12 +374,12 @@ static int ExecuteEntry(entry *entries, int pos)
return 0;
default:
log_printf("File: error, user abort");
update_status_text(STR(LANG_CANTWRITE),buf);
update_status_text_from_tab(LANG_CANTWRITE,buf);
return EXEC_ERROR;
}
}
update_status_text(STR(LANG_EXTRACT),buf4);
update_status_text_from_tab(LANG_EXTRACT,buf4);
ret=GetCompressedDataFromDataBlock(parms[2],hOut);
log_printf3("File: wrote %d to \"%s\"",ret,buf);
@ -468,7 +429,7 @@ static int ExecuteEntry(entry *entries, int pos)
if (DeleteFile(buf2))
{
log_printf2("Delete: DeleteFile(\"%s\")",buf2);
update_status_text(STR(LANG_DELETEFILE),buf2);
update_status_text_from_tab(LANG_DELETEFILE,buf2);
}
else
{
@ -479,7 +440,7 @@ static int ExecuteEntry(entry *entries, int pos)
exec_rebootflag++;
#endif
log_printf2("Delete: DeleteFile on Reboot(\"%s\")",buf2);
update_status_text(STR(LANG_DELETEONREBOOT),buf2);
update_status_text_from_tab(LANG_DELETEONREBOOT,buf2);
MoveFileOnReboot(buf2,NULL);
}
else
@ -714,7 +675,7 @@ static int ExecuteEntry(entry *entries, int pos)
lstrcpy(buf4,buf);
lstrcat(buf4," ");
lstrcat(buf4,buf2);
update_status_text(STR(LANG_EXECSHELL), buf4);
update_status_text_from_tab(LANG_EXECSHELL, buf4);
x=(int)ShellExecute(g_hwnd,buf[0]?buf:NULL,buf2,buf3[0]?buf3:NULL,state_output_directory,parms[3]);
if (x < 33)
{
@ -734,7 +695,7 @@ static int ExecuteEntry(entry *entries, int pos)
HANDLE hProc;
process_string_fromtab(buf,parms[0]);
log_printf2("Exec: command=\"%s\"",buf);
update_status_text(STR(LANG_EXECUTE),buf);
update_status_text_from_tab(LANG_EXECUTE,buf);
hProc=myCreateProcess(buf,*state_output_directory?state_output_directory:NULL);
@ -831,6 +792,10 @@ static int ExecuteEntry(entry *entries, int pos)
if (hres == S_FALSE || hres == S_OK)
{
HANDLE h;
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
if (!parms[0]) lstrcpy(buf,plugin);
else
#endif
process_string_fromtab(buf,parms[0]);
process_string_fromtab(buf2,parms[1]);
@ -861,21 +826,21 @@ static int ExecuteEntry(entry *entries, int pos)
}
else
{
update_status_text(STR(LANG_CANNOTFINDSYMBOL),buf2);
update_status_text_from_tab(LANG_CANNOTFINDSYMBOL,buf2);
log_printf3("Error registering DLL: %s not found in %s",buf2,buf);
}
FreeLibrary(h);
}
else
{
update_status_text(STR(LANG_COULDNOTLOAD),buf);
update_status_text_from_tab(LANG_COULDNOTLOAD,buf);
log_printf2("Error registering DLL: Could not load %s",buf);
}
OleUninitialize();
}
else
{
update_status_text(STR(LANG_NOOLE),buf);
update_status_text_from_tab(LANG_NOOLE,buf);
log_printf("Error registering DLL: Could not initialize OLE");
}
}
@ -895,11 +860,11 @@ static int ExecuteEntry(entry *entries, int pos)
state_output_directory,(parms[4]&0xff00)>>8,parms[4]>>16))
{
exec_errorflag++;
update_status_text(STR(LANG_ERRORCREATINGSHORTCUT),buf3);
update_status_text_from_tab(LANG_ERRORCREATINGSHORTCUT,buf3);
}
else
{
update_status_text(STR(LANG_CREATESHORTCUT),buf3);
update_status_text_from_tab(LANG_CREATESHORTCUT,buf3);
}
return 0;
#endif//NSIS_SUPPORT_CREATESHORTCUT
@ -927,7 +892,7 @@ static int ExecuteEntry(entry *entries, int pos)
res=SHFileOperation(&op);
if (res)
{ // some of these changes were from Edgewise (wiked_edge@yahoo.com)
update_status_text(STR(LANG_COPYFAILED),"");
update_status_text_from_tab(LANG_COPYFAILED,"");
exec_errorflag++;
}
}
@ -1332,11 +1297,11 @@ static int ExecuteEntry(entry *entries, int pos)
log_printf3("created uninstaller: %d, \"%s\"",ret,buf2);
if (ret < 0)
{
update_status_text(STR(LANG_ERRORCREATING),buf);
update_status_text_from_tab(LANG_ERRORCREATING,buf);
DeleteFile(buf2);
}
else
update_status_text(STR(LANG_CREATEDUNINST),buf);
update_status_text_from_tab(LANG_CREATEDUNINST,buf);
}
return 0;
#endif//NSIS_CONFIG_UNINSTALL_SUPPORT
@ -1427,68 +1392,11 @@ static int ExecuteEntry(entry *entries, int pos)
// Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
case EW_PLUGINCOMMANDPREP:
{
// parms[0] - dll name
// parms[1] - function name
// parms[2] - compressed data handle
char* dllPath = DllPathsDetermined(parms[0]);
if (!dllPath)
{
HANDLE hOut;
// parms[0] = dll name
if (!GetTempPath(NSIS_MAX_STRLEN,buf2) ||
!GetTempFileName(buf2,"nst",0,buf))
{
exec_errorflag++;
return 0;
}
hOut = myOpenFile(buf,GENERIC_WRITE,CREATE_ALWAYS);
GetCompressedDataFromDataBlock(parms[2],hOut);
CloseHandle(hOut);
DllPathsAdd(parms[0],buf);
}
else
lstrcpy(buf,dllPath);
// leave buf containing the dll path
// and buf2 containing the function name
process_string_fromtab(buf2,parms[1]);
}
return 0;
case EW_PLUGINCOMMAND:
{
// parms contain command arguments
FARPROC funke;
HANDLE h;
int i;
// Place the command arguments on the stack, then invoke a CallInstDLL
// command on behalf of the user. Error handling needs improving, this
// won't fail gracefully, instead it could leave the stack in a state
// the user script won't expect.
for (i = 0; parms[i] != -1 && i < MAX_ENTRY_OFFSETS; i++)
{
stack_t* s = (stack_t*)GlobalAlloc(GPTR,sizeof(stack_t));
process_string_fromtab(s->text,parms[i]);
s->next = g_st;
g_st = s;
}
h = LoadLibrary(buf);
if (h)
{
funke = GetProcAddress(h,buf2);
if (funke)
{
void (*func)(HWND,int,char*,void*);
func = (void*)funke;
func(g_hwnd,NSIS_MAX_STRLEN,(char*)g_usrvars,(void*)&g_st);
}
FreeLibrary(h);
}
}
if (!*plugins_temp_dir) lstrcpy(plugins_temp_dir,g_usrvars[0]);
lstrcpy(plugin,plugins_temp_dir);
process_string_fromtab(plugin+lstrlen(plugins_temp_dir),parms[0]);
return 0;
#endif // NSIS_CONFIG_PLUGIN_SUPPORT
}

View file

@ -152,10 +152,6 @@ SOURCE=..\crc32.c
# End Source File
# Begin Source File
SOURCE=.\dllpaths.c
# End Source File
# Begin Source File
SOURCE=.\exec.c
# End Source File
# Begin Source File
@ -184,10 +180,6 @@ SOURCE=.\config.h
# End Source File
# Begin Source File
SOURCE=.\dllpaths.h
# End Source File
# Begin Source File
SOURCE=.\exec.h
# End Source File
# Begin Source File

View file

@ -152,10 +152,6 @@ SOURCE=..\crc32.c
# End Source File
# Begin Source File
SOURCE=.\dllpaths.c
# End Source File
# Begin Source File
SOURCE=.\exec.c
# End Source File
# Begin Source File

View file

@ -122,8 +122,7 @@ enum
EW_GETLABELADDR, // both of these get converted to EW_ASSIGNVAR
EW_GETFUNCTIONADDR,
EW_PLUGINCOMMANDPREP,
EW_PLUGINCOMMAND
EW_PLUGINCOMMANDPREP
};
@ -225,7 +224,6 @@ typedef struct
// Settings common to both installers and uninstallers
typedef struct
{
int str_tables_num; // number of strings tables in array
int str_tables; // offset to tables array
int num_entries; // total number of entries

View file

@ -7,6 +7,7 @@ extern common_strings *cur_common_strings_table;
extern uninstall_strings *cur_uninstall_strings_table;
int ui_doinstall(void);
void update_status_text_from_tab(int texttab, const char *text2);
void update_status_text(const char *text1, const char *text2);
extern int ui_st_updateflag;

View file

@ -3,6 +3,7 @@
#include "util.h"
#include "state.h"
#include "config.h"
#include "lang.h"
#include "fileform.h"
#include "ui.h"
@ -26,6 +27,43 @@ HANDLE myCreateProcess(char *cmd, char *dir)
return ProcInfo.hProcess;
}
#ifdef NSIS_SUPPORT_RMDIR
void doRMDir(char *buf, int recurse)
{
if (recurse && is_valid_instpath(buf))
{
int i=lstrlen(buf);
HANDLE h;
WIN32_FIND_DATA fd;
lstrcat(buf,"\\*.*");
h = FindFirstFile(buf,&fd);
if (h != INVALID_HANDLE_VALUE)
{
do
{
if (fd.cFileName[0] != '.' ||
(fd.cFileName[1] != '.' && fd.cFileName[1]))
{
lstrcpy(buf+i+1,fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf,recurse);
else
{
update_status_text_from_tab(LANG_DELETEFILE,buf);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
SetFileAttributes(buf,fd.dwFileAttributes^FILE_ATTRIBUTE_READONLY);
DeleteFile(buf);
}
}
} while (FindNextFile(h,&fd));
FindClose(h);
}
buf[i]=0; // fix buffer
}
log_printf2("RMDir: RemoveDirectory(\"%s\")",buf);
update_status_text_from_tab(LANG_REMOVEDIR,buf);
RemoveDirectory(buf);
}
#endif//NSIS_SUPPORT_RMDIR
void addtrailingslash(char *str)
{

View file

@ -10,7 +10,6 @@ void myRegGetStr(HKEY root, const char *sub, const char *name, char *out);
int myatoi(char *s);
void myitoa(char *s, int d);
#ifdef NSIS_CONFIG_LOG
extern char log_text[NSIS_MAX_STRLEN*4];
void log_write(int close);
@ -34,6 +33,8 @@ extern char g_log_file[1024];
#endif
HANDLE myCreateProcess(char *cmd, char *dir);
void doRMDir(char *buf, int recurse);
HANDLE myOpenFile(const char *fn, DWORD da, DWORD cd);
int CreateShortCut(HWND hwnd, LPCSTR pszShortcutFile, LPCSTR pszIconFile, int iconindex, LPCSTR pszExe, LPCSTR pszArg, LPCSTR workingdir, int showmode, int hotkey);