mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
By request from paulcbetts we need to check that:
1. SQUIRREL_TEMP directory exists 2. The user has write access to it 3. It's not a UNC path
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -177,3 +177,7 @@ nunit-Squirrel.Tests.xml
|
|||||||
|
|
||||||
## Pester Test Output
|
## Pester Test Output
|
||||||
tests/Test.xml
|
tests/Test.xml
|
||||||
|
|
||||||
|
## CPP db crap
|
||||||
|
*.db
|
||||||
|
*.opendb
|
||||||
|
|||||||
@@ -128,6 +128,30 @@ HRESULT CUpdateRunner::ShellExecuteFromExplorer(LPWSTR pszFile, LPWSTR pszParame
|
|||||||
CComVariant(SW_SHOWDEFAULT));
|
CComVariant(SW_SHOWDEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CUpdateRunner::DirectoryExistsW(wchar_t* szPath)
|
||||||
|
{
|
||||||
|
DWORD dwAttrib = GetFileAttributes(szPath);
|
||||||
|
|
||||||
|
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||||
|
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CUpdateRunner::DirectoryIsWritableW(wchar_t * szPath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
wchar_t szTempFileName[MAX_PATH];
|
||||||
|
UINT uRetVal = GetTempFileNameW(szPath, L"Squirrel", 0, szTempFileName);
|
||||||
|
if (uRetVal == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
DeleteFile(szTempFileName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir)
|
int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir)
|
||||||
{
|
{
|
||||||
PROCESS_INFORMATION pi = { 0 };
|
PROCESS_INFORMATION pi = { 0 };
|
||||||
@@ -137,11 +161,20 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback
|
|||||||
wchar_t logFile[MAX_PATH];
|
wchar_t logFile[MAX_PATH];
|
||||||
std::vector<CString> to_delete;
|
std::vector<CString> to_delete;
|
||||||
|
|
||||||
|
bool envSquirrelTempIsOk = false;
|
||||||
wchar_t *envSquirrelTemp = _wgetenv(L"SQUIRREL_TEMP");
|
wchar_t *envSquirrelTemp = _wgetenv(L"SQUIRREL_TEMP");
|
||||||
if (envSquirrelTemp) {
|
if (envSquirrelTemp) {
|
||||||
|
if (DirectoryExistsW(envSquirrelTemp)) {
|
||||||
|
if (DirectoryIsWritableW(envSquirrelTemp)) {
|
||||||
|
if (!PathIsUNCW(envSquirrelTemp)) {
|
||||||
_swprintf_c(targetDir, _countof(targetDir), L"%s", envSquirrelTemp);
|
_swprintf_c(targetDir, _countof(targetDir), L"%s", envSquirrelTemp);
|
||||||
|
bool envSquirrelTempIsOk = false;
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!envSquirrelTempIsOk) {
|
||||||
if (!useFallbackDir) {
|
if (!useFallbackDir) {
|
||||||
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, targetDir);
|
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, targetDir);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,5 +6,7 @@ public:
|
|||||||
static void DisplayErrorMessage(CString& errorMessage, wchar_t* logFile);
|
static void DisplayErrorMessage(CString& errorMessage, wchar_t* logFile);
|
||||||
static HRESULT AreWeUACElevated();
|
static HRESULT AreWeUACElevated();
|
||||||
static HRESULT ShellExecuteFromExplorer(LPWSTR pszFile, LPWSTR pszParameters);
|
static HRESULT ShellExecuteFromExplorer(LPWSTR pszFile, LPWSTR pszParameters);
|
||||||
|
static bool DirectoryExistsW(wchar_t* szPath);
|
||||||
|
static bool DirectoryIsWritableW(wchar_t* szPath);
|
||||||
static int ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir);
|
static int ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user