Add first search path to command param.

This commit is contained in:
zhangcheng 2016-03-04 13:16:37 +08:00
parent 32303b5904
commit 709d79ad14
3 changed files with 33 additions and 66 deletions

View File

@ -50,7 +50,6 @@ ProjectConfig::ProjectConfig()
, _consolePort(kProjectConfigConsolePort) , _consolePort(kProjectConfigConsolePort)
, _fileUploadPort(kProjectConfigUploadPort) , _fileUploadPort(kProjectConfigUploadPort)
, _bindAddress("") , _bindAddress("")
, _useLocalScript(false)
{ {
normalize(); normalize();
} }
@ -273,17 +272,6 @@ void ProjectConfig::setDebuggerType(int debuggerType)
_debuggerType = debuggerType; _debuggerType = debuggerType;
} }
bool ProjectConfig::isUseLocalScript() const
{
return _useLocalScript;
}
void ProjectConfig::setUseLocalScript(bool useLocalScript)
{
_useLocalScript = useLocalScript;
}
void ProjectConfig::parseCommandLine(const vector<string> &args) void ProjectConfig::parseCommandLine(const vector<string> &args)
{ {
auto it = args.begin(); auto it = args.begin();
@ -421,24 +409,11 @@ void ProjectConfig::parseCommandLine(const vector<string> &args)
vector<string> pathes = split((*it), ';'); vector<string> pathes = split((*it), ';');
setSearchPath(pathes); setSearchPath(pathes);
} }
else if (arg.compare("-use-local-script") == 0) else if (arg.compare("-first-search-path") == 0)
{ {
++it; ++it;
if (it == args.end()) break; vector<string> pathes = split((*it), ';');
if ((*it).compare("enable") == 0) setFirstSearchPath(pathes);
{
setUseLocalScript(true);
}
else
{
setUseLocalScript(false);
}
}
else if (arg.compare("-language-data-path") == 0)
{
++it;
if (it == args.end()) break;
setLanguageDataPath(*it);
} }
++it; ++it;
} }
@ -602,17 +577,20 @@ vector<string> ProjectConfig::makeCommandLineVector(unsigned int mask /* = kProj
} }
} }
if (mask & kProjectConfigUseLocalScript) if (mask & kProjectConfigFirstSearchPath)
{ {
if (isUseLocalScript()) if (_searchPath.size() > 0)
{ {
ret.push_back("-use-local-script"); stringstream pathbuff;
ret.push_back("enable"); for (auto &path : _searchPath)
{
pathbuff << dealWithSpaceWithPath(path) << ";";
} }
else string pathArgs = pathbuff.str();
{ pathArgs[pathArgs.length() - 1] = '\0';
ret.push_back("-use-local-script");
ret.push_back("disable"); ret.push_back("-first-search-path");
ret.push_back(pathArgs);
} }
} }
return ret; return ret;
@ -658,26 +636,17 @@ const vector<string> &ProjectConfig::getSearchPath() const
return _searchPath; return _searchPath;
} }
void ProjectConfig::setLanguageDataPath(const std::string &filePath) void ProjectConfig::setFirstSearchPath(const vector<string> &args)
{ {
bool isBinary = true; _firstSearchPath = args;
string jsonExtension = ".json";
int exLength = jsonExtension.length();
if (filePath.length() >= exLength &&
(0 == filePath.compare(filePath.length() - exLength, exLength, jsonExtension)))
{
isBinary = false;
} }
cocostudio::ILocalizationManager* lm; const vector<string> &ProjectConfig::getFirstSearchPath() const
if (isBinary) {
lm = cocostudio::BinLocalizationManager::getInstance(); return _firstSearchPath;
else
lm = cocostudio::JsonLocalizationManager::getInstance();
lm->initLanguageData(filePath);
cocostudio::LocalizationHelper::setCurrentManager(lm, isBinary);
} }
bool ProjectConfig::isAppMenu() const bool ProjectConfig::isAppMenu() const
{ {
return _isAppMenu; return _isAppMenu;

View File

@ -28,11 +28,11 @@ using namespace std;
#define kProjectConfigDebugger 1024 // -debugger-ldt, -debugger-codeide, -disable-debugger #define kProjectConfigDebugger 1024 // -debugger-ldt, -debugger-codeide, -disable-debugger
#define kProjectConfigListen 2048 // #define kProjectConfigListen 2048 //
#define kProjectConfigSearchPath 4096 // #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 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 #define kProjectConfigConsolePort 6010
@ -105,10 +105,8 @@ public:
const std::string &getBindAddress() const; const std::string &getBindAddress() const;
void setSearchPath(const vector<string> &args); void setSearchPath(const vector<string> &args);
const vector<string> &getSearchPath() const; const vector<string> &getSearchPath() const;
void setLanguageDataPath(const std::string &filePath); void setFirstSearchPath(const vector<string> &args);
const vector<string> &getFirstSearchPath() const;
bool isUseLocalScript() const;
void setUseLocalScript(bool useLocalScript);
bool isAppMenu() const; bool isAppMenu() const;
bool isResizeWindow() const; bool isResizeWindow() const;
@ -138,8 +136,7 @@ private:
int _fileUploadPort; int _fileUploadPort;
string _bindAddress; string _bindAddress;
vector<string> _searchPath; vector<string> _searchPath;
bool _useLocalScript; vector<string> _firstSearchPath;
string _languageDataPath;
void normalize(); void normalize();
string replaceProjectDirToMacro(const string &path) const; string replaceProjectDirToMacro(const string &path) const;

View File

@ -223,12 +223,13 @@ void RuntimeEngine::setProjectPath(const std::string &workPath)
g_projectPath = workPath; g_projectPath = workPath;
} }
if (!_project.isUseLocalScript())
{
// add project's root directory to search path // add project's root directory to search path
searchPathArray.insert(searchPathArray.begin(), g_projectPath); searchPathArray.insert(searchPathArray.begin(), g_projectPath);
}
if (!_project.getFirstSearchPath().empty())
{
searchPathArray.insert(searchPathArray.begin(), _project.getFirstSearchPath().begin(), _project.getFirstSearchPath().end());
}
// add writable path to search path // add writable path to search path
searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath()); searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath());