From 709d79ad14f6648b3bf062efb1452d712c9bcd20 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Fri, 4 Mar 2016 13:16:37 +0800 Subject: [PATCH] Add first search path to command param. --- .../lib/ProjectConfig/ProjectConfig.cpp | 77 ++++++------------- .../lib/ProjectConfig/ProjectConfig.h | 13 ++-- .../libsimulator/lib/runtime/Runtime.cpp | 9 ++- 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp index bd6a1c3233..d649c93bf8 100644 --- a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp +++ b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp @@ -50,7 +50,6 @@ ProjectConfig::ProjectConfig() , _consolePort(kProjectConfigConsolePort) , _fileUploadPort(kProjectConfigUploadPort) , _bindAddress("") - , _useLocalScript(false) { normalize(); } @@ -273,17 +272,6 @@ void ProjectConfig::setDebuggerType(int debuggerType) _debuggerType = debuggerType; } - -bool ProjectConfig::isUseLocalScript() const -{ - return _useLocalScript; -} - -void ProjectConfig::setUseLocalScript(bool useLocalScript) -{ - _useLocalScript = useLocalScript; -} - void ProjectConfig::parseCommandLine(const vector &args) { auto it = args.begin(); @@ -421,24 +409,11 @@ void ProjectConfig::parseCommandLine(const vector &args) vector pathes = split((*it), ';'); setSearchPath(pathes); } - else if (arg.compare("-use-local-script") == 0) + else if (arg.compare("-first-search-path") == 0) { ++it; - if (it == args.end()) break; - if ((*it).compare("enable") == 0) - { - setUseLocalScript(true); - } - else - { - setUseLocalScript(false); - } - } - else if (arg.compare("-language-data-path") == 0) - { - ++it; - if (it == args.end()) break; - setLanguageDataPath(*it); + vector pathes = split((*it), ';'); + setFirstSearchPath(pathes); } ++it; } @@ -602,17 +577,20 @@ vector ProjectConfig::makeCommandLineVector(unsigned int mask /* = kProj } } - if (mask & kProjectConfigUseLocalScript) + if (mask & kProjectConfigFirstSearchPath) { - if (isUseLocalScript()) + if (_searchPath.size() > 0) { - ret.push_back("-use-local-script"); - ret.push_back("enable"); - } - else - { - ret.push_back("-use-local-script"); - ret.push_back("disable"); + stringstream pathbuff; + for (auto &path : _searchPath) + { + pathbuff << dealWithSpaceWithPath(path) << ";"; + } + string pathArgs = pathbuff.str(); + pathArgs[pathArgs.length() - 1] = '\0'; + + ret.push_back("-first-search-path"); + ret.push_back(pathArgs); } } return ret; @@ -658,26 +636,17 @@ const vector &ProjectConfig::getSearchPath() const return _searchPath; } -void ProjectConfig::setLanguageDataPath(const std::string &filePath) +void ProjectConfig::setFirstSearchPath(const vector &args) { - bool isBinary = true; - string jsonExtension = ".json"; - int exLength = jsonExtension.length(); - if (filePath.length() >= exLength && - (0 == filePath.compare(filePath.length() - exLength, exLength, jsonExtension))) - { - isBinary = false; - } - - cocostudio::ILocalizationManager* lm; - if (isBinary) - lm = cocostudio::BinLocalizationManager::getInstance(); - else - lm = cocostudio::JsonLocalizationManager::getInstance(); - lm->initLanguageData(filePath); - cocostudio::LocalizationHelper::setCurrentManager(lm, isBinary); + _firstSearchPath = args; } +const vector &ProjectConfig::getFirstSearchPath() const +{ + return _firstSearchPath; +} + + bool ProjectConfig::isAppMenu() const { return _isAppMenu; diff --git a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h index 734cca8939..97c3d2382e 100644 --- a/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h +++ b/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.h @@ -28,11 +28,11 @@ using namespace std; #define kProjectConfigDebugger 1024 // -debugger-ldt, -debugger-codeide, -disable-debugger #define kProjectConfigListen 2048 // #define kProjectConfigSearchPath 4096 // -#define kProjectConfigUseLocalScript 8192 // -use-local-script +#define kProjectConfigFirstSearchPath 8192 // -first-search-path #define kProjectConfigOpenRecent (kProjectConfigProjectDir | kProjectConfigScriptFile | kProjectConfigPackagePath | kProjectConfigWritablePath | kProjectConfigFrameSize | kProjectConfigFrameScale | kProjectConfigShowConsole | kProjectConfigLoadPrecompiledFramework | kProjectConfigWriteDebugLogToFile) -#define kProjectConfigAll (kProjectConfigProjectDir | kProjectConfigScriptFile | kProjectConfigPackagePath | kProjectConfigWritablePath | kProjectConfigFrameSize | kProjectConfigFrameScale | kProjectConfigShowConsole | kProjectConfigLoadPrecompiledFramework | kProjectConfigWriteDebugLogToFile | kProjectConfigWindowOffset | kProjectConfigDebugger | kProjectConfigListen | kProjectConfigSearchPath) +#define kProjectConfigAll (kProjectConfigProjectDir | kProjectConfigScriptFile | kProjectConfigPackagePath | kProjectConfigWritablePath | kProjectConfigFrameSize | kProjectConfigFrameScale | kProjectConfigShowConsole | kProjectConfigLoadPrecompiledFramework | kProjectConfigWriteDebugLogToFile | kProjectConfigWindowOffset | kProjectConfigDebugger | kProjectConfigListen | kProjectConfigSearchPath | kProjectConfigFirstSearchPath) #define kProjectConfigConsolePort 6010 @@ -105,10 +105,8 @@ public: const std::string &getBindAddress() const; void setSearchPath(const vector &args); const vector &getSearchPath() const; - void setLanguageDataPath(const std::string &filePath); - - bool isUseLocalScript() const; - void setUseLocalScript(bool useLocalScript); + void setFirstSearchPath(const vector &args); + const vector &getFirstSearchPath() const; bool isAppMenu() const; bool isResizeWindow() const; @@ -138,8 +136,7 @@ private: int _fileUploadPort; string _bindAddress; vector _searchPath; - bool _useLocalScript; - string _languageDataPath; + vector _firstSearchPath; void normalize(); string replaceProjectDirToMacro(const string &path) const; diff --git a/tools/simulator/libsimulator/lib/runtime/Runtime.cpp b/tools/simulator/libsimulator/lib/runtime/Runtime.cpp index 74190ef796..6e2fe0709e 100644 --- a/tools/simulator/libsimulator/lib/runtime/Runtime.cpp +++ b/tools/simulator/libsimulator/lib/runtime/Runtime.cpp @@ -223,12 +223,13 @@ void RuntimeEngine::setProjectPath(const std::string &workPath) g_projectPath = workPath; } - if (!_project.isUseLocalScript()) + // add project's root directory to search path + searchPathArray.insert(searchPathArray.begin(), g_projectPath); + + if (!_project.getFirstSearchPath().empty()) { - // add project's root directory to search path - searchPathArray.insert(searchPathArray.begin(), g_projectPath); + searchPathArray.insert(searchPathArray.begin(), _project.getFirstSearchPath().begin(), _project.getFirstSearchPath().end()); } - // add writable path to search path searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath());