コード例 #1
0
ファイル: Rhodes.cpp プロジェクト: parrotbait/rhodes
const rho::String& CRhodesModule::getRhoRuntimePath()
{
    if ( m_strRuntimePath.length() == 0 )
    {
        char rootpath[MAX_PATH];
        int len;
        if ( (len = GetModuleFileNameA(NULL,rootpath,MAX_PATH)) == 0 )
            strcpy(rootpath,".");
        else
        {
            while( !(rootpath[len] == '\\'  || rootpath[len] == '/') )
              len--;
            rootpath[len+1]=0;
        }

        m_strRuntimePath = rootpath;
        m_strRuntimePath += "rho\\";

        for(unsigned int i = 0; i < m_strRuntimePath.length(); i++ )
            if ( m_strRuntimePath.at(i) == '\\' )
                m_strRuntimePath[i] = '/';
    }

    return m_strRuntimePath; 
}
コード例 #2
0
ファイル: Rhodes.cpp プロジェクト: parrotbait/rhodes
// This method is called immediately before entering the message loop.
// It contains initialization code for the application.
// Returns:
// S_OK => Success. Continue with RunMessageLoop() and PostMessageLoop().
// S_FALSE => Skip RunMessageLoop(), call PostMessageLoop().
// error code => Failure. Skip both RunMessageLoop() and PostMessageLoop().
HRESULT CRhodesModule::PreMessageLoop(int nShowCmd) throw()
{
    HRESULT hr = __super::PreMessageLoop(nShowCmd);
    if (FAILED(hr))
    {
        return hr;
    }
    // Note: In this sample, we don't respond differently to different hr success codes.

#if !defined(OS_WINDOWS_DESKTOP)
    SetLastError(0);
    HANDLE hEvent = CreateEvent( NULL, false, false, CMainWindow::GetWndClassInfo().m_wc.lpszClassName );

    if ( !m_bRestarting && hEvent != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
    {
        // Rho Running so could bring to foreground
        HWND hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);

        if (hWnd)
        {
            ShowWindow(hWnd, SW_SHOW);
            SendMessage( hWnd, PB_WINDOW_RESTORE, NULL, TRUE);
            SetForegroundWindow( hWnd );

            COPYDATASTRUCT cds = {0};
            cds.cbData = m_strTabName.length()+1;
            cds.lpData = (char*)m_strTabName.c_str();
            SendMessage( hWnd, WM_COPYDATA, (WPARAM)WM_WINDOW_SWITCHTAB, (LPARAM)(LPVOID)&cds);
        }

        return S_FALSE;
    }
#endif

    if ( !rho_sys_check_rollback_bundle(rho_native_rhopath()) )
    {
        rho_sys_impl_exit_with_errormessage( "Bundle update", "Application is corrupted. Reinstall it, please.");
        return S_FALSE;
    }

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    rho_logconf_Init((rho_wmimpl_get_logpath()[0]==0 ? m_strRootPath.c_str() : rho_wmimpl_get_logpath()), m_strRootPath.c_str(), m_logPort.c_str());
    if (rho_wmimpl_get_logurl()[0]!=0)
        LOGCONF().setLogURL(rho_wmimpl_get_logurl());
    if (rho_wmimpl_get_logmaxsize())
        LOGCONF().setMaxLogFileSize(*rho_wmimpl_get_logmaxsize());
    if (rho_wmimpl_get_loglevel())
        LOGCONF().setMinSeverity(*rho_wmimpl_get_loglevel());
    if (rho_wmimpl_get_fullscreen())
        RHOCONF().setBool("full_screen", true, false);
    if (rho_wmimpl_get_logmemperiod())
        LOGCONF().setCollectMemoryInfoInterval(*rho_wmimpl_get_logmemperiod());
#else
    rho_logconf_Init(m_strRootPath.c_str(), m_strRootPath.c_str(), m_logPort.c_str());
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

    LOGCONF().setMemoryInfoCollector(CLogMemory::getInstance());

#ifdef RHODES_EMULATOR
    RHOSIMCONF().setAppConfFilePath(CFilePath::join( m_strRootPath, RHO_EMULATOR_DIR"/rhosimconfig.txt").c_str());
    RHOSIMCONF().loadFromFile();
    if ( m_strRhodesPath.length() > 0 )
        RHOSIMCONF().setString("rhodes_path", m_strRhodesPath, false );
    RHOCONF().setString("rhosim_platform", RHOSIMCONF().getString("platform"), false);
    RHOCONF().setString("app_version", RHOSIMCONF().getString("app_version"), false);
	String start_path = RHOSIMCONF().getString("start_path");
    if ( start_path.length() > 0 )
	    RHOCONF().setString("start_path", start_path, false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/debugger;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/uri;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/timeout;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/digest;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/openssl;"), false);
#endif

    if ( !rho_rhodesapp_canstartapp(g_strCmdLine.c_str(), " /-,") )
    {
		LOG(INFO) + "This is hidden app and can be started only with security key.";
		if (RHOCONF().getString("invalid_security_token_start_path").length() <= 0)
        {
#ifdef OS_WINDOWS_DESKTOP
	    ::MessageBoxW(0, L"This is hidden app and can be started only with security key.", L"Security Token Verification Failed", MB_ICONERROR | MB_OK);
#endif
			return S_FALSE;
        }
    }

	LOG(INFO) + "Rhodes started";
#ifdef OS_WINDOWS_DESKTOP
	if (m_strHttpProxy.length() > 0) {
		parseHttpProxyURI(m_strHttpProxy);
	} else
#endif
	{
		if (RHOCONF().isExist("http_proxy_url")) {
			parseHttpProxyURI(RHOCONF().getString("http_proxy_url"));
#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
		} else {
			// it's important to call this method from here to perform
			// a proper initialization of proxy implementation for Win32
			GetAppWindow().setProxy();
#endif
		}
	}

#ifdef RHODES_EMULATOR
    if (RHOSIMCONF().getString("debug_host").length() > 0)
        SetEnvironmentVariableA("RHOHOST", RHOSIMCONF().getString("debug_host").c_str() );
    if (RHOSIMCONF().getString("debug_port").length() > 0)
        SetEnvironmentVariableA("rho_debug_port", RHOSIMCONF().getString("debug_port").c_str() );
#endif

	//Check for bundle directory is exists.
	HANDLE hFind;
	WIN32_FIND_DATA wfd;
	
	// rootpath + "rho/"
	if (m_strRootPath.at(m_strRootPath.length()-1) == '/') 
    {
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, m_strRootPath.find_last_of('/'))).c_str(), &wfd);
	} 
    else if (m_strRootPath.at(m_strRootPath.length()-1) == '\\') 
    {
		//delete all '\' from the end of the pathname
		int i = m_strRootPath.length();
		for ( ; i != 1; i--) {
			if (m_strRootPath.at(i-1) != '\\')
				break;
		}

		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, i)).c_str(), &wfd);
	}

	if (INVALID_HANDLE_VALUE == hFind || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
    {
		int last = 0, pre_last = 0;
		last = getRhoRootPath().find_last_of('\\');
		pre_last = getRhoRootPath().substr(0, last).find_last_of('\\');
		String appName = getRhoRootPath().substr(pre_last + 1, last - pre_last - 1);

		String messageText = "Bundle directory \"" + 
								m_strRootPath.substr(0, m_strRootPath.find_last_of('/')) + 
								"\" is  missing\n";

		LOG(INFO) + messageText;
		int msgboxID = MessageBox(NULL,
									convertToStringW(messageText).c_str(),
									convertToStringW(appName).c_str(),
									MB_ICONERROR | MB_OK);


		return S_FALSE;
    }

    if (RHOCONF().getBool("Application.autoStart"))
        createAutoStartShortcut();

    rho::common::CRhodesApp::Create(m_strRootPath, m_strRootPath, m_strRuntimePath);

    bool bRE1App = false;

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if (!rho_wmimpl_get_is_version2())
        bRE1App = true;
#endif

    RHODESAPP().setJSApplication(bRE1App || _AtlModule.isJSApplication());

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if ((!rho_wmimpl_get_is_version2()) && (rho_wmimpl_get_startpage()[0] != 0)) {
        String spath = convertToStringA(rho_wmimpl_get_startpage());
        RHOCONF().setString("start_path", spath, false);
    }
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

    DWORD dwStyle = m_bMinimized ? 0 : WS_VISIBLE;

#ifdef OS_WINCE
    m_appWindow.getTabbar().SetStartTabName(m_strTabName);
#else
    m_appWindow.setStartTabName(m_strTabName);
#endif

#if !defined(_WIN32_WCE)
    dwStyle |= WS_OVERLAPPEDWINDOW;
#endif
    // Create the main application window
#if defined(OS_WINDOWS_DESKTOP)
#ifdef RHODES_EMULATOR
    StringW windowTitle = convertToStringW(RHOSIMCONF().getString("app_name"));
#else
    StringW windowTitle = convertToStringW(RHODESAPP().getAppTitle());
#endif
    m_appWindow.Initialize(windowTitle.c_str());
    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }
    if (m_bMinimized)
        nShowCmd = SW_MINIMIZE;

    m_appWindow.ShowWindow(nShowCmd);

#else
    String strTitle = RHODESAPP().getAppTitle();
    m_appWindow.Create(NULL, CWindow::rcDefault, convertToStringW(strTitle).c_str(), dwStyle);

    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }

    m_appWindow.InvalidateRect(NULL, TRUE);
    m_appWindow.UpdateWindow();

    m_appWindow.initBrowserWindow();

    if (m_bMinimized)
        m_appWindow.ShowWindow(SW_MINIMIZE);
#endif

/*
    if (bRE1App)
    {
#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
        registerRhoExtension();
#endif

#if !defined( APP_BUILD_CAPABILITY_WEBKIT_BROWSER ) && defined(OS_WINCE)
	    m_appWindow.Navigate2(_T("about:blank"), -1 );
#endif //!APP_BUILD_CAPABILITY_WEBKIT_BROWSER

        rho_webview_navigate(RHOCONF().getString("start_path").c_str(), 0 );
    }
    else
    { */
        RHODESAPP().startApp();

#if !defined( APP_BUILD_CAPABILITY_WEBKIT_BROWSER ) && defined(OS_WINCE)
        // Navigate to the "loading..." page
	    m_appWindow.Navigate2(_T("about:blank"), -1 );
#endif //APP_BUILD_CAPABILITY_WEBKIT_BROWSER
    //}

#if defined(_WIN32_WCE)&& !defined( OS_PLATFORM_MOTCE )

    DWORD dwConnCount = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
        &dwConnCount
    );
    rho_sysimpl_sethas_network((dwConnCount > 1) ? 1 : 0);

    DWORD dwCellConnected = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
        &dwCellConnected
    );
    rho_sysimpl_sethas_cellnetwork(dwCellConnected);

	// Register for changes in the number of network connections
	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCOUNT, 
		0, 
		NULL, 
		&g_hNotify);

	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCELL, 
		0, 
		NULL, 
		&g_hNotifyCell);

#endif

    return S_OK;
}
コード例 #3
0
ファイル: Rhodes.cpp プロジェクト: parrotbait/rhodes
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);
}
コード例 #4
0
// This method is called immediately before entering the message loop.
// It contains initialization code for the application.
// Returns:
// S_OK => Success. Continue with RunMessageLoop() and PostMessageLoop().
// S_FALSE => Skip RunMessageLoop(), call PostMessageLoop().
// error code => Failure. Skip both RunMessageLoop() and PostMessageLoop().
HRESULT CRhodesModule::PreMessageLoop(int nShowCmd) throw()
{
    HRESULT hr = __super::PreMessageLoop(nShowCmd);
    if (FAILED(hr))
    {
        return hr;
    }
    // Note: In this sample, we don't respond differently to different hr success codes.

#if !defined(OS_WINDOWS_DESKTOP)
    // Allow only one instance of the application.
    // the "| 0x01" activates the correct owned window of the previous instance's main window
	HWND hWnd = NULL;
	for (int wait = 0; wait < m_nRestarting; wait++) {
		hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);
		if (hWnd && m_nRestarting > 1) {
			Sleep(1000);
		} else {
			break;
		}
	}
	//EnumWindows(EnumRhodesWindowsProc, (LPARAM)&hWnd);

	if (hWnd)
	{
        SendMessage( hWnd, PB_WINDOW_RESTORE, NULL, TRUE);
        SetForegroundWindow( hWnd );
		return S_FALSE;
	}

	// creating mutex
/*	m_hMutex = CreateMutex(NULL, TRUE, CMainWindow::GetWndClassInfo().m_wc.lpszClassName);
	if (m_hMutex==NULL) {
		// Failed to create mutex
		return S_FALSE;
	}
	if ((GetLastError() == ERROR_ALREADY_EXISTS) && (WaitForSingleObject(m_hMutex, 60000L) != WAIT_OBJECT_0)) {
        rho_sys_impl_exit_with_errormessage( "Initialization", "Another instance of the application is running. Please, exit it or use Task Manager to terminate it.");
        return S_FALSE;
	}*/
#endif

    if ( !rho_sys_check_rollback_bundle(rho_native_rhopath()) )
    {
        rho_sys_impl_exit_with_errormessage( "Bundle update", "Application is corrupted. Reinstall it, please.");
        return S_FALSE;
    }

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    rho_logconf_Init((rho_wmimpl_get_logpath()[0]==0 ? m_strRootPath.c_str() : rho_wmimpl_get_logpath()), m_strRootPath.c_str(), m_logPort.c_str());
    if (rho_wmimpl_get_logurl()[0]!=0)
		LOGCONF().setLogURL(rho_wmimpl_get_logurl());
	if (rho_wmimpl_get_logmaxsize())
		LOGCONF().setMaxLogFileSize(*rho_wmimpl_get_logmaxsize());
    if (rho_wmimpl_get_loglevel())
		LOGCONF().setMinSeverity(*rho_wmimpl_get_loglevel());
    if (rho_wmimpl_get_fullscreen())
        RHOCONF().setBool("full_screen", true, false);
	if (rho_wmimpl_get_logmemperiod())
		LOGCONF().setCollectMemoryInfoInterval(*rho_wmimpl_get_logmemperiod());
#else
    rho_logconf_Init(m_strRootPath.c_str(), m_strRootPath.c_str(), m_logPort.c_str());
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

//#if !defined(RHODES_EMULATOR) && !defined(OS_WINDOWS_DESKTOP)
	LOGCONF().setMemoryInfoCollector(CLogMemory::getInstance());
//#endif // RHODES_EMULATOR

#ifdef RHODES_EMULATOR
    RHOSIMCONF().setAppConfFilePath(CFilePath::join( m_strRootPath, RHO_EMULATOR_DIR"/rhosimconfig.txt").c_str());
    RHOSIMCONF().loadFromFile();
    if ( m_strRhodesPath.length() > 0 )
        RHOSIMCONF().setString("rhodes_path", m_strRhodesPath, false );
    RHOCONF().setString("rhosim_platform", RHOSIMCONF().getString("platform"), false);
    RHOCONF().setString("app_version", RHOSIMCONF().getString("app_version"), false);
	String start_path = RHOSIMCONF().getString("start_path");
    if ( start_path.length() > 0 )
	    RHOCONF().setString("start_path", start_path, false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/debugger;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/uri;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/timeout;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/digest;"), false);
    RHOSIMCONF().setString("ext_path", RHOSIMCONF().getString("ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/openssl;"), false);
#endif

    if ( !rho_rhodesapp_canstartapp(g_strCmdLine.c_str(), " /-,") )
    {
#ifdef OS_WINDOWS_DESKTOP
	    ::MessageBoxW(0, L"This is hidden app and can be started only with security key.", L"Security Token Verification Failed", MB_ICONERROR | MB_OK);
#endif
		LOG(INFO) + "This is hidden app and can be started only with security key.";
		if (RHOCONF().getString("invalid_security_token_start_path").length() <= 0)
			return S_FALSE;
    }

	LOG(INFO) + "Rhodes started";
#ifdef OS_WINDOWS_DESKTOP
	if (m_strHttpProxy.length() > 0) {
		parseHttpProxyURI(m_strHttpProxy);
	} else
#endif
	{
		if (RHOCONF().isExist("http_proxy_url")) {
			parseHttpProxyURI(RHOCONF().getString("http_proxy_url"));
#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
		} else {
			// it's important to call this method from here to perform
			// a proper initialization of proxy implementation for Win32
			GetAppWindow().setProxy();
#endif
		}
	}

#ifdef RHODES_EMULATOR
    if (RHOSIMCONF().getString("debug_host").length() > 0)
        SetEnvironmentVariableA("RHOHOST", RHOSIMCONF().getString("debug_host").c_str() );
    if (RHOSIMCONF().getString("debug_port").length() > 0)
        SetEnvironmentVariableA("rho_debug_port", RHOSIMCONF().getString("debug_port").c_str() );
#endif

    //::SetThreadPriority(GetCurrentThread(),10);

	//Check for bundle directory is exists.
	HANDLE hFind;
	WIN32_FIND_DATA wfd;
	
	// rootpath + "rho/"
	if (m_strRootPath.at(m_strRootPath.length()-1) == '/') {
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, m_strRootPath.find_last_of('/'))).c_str(), &wfd);
	} else if (m_strRootPath.at(m_strRootPath.length()-1) == '\\') {
		//delete all '\' from the end of the pathname
		int i = m_strRootPath.length();
		for ( ; i != 1; i--) {
			if (m_strRootPath.at(i-1) != '\\')
				break;
		}
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, i)).c_str(), &wfd);
	}

	if (INVALID_HANDLE_VALUE == hFind || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
		int last = 0, pre_last = 0;
		last = getRhoRootPath().find_last_of('\\');
		pre_last = getRhoRootPath().substr(0, last).find_last_of('\\');
		String appName = getRhoRootPath().substr(pre_last + 1, last - pre_last - 1);

		String messageText = "Bundle directory \"" + 
								m_strRootPath.substr(0, m_strRootPath.find_last_of('/')) + 
								"\" is  missing\n";

		LOG(INFO) + messageText;
		int msgboxID = MessageBox(NULL,
									convertToStringW(messageText).c_str(),
									convertToStringW(appName).c_str(),
									MB_ICONERROR | MB_OK);


		return S_FALSE;
    }

    rho::common::CRhodesApp::Create(m_strRootPath, m_strRootPath, m_strRuntimePath);
    RHODESAPP().setExtManager( &m_oExtManager );

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if ((!rho_wmimpl_get_is_version2()) && (rho_wmimpl_get_startpage()[0] != 0)) {
        String spath = convertToStringA(rho_wmimpl_get_startpage());
        RHOCONF().setString("start_path", spath, false);
    }
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

    DWORD dwStyle = WS_VISIBLE;

#if !defined(_WIN32_WCE)
    dwStyle |= WS_OVERLAPPEDWINDOW;
#endif
    // Create the main application window
#if defined(OS_WINDOWS_DESKTOP)
#ifdef RHODES_EMULATOR
    StringW windowTitle = convertToStringW(RHOSIMCONF().getString("app_name"));
#else
    StringW windowTitle = convertToStringW(RHODESAPP().getAppTitle());
#endif
    m_appWindow.Initialize(windowTitle.c_str());
    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }
    m_appWindow.ShowWindow(nShowCmd);

#ifndef RHODES_EMULATOR
    rho_wm_impl_CheckLicense();
#endif

#else
    String strTitle = RHODESAPP().getAppTitle();
    m_appWindow.Create(NULL, CWindow::rcDefault, convertToStringW(strTitle).c_str(), dwStyle);

	//if( m_isRhoConnectPush )
	//	m_appWindow.ShowWindow(SW_MINIMIZE);

    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }

/*#ifdef APP_BUILD_CAPABILITY_WEBKIT_BROWSER
    {
        CBarcodeInit oBarcodeInit;

        if (!rho_wmimpl_get_webkitbrowser( (HWND)m_appWindow.m_hWnd, rho_wmimpl_get_appinstance() )) {
            MessageBox(NULL, L"Failed to initialize WebKit engine.", convertToStringW(strTitle).c_str(), MB_ICONERROR | MB_OK);
	        return S_FALSE;
        }
    }
#endif
*/
    m_appWindow.InvalidateRect(NULL, TRUE);
    m_appWindow.UpdateWindow();

    m_appWindow.initBrowserWindow();
#endif

    bool bRE1App = false;
#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if (!rho_wmimpl_get_is_version2())
        bRE1App = true;
#endif

    if (bRE1App)
    {
#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
        registerRhoExtension();
#endif
	    m_appWindow.Navigate2(_T("about:blank")
#if defined(OS_WINDOWS_DESKTOP)
            , -1
#endif
        );
        
        rho_webview_navigate( RHOCONF().getString("start_path").c_str(), 0 );
/*    	m_appWindow.Navigate2( convertToStringW( RHOCONF().getString("start_path") ).c_str()
#if defined(OS_WINDOWS_DESKTOP)
            , -1
#endif
        );*/
    }
    else
    {
        RHODESAPP().startApp();

        // Navigate to the "loading..." page
	    m_appWindow.Navigate2(_T("about:blank")
    #if defined(OS_WINDOWS_DESKTOP)
            , -1
    #endif
        );
    }
    // Show the main application window
    //m_appWindow.ShowWindow(nShowCmd);

#if defined(_WIN32_WCE)&& !defined( OS_PLATFORM_MOTCE )

    DWORD dwConnCount = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
        &dwConnCount
    );
    rho_sysimpl_sethas_network(dwConnCount);

    DWORD dwCellConnected = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
        &dwCellConnected
    );
    rho_sysimpl_sethas_cellnetwork(dwCellConnected);

	// Register for changes in the number of network connections
	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCOUNT, 
		0, 
		NULL, 
		&g_hNotify);

	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCELL, 
		0, 
		NULL, 
		&g_hNotifyCell);

#elif !defined( OS_PLATFORM_MOTCE )
    if (RHOCONF().getString("test_push_client").length() > 0 ) 
	    rho_clientregister_create(RHOCONF().getString("test_push_client").c_str());//"win32_client");
#endif

    return S_OK;
}
コード例 #5
0
ファイル: Rhodes.cpp プロジェクト: codealot/rhodes
// This method is called immediately before entering the message loop.
// It contains initialization code for the application.
// Returns:
// S_OK => Success. Continue with RunMessageLoop() and PostMessageLoop().
// S_FALSE => Skip RunMessageLoop(), call PostMessageLoop().
// error code => Failure. Skip both RunMessageLoop() and PostMessageLoop().
HRESULT CRhodesModule::PreMessageLoop(int nShowCmd) throw()
{
    HRESULT hr = __super::PreMessageLoop(nShowCmd);
    if (FAILED(hr))
    {
        return hr;
    }
    // Note: In this sample, we don't respond differently to different hr success codes.

#ifndef RHODES_EMULATOR
    // Allow only one instance of the application.
    // the "| 0x01" activates the correct owned window of the previous instance's main window
	HWND hWnd = NULL;
	for (int wait = 0; wait < m_nRestarting; wait++) {
		hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);
		if (hWnd && m_nRestarting > 1) {
			Sleep(1000);
		} else {
			break;
		}
	}
	//EnumWindows(EnumRhodesWindowsProc, (LPARAM)&hWnd);

	if (hWnd)
	{
		SetForegroundWindow( HWND( DWORD(hWnd) | 0x01 ) );
		return S_FALSE;
	}
#endif

    if ( !rho_sys_check_rollback_bundle(rho_native_rhopath()) )
    {
        rho_sys_impl_exit_with_errormessage( "Bundle update.", "Application is currupted. Reinstall it , please.");
        return S_FALSE;
    }

	rho_logconf_Init(m_strRootPath.c_str(), m_logPort.c_str());

#ifdef RHODES_EMULATOR
    RHOSIMCONF().setAppConfFilePath(CFilePath::join( m_strRootPath, RHO_EMULATOR_DIR"/rhosimconfig.txt").c_str());
    RHOSIMCONF().loadFromFile();
    if ( m_strRhodesPath.length() > 0 )
        RHOSIMCONF().setString("rhodes_path", m_strRhodesPath, false );
    RHOCONF().setString( "rhosim_platform", RHOSIMCONF().getString( "platform"), false);
    RHOCONF().setString( "app_version", RHOSIMCONF().getString( "app_version"), false);
    RHOSIMCONF().setString( "ext_path", RHOSIMCONF().getString( "ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/debugger;"), false);
    RHOSIMCONF().setString( "ext_path", RHOSIMCONF().getString( "ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/uri;"), false);
    RHOSIMCONF().setString( "ext_path", RHOSIMCONF().getString( "ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/timeout;"), false);
    RHOSIMCONF().setString( "ext_path", RHOSIMCONF().getString( "ext_path") + CFilePath::join( m_strRhodesPath, "/lib/extensions/digest;"), false);
#endif

    if ( !rho_rhodesapp_canstartapp(g_strCmdLine.c_str(), " /-,") )
    {
		LOG(INFO) + "This is hidden app and can be started only with security key.";
		//return S_FALSE;
    }

	LOG(INFO) + "Rhodes started";
#ifdef OS_WINDOWS
	if (m_strHttpProxy.length() > 0) {
		parseHttpProxyURI(m_strHttpProxy);
	} else {
		if (RHOCONF().isExist("http_proxy_url")) {
			parseHttpProxyURI(RHOCONF().getString("http_proxy_url"));
		}
	}
#ifdef RHODES_EMULATOR
    if (RHOSIMCONF().getString("debug_host").length() > 0)
        SetEnvironmentVariableA("RHOHOST", RHOSIMCONF().getString("debug_host").c_str() );
    if (RHOSIMCONF().getString("debug_port").length() > 0)
        SetEnvironmentVariableA("rho_debug_port", RHOSIMCONF().getString("debug_port").c_str() );
#endif

#endif
    //::SetThreadPriority(GetCurrentThread(),10);

	//Check for bundle directory is exists.
	HANDLE hFind;
	WIN32_FIND_DATA wfd;
	
	// rootpath + "rho/"
	if (m_strRootPath.at(m_strRootPath.length()-1) == '/') {
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, m_strRootPath.find_last_of('/'))).c_str(), &wfd);
	} else if (m_strRootPath.at(m_strRootPath.length()-1) == '\\') {
		//delete all '\' from the end of the pathname
		int i = m_strRootPath.length();
		for ( ; i != 1; i--) {
			if (m_strRootPath.at(i-1) != '\\')
				break;
		}
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, i)).c_str(), &wfd);
	}

	if (INVALID_HANDLE_VALUE == hFind || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
		int last = 0, pre_last = 0;
		last = getRhoRootPath().find_last_of('\\');
		pre_last = getRhoRootPath().substr(0, last).find_last_of('\\');
		String appName = getRhoRootPath().substr(pre_last + 1, last - pre_last - 1);

		String messageText = "Bundle directory \"" + 
								m_strRootPath.substr(0, m_strRootPath.find_last_of('/')) + 
								"\" is  missing\n";

		LOG(INFO) + messageText;
		int msgboxID = MessageBox(NULL,
									convertToStringW(messageText).c_str(),
									convertToStringW(appName).c_str(),
									MB_ICONERROR | MB_OK);


		return S_FALSE;
    }

    rho::common::CRhodesApp::Create(m_strRootPath, m_strRootPath, m_strRuntimePath);
    RHODESAPP().setExtManager( &m_oExtManager );

    DWORD dwStyle = WS_VISIBLE;

#if !defined(_WIN32_WCE)
    dwStyle |= WS_OVERLAPPEDWINDOW;
#endif
    // Create the main application window
#ifdef RHODES_EMULATOR
    m_appWindow.Initialize(convertToStringW(RHOSIMCONF().getString("app_name")).c_str());
#else
    String strTitle = RHODESAPP().getAppTitle();
    m_appWindow.Create(NULL, CWindow::rcDefault, convertToStringW(strTitle).c_str(), dwStyle);

#ifdef APP_BUILD_CAPABILITY_WEBKIT_BROWSER
    {
        CBarcodeInit oBarcodeInit;

        if (!rho_wmimpl_get_webkitbrowser( (HWND)m_appWindow.m_hWnd, rho_wmimpl_get_appinstance() )) {
            MessageBox(NULL, L"Failed to initialize WebKit engine.", convertToStringW(strTitle).c_str(), MB_ICONERROR | MB_OK);
	        return S_FALSE;
        }
    }
#endif

#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
    if (rho_wmimpl_get_startpage()[0] != 0) {
        String spath = convertToStringA(rho_wmimpl_get_startpage());
        RHOCONF().setString("start_path", spath, false);
    }
#endif // APP_BUILD_CAPABILITY_MOTOROLA


    m_appWindow.InitMainWindow();
#endif
    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }


    RHODESAPP().startApp();

    // Navigate to the "loading..." page
	m_appWindow.Navigate2(_T("about:blank")
#ifdef RHODES_EMULATOR
        , -1
#endif
    );
    // Show the main application window
    m_appWindow.ShowWindow(nShowCmd);

#if defined(_WIN32_WCE)&& !defined( OS_PLATFORM_MOTCE )

    DWORD dwConnCount = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
        &dwConnCount
    );
    rho_sysimpl_sethas_network(dwConnCount);

    DWORD dwCellConnected = 0;
    hr = RegistryGetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
        &dwCellConnected
    );
    rho_sysimpl_sethas_cellnetwork(dwCellConnected);

	// Register for changes in the number of network connections
	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CONNECTIONSNETWORKCOUNT_PATH, 
		SN_CONNECTIONSNETWORKCOUNT_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCOUNT, 
		0, 
		NULL, 
		&g_hNotify);

	hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		SN_CELLSYSTEMCONNECTED_PATH, 
		SN_CELLSYSTEMCONNECTED_VALUE, 
		m_appWindow.m_hWnd, 
		WM_CONNECTIONSNETWORKCELL, 
		0, 
		NULL, 
		&g_hNotifyCell);

#else
	rho_clientregister_create("win32_client");
#endif

    return S_OK;
}
コード例 #6
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);
}
コード例 #7
0
ファイル: Rhodes.cpp プロジェクト: rhosilver/rhodes-1
// This method is called immediately before entering the message loop.
// It contains initialization code for the application.
// Returns:
// S_OK => Success. Continue with RunMessageLoop() and PostMessageLoop().
// S_FALSE => Skip RunMessageLoop(), call PostMessageLoop().
// error code => Failure. Skip both RunMessageLoop() and PostMessageLoop().
HRESULT CRhodesModule::PreMessageLoop(int nShowCmd) throw()
{
    HRESULT hr;
	/*HRESULT hr = __super::PreMessageLoop(nShowCmd);
    if (FAILED(hr))
    {
        return hr;
    }*/
    // Note: In this sample, we don't respond differently to different hr success codes.

    //SetLastError(0);
//    HANDLE hEvent = CreateEvent( NULL, false, false, CMainWindow::GetWndClassInfo().m_wc.lpszClassName );

  //  if ( !m_bRestarting && hEvent != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
    //{
        // Rho Running so could bring to foreground
      //  HWND hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);

        //if (hWnd)
        //{
          //  ShowWindow(hWnd, SW_SHOW);
            //SendMessage( hWnd, PB_WINDOW_RESTORE, NULL, TRUE);
            //SetForegroundWindow( hWnd );

            //COPYDATASTRUCT cds = {0};
            //cds.cbData = m_strTabName.length()+1;
            //cds.lpData = (char*)m_strTabName.c_str();
            //SendMessage( hWnd, WM_COPYDATA, (WPARAM)WM_WINDOW_SWITCHTAB, (LPARAM)(LPVOID)&cds);
        //}

        //return S_FALSE;
    //}

    if ( !rho_sys_check_rollback_bundle(rho_native_rhopath()) )
    {
        rho_sys_impl_exit_with_errormessage( "Bundle update", "Application is corrupted. Reinstall it, please.");
        return S_FALSE;
    }

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    rho_logconf_Init((rho_wmimpl_get_logpath()[0]==0 ? m_strRootPath.c_str() : rho_wmimpl_get_logpath()), m_strRootPath.c_str(), m_logPort.c_str());
    if (rho_wmimpl_get_logurl()[0]!=0)
	{
        LOGCONF().setLogURL(rho_wmimpl_get_logurl());
		LOGCONF().setLogToSocket(true);
	}
    if (rho_wmimpl_get_logmaxsize())
        LOGCONF().setMaxLogFileSize(*rho_wmimpl_get_logmaxsize());
    if (rho_wmimpl_get_loglevel())
        LOGCONF().setMinSeverity(*rho_wmimpl_get_loglevel());
    if (rho_wmimpl_get_fullscreen())
        RHOCONF().setBool("full_screen", true, false);
    if (rho_wmimpl_get_logmemperiod())
        LOGCONF().setCollectMemoryInfoInterval(*rho_wmimpl_get_logmemperiod());
    //SR EMBPD00121468
    //Network api via proxy is not working with proxy enable using config.xml 
    //Sabir: The values were getting set from rhoconfig.txt from function rho_logconf_Init
    //fix: we have to override http_proxy_host using config.xml value
    rho::String szHttpProxy =  rho_wmimpl_get_httpproxy();
    parseHttpProxyURI(szHttpProxy);
#else
    rho_logconf_Init(m_strRootPath.c_str(), m_strRootPath.c_str(), m_logPort.c_str());
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

 SetLastError(0);
 HANDLE hEvent = CreateEvent( NULL, false, false, CMainWindow::GetWndClassInfo().m_wc.lpszClassName );

    if ( !m_bRestarting && hEvent != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
    {
        // Rho Running so could bring to foreground
        HWND hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);

        if (hWnd)
        {
            ShowWindow(hWnd, SW_SHOW);
            SendMessage( hWnd, PB_WINDOW_RESTORE, NULL, TRUE);
            SetForegroundWindow( hWnd );

            COPYDATASTRUCT cds = {0};
            cds.cbData = m_strTabName.length()+1;
            cds.lpData = (char*)m_strTabName.c_str();
            SendMessage( hWnd, WM_COPYDATA, (WPARAM)WM_WINDOW_SWITCHTAB, (LPARAM)(LPVOID)&cds);
        }

        return S_FALSE;
    }



    LOGCONF().setMemoryInfoCollector(CLogMemory::getInstance());

    if ( !rho_rhodesapp_canstartapp(g_strCmdLine.c_str(), " /-,") )
    {
		LOG(INFO) + "This is hidden app and can be started only with security key.";
		if (RHOCONF().getString("invalid_security_token_start_path").length() <= 0)
        {
			return S_FALSE;
        }
    }

	LOG(INFO) + "Rhodes started";
	if (RHOCONF().isExist("http_proxy_url")) {
		parseHttpProxyURI(RHOCONF().getString("http_proxy_url"));
	} else if (RHOCONF().isExist("http_proxy_uri")) {
		parseHttpProxyURI(RHOCONF().getString("http_proxy_uri"));
	}


	//Check for bundle directory is exists.
	HANDLE hFind;
	WIN32_FIND_DATA wfd;
	
	// rootpath + "rho/"
	if (m_strRootPath.at(m_strRootPath.length()-1) == '/') 
    {
		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, m_strRootPath.find_last_of('/'))).c_str(), &wfd);
	} 
    else if (m_strRootPath.at(m_strRootPath.length()-1) == '\\') 
    {
		//delete all '\' from the end of the pathname
		int i = m_strRootPath.length();
		for ( ; i != 1; i--) {
			if (m_strRootPath.at(i-1) != '\\')
				break;
		}

		hFind = FindFirstFile(convertToStringW(m_strRootPath.substr(0, i)).c_str(), &wfd);
	}

	if (INVALID_HANDLE_VALUE == hFind || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
    {
		int last = 0, pre_last = 0;
		last = getRhoRootPath().find_last_of('\\');
		pre_last = getRhoRootPath().substr(0, last).find_last_of('\\');
		String appName = getRhoRootPath().substr(pre_last + 1, last - pre_last - 1);

		String messageText = "Bundle directory \"" + 
								m_strRootPath.substr(0, m_strRootPath.find_last_of('/')) + 
								"\" is  missing\n";

		LOG(INFO) + messageText;
		int msgboxID = MessageBox(NULL,
									convertToStringW(messageText).c_str(),
									convertToStringW(appName).c_str(),
									MB_ICONERROR | MB_OK);


		return S_FALSE;
    }

    createPowerManagementThread();

    if (RHOCONF().getBool("Application.autoStart"))
        createAutoStartShortcut();

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if ((!rho_wmimpl_get_is_version2()) && (rho_wmimpl_get_startpage()[0] != 0)) {
        String spath = convertToStringA(rho_wmimpl_get_startpage());
        RHOCONF().setString("start_path", spath, false);
    }
#endif // APP_BUILD_CAPABILITY_SHARED_RUNTIME

    rho::common::CRhodesApp::Create(m_strRootPath, m_strRootPath, m_strRuntimePath);

    set_bridge_direct_callback();

    bool bRE1App = false;

#if defined(APP_BUILD_CAPABILITY_SHARED_RUNTIME)
    if (!rho_wmimpl_get_is_version2())
        bRE1App = true;
#endif

    RHODESAPP().setJSApplication(bRE1App || _AtlModule.isJSApplication());

    DWORD dwStyle = m_bMinimized ? 0 : WS_VISIBLE;

#ifdef OS_WINCE
    m_appWindow.getTabbar().SetStartTabName(m_strTabName);
#else
    m_appWindow.setStartTabName(m_strTabName);
#endif

#if !defined(_WIN32_WCE)
    dwStyle |= WS_OVERLAPPEDWINDOW;
#endif
    // Create the main application window
    String strTitle = RHODESAPP().getAppTitle();
    m_appWindow.Create(NULL, CWindow::rcDefault, convertToStringW(strTitle).c_str(), dwStyle);

    if (NULL == m_appWindow.m_hWnd)
    {
        return S_FALSE;
    }

    m_appWindow.InvalidateRect(NULL, TRUE);
	m_appWindow.SetActiveWindow();	//  Enterprise Browser was failing to launch maximimized through a shortcut, this line ensures it launches maximised
    m_appWindow.UpdateWindow();
#if defined(APP_BUILD_CAPABILITY_SYMBOL)
	initialiseRhoElementsExt();
#endif
    m_appWindow.initBrowserWindow();

    if (m_bMinimized)
        m_appWindow.ShowWindow(SW_MINIMIZE);

/*
    if (bRE1App)
    {
#if defined(APP_BUILD_CAPABILITY_SYMBOL)
        registerRhoExtension();
#endif

#if !defined( APP_BUILD_CAPABILITY_WEBKIT_BROWSER ) && defined(OS_WINCE)
	    m_appWindow.Navigate2(_T("about:blank"), -1 );
#endif //!APP_BUILD_CAPABILITY_WEBKIT_BROWSER

        rho_webview_navigate(RHOCONF().getString("start_path").c_str(), 0 );
    }
    else
    { */
        RHODESAPP().startApp();

#if !defined( APP_BUILD_CAPABILITY_WEBKIT_BROWSER ) && defined(OS_WINCE)
        // Navigate to the "loading..." page
	    m_appWindow.Navigate2(_T("about:blank"), -1 );
#endif //APP_BUILD_CAPABILITY_WEBKIT_BROWSER
    //}

#if defined(_WIN32_WCE)
    if(RHO_IS_WMDEVICE)
    {

        DWORD dwConnCount = 0;
        hr = lpfn_Registry_GetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		    SN_CONNECTIONSNETWORKCOUNT_PATH, 
		    SN_CONNECTIONSNETWORKCOUNT_VALUE, 
            &dwConnCount
        );
        rho_sysimpl_sethas_network((dwConnCount > 1) ? 1 : 0);

        DWORD dwCellConnected = 0;
        hr = lpfn_Registry_GetDWORD( SN_CONNECTIONSNETWORKCOUNT_ROOT,
		    SN_CELLSYSTEMCONNECTED_PATH, 
		    SN_CELLSYSTEMCONNECTED_VALUE, 
            &dwCellConnected
        );
        rho_sysimpl_sethas_cellnetwork(dwCellConnected);

	    // Register for changes in the number of network connections
	    hr = lpfn_Registry_NotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		    SN_CONNECTIONSNETWORKCOUNT_PATH, 
		    SN_CONNECTIONSNETWORKCOUNT_VALUE, 
		    m_appWindow.m_hWnd, 
		    WM_CONNECTIONSNETWORKCOUNT, 
		    0, 
		    NULL, 
		    &g_hNotify);

	    hr = lpfn_Registry_NotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
		    SN_CELLSYSTEMCONNECTED_PATH, 
		    SN_CELLSYSTEMCONNECTED_VALUE, 
		    m_appWindow.m_hWnd, 
		    WM_CONNECTIONSNETWORKCELL, 
		    0, 
		    NULL, 
		    &g_hNotifyCell);
    }
#endif

    return S_OK;
}