Files are not valid installation folders
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3142 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
ff2edfc360
commit
343f7c9408
3 changed files with 67 additions and 48 deletions
|
@ -49,10 +49,18 @@ HWND g_hwnd;
|
|||
HANDLE g_hInstance;
|
||||
#endif
|
||||
|
||||
char *ValidateTempDir()
|
||||
{
|
||||
validate_filename(state_temp_dir);
|
||||
CreateDirectory(state_temp_dir, NULL);
|
||||
// g_caption is used as a temp var here
|
||||
return my_GetTempFileName(g_caption, state_temp_dir);
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow)
|
||||
{
|
||||
int ret;
|
||||
const char *m_Err = 0;
|
||||
const char *m_Err = _LANG_ERRORWRITINGTEMP;
|
||||
|
||||
int cl_flags = 0;
|
||||
|
||||
|
@ -69,20 +77,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
|
|||
}
|
||||
#endif
|
||||
|
||||
GetTempPath(sizeof(state_temp_dir), state_temp_dir);
|
||||
validate_filename(state_temp_dir);
|
||||
CreateDirectory(state_temp_dir, NULL);
|
||||
|
||||
// g_caption is used as a temp var here
|
||||
if (!my_GetTempFileName(g_caption, state_temp_dir))
|
||||
GetTempPath(NSIS_MAX_STRLEN, state_temp_dir);
|
||||
if (!ValidateTempDir())
|
||||
{
|
||||
GetWindowsDirectory(state_temp_dir, sizeof(state_temp_dir));
|
||||
GetWindowsDirectory(state_temp_dir, NSIS_MAX_STRLEN - 5); // leave space for \Temp
|
||||
lstrcat(state_temp_dir, "\\Temp");
|
||||
validate_filename(state_temp_dir);
|
||||
CreateDirectory(state_temp_dir, NULL);
|
||||
if (!my_GetTempFileName(g_caption, state_temp_dir))
|
||||
if (!ValidateTempDir())
|
||||
{
|
||||
m_Err = _LANG_ERRORWRITINGTEMP;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +201,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
|
|||
lstrcat(buf2," _?=");
|
||||
lstrcat(buf2,ibuf);
|
||||
// add a trailing backslash to make sure is_valid_instpath will not fail when it shouldn't
|
||||
lstrcat(buf2,"\\");
|
||||
addtrailingslash(buf2);
|
||||
hProc=myCreateProcess(buf2,state_temp_dir);
|
||||
if (hProc)
|
||||
{
|
||||
|
|
|
@ -177,9 +177,12 @@ int NSISCALL ui_doinstall(void)
|
|||
{
|
||||
if (header->install_reg_key_ptr)
|
||||
{
|
||||
myRegGetStr((HKEY)header->install_reg_rootkey,
|
||||
myRegGetStr(
|
||||
(HKEY)header->install_reg_rootkey,
|
||||
GetNSISStringNP(header->install_reg_key_ptr),
|
||||
GetNSISStringNP(header->install_reg_value_ptr),ps_tmpbuf);
|
||||
GetNSISStringNP(header->install_reg_value_ptr),
|
||||
ps_tmpbuf
|
||||
);
|
||||
if (ps_tmpbuf[0])
|
||||
{
|
||||
char *p=ps_tmpbuf;
|
||||
|
@ -728,6 +731,20 @@ static char * NSISCALL inttosizestr(int kb, char *str)
|
|||
return str;
|
||||
}
|
||||
|
||||
static int NSISCALL getreqsize()
|
||||
{
|
||||
int x,total;
|
||||
section *sections = g_sections;
|
||||
for (total = x = 0; x < num_sections; x++)
|
||||
{
|
||||
#ifdef NSIS_CONFIG_COMPONENTPAGE
|
||||
if (sections[x].flags & SF_SELECTED)
|
||||
#endif
|
||||
total += sections[x].size_kb;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
char *dir = g_usrvars[g_this_page->parms[4]];
|
||||
|
@ -809,8 +826,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
static char s[NSIS_MAX_STRLEN];
|
||||
char *p;
|
||||
int is_valid_path;
|
||||
int x;
|
||||
int total=0, available=-1;
|
||||
int total, available=-1;
|
||||
DWORD spc,bps,fc,tc;
|
||||
|
||||
GetUIText(IDC_DIR,dir,NSIS_MAX_STRLEN);
|
||||
|
@ -827,13 +843,8 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
if (r > 0x7fffffff) r=0x7fffffff;
|
||||
available=(int)r;
|
||||
}
|
||||
for (x = 0; x < num_sections; x ++)
|
||||
{
|
||||
#ifdef NSIS_CONFIG_COMPONENTPAGE
|
||||
if (g_sections[x].flags&SF_SELECTED)
|
||||
#endif
|
||||
total+=g_sections[x].size_kb;
|
||||
}
|
||||
|
||||
total = getreqsize();
|
||||
|
||||
if (LANG_STR_TAB(LANG_SPACE_REQ)) {
|
||||
SetUITextNT(IDC_SPACEREQUIRED,inttosizestr(total,GetNSISString(s,LANG_SPACE_REQ)));
|
||||
|
@ -1345,14 +1356,8 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
} // end of typecheckshit
|
||||
|
||||
if (LANG_STR_TAB(LANG_SPACE_REQ)) {
|
||||
int x,total;
|
||||
char s[128];
|
||||
for (total=x=0; x < num_sections; x ++)
|
||||
{
|
||||
if (sections[x].flags&SF_SELECTED)
|
||||
total+=sections[x].size_kb;
|
||||
}
|
||||
SetUITextNT(IDC_SPACEREQUIRED,inttosizestr(total,GetNSISString(s,LANG_SPACE_REQ)));
|
||||
SetUITextNT(IDC_SPACEREQUIRED,inttosizestr(getreqsize(),GetNSISString(s,LANG_SPACE_REQ)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1389,20 +1394,14 @@ void NSISCALL update_status_text(int strtab, const char *text) {
|
|||
{
|
||||
new_item.mask = LVIF_TEXT;
|
||||
new_item.pszText = tmp;
|
||||
new_item.iItem = ListView_GetItemCount(linsthwnd);
|
||||
new_item.iItem = ListView_GetItemCount(linsthwnd) - (updateflag & 1);
|
||||
new_item.iSubItem = 0;
|
||||
if (updateflag & 1)
|
||||
{
|
||||
new_item.iItem--;
|
||||
ListView_SetItem(linsthwnd, &new_item);
|
||||
}
|
||||
else
|
||||
ListView_InsertItem(linsthwnd, &new_item);
|
||||
SendMessage(linsthwnd, (updateflag & 1) ? LVM_SETITEM : LVM_INSERTITEM, 0, (LPARAM) &new_item);
|
||||
ListView_EnsureVisible(linsthwnd, new_item.iItem, 0);
|
||||
}
|
||||
|
||||
if (updateflag & 1)
|
||||
tmp[tmplen]=0;
|
||||
tmp[tmplen] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -181,16 +181,35 @@ char * NSISCALL skip_root(char *path)
|
|||
|
||||
int NSISCALL is_valid_instpath(char *s)
|
||||
{
|
||||
int ret = 0;
|
||||
char *p = skip_root(s);
|
||||
if (p && ((*p && *p != '\\') || !(g_flags & CH_FLAGS_NO_ROOT_DIR)))
|
||||
static char tmp[NSIS_MAX_STRLEN];
|
||||
char *root;
|
||||
|
||||
mystrcpy(tmp, s);
|
||||
|
||||
root = skip_root(tmp);
|
||||
|
||||
if (!root)
|
||||
return 0;
|
||||
|
||||
if ((g_flags & CH_FLAGS_NO_ROOT_DIR) && (!*root || *root == '\\'))
|
||||
return 0;
|
||||
|
||||
while (mystrlen(tmp) > root - tmp)
|
||||
{
|
||||
char pb = *p;
|
||||
*p = 0;
|
||||
ret = GetFileAttributes(s) != (DWORD)-1;
|
||||
*p = pb;
|
||||
WIN32_FIND_DATA *fd = file_exists(tmp);
|
||||
// if the directory bit not set then it's a file, which is not a valid inst dir...
|
||||
// GetFileAttributes is not used because it doesn't work with certain files (error 32)
|
||||
// as for concers of the user using * or ?, that's invalid anyway...
|
||||
if (fd && !(fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
return 0;
|
||||
trimslashtoend(tmp);
|
||||
}
|
||||
return ret;
|
||||
|
||||
// if the root drive exists
|
||||
if (GetFileAttributes(tmp) == (DWORD)-1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char * NSISCALL mystrstr(char *a, char *b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue