// append another piece to the existing path
void SGPath::append( const string& p ) {
- if ( path.size() == 0 ) {
+ if ( path.empty() ) {
path = p;
} else {
if ( p[0] != sgDirPathSep ) {
// concatenate a string to the end of the path without inserting a
// path separator
void SGPath::concat( const string& p ) {
- if ( path.size() == 0 ) {
+ if ( path.empty() ) {
path = p;
} else {
path += p;
string_list sgPathBranchSplit( const string &dirpath ) {
string_list path_elements;
string element, path = dirpath;
- while ( path.size() ) {
+ while ( ! path.empty() ) {
size_t p = path.find( sgDirPathSep );
if ( p != string::npos ) {
element = path.substr( 0, p );
element = path;
path = "";
}
- if ( element.size() )
+ if ( ! element.empty() )
path_elements.push_back( element );
}
return path_elements;
#endif
#ifdef _WIN32
+
+#include <ShlObj.h> // for CSIDL
+
//------------------------------------------------------------------------------
SGPath SGPath::desktop()
{
- // TODO
- return SGPath();
+ 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_DESKTOPDIRECTORY, false)) {
+ return SGPath(path);
+ }
+
+ SG_LOG(SG_GENERAL, SG_ALERT, "SGPath::desktop() failed, bad" );
+ return SGPath();
}
#elif __APPLE__
#include <CoreServices/CoreServices.h>