Changed: Remember startup path (the initial current directory)

--HG--
branch : develop
This commit is contained in:
kervala 2016-02-13 23:29:00 +01:00
parent 5d44cc4075
commit a4d98fb13b
4 changed files with 16 additions and 1 deletions

View file

@ -118,6 +118,7 @@ public:
/// Returns program name or path passed as first parameter to parse() method
std::string getProgramName() const { return _ProgramName; }
std::string getProgramPath() const { return _ProgramPath; }
std::string getStartupPath() const { return _StartupPath; }
/// Set or get description to display in help
void setDescription(const std::string &description) { _Description = description; }
@ -129,6 +130,7 @@ public:
protected:
std::string _ProgramName; // filename of the program
std::string _ProgramPath; // full path of the program
std::string _StartupPath; // initial startup path
std::string _Description; // description of the program
std::string _Version; // version of the program

View file

@ -264,6 +264,9 @@ bool CCmdArgs::parse(const std::vector<std::string> &argv)
_ProgramName = CFile::getFilename(argv.front());
_ProgramPath = CPath::makePathAbsolute(CPath::standardizePath(CFile::getPath(argv.front())), CPath::getCurrentPath(), true);
// current path
_StartupPath = CPath::standardizePath(CPath::getCurrentPath());
// set process name for logs
CLog::setProcessName(_ProgramName);

View file

@ -25,6 +25,7 @@
#include "nel/misc/config_file.h"
#include "nel/misc/bit_mem_stream.h"
#include "nel/misc/i18n.h"
#include "nel/misc/cmd_args.h"
// Client.
#include "client_cfg.h"
#include "entities.h"
@ -256,6 +257,8 @@ extern string Cookie;
extern string FSAddr;
#endif
extern NLMISC::CCmdArgs Args;
/////////////
// METHODS //
/////////////
@ -2224,7 +2227,11 @@ bool CClientConfig::getDefaultConfigLocation(std::string& p_name) const
if (CFile::isExists(defaultConfigFileName))
p_name = defaultConfigFileName;
// if not in working directory, check using prefix path
// look in startup directory
else if (CFile::isExists(Args.getStartupPath() + defaultConfigFileName))
p_name = Args.getStartupPath() + defaultConfigFileName;
// look in prefix path
else if (CFile::isExists(defaultConfigPath + defaultConfigFileName))
p_name = defaultConfigPath + defaultConfigFileName;

View file

@ -661,6 +661,9 @@ static void addPaths(IProgressCallback &progress, const std::vector<std::string>
// current directory has priority everywhere
directoryPrefixes.push_back(CPath::standardizePath(CPath::getCurrentPath()));
// startup directory
directoryPrefixes.push_back(Args.getStartupPath());
#if defined(NL_OS_WINDOWS)
// check in same directory as executable
directoryPrefixes.push_back(Args.getProgramPath());