예제 #1
0
파일: rhosupport.c 프로젝트: myogesh/rhodes
static VALUE find_file(VALUE fname)
{
    VALUE res;
    int nOK = 0;

    if ( strncmp(RSTRING_PTR(fname), RhoGetRootPath(), strlen(RhoGetRootPath())) == 0 ){
        res = rb_str_dup(fname);
        rb_str_cat(res,".iseq",5);
    }else{
        int i = 0;
        VALUE load_path = GET_VM()->load_path;
        VALUE dir;
        fname = checkRhoBundleInPath(fname);

        //TODO: support document relative require in case of multiple apps
        if (RARRAY_LEN(load_path)>1){
            for( ; i < RARRAY_LEN(load_path); i++ ){
                VALUE dir = RARRAY_PTR(load_path)[i];
                res = rb_str_dup(dir);
                rb_str_cat(res,"/",1);
                rb_str_cat(res,RSTRING_PTR(fname),RSTRING_LEN(fname));
                rb_str_cat(res,".iseq",5);

                if( eaccess(RSTRING_PTR(res), R_OK) == 0 ){
                    nOK = 1;
                    break;
                }
            }
            if ( !nOK )
                return 0;
        } /*else {
            dir = RARRAY_PTR(load_path)[RARRAY_LEN(load_path)-1];

            res = rb_str_dup(dir);
            rb_str_cat(res,"/",1);
            rb_str_cat(res,RSTRING_PTR(fname),RSTRING_LEN(fname));
            rb_str_cat(res,".iseq",5);

            if ( g_curAppPath != 0 && eaccess(RSTRING_PTR(res), R_OK) != 0 ){
                res = rb_str_new2(g_curAppPath);
                rb_str_cat(res,"/",1);
                rb_str_cat(res,RSTRING_PTR(fname),RSTRING_LEN(fname));
                rb_str_cat(res,".iseq",5);
            }
        } */
    }

    res = RhoPreparePath(res);
    if ( !nOK )
        nOK = 1;//eaccess(RSTRING_PTR(res), R_OK) == 0 ? 1 : 0;

    return nOK ? res : 0;
}
예제 #2
0
void CSyncEngineWrap::StartSyncEngine()
	{
		lock_sync_mutex();
		
		char dbpath[KMaxFileName];
		sprintf(dbpath,"%sdb\\syncdb.sqlite",RhoGetRootPath());
		sqlite3_open(dbpath, &iDatabase);
		start_sync_engine(iDatabase);

		unlock_sync_mutex();
	}
예제 #3
0
void CAppManager::ReloadRhoBundle(const char* szUrl, const char* szZipPassword)
{
	if ( szUrl )
	{
		//get zip file with rhodes
		DWORD dwDataSize = 0;
		char* zipData = remote_data( L"GET", const_cast<char*>(szUrl), NULL, 0, false, true, false, &dwDataSize );

		LPWSTR rootw = wce_mbtowc(RhoGetRootPath());  

		//TODO: Add error handling
		if ( zipData && dwDataSize > 0 )
		{
			ZIPENTRY ze; 
			// Open zip file
			HZIP hz = OpenZip(zipData, dwDataSize, szZipPassword);
			
			if ( hz )
			{
				//Stop HTTP Server
				CHttpServer::Instance()->FreezeThread();

				// Set base for unziping
				SetUnzipBaseDir(hz, rootw);
				
				// Get info about the zip
				// -1 gives overall information about the zipfile
				GetZipItem(hz,-1,&ze);
				int numitems = ze.index;
				
				// Iterate through items and unzip them
				for (int zi = 0; zi<numitems; zi++)
				{ 
					// fetch individual details, e.g. the item's name.
					GetZipItem(hz,zi,&ze); 
					// unzip item
					UnzipItem(hz, zi, ze.name);         
				}
				
				CloseZip(hz);

				//Show MessageBox
				MessageBox(NULL, _T("Rhobundle has been updated successfully.\n\nPlease restart application."), _T("Information"), MB_OK | MB_ICONINFORMATION );
			}
		}

		if ( rootw )
			free(rootw);

		if ( zipData )
			delete zipData;
	}
}
예제 #4
0
void CSyncEngineWrap::StartSyncEngine()
	{
		//lock_sync_mutex();
		if (!get_database())
		{
			char dbpath[KMaxFileName];
			sprintf(dbpath, "%sdb\\syncdb.sqlite", RhoGetRootPath());
			sqlite3 * iDatabase = 0;			
			sqlite3_open(dbpath, &iDatabase);

			rhoInitDatabase(iDatabase);
		}
		//unlock_sync_mutex();
	

	}
예제 #5
0
void CHttpServer::InitHttpServer()
	{
		//Init http server
	  	ctx = shttpd_init(0,NULL);
		
	    //
	    const char *rootpath = RhoGetRootPath();
	    char httproot[260];
	    
	    sprintf(httproot,"%sapps",rootpath);
	    shttpd_set_option(ctx, "root",httproot);
	    //
	    //shttpd_register_uri(ctx, "/system/geolocation", &show_geolocation, NULL);
	  	
//	  	shttpd_set_option(ctx, "root", APPS_PATH);
	}
예제 #6
0
bool CSyncEngine::StartSyncEngine()
{
  ATLTRACE(_T("Starting sync engine\n"));
  char dbpath[MAX_PATH];
  sprintf(dbpath,"%sdb\\syncdb.sqlite",RhoGetRootPath());

  Lock();
  sqlite3_open(dbpath,&m_database);
  Unlock();

  // Set the delay based on records from the database
  m_delaySync = get_object_count_from_database(m_database);
  start_sync_engine(m_database);
  m_bSyncInitialized = true;
  stop_running = 0;

  return true;
}
예제 #7
0
HRESULT Camera::selectPicture(HWND hwndOwner,LPTSTR pszFilename) {
	RHO_ASSERT(pszFilename);
	OPENFILENAMEEX ofn = {0};

	ofn.lStructSize     = sizeof(ofn);
	ofn.lpstrFilter     = NULL;
	ofn.lpstrFile       = pszFilename;
	ofn.nMaxFile        = MAX_PATH;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrTitle      = _T("Select an image");
	ofn.ExFlags         = OFN_EXFLAG_THUMBNAILVIEW|OFN_EXFLAG_NOFILECREATE|OFN_EXFLAG_LOCKDIRECTORY;

	if (GetOpenFileNameEx(&ofn)) {
		HRESULT hResult = S_OK;

		TCHAR rhoroot[MAX_PATH];
		wchar_t* root  = wce_mbtowc(RhoGetRootPath());
		wsprintf(rhoroot,L"%s%s",root,L"apps\\public\\db-files");
		free(root);

		create_folder(rhoroot);

		TCHAR filename[256];
		generate_filename(filename);
		
		int len = wcslen(rhoroot) + wcslen(L"\\") + wcslen(filename);
		wchar_t* full_name = (wchar_t*) malloc((len+2)*sizeof(wchar_t));
		wsprintf(full_name,L"%s\\%s",rhoroot,filename);

		if (copy_file(pszFilename,full_name)) {
			StringCchCopy(pszFilename, MAX_PATH, filename);	
		} else {
			hResult = E_INVALIDARG;
		}

		free(full_name);

		return hResult;
	} else if (GetLastError()==ERROR_SUCCESS) {
		return S_FALSE; //user cancel op
	}
	return E_INVALIDARG;
}
예제 #8
0
HRESULT Camera::takePicture(HWND hwndOwner,LPTSTR pszFilename) {
    HRESULT         hResult;
    SHCAMERACAPTURE shcc;

    wchar_t* root  = wce_mbtowc(RhoGetRootPath());
    wsprintf(pszFilename,L"%s%s",root,L"apps\\public\\db-files");
    free(root);

	create_folder(pszFilename);

    TCHAR filename[256];
	generate_filename(filename);

    // Set the SHCAMERACAPTURE structure.
    ZeroMemory(&shcc, sizeof(shcc));
    shcc.cbSize             = sizeof(shcc);
    shcc.hwndOwner          = hwndOwner;
    shcc.pszInitialDir      = pszFilename;
    shcc.pszDefaultFileName = filename;
    shcc.pszTitle           = TEXT("Camera");
    shcc.VideoTypes			= CAMERACAPTURE_VIDEOTYPE_MESSAGING;
    shcc.nResolutionWidth   = 176;
    shcc.nResolutionHeight  = 144;
    shcc.nVideoTimeLimit    = 15;
    shcc.Mode               = CAMERACAPTURE_MODE_STILL;

    // Display the Camera Capture dialog.
    hResult = SHCameraCapture(&shcc);

    // The next statements will execute only after the user takes
    // a picture or video, or closes the Camera Capture dialog.
    if (S_OK == hResult) {
        LPTSTR fname = get_file_name(shcc.szFile,pszFilename);
		if (fname) {
			StringCchCopy(pszFilename, MAX_PATH, fname);
			free(fname);
		} else {
			hResult = E_INVALIDARG;
		}
    }

    return hResult;
}
예제 #9
0
파일: Rhodes.cpp 프로젝트: Netfart/rhodes
	bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode ) throw( ) {
		m_nRestarting = 1;

		TCHAR szTokens[] = _T("-/");
		LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
		while (lpszToken != NULL)
		{
			if (WordCmpI(lpszToken, _T("Restarting"))==0) {
				m_nRestarting = 10;
			}
#if defined(OS_WINDOWS)
			else if (wcsncmp(lpszToken, _T("approot"),7)==0) {
				char* token = wce_wctomb(lpszToken);
				//parseToken will allocate extra byte at the end of the returned token value
				char* path = parseToken( token, strlen(token) );
				if (path) {
					int len = strlen(path);
					if (!(path[len]=='\\' || path[len]=='/')) {
						path[len] = '\\';
						path[len+1]  = 0;
					}
					__setRootPath(path);
					free(path);
				}
				free(token);
			}
#endif
			lpszToken = FindOneOf(lpszToken, szTokens);
		}

		//
		rho_logconf_Init(RhoGetRootPath());
		//	runAllLogTests();

		return __super::ParseCommandLine(lpCmdLine, pnRetCode);
	}
예제 #10
0
파일: rhosupport.c 프로젝트: myogesh/rhodes
VALUE __rhoGetCurrentDir(void)
{
    return rb_str_new2(RhoGetRootPath());
}
예제 #11
0
void RhoRubyStart()
{
#ifdef HAVE_LOCALE_H
    setlocale(LC_CTYPE, "");
#endif
    {
#ifdef ENABLE_RUBY_VM_STAT
    g_collect_stat = 1; 
#endif    
    
		RUBY_INIT_STACK;
		ruby_init();
#if defined(WIN32)
		rb_w32_sysinit(NULL,NULL);
#endif

#if defined(DEBUG)
		//enable_gc_profile();
#endif
        //rb_funcall(rb_mGC, rb_intern("stress="), 1, Qtrue);

		ruby_init_loadpath(RhoGetRootPath());
		Init_strscan();
		Init_sqlite3_api();
		Init_GeoLocation();
		Init_SyncEngine();
		Init_System();
		Init_Phonebook();
		Init_WebView();
		Init_RhoConf();
		Init_Alert();
        Init_Camera();
		Init_stringio();

    Init_RhoSupport();

#ifdef ENABLE_RUBY_VM_STAT
    struct timeval  start;
    struct timeval  end;
    
    gettimeofday (&start, NULL);
#endif    

    require_compiled(rb_str_new2("rhoframework"), &framework );

#ifdef ENABLE_RUBY_VM_STAT
    gettimeofday (&end, NULL);
    
    if ( end.tv_sec > 0 )
    	g_require_compiled_msec += (end.tv_sec  - start.tv_sec) * 1000;
    else
    	g_require_compiled_msec += (end.tv_usec - start.tv_usec)/1000; 
    
#endif    

    rb_gc_register_mark_object(framework);
		CONST_ID(framework_mid, "serve");
		CONST_ID(framework_mid2, "serve_index");
		
#ifdef ENABLE_RUBY_VM_STAT
	g_collect_stat = 0; 
#endif    
		
	}	
}