From b8d7b685f55e4a4fc1419ebc98e263ea73f2b229 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:43:46 +0100 Subject: [PATCH 01/23] Fixed: Save filenames in .bank with / instead of system separator --- code/nel/include/nel/3d/tile_bank.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/3d/tile_bank.h b/code/nel/include/nel/3d/tile_bank.h index 00e0f2cae..32a205e6d 100644 --- a/code/nel/include/nel/3d/tile_bank.h +++ b/code/nel/include/nel/3d/tile_bank.h @@ -20,6 +20,7 @@ #include "nel/misc/debug.h" #include "nel/misc/stream.h" #include "nel/misc/rgba.h" +#include "nel/misc/path.h" #include #include #include @@ -82,8 +83,8 @@ public: // not free _Flags&=~NL3D_CTILE_FREE_FLAG; - // set filename - _BitmapName[bitmapType]=name; + // set filename, replacing \\ by / if needed + _BitmapName[bitmapType] = NLMISC::CPath::standardizePath(name, false); } std::string getFileName (TBitmap bitmapType) const From 179499a5c1a7617cacf557c2c4ad4156c49a0790 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:45:02 +0100 Subject: [PATCH 02/23] Changed: Implement expandEnvironmentVariables function --- code/nel/include/nel/misc/common.h | 5 ++ code/nel/src/misc/common.cpp | 74 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 7dc394f24..710a9e6df 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -360,6 +360,11 @@ sint launchProgramAndWaitForResult (const std::string &programName, const std::s /// This function executes a program and returns output as a string std::string getCommandOutput(const std::string &command); +/// This function replace all environment variables in a string by their content. +/// Environment variables names can use both Windows (%NAME%) and UNIX syntax ($NAME) +/// Authorized characters in names are A-Z, a-z, 0-9 and _ +std::string expandEnvironmentVariables(const std::string &s); + /// This function kills a program using his pid (on unix, it uses the kill() POSIX function) bool killProgram(uint32 pid); diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 982d42da3..e57ce635b 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -913,6 +913,80 @@ std::string getCommandOutput(const std::string &command) return result; } +std::string expandEnvironmentVariables(const std::string &s) +{ + size_t len = s.length(); + std::string ret; + + std::string::size_type pos1 = 0, pos2 = 0; + + // look for environement variables delimiters + while(pos2 < len && (pos1 = s.find_first_of("%$", pos2)) != std::string::npos) + { + // copy string unprocessed part + ret += s.substr(pos2, pos1-pos2); + + // extract a valid variable name (a-zA-Z0-9_) + pos2 = pos1+1; + + while(pos2 < len && (isalnum(s[pos2]) || s[pos2] == '_')) ++pos2; + + // check if variable name is empty + bool found = pos2 > pos1+1; + + std::string name; + + if (found) + { + // found at least 1 character + name = s.substr(pos1+1, pos2-pos1-1); + } + + // Windows format needs a trailing % delimiter + if (found && s[pos1] == '%') + { + if (pos2 >= len || s[pos2] != '%') + { + // not a variable name, because no trailing % + found = false; + } + else + { + // found a trailing %, next character to check + ++pos2; + } + } + + // get variable value if name found + if (found) + { + const char *value = getenv(name.c_str()); + + if (value) + { + // value found + ret += std::string(value); + } + else + { + // value not found + found = false; + } + } + + if (!found) + { + // variable or value not found, don't evaluate variable + ret += s.substr(pos1, pos2-pos1); + } + } + + // copy last unprocessed part + ret += s.substr(pos2); + + return ret; +} + /* * Display the bits (with 0 and 1) composing a byte (from right to left) */ From 12e16e83e2af38bdff8f58da38fd7d396e69808a Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:46:27 +0100 Subject: [PATCH 03/23] Changed: Implement CPath::isAbsolutePath --- code/nel/include/nel/misc/path.h | 6 ++++++ code/nel/src/misc/path.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index ff7711b06..fed90efd5 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -514,6 +514,12 @@ public: */ static std::string makePathAbsolute (const std::string &relativePath, const std::string &directory ); + /** Return if a path is absolute or not. + * \param path - The path + * returns true if path is absolute or false if relative. + */ + static bool isAbsolutePath (const std::string &path); + /** If File in this list is added more than one in an addSearchPath, it doesn't launch a warning. */ static void addIgnoredDoubleFile(const std::string &ignoredFile); diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index de36efa56..19403c964 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -2597,6 +2597,25 @@ std::string CPath::makePathAbsolute( const std::string &relativePath, const std: return npath; } +bool CPath::isAbsolutePath(const std::string &path) +{ + if (path.empty()) return false; + +#ifdef NL_OS_WINDOWS + // Windows root of current disk. Eg.: "\" or + // Windows network address. Eg.: \\someshare\path + if (path[0] == '\\') return true; + + // Normal Windows absolute path. Eg.: C:\something + if (path.length() > 2 && isalpha(path[0]) && (path[1] == ':' ) && ((path[2] == '\\') || (path[2] == '/' ))) return true; +#endif + + // Unix filesystem absolute path (works also under Windows) + if (path[0] == '/') return true; + + return false; +} + bool CFile::setRWAccess(const std::string &filename) { #ifdef NL_OS_WINDOWS From 50c796236ba3976c22783b8b8f09aa7fc0b84161 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:47:35 +0100 Subject: [PATCH 04/23] Fixed: getLastSeparator should return std::string::size_type instead of an integer --- code/nel/include/nel/misc/path.h | 2 +- code/nel/src/misc/path.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index fed90efd5..ffae98f92 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -618,7 +618,7 @@ struct CFile * Return the position between [begin,end[ of the last separator between path and filename ('/' or '\'). * If there's no separator, it returns string::npos. */ - static int getLastSeparator (const std::string &filename); + static std::string::size_type getLastSeparator (const std::string &filename); static std::string getFilenameWithoutExtension (const std::string &filename); static std::string getExtension (const std::string &filename); diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index 19403c964..7ec61fdd7 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -1854,7 +1854,7 @@ std::string CFileContainer::getTemporaryDirectory() ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// -int CFile::getLastSeparator (const string &filename) +std::string::size_type CFile::getLastSeparator (const string &filename) { string::size_type pos = filename.find_last_of ('/'); if (pos == string::npos) @@ -1865,7 +1865,7 @@ int CFile::getLastSeparator (const string &filename) pos = filename.find_last_of ('@'); } } - return (int)pos; + return pos; } string CFile::getFilename (const string &filename) From 9ab71b6c27d21276e643dd613e903abc10b3b7e2 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:51:00 +0100 Subject: [PATCH 05/23] Fixed: Convert .bank filenames with / and use existing CFile::fileExists --- .../3d/build_far_bank/build_far_bank.cpp | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp index bd060417e..2699dca7b 100644 --- a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp +++ b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp @@ -50,16 +50,6 @@ bool recompute (const char* f1, const char* f2) return buf1.st_mtime > buf2.st_mtime; } -// Return true if the file exist -bool isFileExist (const char* sName) -{ - FILE *pFile=fopen (sName, "rb"); - if (!pFile) - return false; - fclose (pFile); - return true; -} - // Fill tile far pixel with this bitmap bool fillTileFar (uint tile, const char* sName, CTileFarBank::TFarType type, CTileFarBank& farBank, bool _256, uint8 rotate) { @@ -287,8 +277,8 @@ int main (int argc, char **argv) if (pTile->getRelativeFileName (CTile::diffuse)!="") { // File exist ? - string tileFilename = bank.getAbsPath()+pTile->getRelativeFileName (CTile::diffuse); - if (isFileExist (tileFilename.c_str())) + string tileFilename = bank.getAbsPath()+CPath::standardizePath(pTile->getRelativeFileName (CTile::diffuse), false); + if (CFile::fileExists(tileFilename)) { // Recompute it? if (recompute (tileFilename.c_str(), argv[2])||forceRecomputation) @@ -318,8 +308,8 @@ int main (int argc, char **argv) if (pTile->getRelativeFileName (CTile::additive)!="") { // File exist ? - string tileFilename = bank.getAbsPath()+pTile->getRelativeFileName (CTile::additive); - if (isFileExist (tileFilename.c_str())) + string tileFilename = bank.getAbsPath()+CPath::standardizePath(pTile->getRelativeFileName (CTile::additive), false); + if (CFile::fileExists(tileFilename)) { // Recompute it? if (recompute (tileFilename.c_str(), argv[2])||forceRecomputation) @@ -349,8 +339,8 @@ int main (int argc, char **argv) if (pTile->getRelativeFileName (CTile::alpha)!="") { // File exist ? - string tileFilename = bank.getAbsPath()+pTile->getRelativeFileName (CTile::alpha); - if (isFileExist (tileFilename.c_str())) + string tileFilename = bank.getAbsPath()+CPath::standardizePath(pTile->getRelativeFileName (CTile::alpha), false); + if (CFile::fileExists(tileFilename)) { // Recompute it? if (recompute (tileFilename.c_str(), argv[2])||forceRecomputation) From 2a3e173488a0573e222a6410d268163e4812d3bf Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:52:58 +0100 Subject: [PATCH 06/23] Changed: Try different alternative paths for game folders --- code/ryzom/client/src/init.cpp | 140 ++++++++++++++------------------- 1 file changed, 61 insertions(+), 79 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,6 +616,63 @@ void initStereoDisplayDevice() IStereoDisplay::releaseUnusedLibraries(); } +static void addPaths(IProgressCallback &progress, const std::vector &paths, bool recurse) +{ + // all prefixes for paths + std::vector directoryPrefixes; + + // current directory has priority everywhere + directoryPrefixes.push_back(""); + +#if defined(NL_OS_WINDOWS) + char path[MAX_PATH]; + GetModuleFileNameA(GetModuleHandleA(NULL), path, MAX_PATH); + + // 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")); + + // 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 + + float total = (float)(directoryPrefixes.size() * paths.size()); + float current = 0.f, next = 0.f; + + for (uint j = 0; j < directoryPrefixes.size(); j++) + { + std::string directoryPrefix = directoryPrefixes[j]; + + for (uint i = 0; i < paths.size(); i++) + { + std::string directory = NLMISC::expandEnvironmentVariables(paths[i]); + + // only prepend default directory if path is relative + if (!directory.empty() && !directoryPrefix.empty() && !CPath::isAbsolutePath(directory)) + { + directory = directoryPrefix + directory; + } + + // update next progress value + next += 1.f; + + progress.progress (current/total); + progress.pushCropedValues (current/total, next/total); + + // next is current value + current = next; + + CPath::addSearchPath(directory, recurse, false, &progress); + + progress.popCropedValues (); + } + } +} + void addSearchPaths(IProgressCallback &progress) { // Add search path of UI addon. Allow only a subset of files. @@ -625,54 +682,13 @@ void addSearchPaths(IProgressCallback &progress) // 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()); - CPath::addSearchPath(ClientCfg.DataPath[i], true, false, &progress); - - progress.popCropedValues (); - } + addPaths(progress, ClientCfg.DataPath, true); CPath::loadRemappedFiles("remap_files.csv"); } - for (uint i = 0; i < ClientCfg.DataPathNoRecurse.size(); i++) - { - progress.progress ((float)i/(float)ClientCfg.DataPathNoRecurse.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.DataPathNoRecurse.size(), (float)(i+1)/(float)ClientCfg.DataPathNoRecurse.size()); - - CPath::addSearchPath(ClientCfg.DataPathNoRecurse[i], false, false, &progress); - - progress.popCropedValues (); - } - - std::string defaultDirectory; - -#ifdef NL_OS_MAC - defaultDirectory = CPath::standardizePath(getAppBundlePath() + "/Contents/Resources"); -#elif defined(NL_OS_UNIX) - if (CFile::isDirectory(getRyzomSharePrefix())) defaultDirectory = CPath::standardizePath(getRyzomSharePrefix()); -#endif - - // 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()); - - CPath::addSearchPath(defaultDirectory + ClientCfg.DataPath[i], true, false, &progress); - - progress.popCropedValues (); - } - } - } + addPaths(progress, ClientCfg.DataPathNoRecurse, false); } void addPreDataPaths(NLMISC::IProgressCallback &progress) @@ -681,43 +697,9 @@ void addPreDataPaths(NLMISC::IProgressCallback &progress) H_AUTO(InitRZAddSearchPaths); - for (uint i = 0; i < ClientCfg.PreDataPath.size(); i++) - { - progress.progress ((float)i/(float)ClientCfg.PreDataPath.size()); - progress.pushCropedValues ((float)i/(float)ClientCfg.PreDataPath.size(), (float)(i+1)/(float)ClientCfg.PreDataPath.size()); - - CPath::addSearchPath(ClientCfg.PreDataPath[i], true, false, &progress); - - progress.popCropedValues (); - } + addPaths(progress, ClientCfg.PreDataPath, true); //nlinfo ("PROFILE: %d seconds for Add search paths Predata", (uint32)(ryzomGetLocalTime ()-initPaths)/1000); - - std::string defaultDirectory; - -#ifdef NL_OS_MAC - defaultDirectory = CPath::standardizePath(getAppBundlePath() + "/Contents/Resources"); -#elif defined(NL_OS_UNIX) - if (CFile::isDirectory(getRyzomSharePrefix())) defaultDirectory = CPath::standardizePath(getRyzomSharePrefix()); -#endif - - // 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()); - - CPath::addSearchPath(defaultDirectory + ClientCfg.PreDataPath[i], true, false, &progress); - - progress.popCropedValues (); - } - } - } } 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(); } } From 2c8b51e9f917676e4315083cf2bab7bf75cc6594 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:53:20 +0100 Subject: [PATCH 07/23] Changed: Remove duplicate lines --- code/nel/tools/3d/build_far_bank/build_far_bank.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp index 2699dca7b..05130b908 100644 --- a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp +++ b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp @@ -153,8 +153,6 @@ int main (int argc, char **argv) outputVersion=true; if (strcmp (argv[n], "-?")==0) outputHelp=true; - if (strcmp (argv[n], "-?")==0) - outputHelp=true; if (strncmp (argv[n], "-d", 2)==0) { rootDir = argv[n]; @@ -182,7 +180,6 @@ int main (int argc, char **argv) "\t-d#: change the root directory of the small bank. # is the new directory\n" "\t-p#: postfix tiles filename by #\n" "\t-r: load the bitmaps from the current directory\n" - "\t-r: load the bitmaps from the current directory\n" "\t-f: force recomputation of all the tiles\n" "\t-v: print the version\n" "\t-?: print help\n" From b05b865cfb5c15d9a2751c0ff4b431f2c2e7867f Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:54:23 +0100 Subject: [PATCH 08/23] Changed: Minor changes --- code/nel/include/nel/misc/path.h | 22 +++++++++---------- .../3d/build_far_bank/build_far_bank.cpp | 8 +++---- .../tools/skill_extractor/skill_extractor.cpp | 2 -- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index ffae98f92..20ea9b2a9 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -497,7 +497,7 @@ public: static void getFileListByName(const std::string &extension, const std::string &name, std::vector &filenames); /** Create a list of file having the requested string in the path and the requested extension - */ + */ static void getFileListByPath(const std::string &extension, const std::string &path, std::vector &filenames); /** Make a path relative to another if possible, else doesn't change it. @@ -508,10 +508,10 @@ public: static bool makePathRelative (const char *basePath, std::string &relativePath); /** Make path absolute - * \param relativePath - The relative path - * \param directory - the directory to which the path is relative to - * returns the absolute path, or empty if something went wrong. - */ + * \param relativePath - The relative path + * \param directory - the directory to which the path is relative to + * returns the absolute path, or empty if something went wrong. + */ static std::string makePathAbsolute (const std::string &relativePath, const std::string &directory ); /** Return if a path is absolute or not. @@ -525,7 +525,7 @@ public: static void addIgnoredDoubleFile(const std::string &ignoredFile); /** For the moment after memoryCompress you cant addsearchpath anymore - */ + */ static void memoryCompress(); static void memoryUncompress(); @@ -533,17 +533,17 @@ public: static bool isMemoryCompressed() { return getInstance()->_FileContainer.isMemoryCompressed(); } /** Get the ms windows directory (in standardized way with end slash), or returns an empty string on other os - */ + */ static std::string getWindowsDirectory(); /** Get application directory. - * \return directory where applications should write files. - */ + * \return directory where applications should write files. + */ static std::string getApplicationDirectory(const std::string &appName = ""); /** Get a temporary directory. - * \return temporary directory where applications should write files. - */ + * \return temporary directory where applications should write files. + */ static std::string getTemporaryDirectory(); // release singleton diff --git a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp index 05130b908..dfc3f7f65 100644 --- a/code/nel/tools/3d/build_far_bank/build_far_bank.cpp +++ b/code/nel/tools/3d/build_far_bank/build_far_bank.cpp @@ -80,7 +80,7 @@ bool fillTileFar (uint tile, const char* sName, CTileFarBank::TFarType type, CTi // Get bitmap size uint width=bitmap.getWidth(); uint height=bitmap.getHeight(); - + // Check size.. if ((!((_256&&(width==256)&&(height==256))||((!_256)&&(width==128)&&(height==128))))) @@ -210,7 +210,7 @@ int main (int argc, char **argv) // Serial the bank in input farBank.serial (inputFarBank); } - + // Force recomputation ? if (recompute (argv[1], argv[2])) { @@ -294,7 +294,7 @@ int main (int argc, char **argv) { // One more tile tileCount++; - + printf ("Skipping %s...\n", tileFilename.c_str()); bDeleteDiffuse=false; } @@ -405,7 +405,7 @@ int main (int argc, char **argv) { nlwarning ("ERROR Can't open file %s for reading\n", argv[1]); } - } + } // exit return 0; diff --git a/code/ryzom/tools/skill_extractor/skill_extractor.cpp b/code/ryzom/tools/skill_extractor/skill_extractor.cpp index a37d22ba8..054d5788c 100644 --- a/code/ryzom/tools/skill_extractor/skill_extractor.cpp +++ b/code/ryzom/tools/skill_extractor/skill_extractor.cpp @@ -542,7 +542,6 @@ sint main( sint argc, char ** argv ) // output begin skill.h file - //if( ! fo.open( string( "r:/code/ryzom/src_v2/game_share/skills.h" ) ) ) if( ! fo.open( srcDir + string( "skills.h" ) ) ) { nlwarning(" Can't open file %s for writing", "skills.h" ); @@ -648,7 +647,6 @@ sint main( sint argc, char ** argv ) ///////////////////////////////////////////////////////////////////////////////////// // begin output skill.cpp file -// if( ! fo.open( string( "r:/code/ryzom/src_v2/game_share/skills.cpp" ) ) ) if( ! fo.open( srcDir + string( "skills.cpp" ) ) ) { nlwarning(" Can't open file skills.cpp for writing"); From 02f6248bd45392edb9e5ce37b63f7a3fff2fe177 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 19:59:09 +0100 Subject: [PATCH 09/23] Changed: Expand environment variables in paths read from cfg files --- code/nel/src/net/service.cpp | 4 ++-- code/ryzom/server/src/ai_service/sheets.cpp | 8 ++++---- code/ryzom/tools/client/client_patcher/main.cpp | 2 +- .../leveldesign/alias_synchronizer/alias_synchronizer.cpp | 2 +- code/ryzom/tools/make_alias_file/make_alias_file.cpp | 2 +- .../build_world_packed_col/build_world_packed_col.cpp | 2 +- code/ryzom/tools/sheets_packer/sheets_packer_init.cpp | 2 +- code/ryzom/tools/translation_tools/extract_bot_names.cpp | 6 +++--- .../tools/translation_tools/extract_new_sheet_names.cpp | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/code/nel/src/net/service.cpp b/code/nel/src/net/service.cpp index 1f3436d1c..f7dc40da1 100644 --- a/code/nel/src/net/service.cpp +++ b/code/nel/src/net/service.cpp @@ -1169,7 +1169,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName, { for (uint i = 0; i < var->size(); i++) { - CPath::addSearchPath (var->asString(i), true, false); + CPath::addSearchPath (NLMISC::expandEnvironmentVariables(var->asString(i)), true, false); } } @@ -1177,7 +1177,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName, { for (uint i = 0; i < var->size(); i++) { - CPath::addSearchPath (var->asString(i), false, false); + CPath::addSearchPath (NLMISC::expandEnvironmentVariables(var->asString(i)), false, false); } } diff --git a/code/ryzom/server/src/ai_service/sheets.cpp b/code/ryzom/server/src/ai_service/sheets.cpp index 56060db1e..57b26f4d2 100644 --- a/code/ryzom/server/src/ai_service/sheets.cpp +++ b/code/ryzom/server/src/ai_service/sheets.cpp @@ -906,7 +906,7 @@ void AISHEETS::CSheets::packSheets(const std::string &writeFilesDirectoryName) { addSearchPath=true; for (uint32 i=0;isize();++i) - CPath::addSearchPath(varPtr->asString(i).c_str(), true, false); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(varPtr->asString(i)), true, false); } loadForm2("aiaction", writeFilesDirectoryName+AISPackedActionSheetsFilename, _ActionSheets, true); } @@ -918,7 +918,7 @@ void AISHEETS::CSheets::packSheets(const std::string &writeFilesDirectoryName) { addSearchPath=true; for (uint32 i=0;isize();++i) - CPath::addSearchPath(varPtr->asString(i).c_str(), true, false); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(varPtr->asString(i)), true, false); } loadForm("actionlist", writeFilesDirectoryName+AISPackedFightConfigSheetsFilename, _ActionListSheets, true); } @@ -931,7 +931,7 @@ void AISHEETS::CSheets::packSheets(const std::string &writeFilesDirectoryName) { addSearchPath=true; for (uint32 i=0;isize();++i) - CPath::addSearchPath(varPtr->asString(i).c_str(), true, false); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(varPtr->asString(i)), true, false); } loadForm2("creature", writeFilesDirectoryName+AISPackedSheetsFilename, _Sheets, true); } @@ -943,7 +943,7 @@ void AISHEETS::CSheets::packSheets(const std::string &writeFilesDirectoryName) { addSearchPath=true; for (uint32 i=0;isize();++i) - CPath::addSearchPath(varPtr->asString(i).c_str(), true, false); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(varPtr->asString(i)), true, false); } loadForm2("race_stats", writeFilesDirectoryName+AISPackedRaceStatsSheetsFilename, _RaceStatsSheets, true); } diff --git a/code/ryzom/tools/client/client_patcher/main.cpp b/code/ryzom/tools/client/client_patcher/main.cpp index a0730b19f..004e3d861 100644 --- a/code/ryzom/tools/client/client_patcher/main.cpp +++ b/code/ryzom/tools/client/client_patcher/main.cpp @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) { for(uint i = 0; i < ClientCfg.PreDataPath.size(); ++i) { - CPath::addSearchPath(ClientCfg.PreDataPath[i], true, false); + CPath::addSearchPath(NLMISC::expandEnvironmentVariables(ClientCfg.PreDataPath[i]), true, false); } } diff --git a/code/ryzom/tools/leveldesign/alias_synchronizer/alias_synchronizer.cpp b/code/ryzom/tools/leveldesign/alias_synchronizer/alias_synchronizer.cpp index c080fd038..5bfd98eae 100644 --- a/code/ryzom/tools/leveldesign/alias_synchronizer/alias_synchronizer.cpp +++ b/code/ryzom/tools/leveldesign/alias_synchronizer/alias_synchronizer.cpp @@ -390,7 +390,7 @@ int main() // add the search paths for (uint i=0; i Date: Wed, 13 Jan 2016 20:01:36 +0100 Subject: [PATCH 10/23] Fixed: Remove some hardcoded paths and replaced them by LeveldesignDataPath variable --- .../translation_tools/extract_new_sheet_names.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/ryzom/tools/translation_tools/extract_new_sheet_names.cpp b/code/ryzom/tools/translation_tools/extract_new_sheet_names.cpp index d593a44b1..70d01c93f 100644 --- a/code/ryzom/tools/translation_tools/extract_new_sheet_names.cpp +++ b/code/ryzom/tools/translation_tools/extract_new_sheet_names.cpp @@ -356,6 +356,7 @@ int extractNewSheetNames(int argc, char *argv[]) CConfigFile::CVar &paths = cf.getVar("Paths"); CConfigFile::CVar &pathNoRecurse= cf.getVar("PathsNoRecurse"); CConfigFile::CVar &ligoClassFile= cf.getVar("LigoClassFile"); + CConfigFile::CVar &leveldesignDataPathVar = cf.getVar("LeveldesignDataPath"); // parse path for (uint i=0; i Date: Wed, 13 Jan 2016 20:02:24 +0100 Subject: [PATCH 11/23] Changed: Replace \\ by / --- code/ryzom/tools/leveldesign/mp_generator/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/tools/leveldesign/mp_generator/main.cpp b/code/ryzom/tools/leveldesign/mp_generator/main.cpp index 0d3402e84..45ae45b05 100644 --- a/code/ryzom/tools/leveldesign/mp_generator/main.cpp +++ b/code/ryzom/tools/leveldesign/mp_generator/main.cpp @@ -145,7 +145,7 @@ void LoadCraftParts() void LoadCreatureFiles() { printf( "-- REGISTERING CREATURE FILES --\n" ); - CSString inputSheetPath = LEVEL_DESIGN_PATH + "leveldesign\\Game_elem\\Creature\\Fauna\\bestiary"; + CSString inputSheetPath = LEVEL_DESIGN_PATH + "leveldesign/Game_elem/Creature/Fauna/bestiary"; CPath::addSearchPath( inputSheetPath, true, false ); vector files; From d55b78137485c041afd24509945c91d3e4906ee8 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 20:04:01 +0100 Subject: [PATCH 12/23] Fixed: Use map for faster search for example (implemented a TODO of GUIGUI) --- .../src/game_share/visual_slot_manager.cpp | 51 ++++++++----------- .../src/game_share/visual_slot_manager.h | 6 +++ .../tools/leveldesign/mp_generator/main.cpp | 1 + 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/code/ryzom/common/src/game_share/visual_slot_manager.cpp b/code/ryzom/common/src/game_share/visual_slot_manager.cpp index eed01388d..bc2410eea 100644 --- a/code/ryzom/common/src/game_share/visual_slot_manager.cpp +++ b/code/ryzom/common/src/game_share/visual_slot_manager.cpp @@ -94,70 +94,59 @@ void CVisualSlotManager::init() f.close(); // Display elements read. -// for(uint i=0; i<_VisualSlot.size(); ++i) -// { + for(uint i=0, len = _VisualSlot.size(); i you probably need to rebuild the tab."); - - // No Item - return 0; + return sheet2Index(id, SLOTTYPE::RIGHT_HAND_SLOT); }// rightItem2Index // //----------------------------------------------- // leftItem2Index : // Return the visual slot index from a sheet Id for items in left hand. -// \todo GUIGUI : Use map for faster search for example //----------------------------------------------- uint32 CVisualSlotManager::leftItem2Index(const NLMISC::CSheetId &id) { - if(SLOTTYPE::LEFT_HAND_SLOT < _VisualSlot.size()) - { - for(uint i=0; i<_VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element.size(); ++i) - if(_VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element[i].SheetId == id) - return _VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element[i].Index; - } - else - nlwarning("VSMngr:leftItem2Index: Bad slot -> you probably need to rebuild the tab."); - - // No Item - return 0; + return sheet2Index(id, SLOTTYPE::LEFT_HAND_SLOT); }// leftItem2Index // //----------------------------------------------- // sheet2Index : // Return the visual index from a sheet Id and the visual slot. -// \todo GUIGUI : Use map for faster search for example //----------------------------------------------- uint32 CVisualSlotManager::sheet2Index(const NLMISC::CSheetId &id, SLOTTYPE::EVisualSlot slot) { if((uint)slot < _VisualSlot.size()) { - for(uint i=0; i<_VisualSlot[slot].Element.size(); ++i) - if(_VisualSlot[slot].Element[i].SheetId == id) - return _VisualSlot[slot].Element[i].Index; + const TElementList &el = _VisualSlot[slot]; + TElementList::SheetIdToIndexMapType::const_iterator it = el.SheetIdToIndexMap.find(id); + if (it != el.SheetIdToIndexMap.end()) return it->second; } else nlwarning("VSMngr:sheet2Index: Bad slot '%d' -> you probably need to rebuild the tab.", (sint)slot); diff --git a/code/ryzom/common/src/game_share/visual_slot_manager.h b/code/ryzom/common/src/game_share/visual_slot_manager.h index 9d2f67dc0..ee9d8371a 100644 --- a/code/ryzom/common/src/game_share/visual_slot_manager.h +++ b/code/ryzom/common/src/game_share/visual_slot_manager.h @@ -71,11 +71,17 @@ public: // elements list for a visual slot. std::vector Element; + // std::map to increase access speed + typedef std::map SheetIdToIndexMapType; + SheetIdToIndexMapType SheetIdToIndexMap; + /// Load/Save the values using the serial system void serial(class NLMISC::IStream &s) throw(NLMISC::EStream) { s.serialCont(Element); } + + void updateMaps(); } TElementList; typedef std::vector TVisualSlot; diff --git a/code/ryzom/tools/leveldesign/mp_generator/main.cpp b/code/ryzom/tools/leveldesign/mp_generator/main.cpp index 45ae45b05..935ba31d6 100644 --- a/code/ryzom/tools/leveldesign/mp_generator/main.cpp +++ b/code/ryzom/tools/leveldesign/mp_generator/main.cpp @@ -1472,6 +1472,7 @@ void SetupDirectories() data.readFromFile( "raw_material_generation.cfg" ); + // beurk :s Use CConfigFile instead LEVEL_DESIGN_PATH = data.splitFrom( "LevelDesignPath = \"").splitTo( "\"" ); TRANSLATION_PATH = data.splitFrom( "TranslationPath = \"" ).splitTo( "\"" ); From e5d414fc5baefa4f3ea0f59464fe5ec9bfe608c9 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 10:21:50 +0100 Subject: [PATCH 13/23] Fixed: Compilation under OS X --- code/ryzom/client/src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index b0098ccba..35a2c1302 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -635,7 +635,7 @@ static void addPaths(IProgressCallback &progress, const std::vector directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath() + "/Contents/Resources")); // check in same directory as bundle (Steam) - directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath()); + directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath())); #elif defined(NL_OS_UNIX) if (CFile::isDirectory(getRyzomSharePrefix())) directoryPrefixes.push_back(CPath::standardizePath(getRyzomSharePrefix())); #endif From 2682f4f4af3b1c01cad3601a1594364c859d8f56 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 21:26:10 +0100 Subject: [PATCH 14/23] Improve CCmdArgs (a generic command line parser in NeL Misc), fixes #257 --- code/nel/include/nel/misc/cmd_args.h | 82 ++++- code/nel/src/misc/cmd_args.cpp | 465 +++++++++++++++++++++---- code/nel/tools/3d/mesh_export/main.cpp | 81 +++-- 3 files changed, 501 insertions(+), 127 deletions(-) diff --git a/code/nel/include/nel/misc/cmd_args.h b/code/nel/include/nel/misc/cmd_args.h index af0fe28e8..26e097eee 100644 --- a/code/nel/include/nel/misc/cmd_args.h +++ b/code/nel/include/nel/misc/cmd_args.h @@ -31,36 +31,86 @@ namespace NLMISC class CCmdArgs { public: - /// Sets the command line and init _Args variable. You must call this before calling main() - void setArgs (int argc, const char **argv); + CCmdArgs(); - /// Sets the command line and init _Args variable. You must call this before calling main() - void setArgs (const char *args); + struct TArg + { + std::string shortName; // short argument. Eg: o for -o + std::string longName; // long argument. Eg: output for --output + + std::string helpName; // name of argument in help. Eg: + std::string helpDescription; // description of argument in help. Eg: Specifies the directory where to write generated files + + bool found; // all values for this argument + std::vector values; // all values for this argument + }; + + typedef std::vector TArgs; + + /// Add a TArg structure to arguments list. + void addArg(const TArg &arg); + + /// Add an full argument to arguments list. + /// shortName is "p" of the argument is -p + /// longName is "print" of the argument is --print + /// helpName is the name that will be displayed in help if it's a required argument + /// helpDescription is the description of the argument that will be displayed in help + void addArg(const std::string &shortName, const std::string &longName, const std::string &helpName, const std::string &helpDescription); + + /// Add a required argument to arguments list. + /// helpName is the name that will be displayed in help if it's a required argument + /// helpDescription is the description of the argument that will be displayed in help + void addArg(const std::string &helpName, const std::string &helpDescription); + + /// Parse the command line from main() parameters argc and argv and process default arguments. + bool parse(int argc, char **argv); + + /// Parse the command line from a std::string and process default arguments. + bool parse(const std::string &args); + + /// Parse the command linefrom a std::vector and process default arguments. + bool parse(const std::vector &args); /// Returns arguments of the program pass from the user to the program using parameters (ie: "myprog param1 param2") - const NLMISC::CVectorSString &getArgs () const { return _Args; } + const TArgs& getArgs() const { return _Args; } - /// Returns true if the argument if present in the command line (ie: haveArg('p') will return true if -p is in the command line) - bool haveArg (char argName) const; + /// Returns true if the argument if present in the command line (ie: haveArg("p") will return true if -p is in the command line) + bool haveArg(const std::string &argName) const; - /** Returns the parameter linked to an option - * getArg('p') will return toto if -ptoto is in the command line - * getArg('p') will return C:\Documents and Settings\toto.tmp if -p"C:\Documents and Settings\toto.tmp" is in the command line - * It'll thrown an Exception if the argName is not found + /** Returns the parameters linked to an option + * getArg("p") will return toto if -ptoto is in the command line + * getArg("p") will return C:\Documents and Settings\toto.tmp if -p"C:\Documents and Settings\toto.tmp" is in the command line */ - std::string getArg (char argName) const; + std::vector getArg(const std::string &argName) const; /// return true if named long arg is present on the commandline /// eg haveLongArg("toto") returns true if "--toto" or "--toto=xxx" can be found on commandline - bool haveLongArg (const char* argName) const; + bool haveLongArg(const std::string &argName) const; - /// returns the value associated with the given named argument + /// returns values associated with the given named argument /// both "--toto=xxx" and "--toto xxx" are acceptable /// quotes round arguments are stripped - std::string getLongArg (const char* argName) const; + std::vector getLongArg(const std::string &argName) const; + + /// return true if there are arguments that are required + bool needRequiredArg() const; + + /// return true if required or optional args are present on the commandline + bool haveRequiredArg() const; + + /// Returns all additional required parameters + std::vector getRequiredArg() const; + + /// Display help of the program. + void displayHelp(); + + /// Display version of the program. + void displayVersion(); protected: + std::string _ProgramName; + /// Array of arguments pass from the command line - NLMISC::CVectorSString _Args; + TArgs _Args; }; // class CCmdArgs }; // NAMESPACE NLMISC diff --git a/code/nel/src/misc/cmd_args.cpp b/code/nel/src/misc/cmd_args.cpp index 2ef32a6c9..39f4cb849 100644 --- a/code/nel/src/misc/cmd_args.cpp +++ b/code/nel/src/misc/cmd_args.cpp @@ -18,12 +18,12 @@ // Includes // #include "stdmisc.h" - -#include "nel/misc/types_nl.h" -#include "nel/misc/sstring.h" - #include "nel/misc/cmd_args.h" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #ifdef DEBUG_NEW #define new DEBUG_NEW #endif @@ -31,114 +31,170 @@ namespace NLMISC { -bool CCmdArgs::haveArg(char argName) const +CCmdArgs::CCmdArgs() { - for(uint32 i = 0; i < _Args.size(); i++) + // add help + addArg("h", "help", "", "Display this help"); + + // add version + addArg("v", "version", "", "Display version of this program"); +} + +void CCmdArgs::addArg(const TArg &arg) +{ + _Args.push_back(arg); +} + +void CCmdArgs::addArg(const std::string &shortName, const std::string &longName, const std::string &helpName, const std::string &helpDescription) +{ + TArg arg; + arg.shortName = shortName; + arg.longName = longName; + arg.helpName = helpName; + arg.helpDescription = helpDescription; + arg.found = false; + + addArg(arg); +} + +void CCmdArgs::addArg(const std::string &helpName, const std::string &helpDescription) +{ + TArg arg; + arg.helpName = helpName; + arg.helpDescription = helpDescription; + arg.found = false; + + addArg(arg); +} + +bool CCmdArgs::haveArg(const std::string &argName) const +{ + // process each argument + for(uint i = 0; i < _Args.size(); i) { - if(_Args[i].size() >= 2 && _Args[i][0] == '-') - { - if(_Args[i][1] == argName) - { - return true; - } - } + const TArg &arg = _Args[i]; + + // return true if long arg found + if (arg.shortName == argName) return arg.found; } + return false; } -std::string CCmdArgs::getArg(char argName) const +std::vector CCmdArgs::getArg(const std::string &argName) const { - for(uint32 i = 0; i < _Args.size(); i++) + // process each argument + for(uint i = 0; i < _Args.size(); ++i) { - if(_Args[i].size() >= 2 && _Args[i][0] == '-') - { - if(_Args[i][1] == argName) - { - /* Remove the first and last '"' : - -c"C:\Documents and Settings\toto.tmp" - will return : - C:\Documents and Settings\toto.tmp - */ - uint begin = 2; - if(_Args[i].size() < 3) - return ""; - //throw Exception ("Parameter '-%c' is malformed, missing content", argName); + const TArg &arg = _Args[i]; - if(_Args[i][begin] == '"') - begin++; - - // End - uint size = (uint)_Args[i].size(); - if(size && _Args[i][size-1] == '"') - size--; - size = (uint)(std::max((int)0, (int)size-(int)begin)); - return _Args[i].substr(begin, size); - } - } + // return values if short arg found + if (arg.shortName == argName && arg.found) return arg.values; } - throw Exception("Parameter '-%c' is not found in command line", argName); + + // return an empty vector + return std::vector(); } -bool CCmdArgs::haveLongArg(const char* argName) const +bool CCmdArgs::haveLongArg(const std::string &argName) const { - for(uint32 i = 0; i < _Args.size(); i++) + // process each argument + for(uint i = 0; i < _Args.size(); ++i) { - if(_Args[i].left(2)=="--" && _Args[i].leftCrop(2).splitTo('=')==argName) - { + const TArg &arg = _Args[i]; + + // return true if long arg found + if (arg.longName == argName) return arg.found; + } + + return false; +} + +std::vector CCmdArgs::getLongArg(const std::string &argName) const +{ + // process each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // return values if long arg found + if (arg.longName == argName && arg.found) return arg.values; + } + + // return an empty vector + return std::vector(); +} + +bool CCmdArgs::needRequiredArg() const +{ + // process each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // they don't have any short or long name, but need a name in help + if (arg.shortName.empty() && arg.longName.empty() && !arg.helpName.empty()) return true; - } } + return false; } -std::string CCmdArgs::getLongArg (const char* argName) const +bool CCmdArgs::haveRequiredArg() const { - for (uint32 i = 0; i < _Args.size(); i++) - { - if (_Args[i].left(2)=="--" && _Args[i].leftCrop(2).splitTo('=')==argName) - { - NLMISC::CSString val= _Args[i].splitFrom('='); - if (!val.empty()) - { - return val.unquoteIfQuoted(); - } - if (i+1<_Args.size() && _Args[i+1].c_str()[0]!='-') - { - return _Args[i+1].unquoteIfQuoted(); - } + // process each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; - return std::string(); - } + // they don't have any short or long name, but need a name in help + if (arg.shortName.empty() && arg.longName.empty() && !arg.helpName.empty()) + return !arg.values.empty(); } - return std::string(); + + return false; } -void CCmdArgs::setArgs(const char *args) +std::vector CCmdArgs::getRequiredArg() const { - _Args.push_back (""); + // process each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; - std::string sargs (args); + // they don't have any short or long name, but need a name in help + if (arg.shortName.empty() && arg.longName.empty() && !arg.helpName.empty()) + return arg.values; + } + + // return an empty vector + return std::vector(); +} + +bool CCmdArgs::parse(const std::string &args) +{ + std::vector argv; std::string::size_type pos1 = 0, pos2 = 0; do { // Look for the first non space character - pos1 = sargs.find_first_not_of (" ", pos2); + pos1 = args.find_first_not_of (" ", pos2); if(pos1 == std::string::npos) break; // Look for the first space or " - pos2 = sargs.find_first_of (" \"", pos1); + pos2 = args.find_first_of (" \"", pos1); if(pos2 != std::string::npos) { // " ? - if(sargs[pos2] == '"') + if(args[pos2] == '"') { // Look for the final \" - pos2 = sargs.find_first_of ("\"", pos2+1); + pos2 = args.find_first_of ("\"", pos2+1); if(pos2 != std::string::npos) { // Look for the first space - pos2 = sargs.find_first_of (" ", pos2+1); + pos2 = args.find_first_of (" ", pos2+1); } } } @@ -146,18 +202,277 @@ void CCmdArgs::setArgs(const char *args) // Compute the size of the string to extract std::string::difference_type length = (pos2 != std::string::npos) ? pos2-pos1 : std::string::npos; - std::string tmp = sargs.substr (pos1, length); - _Args.push_back (tmp); + std::string tmp = args.substr (pos1, length); + argv.push_back (tmp); } while(pos2 != std::string::npos); + + return parse(argv); } -void CCmdArgs::setArgs(int argc, const char **argv) +bool CCmdArgs::parse(int argc, char **argv) { - for (sint i = 0; i < argc; i++) + // convert C strings to STL strings + std::vector args; + + for(sint i = 0; i < argc; ++i) { - _Args.push_back (argv[i]); + args.push_back(argv[i]); } + + return parse(args); +} + +bool CCmdArgs::parse(const std::vector &argv) +{ + // no parameters + if (argv.empty()) return false; + + // first argument is always the program name + _ProgramName = CFile::getFilename(argv.front()); + + // arguments count + uint argc = argv.size(); + + // process each argument + for (sint i = 1; i < argc; i++) + { + std::string name = argv[i]; + +#ifdef NL_OS_WINDOWS + // support / and - under Windows, arguments should be at least 2 characters + if (name.size() > 1 && (name[0] == '-' || name[0] == '/')) +#else + if (name.size() > 1 && name[0] == '-') +#endif + { + // it's a long name if using -- + bool useLongName = name[0] == '-' && name[1] == '-'; + + // extract argument name + name = name.substr(useLongName ? 2:1); + + std::string value; + + if (useLongName) + { + // look if using = to define value + std::string::size_type pos = name.find('='); + + if (pos != std::string::npos) + { + // value is second part, name the first one + value = name.substr(pos+1); + name = name.substr(0, pos); + } + } + else if (name.length() > 1) + { + value = name.substr(1); + name = name.substr(0, 1); + } + + // process each argument definition + for(uint j = 0; j < _Args.size(); ++j) + { + TArg &arg = _Args[j]; + + // only process arguments of the right type + if ((useLongName && name != arg.longName) || (!useLongName && name != arg.shortName)) continue; + + // argument is found + arg.found = true; + + // another argument is required + if (!arg.helpName.empty()) + { + // if the value hasn't be specified by = + if (value.empty() && i+1 < argc) + { + // take next argument + value = argv[++i]; + } + + // add argument value if not empty + if (!value.empty()) + { + arg.values.push_back(value); + } + } + + break; + } + } + else + { + // process each argument definition + for(uint j = 0, len = _Args.size(); j < len; ++j) + { + TArg &arg = _Args[j]; + + // only process arguments that don't have a name + if (!arg.shortName.empty() || !arg.longName.empty()) continue; + + // in fact, if there are more than one required arguments, all arguments are added in first one to simplify + arg.values.push_back(name); + + break; + } + } + } + + // process help if requested or if required arguments are missing + if (haveLongArg("help") || (needRequiredArg() && !haveRequiredArg())) + { + displayHelp(); + return false; + } + + // process version + if (haveLongArg("version")) + { + displayVersion(); + return false; + } + + return true; +} + +void CCmdArgs::displayHelp() +{ + // display program name + printf("Usage: %s ", _ProgramName.c_str()); + + // display optional parameters + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // only short argument is displayed + if (!arg.shortName.empty()) + { + printf("[-%s", arg.shortName.c_str()); + + // a parameter is required + if (!arg.helpName.empty()) + { + printf("<%s>", arg.helpName.c_str()); + } + + printf("]"); + } + } + + sint last = -1; + + // look for last required argument + for(uint i = 0; i < _Args.size(); ++i) + { + if (_Args[i].shortName.empty()) last = (sint)i; + } + + // display required arguments + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // they don't have any short or long name, but need a name in help + if (arg.shortName.empty() && arg.longName.empty() && !arg.helpName.empty()) + { + printf(" <%s>", arg.helpName.c_str()); + + // if last argument, it can support additional arguments + if ((sint)i == last) + { + printf(" [%s...]", arg.helpName.c_str()); + } + } + } + + printf("\n"); + + // display details on each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // not an optional argument + if (arg.shortName.empty() && arg.longName.empty()) continue; + + // a tab + printf("\t"); + + // display short argument + if (!arg.shortName.empty()) + { + printf("-%s", arg.shortName.c_str()); + + // and it's required argument + if (!arg.helpName.empty()) + { + printf(" <%s>", arg.helpName.c_str()); + printf(" or -%s<%s>", arg.shortName.c_str(), arg.helpName.c_str()); + } + } + + // display long argument + if (!arg.longName.empty()) + { + if (!arg.helpName.empty()) + { + // prepend a coma if a short argument was already displayed + if (!arg.shortName.empty()) + { + printf(", "); + } + + // display first syntax for long argument, --arg + printf("--%s <%s>", arg.longName.c_str(), arg.helpName.c_str()); + } + + // prepend " or " if 3 formats for argument + if (!arg.shortName.empty() || !arg.helpName.empty()) + { + printf(" or "); + } + + // display second syntax for long argument, --arg= + printf("--%s", arg.longName.c_str()); + + if (!arg.helpName.empty()) + { + printf("=<%s>", arg.helpName.c_str()); + } + } + + // display argument description + if (!arg.helpDescription.empty()) + { + printf(" : %s", arg.helpDescription.c_str()); + } + + printf("\n"); + } + + // process each argument + for(uint i = 0; i < _Args.size(); ++i) + { + const TArg &arg = _Args[i]; + + // only display required arguments + if (arg.shortName.empty() && arg.longName.empty() && !arg.helpName.empty() && !arg.helpDescription.empty()) + { + printf("\t%s : %s\n", arg.helpName.c_str(), arg.helpDescription.c_str()); + } + } +} + +void CCmdArgs::displayVersion() +{ + // display a verbose version string +#ifdef BUILD_DATE + printf("%s %s (built on %s)\nCopyright (C) %s\n", _ProgramName.c_str(), NL_VERSION, BUILD_DATE, COPYRIGHT); +#endif } }; // NAMESPACE NLMISC diff --git a/code/nel/tools/3d/mesh_export/main.cpp b/code/nel/tools/3d/mesh_export/main.cpp index 81b850a23..b135d719f 100644 --- a/code/nel/tools/3d/mesh_export/main.cpp +++ b/code/nel/tools/3d/mesh_export/main.cpp @@ -24,54 +24,63 @@ #include #include -int printHelp(const NLMISC::CCmdArgs &args) -{ - printf("NeL Mesh Export\n"); - return EXIT_SUCCESS; -} - int main(int argc, char *argv[]) { NLMISC::CApplicationContext app; NLMISC::CCmdArgs args; - args.setArgs(argc, (const char **)argv); - if (args.getArgs().size() == 1 - || args.haveArg('h') - || args.haveLongArg("help")) - return printHelp(args); + args.addArg("d", "dst", "destination", "Destination directory path"); + args.addArg("", "dependlog", "log", "Dependencies log path"); + args.addArg("", "errorlog", "log", "Errors log path"); + args.addArg("filename", "Filename of 3D model to convert"); - const NLMISC::CSString &filePath = args.getArgs().back(); - if (!NLMISC::CFile::fileExists(filePath)) - { - printHelp(args); - nlerror("File '%s' does not exist", filePath.c_str()); - return EXIT_FAILURE; - } + if (!args.parse(argc, argv)) return EXIT_SUCCESS; - CMeshUtilsSettings settings; - settings.SourceFilePath = filePath; - - if (args.haveArg('d')) - settings.DestinationDirectoryPath = args.getArg('d'); - if (settings.DestinationDirectoryPath.empty()) - settings.DestinationDirectoryPath = args.getLongArg("dst"); - if (settings.DestinationDirectoryPath.empty()) - settings.DestinationDirectoryPath = filePath + "_export"; - settings.DestinationDirectoryPath += "/"; - - settings.ToolDependLog = args.getLongArg("dependlog"); - if (settings.ToolDependLog.empty()) - settings.ToolDependLog = settings.DestinationDirectoryPath + "depend.log"; - settings.ToolErrorLog = args.getLongArg("errorlog"); - if (settings.ToolErrorLog.empty()) - settings.ToolErrorLog = settings.DestinationDirectoryPath + "error.log"; + const std::vector &filePathes = args.getRequiredArg(); NL3D::CScene::registerBasics(); NL3D::registerSerial3d(); - return exportScene(settings); + sint res = 0; + + for(uint i = 0; i < filePathes.size(); ++i) + { + std::string filePath = filePathes[i]; + + if (!NLMISC::CFile::fileExists(filePath)) + { + nlerror("File '%s' does not exist", filePath.c_str()); + return EXIT_FAILURE; + } + + CMeshUtilsSettings settings; + settings.SourceFilePath = filePath; + + if (args.haveArg("d")) + settings.DestinationDirectoryPath = args.getArg("d").front(); + + if (settings.DestinationDirectoryPath.empty()) + settings.DestinationDirectoryPath = filePath + "_export"; + + settings.DestinationDirectoryPath = NLMISC::standardizePath(settings.DestinationDirectoryPath); + + if (args.haveLongArg("dependlog")) + settings.ToolDependLog = args.getLongArg("dependlog").front(); + + if (settings.ToolDependLog.empty()) + settings.ToolDependLog = settings.DestinationDirectoryPath + "depend.log"; + + if (args.haveLongArg("errorlog")) + settings.ToolErrorLog = args.getLongArg("errorlog").front(); + + if (settings.ToolErrorLog.empty()) + settings.ToolErrorLog = settings.DestinationDirectoryPath + "error.log"; + + res = exportScene(settings); + } + + return res; } /* end of file */ From 823818f31fd0dd884402df44541fb3568a18aa44 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 21:26:47 +0100 Subject: [PATCH 15/23] Fixed: Don't display D3D page under Linux and OS X --- .../tools/client/client_config_qt/client_config_dialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/ryzom/tools/client/client_config_qt/client_config_dialog.cpp b/code/ryzom/tools/client/client_config_qt/client_config_dialog.cpp index a744b82f8..895db9873 100644 --- a/code/ryzom/tools/client/client_config_qt/client_config_dialog.cpp +++ b/code/ryzom/tools/client/client_config_qt/client_config_dialog.cpp @@ -83,7 +83,10 @@ CClientConfigDialog::CClientConfigDialog( QWidget *parent ) : CategoryStackedWidget->addWidget( new CSoundSettingsWidget( CategoryStackedWidget ) ); CategoryStackedWidget->addWidget( new CSysInfoWidget( CategoryStackedWidget ) ); CategoryStackedWidget->addWidget( new CSysInfoOpenGLWidget( CategoryStackedWidget ) ); + +#ifdef Q_OS_WIN CategoryStackedWidget->addWidget( new CSysInfoD3DWidget( CategoryStackedWidget ) ); +#endif for( sint32 i = 0; i < CategoryStackedWidget->count(); i++ ) { From ef6cc501e0daec8f93cd89e8e9032aed1ad772ca Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 21:27:10 +0100 Subject: [PATCH 16/23] Fixed: Right directory under OS X --- code/ryzom/client/src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index 35a2c1302..c220358c5 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -635,7 +635,7 @@ static void addPaths(IProgressCallback &progress, const std::vector directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath() + "/Contents/Resources")); // check in same directory as bundle (Steam) - directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath())); + directoryPrefixes.push_back(CPath::standardizePath(getAppBundlePath() + "/..")); #elif defined(NL_OS_UNIX) if (CFile::isDirectory(getRyzomSharePrefix())) directoryPrefixes.push_back(CPath::standardizePath(getRyzomSharePrefix())); #endif From bed94fb47e0a6fdb59103aefd24c851ee03425b4 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 21:27:42 +0100 Subject: [PATCH 17/23] Fixed: Warning with clang --- code/ryzom/client/src/entity_cl.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/ryzom/client/src/entity_cl.h b/code/ryzom/client/src/entity_cl.h index f7a26e03f..fb04576bc 100644 --- a/code/ryzom/client/src/entity_cl.h +++ b/code/ryzom/client/src/entity_cl.h @@ -86,11 +86,10 @@ namespace NL3D class CEntitySheet; class CEntityCL; +class CAttackInfo; class CItemSheet; -class CPhysicalDamage; - namespace NLMISC{ class CCDBNodeLeaf; class CCDBNodeBranch; @@ -586,7 +585,7 @@ public: virtual void impact(uint /* impactType */, uint /* type */, uint /* id */, uint /* intensity */) {} /** Try to play a melee impact on this entity. */ - virtual void meleeImpact(const CPhysicalDamage &/* damage */) {} + virtual void meleeImpact(const CAttackInfo &/* attack */) {} /** Play the magic impact on the entity * \param type : type of the impact (host/good/neutral). * \param intensity : intensity of the impact. From 4bcc9cf6e0b1819b4d276648fd7d55a180d8a09d Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 22:42:34 +0100 Subject: [PATCH 18/23] Fixed: Use language name in native language in config window --- code/ryzom/tools/translation/translated/de.uxt | 8 ++++---- code/ryzom/tools/translation/translated/en.uxt | 4 ++-- code/ryzom/tools/translation/translated/es.uxt | 8 ++++---- code/ryzom/tools/translation/translated/fr.uxt | 8 ++++---- code/ryzom/tools/translation/translated/ru.uxt | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/code/ryzom/tools/translation/translated/de.uxt b/code/ryzom/tools/translation/translated/de.uxt index 4ea6f6a24..75d8d2219 100644 --- a/code/ryzom/tools/translation/translated/de.uxt +++ b/code/ryzom/tools/translation/translated/de.uxt @@ -3197,11 +3197,11 @@ uigcChatColor [CHAT] // HASH_VALUE 4B01AC26C830BC29 // INDEX 797 -uigcEnglish [ENGLISCH] +uigcEnglish [ENGLISH] // HASH_VALUE 4C5024185050140C // INDEX 798 -uigcFrancais [FRANZÖSISCH] +uigcFrancais [FRANCAIS] // HASH_VALUE 8D229C20C911A81F // INDEX 799 @@ -3209,11 +3209,11 @@ uigcDeutch [DEUTSCH] // HASH_VALUE 0912144D9193DC2A // INDEX 800 -uigcRussian [RUSSISCH] +uigcRussian [РУССКИЙ] // HASH_VALUE CBC1A432CBD2FC37 // INDEX 801 -uigcSpanish [SPANISCH] +uigcSpanish [ESPANOL] // HASH_VALUE D72E51D69923FABB // INDEX 802 diff --git a/code/ryzom/tools/translation/translated/en.uxt b/code/ryzom/tools/translation/translated/en.uxt index 5d280a8fe..19c5f118e 100644 --- a/code/ryzom/tools/translation/translated/en.uxt +++ b/code/ryzom/tools/translation/translated/en.uxt @@ -3203,11 +3203,11 @@ uigcDeutch [DEUTSCH] // HASH_VALUE 0912144D9193DC2A // INDEX 800 -uigcRussian [RUSSIAN] +uigcRussian [РУССКИЙ] // HASH_VALUE CBC1A432CBD2FC37 // INDEX 801 -uigcSpanish [SPANISH] +uigcSpanish [ESPANOL] // HASH_VALUE D72E51D69923FABB // INDEX 802 diff --git a/code/ryzom/tools/translation/translated/es.uxt b/code/ryzom/tools/translation/translated/es.uxt index 23c60e701..5d51cfbf5 100644 --- a/code/ryzom/tools/translation/translated/es.uxt +++ b/code/ryzom/tools/translation/translated/es.uxt @@ -3192,19 +3192,19 @@ uigcChatColor [COLORES DEL CHAT] // HASH_VALUE 4B01AC26C830BC29 // INDEX 797 -uigcEnglish [INGLÉS] +uigcEnglish [ENGLISH] // HASH_VALUE 4C5024185050140C // INDEX 798 -uigcFrancais [FRANCÉS] +uigcFrancais [FRANCAIS] // HASH_VALUE 8D229C20C911A81F // INDEX 799 -uigcDeutch [ALEMÁN] +uigcDeutch [DEUTSCH] // HASH_VALUE 0912144D9193DC2A // INDEX 800 -uigcRussian [RUSO] +uigcRussian [РУССКИЙ] // HASH_VALUE CBC1A432CBD2FC37 // INDEX 801 diff --git a/code/ryzom/tools/translation/translated/fr.uxt b/code/ryzom/tools/translation/translated/fr.uxt index 4022e1512..00a167f20 100644 --- a/code/ryzom/tools/translation/translated/fr.uxt +++ b/code/ryzom/tools/translation/translated/fr.uxt @@ -3191,7 +3191,7 @@ uigcChatColor [CHAT] // HASH_VALUE 4B01AC26C830BC29 // INDEX 797 -uigcEnglish [ANGLAIS] +uigcEnglish [ENGLISH] // HASH_VALUE 4C5024185050140C // INDEX 798 @@ -3199,15 +3199,15 @@ uigcFrancais [FRANCAIS] // HASH_VALUE 8D229C20C911A81F // INDEX 799 -uigcDeutch [ALLEMAND] +uigcDeutch [DEUTSCH] // HASH_VALUE 0912144D9193DC2A // INDEX 800 -uigcRussian [RUSSE] +uigcRussian [РУССКИЙ] // HASH_VALUE CBC1A432CBD2FC37 // INDEX 801 -uigcSpanish [ESPAGNOL] +uigcSpanish [ESPANOL] // HASH_VALUE D72E51D69923FABB // INDEX 802 diff --git a/code/ryzom/tools/translation/translated/ru.uxt b/code/ryzom/tools/translation/translated/ru.uxt index 6902c35ea..3c8a6da66 100644 --- a/code/ryzom/tools/translation/translated/ru.uxt +++ b/code/ryzom/tools/translation/translated/ru.uxt @@ -3193,15 +3193,15 @@ uigcChatColor [ЧАТ] // HASH_VALUE 4B01AC26C830BC29 // INDEX 797 -uigcEnglish [Английский] +uigcEnglish [ENGLISH] // HASH_VALUE 4C5024185050140C // INDEX 798 -uigcFrancais [Французский] +uigcFrancais [FRANCAIS] // HASH_VALUE 8D229C20C911A81F // INDEX 799 -uigcDeutch [Немецкий] +uigcDeutch [DEUTSCH] // HASH_VALUE 0912144D9193DC2A // INDEX 800 @@ -3209,7 +3209,7 @@ uigcRussian [РУССКИЙ] // HASH_VALUE CBC1A432CBD2FC37 // INDEX 801 -uigcSpanish [ИСПАНСКИЙ] +uigcSpanish [ESPANOL] /* OLD VALUE : [??? ????, ????? ????????? ???????? ? ????, ?????????? ????????????? ??????] */ // HASH_VALUE D72E51D69923FABB From 1720f33c531b61ca159a79953670b4e9e33f6b0d Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 23:46:19 +0100 Subject: [PATCH 19/23] Fixed: Compilation --- code/nel/tools/3d/mesh_export/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/nel/tools/3d/mesh_export/main.cpp b/code/nel/tools/3d/mesh_export/main.cpp index b135d719f..a042d6d0f 100644 --- a/code/nel/tools/3d/mesh_export/main.cpp +++ b/code/nel/tools/3d/mesh_export/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) if (settings.DestinationDirectoryPath.empty()) settings.DestinationDirectoryPath = filePath + "_export"; - settings.DestinationDirectoryPath = NLMISC::standardizePath(settings.DestinationDirectoryPath); + settings.DestinationDirectoryPath = NLMISC::CPath::standardizePath(settings.DestinationDirectoryPath); if (args.haveLongArg("dependlog")) settings.ToolDependLog = args.getLongArg("dependlog").front(); From 8040a6495bdd149bab90e36b6b7089470c09f01e Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 23:47:24 +0100 Subject: [PATCH 20/23] Changed: Invert version and help checks --- code/nel/src/misc/cmd_args.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/nel/src/misc/cmd_args.cpp b/code/nel/src/misc/cmd_args.cpp index 39f4cb849..82863ba1b 100644 --- a/code/nel/src/misc/cmd_args.cpp +++ b/code/nel/src/misc/cmd_args.cpp @@ -321,13 +321,6 @@ bool CCmdArgs::parse(const std::vector &argv) } } - // process help if requested or if required arguments are missing - if (haveLongArg("help") || (needRequiredArg() && !haveRequiredArg())) - { - displayHelp(); - return false; - } - // process version if (haveLongArg("version")) { @@ -335,6 +328,13 @@ bool CCmdArgs::parse(const std::vector &argv) return false; } + // process help if requested or if required arguments are missing + if (haveLongArg("help") || (needRequiredArg() && !haveRequiredArg())) + { + displayHelp(); + return false; + } + return true; } From 3d9d77484afe134e34254df75da06a814f5fa5f6 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 23:53:17 +0100 Subject: [PATCH 21/23] Changed: Minor changes --- code/nel/src/misc/bitmap.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 60ca9a752..6d4260e17 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -19,7 +19,6 @@ #include "nel/misc/bitmap.h" #include "nel/misc/stream.h" #include "nel/misc/file.h" -#include "nel/misc/system_info.h" // Define this to force all bitmap white (debug) // #define NEL_ALL_BITMAP_WHITE @@ -477,7 +476,7 @@ uint8 CBitmap::readDDS(NLMISC::IStream &f, uint mipMapSkip) uint32 size = 0; f.serial(size); // size in Bytes of header(without "DDS") - uint32 * _DDSSurfaceDesc = new uint32[size]; + uint32 * _DDSSurfaceDesc = new uint32[size]; _DDSSurfaceDesc[0]= size; #ifdef NL_LITTLE_ENDIAN @@ -508,6 +507,7 @@ uint8 CBitmap::readDDS(NLMISC::IStream &f, uint mipMapSkip) // If no mipmap. if(_MipMapCount==0) _MipMapCount=1; + switch (_DDSSurfaceDesc[20]) { case DXTC1HEADER: @@ -2761,7 +2761,6 @@ bool CBitmap::writeTGA( NLMISC::IStream &f, uint32 d, bool upsideDown) for(y=0; y<(sint32)height; y++) { - uint32 k=0; if (PixelFormat == Alpha) { @@ -3569,7 +3568,7 @@ void CBitmap::loadSize(NLMISC::IStream &f, uint32 &retWidth, uint32 &retHeight) f.serial(imageType); if(imageType!=2 && imageType!=3 && imageType!=10 && imageType!=11) { - nlwarning("Invalid TGA format, type %u in not supported (must be 2,3,10 or 11)", imageType); + nlwarning("Invalid TGA format, type %u in not supported (must be 2, 3, 10 or 11)", imageType); return; } f.serial(tgaOrigin); From 13f1ddd6f3fc6b66e4525e58b53282ca83d83a10 Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Jan 2016 23:58:04 +0100 Subject: [PATCH 22/23] Fixed: Compilation --- code/nel/src/misc/bitmap.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 6d4260e17..c1249319e 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -19,6 +19,7 @@ #include "nel/misc/bitmap.h" #include "nel/misc/stream.h" #include "nel/misc/file.h" +#include "nel/misc/system_info.h" // Define this to force all bitmap white (debug) // #define NEL_ALL_BITMAP_WHITE From 1c30bd835f45693ed51e0ac4cb30d879ef72d834 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 15 Jan 2016 10:46:34 +0100 Subject: [PATCH 23/23] Changed: Update WindowsSDK CMake module for VC++ 2015 --- code/CMakeModules/FindWindowsSDK.cmake | 103 ++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/code/CMakeModules/FindWindowsSDK.cmake b/code/CMakeModules/FindWindowsSDK.cmake index 22e000764..c5e8c2897 100644 --- a/code/CMakeModules/FindWindowsSDK.cmake +++ b/code/CMakeModules/FindWindowsSDK.cmake @@ -17,13 +17,28 @@ SET(WINSDK_VERSION "CURRENT" CACHE STRING "Windows SDK version to prefer") MACRO(DETECT_WINSDK_VERSION_HELPER _ROOT _VERSION) GET_FILENAME_COMPONENT(WINSDK${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v${_VERSION};InstallationFolder]" ABSOLUTE) - IF(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") + IF(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry" AND EXISTS "${WINSDK${_VERSION}_DIR}/Include") SET(WINSDK${_VERSION}_FOUND ON) GET_FILENAME_COMPONENT(WINSDK${_VERSION}_VERSION_FULL "[${_ROOT}\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v${_VERSION};ProductVersion]" NAME) IF(NOT WindowsSDK_FIND_QUIETLY) MESSAGE(STATUS "Found Windows SDK ${_VERSION} in ${WINSDK${_VERSION}_DIR}") - ENDIF(NOT WindowsSDK_FIND_QUIETLY) - ELSE(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") + ENDIF() + ELSE() + SET(WINSDK${_VERSION}_DIR "") + ENDIF() +ENDMACRO() + +MACRO(DETECT_WINKIT_VERSION _VERSION _SUFFIX) + GET_FILENAME_COMPONENT(WINSDK${_VERSION}_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot${_SUFFIX}]" ABSOLUTE) + + IF(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") + SET(WINSDK${_VERSION}_FOUND ON) + SET(WINSDK${_VERSION}_VERSION_FULL "${_VERSION}") + IF(NOT WindowsSDK_FIND_QUIETLY) + MESSAGE(STATUS "Found Windows SDK ${_VERSION} in ${WINSDK${_VERSION}_DIR}") + ENDIF() + LIST(APPEND WINSDK_DETECTED_VERSIONS ${_VERSION}) + ELSE() SET(WINSDK${_VERSION}_DIR "") ENDIF() ENDMACRO() @@ -37,9 +52,16 @@ MACRO(DETECT_WINSDK_VERSION _VERSION) ENDIF() ENDMACRO() -SET(WINSDK_VERSIONS "8.1" "8.0" "7.1" "7.1A" "7.0" "7.0A" "6.1" "6.0" "6.0A") SET(WINSDK_DETECTED_VERSIONS) +# Fixed versions for Windows Kits (VC++ from 2012) +DETECT_WINKIT_VERSION("10.0" "10") +DETECT_WINKIT_VERSION("8.1" "81") +DETECT_WINKIT_VERSION("8.0" "") + +# For VC++ up to 2010 +SET(WINSDK_VERSIONS "7.1" "7.1A" "7.0" "7.0A" "6.1" "6.0" "6.0A") + # Search all supported Windows SDKs FOREACH(_VERSION ${WINSDK_VERSIONS}) DETECT_WINSDK_VERSION(${_VERSION}) @@ -51,7 +73,9 @@ ENDFOREACH() SET(WINSDK_SUFFIXES) -IF(TARGET_ARM) +IF(TARGET_ARM64) + SET(WINSDK8_SUFFIX "arm64") +ELSEIF(TARGET_ARM) SET(WINSDK8_SUFFIX "arm") ELSEIF(TARGET_X64) SET(WINSDK8_SUFFIX "x64") @@ -216,7 +240,9 @@ MACRO(USE_CURRENT_WINSDK) IF(NOT WINSDK_DIR) # Use Windows SDK versions installed with VC++ when possible - IF(MSVC12) + IF(MSVC14) + SET(WINSDK_VERSION "8.1") + ELSEIF(MSVC12) SET(WINSDK_VERSION "8.1") ELSEIF(MSVC11) SET(WINSDK_VERSION "8.0") @@ -267,6 +293,16 @@ MACRO(USE_CURRENT_WINSDK) ENDIF() ENDMACRO() +IF(MSVC14) + # Under VC++ 2015, stdio.h, stdlib.h, etc... are part of UCRT + SET(WINSDK_UCRT_VERSION "10.0") +ENDIF() + +# Look for correct UCRT +IF(WINSDK_UCRT_VERSION AND WINSDK${WINSDK_UCRT_VERSION}_FOUND) + SET(WINSDK_UCRT_DIR "${WINSDK${WINSDK_UCRT_VERSION}_DIR}") +ENDIF() + IF(WINSDK_VERSION STREQUAL "CURRENT") USE_CURRENT_WINSDK() ELSE() @@ -291,11 +327,16 @@ FIND_PATH(WINSDK_INCLUDE_DIR Windows.h ${WINSDK_DIR}/Include ) +# directory where WinRT headers are found +FIND_PATH(WINSDK_WINRT_INCLUDE_DIR winstring.h + HINTS + ${WINSDK_DIR}/Include/winrt +) + # directory where DirectX headers are found FIND_PATH(WINSDK_SHARED_INCLUDE_DIR d3d9.h HINTS ${WINSDK_DIR}/Include/shared - ${WINSDK_DIR}/Include ) # directory where OpenGL headers are found @@ -303,12 +344,13 @@ FIND_PATH(WINSDK_OPENGL_INCLUDE_DIR GL.h HINTS ${WINSDK_DIR}/Include/um/gl ${WINSDK_DIR}/Include/gl - ${WINSDK_DIR}/Include ) SET(WINSDK_LIBRARY_DIRS ${WINSDK_DIR}/Lib/winv6.3/um/${WINSDK8_SUFFIX} - ${WINSDK_DIR}/Lib/win8/um/${WINSDK8_SUFFIX}) + ${WINSDK_DIR}/Lib/win8/um/${WINSDK8_SUFFIX} + ${WINSDK_DIR}/Lib/${WINSDK_SUFFIX} +) IF(WINSDK_SUFFIXES) FOREACH(_SUFFIX ${WINSDK_SUFFIXES}) @@ -324,6 +366,22 @@ FIND_PATH(WINSDK_LIBRARY_DIR ComCtl32.lib ${WINSDK_LIBRARY_DIRS} ) +IF(WINSDK_UCRT_DIR) + # directory where UCRT headers are found + FIND_PATH(WINSDK_UCRT_INCLUDE_DIR corecrt.h + HINTS + ${WINSDK_UCRT_DIR}/Include/10.0.10056.0/ucrt + ${WINSDK_UCRT_DIR}/Include/10.0.10150.0/ucrt + ) + + # directory where UCRT libraries are found + FIND_PATH(WINSDK_UCRT_LIBRARY_DIR ucrt.lib + HINTS + ${WINSDK_UCRT_DIR}/Lib/10.0.10056.0/ucrt/${WINSDK8_SUFFIX} + ${WINSDK_UCRT_DIR}/Lib/10.0.10150.0/ucrt/${WINSDK8_SUFFIX} + ) +ENDIF() + # signtool is used to sign executables FIND_PROGRAM(WINSDK_SIGNTOOL signtool HINTS @@ -342,10 +400,33 @@ FIND_PROGRAM(WINSDK_MIDL midl IF(WINSDK_INCLUDE_DIR) SET(WINSDK_FOUND ON) - SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIR} ${WINSDK_SHARED_INCLUDE_DIR} ${WINSDK_OPENGL_INCLUDE_DIR}) - SET(CMAKE_LIBRARY_PATH ${WINSDK_LIBRARY_DIR} ${CMAKE_LIBRARY_PATH}) + + IF(WINSDK_UCRT_INCLUDE_DIR) + SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIRS} ${WINSDK_UCRT_INCLUDE_DIR}) + ENDIF() + + IF(WINSDK_SHARED_INCLUDE_DIR) + SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIRS} ${WINSDK_SHARED_INCLUDE_DIR}) + ENDIF() + + SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIRS} ${WINSDK_INCLUDE_DIR}) + + IF(WINSDK_OPENGL_INCLUDE_DIR) + SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIRS} ${WINSDK_OPENGL_INCLUDE_DIR}) + ENDIF() + + IF(WINSDK_WINRT_INCLUDE_DIR) + SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIRS} ${WINSDK_WINRT_INCLUDE_DIR}) + ENDIF() + INCLUDE_DIRECTORIES(${WINSDK_INCLUDE_DIRS}) # TODO: Move this after all other includes somehow... + IF(WINSDK_UCRT_LIBRARY_DIR) + SET(CMAKE_LIBRARY_PATH ${WINSDK_UCRT_LIBRARY_DIR} ${CMAKE_LIBRARY_PATH}) + ENDIF() + + SET(CMAKE_LIBRARY_PATH ${WINSDK_LIBRARY_DIR} ${CMAKE_LIBRARY_PATH}) + # Fix for using Windows SDK 7.1 with Visual C++ 2012 IF(WINSDK_VERSION STREQUAL "7.1" AND MSVC11) ADD_DEFINITIONS(-D_USING_V110_SDK71_)