Add desktop() accessor to SGPath
(Windows-only for the moment)
This commit is contained in:
+42
-19
@@ -55,6 +55,34 @@ static const char sgSearchPathSep = ';';
|
|||||||
static const char sgSearchPathSep = ':';
|
static const char sgSearchPathSep = ':';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#include <ShlObj.h> // for CSIDL
|
||||||
|
|
||||||
|
static SGPath pathForCSIDL(int csidl, const SGPath::PermissonChecker& checker)
|
||||||
|
{
|
||||||
|
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPSTR, int, BOOL);
|
||||||
|
static GetSpecialFolderPath SHGetSpecialFolderPath = NULL;
|
||||||
|
|
||||||
|
// lazy open+resolve of shell32
|
||||||
|
if (!SHGetSpecialFolderPath) {
|
||||||
|
HINSTANCE shellDll = ::LoadLibrary("shell32");
|
||||||
|
SHGetSpecialFolderPath = (GetSpecialFolderPath) GetProcAddress(shellDll, "SHGetSpecialFolderPathA");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SHGetSpecialFolderPath){
|
||||||
|
return SGPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
char path[MAX_PATH];
|
||||||
|
if (SHGetSpecialFolderPath(0, path, csidl, false)) {
|
||||||
|
return SGPath(path, checker);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SGPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// For windows, replace "\" by "/".
|
// For windows, replace "\" by "/".
|
||||||
void
|
void
|
||||||
@@ -644,33 +672,28 @@ SGPath SGPath::home(const SGPath& def)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <ShlObj.h> // for CSIDL
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
SGPath SGPath::desktop(const SGPath& def)
|
SGPath SGPath::desktop(const SGPath& def)
|
||||||
{
|
{
|
||||||
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPSTR, int, BOOL);
|
SGPath r = pathForCSIDL(CSIDL_DESKTOPDIRECTORY, def._permission_checker);
|
||||||
static GetSpecialFolderPath SHGetSpecialFolderPath = NULL;
|
if (!r.isNull()) {
|
||||||
|
return r;
|
||||||
// lazy open+resolve of shell32
|
|
||||||
if (!SHGetSpecialFolderPath) {
|
|
||||||
HINSTANCE shellDll = ::LoadLibrary("shell32");
|
|
||||||
SHGetSpecialFolderPath = (GetSpecialFolderPath) GetProcAddress(shellDll, "SHGetSpecialFolderPathA");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SHGetSpecialFolderPath){
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
|
|
||||||
char path[MAX_PATH];
|
|
||||||
if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, false)) {
|
|
||||||
return SGPath(path, def._permission_checker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "SGPath::desktop() failed, bad" );
|
SG_LOG(SG_GENERAL, SG_ALERT, "SGPath::desktop() failed, bad" );
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGPath SGPath::documents(const SGPath& def)
|
||||||
|
{
|
||||||
|
SGPath r = pathForCSIDL(CSIDL_MYDOCUMENTS, def._permission_checker);
|
||||||
|
if (!r.isNull()) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "SGPath::documents() failed, bad" );
|
||||||
|
return def;
|
||||||
|
}
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
|
|
||||||
|
|||||||
@@ -276,6 +276,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
static SGPath desktop(const SGPath& def = SGPath());
|
static SGPath desktop(const SGPath& def = SGPath());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get path to the user's documents directory
|
||||||
|
*/
|
||||||
|
static SGPath documents(const SGPath& def = SGPath());
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void fix();
|
void fix();
|
||||||
|
|||||||
Reference in New Issue
Block a user