improve path finding logic
This commit is contained in:
parent
5f5eea8067
commit
5725b104cc
|
|
@ -194,60 +194,53 @@ static HRESULT (WINAPI *qSHGetKnownFolderPath) (qREFKNOWNFOLDERID rfid, DWORD dw
|
||||||
#endif
|
#endif
|
||||||
void HomePaths_Realise()
|
void HomePaths_Realise()
|
||||||
{
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
const char* prefix = g_pGameDescription->getKeyValue("prefix");
|
||||||
|
if(!string_empty(prefix))
|
||||||
|
{
|
||||||
|
StringOutputStream path(256);
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
const char* prefix = g_pGameDescription->getKeyValue("prefix");
|
|
||||||
if(!string_empty(prefix))
|
|
||||||
{
|
|
||||||
StringOutputStream path(256);
|
|
||||||
path << DirectoryCleaned(g_get_home_dir()) << "Library/Application Support" << (prefix+1) << "/";
|
|
||||||
if(!file_is_directory(path.c_str()))
|
|
||||||
{
|
|
||||||
path.clear();
|
path.clear();
|
||||||
path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
|
path << DirectoryCleaned(g_get_home_dir()) << "Library/Application Support" << (prefix+1) << "/";
|
||||||
}
|
if(file_is_directory(path.c_str()))
|
||||||
g_qeglobals.m_userEnginePath = path.c_str();
|
{
|
||||||
Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
|
g_qeglobals.m_userEnginePath = path.c_str();
|
||||||
}
|
break;
|
||||||
else
|
}
|
||||||
#elif defined(POSIX)
|
#endif
|
||||||
const char* prefix = g_pGameDescription->getKeyValue("prefix");
|
|
||||||
if(!string_empty(prefix))
|
#if defined(WIN32)
|
||||||
{
|
TCHAR mydocsdir[MAX_PATH + 1];
|
||||||
StringOutputStream path(256);
|
wchar_t *mydocsdirw;
|
||||||
path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
|
HMODULE shfolder = LoadLibrary("shfolder.dll");
|
||||||
g_qeglobals.m_userEnginePath = path.c_str();
|
if(shfolder)
|
||||||
Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
|
qSHGetKnownFolderPath = GetProcAddress("SHGetFolderPathA");
|
||||||
}
|
else
|
||||||
else
|
qSHGetKnownFolderPath = NULL;
|
||||||
#elif defined(WIN32)
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||||
const char* prefix = g_pGameDescription->getKeyValue("prefix");
|
|
||||||
if(!string_empty(prefix))
|
|
||||||
{
|
|
||||||
StringOutputStream path(256);
|
|
||||||
TCHAR mydocsdir[MAX_PATH + 1];
|
|
||||||
wchar_t *mydocsdirw;
|
|
||||||
HMODULE shfolder = LoadLibrary("shfolder.dll");
|
|
||||||
if(shfolder)
|
|
||||||
qSHGetKnownFolderPath = GetProcAddress("SHGetFolderPathA");
|
|
||||||
else
|
|
||||||
qSHGetKnownFolderPath = NULL;
|
|
||||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if(qSHGetKnownFolderPath && qSHGetKnownFolderPath(qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw) == S_OK)
|
if(qSHGetKnownFolderPath && qSHGetKnownFolderPath(qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw) == S_OK)
|
||||||
{
|
{
|
||||||
memset(mydocsdir, 0, sizeof(mydocsdir));
|
memset(mydocsdir, 0, sizeof(mydocsdir));
|
||||||
wctombs(mydocsdir, mydocsdirw, sizeof(mydocsdir)-1);
|
wctombs(mydocsdir, mydocsdirw, sizeof(mydocsdir)-1);
|
||||||
CoTaskMemFree(mydocsdirw);
|
CoTaskMemFree(mydocsdirw);
|
||||||
|
path.clear();
|
||||||
path << DirectoryCleaned(mydocsdir) << (prefix+1) << "/";
|
path << DirectoryCleaned(mydocsdir) << (prefix+1) << "/";
|
||||||
if(file_is_directory(path.c_str()))
|
if(file_is_directory(path.c_str()))
|
||||||
{
|
{
|
||||||
g_qeglobals.m_userEnginePath = path.c_str();
|
g_qeglobals.m_userEnginePath = path.c_str();
|
||||||
|
CoUninitialize();
|
||||||
|
FreeLibrary(shfolder);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CoUninitialize();
|
||||||
|
if(shfolder)
|
||||||
|
FreeLibrary(shfolder);
|
||||||
if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir))
|
if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir))
|
||||||
{
|
{
|
||||||
|
path.clear();
|
||||||
path << DirectoryCleaned(mydocsdir) << "My Games/" << (prefix+1) << "/";
|
path << DirectoryCleaned(mydocsdir) << "My Games/" << (prefix+1) << "/";
|
||||||
// win32: only add it if it already exists
|
// win32: only add it if it already exists
|
||||||
if(file_is_directory(path.c_str()))
|
if(file_is_directory(path.c_str()))
|
||||||
|
|
@ -256,18 +249,21 @@ void HomePaths_Realise()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_qeglobals.m_userEnginePath = EnginePath_get();
|
|
||||||
}
|
|
||||||
while(0);
|
|
||||||
CoUninitialize();
|
|
||||||
if(shfolder)
|
|
||||||
FreeLibrary(shfolder);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
|
#if defined(POSIX)
|
||||||
|
path.clear();
|
||||||
|
path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
|
||||||
|
g_qeglobals.m_userEnginePath = path.c_str();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
g_qeglobals.m_userEnginePath = EnginePath_get();
|
g_qeglobals.m_userEnginePath = EnginePath_get();
|
||||||
}
|
}
|
||||||
|
while(0);
|
||||||
|
|
||||||
|
Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
|
||||||
|
|
||||||
{
|
{
|
||||||
StringOutputStream path(256);
|
StringOutputStream path(256);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user