예제 #1
0
bool CRhodesModule::ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode ) throw()
{
	m_bRestarting      = false;
    m_bMinimized       = false;
    m_startAtBoot      = false;
#ifdef RHO_NO_RUBY
    m_bJSApplication   = true;        
#else
    m_bJSApplication   = false;
#endif

    m_logPort          = "";
    m_isRhoConnectPush = false;
    LPCTSTR lpszToken  = lpCmdLine;
	LPCTSTR nextToken;

    getRhoRootPath();

	while (lpszToken != NULL)
	{
		// skip leading spaces and double-quote (if present)
	    bool doubleQuote = false;
		while ((*lpszToken != 0) && ((*lpszToken==' ') || ((!doubleQuote) && (*lpszToken=='"')))) {
			if (*lpszToken=='"')
				doubleQuote = true;
			lpszToken++;
		}
		// skip leading spaces and check for leading '/' or '-' of command line option
		bool isCmdLineOpt = false;
		while ((*lpszToken != 0) && ((*lpszToken==' ') || ((!isCmdLineOpt) && ((*lpszToken=='/') || (*lpszToken=='-'))))) {
			if ((*lpszToken=='/') || (*lpszToken=='-'))
				isCmdLineOpt = true;
			lpszToken++;
		}
		// finish command line processing on EOL
		if (*lpszToken == 0) break;

		// if option starts with double-quote, find its end by next double-quote;
		// otherwise the end will be found automatically
		nextToken = doubleQuote ? FindOneOf(lpszToken, _T("\"")) : NULL;

		//parseToken will allocate extra byte at the end of the returned token value
		LPTSTR value = parseToken( lpszToken, &nextToken );

		if (isCmdLineOpt) {
			if (WordCmpI(lpszToken, _T("Restarting"))==0) {
				m_bRestarting = true;
			}

            if (wcsncmp(lpszToken, _T("minimized"), 9)==0) {
				m_bMinimized = true;
			}

            if (wcsncmp(lpszToken, _T("tabname"), 7)==0) {
				m_strTabName = convertToStringA(value);
			}

			if (WordCmpI(lpszToken, _T("rhoconnectpush"))==0) {
				m_isRhoConnectPush = true;
			}

			else if (wcsncmp(lpszToken, _T("log"), 3)==0) 
			{
				if (value) {
					m_logPort = convertToStringA(value);
				}
				else {
					m_logPort = rho::String("11000");
				}
			}
            else if (wcsnicmp(lpszToken, _T("approot"),7)==0 || wcsnicmp(lpszToken, _T("jsapproot"),9)==0)
			{
				if (value) 
                {
					m_strRootPath = convertToStringA(value);
					if (m_strRootPath.substr(0,7).compare("file://")==0)
						m_strRootPath.erase(0,7);
					String_replace(m_strRootPath, '\\', '/');
					if (m_strRootPath.at(m_strRootPath.length()-1)!='/')
						m_strRootPath.append("/");

#if defined(OS_WINCE)
					m_strRootPath.append("rho/");
#ifdef APP_BUILD_CAPABILITY_SHARED_RUNTIME
					rho_wmimpl_set_is_version2(m_strRootPath.c_str());
#endif
#endif
        		}

                if ( wcsnicmp(lpszToken, _T("jsapproot"),9)==0 )
                    m_bJSApplication = true;
            }
#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
			else if (wcsnicmp(lpszToken, _T("s"),1)==0)
			{
				if (value) {
					// RhoElements v1.0 compatibility mode
					String strPath = convertToStringA(value);
					rho_wmimpl_set_startpage(strPath.c_str());
				}
			}
			else if (wcsnicmp(lpszToken, _T("c"),1)==0)
			{
				if (value) {
					String strPath = convertToStringA(value);
					if (strPath.substr(0,7).compare("file://")==0)
						strPath.erase(0,7);
					rho_wmimpl_set_configfilepath(strPath.c_str());
				}
			}
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

#if defined(OS_WINDOWS_DESKTOP)
			else if (wcsncmp(lpszToken, _T("http_proxy_url"),14)==0) 
			{
				if (value) {
					m_strHttpProxy = convertToStringA(value);
				}
				else 
					LOG(WARNING) + "invalid value for \"http_proxy_url\" cmd parameter";

			} else if (wcsncmp(lpszToken, _T("rhodespath"),10)==0) 
			{
				if (value) {
					m_strRhodesPath = convertToStringA(value);
					String_replace(m_strRhodesPath, '\\', '/');
				}
			} /* else if (wcsncmp(lpszToken, _T("appname"),7)==0) 
			{
				if (value) {
					m_strAppNameW = convertToStringW(value);
				}
			} else if (wcsncmp(lpszToken, _T("debughost"),9)==0) 
			{
				if (value) {
					m_strDebugHost = convertToStringA(value);
				}
			} else if (wcsncmp(lpszToken, _T("debugport"),9)==0) 
			{
				if (value) {
					m_strDebugPort = convertToStringA(value);
				}
			} */
#endif
		}
		if (value) free(value);
		lpszToken = nextToken;
	}

	return __super::ParseCommandLine(lpCmdLine, pnRetCode);
}
예제 #2
0
파일: Rhodes.cpp 프로젝트: codealot/rhodes
bool CRhodesModule::ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode ) throw( )
{
	m_nRestarting = 1;
	TCHAR szTokens[] = _T("-/");
	LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    getRhoRootPath();

	m_logPort = "";

	while (lpszToken != NULL)
	{
		if (WordCmpI(lpszToken, _T("Restarting"))==0) {
			m_nRestarting = 10;
		}

		if (wcsncmp(lpszToken, _T("log"), 3)==0) 
		{
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
			char* port = parseToken( token.c_str(), token.length() );
			if (port) {
				String strLogPort = port;
				m_logPort = strLogPort;
				free(port);
			}
			else {
				m_logPort = rho::String("11000");
			}
		}

#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
        else if (wcsnicmp(lpszToken, _T("s"),1)==0)
        {
			String token = convertToStringA(lpszToken);
			char* path = parseToken( token.c_str(), token.length() );
			if (path) {
				// RhoElements v1.0 compatibility mode
				rho_wmimpl_set_startpage(path);
				free(path);
			}
        }
        else if (wcsnicmp(lpszToken, _T("c"),1)==0)
        {
			String token = convertToStringA(lpszToken);
            char* path = parseToken( token.c_str(), token.length() );
			if (path) {
				rho_wmimpl_set_configfilepath(path);
				free(path);
			}
        }
#endif // APP_BUILD_CAPABILITY_MOTOROLA

#if defined(OS_WINDOWS)
		else if (wcsncmp(lpszToken, _T("http_proxy_url"),14)==0) 
        {
			String token = convertToStringA(lpszToken);
            char *proxy = parseToken( token.c_str(), token.length() );
			
			if (proxy)
            {
				m_strHttpProxy = proxy;
                free(proxy);
            }
			else 
				LOG(WARNING) + "invalid value for \"http_proxy_url\" cmd parameter";

		} else if (wcsncmp(lpszToken, _T("approot"),7)==0) 
        {
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
            char* path = parseToken( token.c_str(), token.length() );
			if (path) {
				int len = strlen(path);
				if (!(path[len-1]=='\\' || path[len-1]=='/')) {
#ifdef RHODES_EMULATOR
					path[len] = '/';
#else
					path[len] = '\\';
#endif
					path[len+1]  = 0;
				}
				m_strRootPath = path;
				free(path);
			}
		} else if (wcsncmp(lpszToken, _T("rhodespath"),10)==0) 
        {
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
            char* path = parseToken( token.c_str(), token.length() );
			if (path) {
				m_strRhodesPath = path;
				free(path);
			}
		} /* else if (wcsncmp(lpszToken, _T("appname"),7)==0) 
        {
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
            char* path = parseToken( token.c_str(), token.length() );
			if (path) {
                convertToStringW(path, m_strAppNameW);
				free(path);
			}
		} else if (wcsncmp(lpszToken, _T("debughost"),9)==0) 
        {
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
            char* host = parseToken( token.c_str(), token.length() );
			if (host) {
				m_strDebugHost = host;
				free(host);
			}
		} else if (wcsncmp(lpszToken, _T("debugport"),9)==0) 
        {
			String token = convertToStringA(lpszToken);
			//parseToken will allocate extra byte at the end of the returned token value
            char* port = parseToken( token.c_str(), token.length() );
			if (port) {
				m_strDebugPort = port;
				free(port);
			}
		} */
#else
        else if (wcsnicmp(lpszToken, _T("approot"),7)==0)
        {
            String token = convertToStringA(lpszToken);
			char* path = parseToken( token.c_str(), token.length() );
			if (path) {
				// RhoElements v2.0 Shared Runtime command line parameter
				m_strRootPath = path;
                if (m_strRootPath.substr(0,7).compare("file://")==0)
                    m_strRootPath.erase(0,7);
                ::std::replace(m_strRootPath.begin(), m_strRootPath.end(), '\\', '/');
                if (m_strRootPath.at(m_strRootPath.length()-1)!='/')
                    m_strRootPath.append("/");
                m_strRootPath.append("rho/");
        	}
			free(path);
        }
#endif
		lpszToken = FindOneOf(lpszToken, szTokens);
	}

	return __super::ParseCommandLine(lpCmdLine, pnRetCode);
}