Merge branch '2012_02_getspecialfolderpath_overflow' of https://github.com/laanwj/bitcoin
This commit is contained in:
commit
6dd5ae41ac
1 changed files with 10 additions and 33 deletions
37
src/util.cpp
37
src/util.cpp
|
@ -787,46 +787,23 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
|
||||||
strMiscWarning = pszMessage;
|
strMiscWarning = pszMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
|
|
||||||
|
|
||||||
string MyGetSpecialFolderPath(int nFolder, bool fCreate)
|
string MyGetSpecialFolderPath(int nFolder, bool fCreate)
|
||||||
{
|
{
|
||||||
char pszPath[MAX_PATH+100] = "";
|
char pszPath[MAX_PATH] = "";
|
||||||
|
if(SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate))
|
||||||
// SHGetSpecialFolderPath isn't always available on old Windows versions
|
|
||||||
HMODULE hShell32 = LoadLibraryA("shell32.dll");
|
|
||||||
if (hShell32)
|
|
||||||
{
|
{
|
||||||
PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
|
return pszPath;
|
||||||
(PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
|
|
||||||
if (pSHGetSpecialFolderPath)
|
|
||||||
(*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
|
|
||||||
FreeModule(hShell32);
|
|
||||||
}
|
}
|
||||||
|
else if (nFolder == CSIDL_STARTUP)
|
||||||
// Backup option
|
|
||||||
if (pszPath[0] == '\0')
|
|
||||||
{
|
{
|
||||||
if (nFolder == CSIDL_STARTUP)
|
return string(getenv("USERPROFILE")) + "\\Start Menu\\Programs\\Startup";
|
||||||
{
|
|
||||||
strcpy(pszPath, getenv("USERPROFILE"));
|
|
||||||
strcat(pszPath, "\\Start Menu\\Programs\\Startup");
|
|
||||||
}
|
}
|
||||||
else if (nFolder == CSIDL_APPDATA)
|
else if (nFolder == CSIDL_APPDATA)
|
||||||
{
|
{
|
||||||
strcpy(pszPath, getenv("APPDATA"));
|
return getenv("APPDATA");
|
||||||
}
|
}
|
||||||
}
|
return "";
|
||||||
|
|
||||||
return pszPath;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue