From a4dd37efc9c670e4fd8be6e075a63ce456d4191b Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:52:58 +0100 Subject: [PATCH] Changed: Try different alternative paths for game folders --HG-- branch : develop --- code/ryzom/client/src/init.cpp | 130 ++++++++++++++------------------- 1 file changed, 56 insertions(+), 74 deletions(-) diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index fec51a93e..b0098ccba 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -616,108 +616,90 @@ void initStereoDisplayDevice() IStereoDisplay::releaseUnusedLibraries(); } -void addSearchPaths(IProgressCallback &progress) +static void addPaths(IProgressCallback &progress, const std::vector &paths, bool recurse) { - // Add search path of UI addon. Allow only a subset of files. - // Must do it first because take precedence other standard files - InterfaceAddOnManager.addSearchFiles("uiaddon", "*.xml;*.lua;*.tga", "login_*.xml;out_v2_*.xml", &progress); + // all prefixes for paths + std::vector directoryPrefixes; - // Add Standard search paths - { - H_AUTO(InitRZAddSearchPath2) - for (uint i = 0; i < ClientCfg.DataPath.size(); i++) - { - progress.progress ((float)i/(float)ClientCfg.DataPath.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.DataPath.size(), (float)(i+1)/(float)ClientCfg.DataPath.size()); + // current directory has priority everywhere + directoryPrefixes.push_back(""); - CPath::addSearchPath(ClientCfg.DataPath[i], true, false, &progress); +#if defined(NL_OS_WINDOWS) + char path[MAX_PATH]; + GetModuleFileNameA(GetModuleHandleA(NULL), path, MAX_PATH); - progress.popCropedValues (); - } + // check in same directory as executable + directoryPrefixes.push_back(CPath::standardizePath(CFile::getPath(path))); +#elif defined(NL_OS_MAC) + // check in bundle (Installer) + directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath() + "/Contents/Resources")); - CPath::loadRemappedFiles("remap_files.csv"); - } + // check in same directory as bundle (Steam) + directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath()); +#elif defined(NL_OS_UNIX) + if (CFile::isDirectory(getRyzomSharePrefix())) directoryPrefixes.push_back(CPath::standardizePath(getRyzomSharePrefix())); +#endif - for (uint i = 0; i < ClientCfg.DataPathNoRecurse.size(); i++) + float total = (float)(directoryPrefixes.size() * paths.size()); + float current = 0.f, next = 0.f; + + for (uint j = 0; j < directoryPrefixes.size(); j++) { - progress.progress ((float)i/(float)ClientCfg.DataPathNoRecurse.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.DataPathNoRecurse.size(), (float)(i+1)/(float)ClientCfg.DataPathNoRecurse.size()); + std::string directoryPrefix = directoryPrefixes[j]; - CPath::addSearchPath(ClientCfg.DataPathNoRecurse[i], false, false, &progress); + for (uint i = 0; i < paths.size(); i++) + { + std::string directory = NLMISC::expandEnvironmentVariables(paths[i]); - progress.popCropedValues (); - } + // only prepend default directory if path is relative + if (!directory.empty() && !directoryPrefix.empty() && !CPath::isAbsolutePath(directory)) + { + directory = directoryPrefix + directory; + } - std::string defaultDirectory; + // update next progress value + next += 1.f; -#ifdef NL_OS_MAC - defaultDirectory = CPath::standardizePath(getAppBundlePath() + "/Contents/Resources"); -#elif defined(NL_OS_UNIX) - if (CFile::isDirectory(getRyzomSharePrefix())) defaultDirectory = CPath::standardizePath(getRyzomSharePrefix()); -#endif + progress.progress (current/total); + progress.pushCropedValues (current/total, next/total); - // add in last position, a specific possibly read only directory - if (!defaultDirectory.empty()) - { - for (uint i = 0; i < ClientCfg.DataPath.size(); i++) - { - // don't prepend default directory if path is absolute - if (!ClientCfg.DataPath[i].empty() && ClientCfg.DataPath[i][0] != '/') - { - progress.progress ((float)i/(float)ClientCfg.DataPath.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.DataPath.size(), (float)(i+1)/(float)ClientCfg.DataPath.size()); + // next is current value + current = next; - CPath::addSearchPath(defaultDirectory + ClientCfg.DataPath[i], true, false, &progress); + CPath::addSearchPath(directory, recurse, false, &progress); - progress.popCropedValues (); - } + progress.popCropedValues (); } } } -void addPreDataPaths(NLMISC::IProgressCallback &progress) +void addSearchPaths(IProgressCallback &progress) { - NLMISC::TTime initPaths = ryzomGetLocalTime (); - - H_AUTO(InitRZAddSearchPaths); + // Add search path of UI addon. Allow only a subset of files. + // Must do it first because take precedence other standard files + InterfaceAddOnManager.addSearchFiles("uiaddon", "*.xml;*.lua;*.tga", "login_*.xml;out_v2_*.xml", &progress); - for (uint i = 0; i < ClientCfg.PreDataPath.size(); i++) + // Add Standard search paths { - progress.progress ((float)i/(float)ClientCfg.PreDataPath.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.PreDataPath.size(), (float)(i+1)/(float)ClientCfg.PreDataPath.size()); + H_AUTO(InitRZAddSearchPath2) - CPath::addSearchPath(ClientCfg.PreDataPath[i], true, false, &progress); + addPaths(progress, ClientCfg.DataPath, true); - progress.popCropedValues (); + CPath::loadRemappedFiles("remap_files.csv"); } - //nlinfo ("PROFILE: %d seconds for Add search paths Predata", (uint32)(ryzomGetLocalTime ()-initPaths)/1000); - - std::string defaultDirectory; + addPaths(progress, ClientCfg.DataPathNoRecurse, false); +} -#ifdef NL_OS_MAC - defaultDirectory = CPath::standardizePath(getAppBundlePath() + "/Contents/Resources"); -#elif defined(NL_OS_UNIX) - if (CFile::isDirectory(getRyzomSharePrefix())) defaultDirectory = CPath::standardizePath(getRyzomSharePrefix()); -#endif +void addPreDataPaths(NLMISC::IProgressCallback &progress) +{ + NLMISC::TTime initPaths = ryzomGetLocalTime (); - // add in last position, a specific possibly read only directory - if (!defaultDirectory.empty()) - { - for (uint i = 0; i < ClientCfg.PreDataPath.size(); i++) - { - // don't prepend default directory if path is absolute - if (!ClientCfg.PreDataPath[i].empty() && ClientCfg.PreDataPath[i][0] != '/') - { - progress.progress ((float)i/(float)ClientCfg.PreDataPath.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.PreDataPath.size(), (float)(i+1)/(float)ClientCfg.PreDataPath.size()); + H_AUTO(InitRZAddSearchPaths); - CPath::addSearchPath(defaultDirectory + ClientCfg.PreDataPath[i], true, false, &progress); + addPaths(progress, ClientCfg.PreDataPath, true); - progress.popCropedValues (); - } - } - } + //nlinfo ("PROFILE: %d seconds for Add search paths Predata", (uint32)(ryzomGetLocalTime ()-initPaths)/1000); } static void addPackedSheetUpdatePaths(NLMISC::IProgressCallback &progress) @@ -726,7 +708,7 @@ static void addPackedSheetUpdatePaths(NLMISC::IProgressCallback &progress) { progress.progress((float)i/(float)ClientCfg.UpdatePackedSheetPath.size()); progress.pushCropedValues ((float)i/(float)ClientCfg.UpdatePackedSheetPath.size(), (float)(i+1)/(float)ClientCfg.UpdatePackedSheetPath.size()); - CPath::addSearchPath(ClientCfg.UpdatePackedSheetPath[i], true, false, &progress); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(ClientCfg.UpdatePackedSheetPath[i]), true, false, &progress); progress.popCropedValues(); } }