示例#1
0
int main()
{
	VERIFY_HRESULT(CeRapiInit());

	WCHAR buffer[MAX_PATH];
	DWORD length;
	
	// XXX: CSIDL_DESKTOPDIRECTORY does not work, but that's probably OK
	//TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_DESKTOPDIRECTORY, MAX_PATH, buffer));

	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_FAVORITES, MAX_PATH, buffer));
	printf("CSIDL_FAVORITES: %s\n", from_unicode(buffer));
	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_FONTS, MAX_PATH, buffer));
	printf("CSIDL_FONTS: %s\n", from_unicode(buffer));
	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_PERSONAL, MAX_PATH, buffer));
	printf("CSIDL_PERSONAL: %s\n", from_unicode(buffer));
	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_PROGRAMS, MAX_PATH, buffer));
	printf("CSIDL_PROGRAMS: %s\n", from_unicode(buffer));
	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_RECENT, MAX_PATH, buffer));
	printf("CSIDL_RECENT: %s\n", from_unicode(buffer));
	TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_STARTUP, MAX_PATH, buffer));
	printf("CSIDL_STARTUP: %s\n", from_unicode(buffer));
	
	VERIFY_HRESULT(CeRapiUninit());
	return TEST_SUCCEEDED;
}
int main()
{
	VERIFY_HRESULT(CeRapiInit());

	CEOSVERSIONINFO version;
	
	memset(&version, 0, sizeof(CEOSVERSIONINFO));
	version.dwOSVersionInfoSize = sizeof(CEOSVERSIONINFO);
	
	printf("size = 0x%x\n", sizeof(CEOSVERSIONINFO));
	
	TEST_NOT_EQUAL(0, CeGetVersionEx(&version));
	
	printf("dwMajorVersion=%i, dwMinorVersion=%i, dwBuildNumber=%i, dwPlatformId=%i, szCSDVersion=\"%s\"\n",
			version.dwMajorVersion,
			version.dwMinorVersion,
			version.dwBuildNumber,
			version.dwPlatformId,	// 3 == VER_PLATFORM_WIN32_CE
			from_unicode(version.szCSDVersion));

	if (3 != version.dwPlatformId)
	{
		printf("Platform ID is not 3!\n");
		return TEST_FAILED;
	}
	
	VERIFY_HRESULT(CeRapiUninit());
	return TEST_SUCCEEDED;
}
int _tmain(int argc, _TCHAR* argv[])
{
	
	// Initialize RAPI
	HRESULT hr = CeRapiInit();

	hr = CeDeleteFile(L"\\Program Files\\shell\\avmshell.exe");


	if (argc>1) {

	// Filename will be passed in argv[0]
	HANDLE hFile = ::CreateFile(argv[1], 
								GENERIC_READ, FILE_SHARE_READ,
								NULL, OPEN_EXISTING,
								FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile==INVALID_HANDLE_VALUE)
	{
		printf("Error copying file %s to device",argv[1]);
		CeRapiUninit();
		return -1;
	}


	// Create the file on the device in the temp directory
	WCHAR ceFilename[MAX_PATH];
	DWORD dwmblen = ::MultiByteToWideChar(CP_ACP, MB_COMPOSITE, (const char *)argv[1], strlen((const char *)argv[1]), ceFilename, MAX_PATH); 
	ceFilename[dwmblen] = 0;


	WCHAR cePath[MAX_PATH];
	HANDLE ceFile = CeCreateFile(L"\\Program Files\\shell\\avmshell.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);

	char localBuf[4096];
	DWORD dwBufsize=4096, dwFilesize = ::GetFileSize(hFile, NULL);
	if (dwFilesize<4096)
		dwBufsize = dwFilesize;


	DWORD dwCeBytes=0, dwRead;
	while (ReadFile(hFile, localBuf, dwBufsize, &dwRead, NULL))
	{
		hr = CeWriteFile(ceFile, (void*)localBuf, dwRead, &dwCeBytes, NULL);
		dwFilesize -= dwRead;
		if (dwFilesize<4096)
			dwBufsize = dwFilesize;
		if (dwBufsize<=0)
			break;
	}
	}
	// Uninitialize RAPI
	CeRapiUninit();
	return 0;
}
示例#4
0
bool wceConnect (void) 
{
	HRESULT hRapiResult;

	//_tprintf( TEXT("Connecting to Windows CE..."));
	hRapiResult = CeRapiInit();
	if (FAILED(hRapiResult)) {
        _tprintf( TEXT("Failed\n"));
        return false;
    }
    //_tprintf( TEXT("Success\n"));

	return true;

	/*
	RAPIINIT riCopy = {sizeof(RAPIINIT), 0, 0};
    bool fInitialized = false;
	DWORD dwTimeOut = 5000;

    CeRapiUninit();

    hRapiResult = CeRapiInitEx(&riCopy);

	if (FAILED(hRapiResult)) {
		return false;
	}

    DWORD dwRapiInit = 0;

    dwRapiInit = WaitForSingleObject(
		riCopy.heRapiInit,
		dwTimeOut);

    if (WAIT_OBJECT_0 == dwRapiInit) {
        // heRapiInit signaled:
        // set return error code to return value of RAPI Init function
        hRapiResult = riCopy.hrRapiInit;  
    } else if (WAIT_TIMEOUT == dwRapiInit) {
        // timed out: device is probably not connected
        // or not responding
        hRapiResult = HRESULT_FROM_WIN32(ERROR_TIMEOUT);
    } else {
        // WaitForSingleObject failed
        hRapiResult = HRESULT_FROM_WIN32(GetLastError());
    }

	if (FAILED(hRapiResult)) {
        CeRapiUninit();
		return false;
	}
	return true;
	*/
}
int rapi_mkdir(char *dir) {
    HRESULT hr;
    WCHAR* wide_path = NULL;
    char *path = NULL;
    
    path = (char *) strdup(dir);
    
    hr = CeRapiInit();

    if (RAPI_FAILED(hr))
    {
        fprintf(stderr, "Unable to initialize RAPI: %s\n",
                synce_strerror(hr));
        if (wide_path)
            wstr_free_string(wide_path);

        if (path)
            free(path);

        CeRapiUninit();
        return (-1);
    }

    convert_to_backward_slashes(path);
    wide_path = wstr_from_utf8(path);
    wide_path = adjust_remote_path(wide_path, true);
    
    if (!CeCreateDirectory(wide_path, NULL))
    {
        fprintf(stderr, "Failed to create directory '%s': %s\n",
                path,
                synce_strerror(CeGetLastError()));
        if (wide_path)
            wstr_free_string(wide_path);

        if (path)
            free(path);

        CeRapiUninit();
        return (-2);
    }

    if (wide_path)
        wstr_free_string(wide_path);

    if (path)
        free(path);

    CeRapiUninit();
    return 0;
}
示例#6
0
bool wceConnect (void) 
{
	HRESULT hRapiResult;

	//_tprintf( TEXT("Connecting to Windows CE..."));
	hRapiResult = CeRapiInit();
	if (FAILED(hRapiResult)) {
        _tprintf( TEXT("Failed\n"));
        return false;
    }
    //_tprintf( TEXT("Success\n"));

	return true;
}
int main(int argc, char** argv)
{
  int result = 0;
  RapiConnection* connection = NULL;
  HRESULT hr;
  char *shortcut, *target;
  WCHAR* wide_shortcut = NULL;
  WCHAR* wide_target = NULL;
  WCHAR *tmp, *tmp_quote;
  int tmpsize;

  if (!handle_parameters(argc, argv, &shortcut, &target))
    goto exit;

  if ((connection = rapi_connection_from_path(devpath)) == NULL)
  {
    fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
            argv[0],
            devpath?devpath:"(Default)");
    goto exit;
  }
  rapi_connection_select(connection);
  hr = CeRapiInit();

  if (FAILED(hr))
  {
    fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
            argv[0],
        synce_strerror(hr));
    result = 1;
    goto exit;
  }


  convert_to_backward_slashes(shortcut);
  wide_shortcut = wstr_from_current(shortcut);
  wide_shortcut = adjust_remote_path(wide_shortcut, true);

  convert_to_backward_slashes(target);
  wide_target = wstr_from_current(target);
  wide_target = adjust_remote_path(wide_target, true);
  /* Wrap target in quotes.  This is required for paths with spaces (for some reason) */
  tmp_quote = wstr_from_current("\"");
  tmpsize = (wstrlen(wide_target) + 3) * sizeof(WCHAR);
  tmp = malloc(tmpsize);
  if (!tmp)
    goto exit;
  wstrcpy(tmp,tmp_quote);
  if (!wstr_append(tmp,wide_target,tmpsize))
    goto exit;
  if (!wstr_append(tmp,tmp_quote,tmpsize))
    goto exit;
  wstr_free_string(wide_target);
  wstr_free_string(tmp_quote);
  wide_target = tmp;
  
  BOOL res = CeSHCreateShortcut(wide_shortcut, wide_target);
  if (!res)
  {
    fprintf(stderr, "%s: Unable to create shortcut to '%s' at '%s': %s\n",
            argv[0],target,shortcut,
        synce_strerror(hr));
    result = 1;
    goto exit;
  }

 exit:
  wstr_free_string(wide_shortcut);
  wstr_free_string(wide_target);
  
  if (shortcut)
    free(shortcut);
  
  if (target)
    free(target);

  CeRapiUninit();
  rapi_connection_destroy(connection);
  
  return result;
}
示例#8
0
int _tmain(int argc, _TCHAR* argv[])
{
	TCHAR *emu_name = NULL;
	TCHAR *cab_file = NULL;
	TCHAR *bundle_path = NULL;
	TCHAR *app_exe = NULL;
	TCHAR *log_file = NULL;
	TCHAR *log_port = NULL;
	TCHAR params_buf[MAX_PATH + 16];
	//WIN32_FIND_DATAW findData;
	int new_copy = 0;
	int deploy_type;

	USES_CONVERSION;

	if (argc >= 5) {        //assuming that need to start emulator
		if (strcmp(T2A(argv[1]), "emu") == 0) {
			emu_name    = argv[2];
			app_name    = argv[3];
			bundle_path = argv[4];
			app_exe     = argv[5];
			log_port    = argv[6];
			deploy_type = DEPLOY_EMU;
		}
		if (strcmp(T2A(argv[1]), "emucab") == 0) {
			emu_name = argv[2];
			cab_file = argv[3];
			app_name = argv[4];
			log_port = argv[5];
			deploy_type = DEPLOY_EMUCAB;
		}

		if (strcmp(T2A(argv[1]), "dev") == 0) {
			app_name    = argv[2];
			bundle_path = argv[3];
			app_exe     = argv[4];
			log_port    = argv[5];
			deploy_type = DEPLOY_DEV;
		}
	} else if (argc == 5) { //assuming that need to deploy and start on device
		cab_file = argv[2];
		app_name = argv[3];
		log_port = argv[4];
		deploy_type = DEPLOY_DEVCAB;
	} else if (argc == 4) { // log
		if (strcmp(T2A(argv[1]), "log") == 0) {
			log_file = argv[2];
			log_port = argv[3];
			app_name = _T("");
			deploy_type = DEPLOY_LOG;
		}
	}
	else {
		usage();
		return EXIT_FAILURE;
	}

	TCHAR app_dir[MAX_PATH];
	_tcscpy(app_dir, TEXT("\\Program Files\\"));
	_tcscat(app_dir, app_name);
	_tprintf( TEXT("%s\n"), app_dir);

	if (deploy_type == DEPLOY_EMU) {
		if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
			HANDLE hFind;
			CE_FIND_DATA findData;

			CreateThread(NULL, 0, startDEM, NULL, 0, NULL);

			_tprintf( TEXT("Starting emulator... "));
			if (!emuConnect (emu_name)) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
				
			_tprintf( TEXT("Cradle emulator... "));
			if(!emuCradle (emu_name)) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
	
			if (!wceConnect ()) {
				printf ("Failed to connect to remote device.\n");
				goto stop_emu_deploy;
			} else {

				hFind = CeFindFirstFile(app_dir, &findData);
				if (INVALID_HANDLE_VALUE == hFind) {
					_tprintf( TEXT("Application directory on device was no found\n"));
					
					new_copy = 1;

					if (!CeCreateDirectory(app_dir, NULL)) {
						printf ("Failed to create app directory\n");
						goto stop_emu_deploy;
					}
				}
				FindClose( hFind);

				if (!findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					_tprintf( TEXT("Error: target directory is file\n"));
					goto stop_emu_deploy;
				}
				

				TCHAR remote_bundle_path[MAX_PATH];

				_tcscpy(remote_bundle_path, app_dir);
				_tcscat(remote_bundle_path, _T("\\rho"));

				hFind = CeFindFirstFile(remote_bundle_path, &findData);
				if (INVALID_HANDLE_VALUE == hFind) {
					_tprintf( TEXT("Bundle directory on device was no found\n"));
	
					if (!CeCreateDirectory(remote_bundle_path, NULL)) {
						printf ("Failed to create bundle directory\n");
						goto stop_emu_deploy;
					}
				}
				FindClose( hFind);

				int retval = copyExecutable (app_exe, app_dir);
				if (retval != EXIT_SUCCESS) {
					printf ("Failed to copy application executable\n");
					if (retval == 32) {
						printf ("Please, stop application on device and try again.\n");
					}
					goto stop_emu_deploy;
				}

				if (copyBundle(bundle_path, _T("/"), remote_bundle_path) == EXIT_FAILURE) {
					printf ("Failed to copy bundle\n");
					goto stop_emu_deploy;
				}

				emuBringToFront(emu_name);

				_tprintf( TEXT("Starting application..."));
				_tcscpy(params_buf, TEXT("\\Program Files\\"));
				_tcscat(params_buf, app_name);
				_tcscat(params_buf, _T("\\"));
				_tcscat(params_buf, app_name);
				_tcscat(params_buf, _T(".exe"));

				TCHAR params[128];
				_tcscpy(params, _T("-log="));
				_tcscat(params, log_port);

				if(!wceRunProcess(T2A(params_buf), T2A(params))) {
					_tprintf( TEXT("FAILED\n"));
					goto stop_emu_deploy;
				}
				_tprintf( TEXT("DONE\n"));

				wceDisconnect();
			}
	
			CoUninitialize();

			ExitProcess(EXIT_SUCCESS);
		}

//		emu "Windows Mobile 6 Professional Emulator" RhodesApplication1 c:/android/runtime-rhostudio.product/RhodesApplication1/bin/RhoBundle "C:/Android/rhodes/platform/wm/bin/Windows Mobile 6 Professional SDK (ARMV4I)/rhodes/Release/RhodesApplication1.exe" 11000
	}
	if (deploy_type == DEPLOY_EMUCAB) {
		if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
			CreateThread(NULL, 0, startDEM, NULL, 0, NULL);

			_tprintf( TEXT("Starting emulator... "));
			if (!emuConnect (emu_name)) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
			
			_tprintf( TEXT("Cradle emulator... "));
			if(!emuCradle (emu_name)) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));

			_tprintf( TEXT("Loading cab file..."));		
			if (!wcePutFile (T2A(cab_file), "")) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));

			_tprintf( TEXT("Loading utility dll..."));
			if (!wcePutFile (RHOSETUP_DLL, "")) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
			
			_tprintf( TEXT("Setup application..."));

			//FIXME: rake gives pathname with unix-like '/' file separators,
			//so if we want to use this tool outside of rake, we should remember this
			//or check and convert cab_file
			TCHAR *p = _tcsrchr (cab_file, '/');
			if (p) p++;
			_tcscpy(params_buf, TEXT("/noui "));
			_tcscat(params_buf, p != NULL ? p : cab_file);

			if(!wceInvokeCabSetup(T2A(params_buf))) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));

			emuBringToFront(emu_name);

			_tprintf( TEXT("Starting application..."));
			_tcscpy(params_buf, TEXT("\\Program Files\\"));
			_tcscat(params_buf, app_name);
			_tcscat(params_buf, _T("\\"));
			_tcscat(params_buf, app_name);
			_tcscat(params_buf, _T(".exe"));

			TCHAR params[128];
			_tcscpy(params, _T("-log="));
			_tcscpy(params, log_port);

			if(!wceRunProcess(T2A(params_buf), T2A(params))) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));


			CoUninitialize();
			ExitProcess(EXIT_SUCCESS);
	stop_emu_deploy:
			CoUninitialize();
			ExitProcess(EXIT_FAILURE);
		}
	}

	if (deploy_type == DEPLOY_DEV) {
		HANDLE hFind;
		CE_FIND_DATA findData;

		_tprintf( TEXT("Searching for Windows CE device..."));

		HRESULT hRapiResult;
		hRapiResult = CeRapiInit();
		if (FAILED(hRapiResult)) {
			_tprintf( TEXT("FAILED\n"));
			return false;
		}
		_tprintf( TEXT("DONE\n"));

		hFind = CeFindFirstFile(app_dir, &findData);
		if (INVALID_HANDLE_VALUE == hFind) {
			_tprintf( TEXT("Application directory on device was no found\n"));
					
			new_copy = 1;

			if (!CeCreateDirectory(app_dir, NULL)) {
				printf ("Failed to create app directory\n");
				goto stop_emu_deploy;
			}
		}
		FindClose( hFind);

		if (!findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			_tprintf( TEXT("Error: target directory is file\n"));
			goto stop_emu_deploy;
		}
				

		TCHAR remote_bundle_path[MAX_PATH];

		_tcscpy(remote_bundle_path, app_dir);
		_tcscat(remote_bundle_path, _T("\\rho"));

		hFind = CeFindFirstFile(remote_bundle_path, &findData);
		if (INVALID_HANDLE_VALUE == hFind) {
			_tprintf( TEXT("Bundle directory on device was no found\n"));
	
			if (!CeCreateDirectory(remote_bundle_path, NULL)) {
				printf ("Failed to create bundle directory\n");
				goto stop_emu_deploy;
			}
		}
		FindClose( hFind);

		
		int retval = copyExecutable (app_exe, app_dir);
		if (retval != EXIT_SUCCESS) {
			printf ("Failed to copy application executable\n");
			if (retval == 32) {
				printf ("Please, stop application on device and try again.\n");
			}
			goto stop_emu_deploy;
		}

		if (copyBundle(bundle_path, _T("/"), remote_bundle_path) == EXIT_FAILURE) {
			printf ("Failed to copy bundle\n");
			goto stop_emu_deploy;
		}

		Sleep(2 * 1000);

		_tprintf( TEXT("Starting application..."));
		_tcscpy(params_buf, TEXT("\\Program Files\\"));
		_tcscat(params_buf, app_name);
		_tcscat(params_buf, _T("\\"));
		_tcscat(params_buf, app_name);
		_tcscat(params_buf, _T(".exe"));
		_tprintf( TEXT("%s\n"), params_buf);

		TCHAR params[128];
		_tcscpy(params, _T("-log="));
		_tcscpy(params, log_port);

		if(!wceRunProcess(T2A(params_buf), T2A(params))) {
			_tprintf( TEXT("FAILED\n"));
			goto stop_emu_deploy;
		}
		_tprintf( TEXT("DONE\n"));

		ExitProcess(EXIT_SUCCESS);
	}

	if (deploy_type == DEPLOY_DEVCAB) {
			_tprintf( TEXT("Searching for Windows CE device..."));

			HRESULT hRapiResult;
			hRapiResult = CeRapiInit();
			if (FAILED(hRapiResult)) {
					_tprintf( TEXT("FAILED\n"));
					return false;
			}
			_tprintf( TEXT("DONE\n"));

			_tprintf( TEXT("Loading cab file to device..."));
			USES_CONVERSION;
			if (!wcePutFile (T2A(cab_file), "")) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));

			_tprintf( TEXT("Loading utility dll..."));
			if (!wcePutFile (RHOSETUP_DLL, "")) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
			
			_tprintf( TEXT("Setup application..."));

			//FIXME: rake gives pathname with unix-like '/' file separators,
			//so if we want to use this tool outside of rake, we should remember this
			//or check and convert cab_file
			TCHAR *p = _tcsrchr (cab_file, '/');
			if (p) p++;
			_tcscpy(params_buf, p != NULL ? p : cab_file);
			//_tcscat(params_buf, p != NULL ? p : cab_file);

			if(!wceInvokeCabSetup(T2A(params_buf))) {
				_tprintf( TEXT("FAILED\n"));

				_tprintf( TEXT("Starting installator GUI ..."));
				if(!wceRunProcess ("\\windows\\wceload.exe", T2A(p != NULL ? p : cab_file))) {
					_tprintf( TEXT("FAILED\n"));
					ExitProcess(EXIT_FAILURE);
				} else {
					_tprintf( TEXT("DONE\n"));
					_tprintf( TEXT("Please continue manually...\n"));
					ExitProcess(EXIT_SUCCESS);
				}

				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));

			_tprintf( TEXT("Starting application..."));
			_tcscpy(params_buf, TEXT("\\Program Files\\"));
			_tcscat(params_buf, app_name);
			_tcscat(params_buf, _T("\\"));
			_tcscat(params_buf, app_name);
			_tcscat(params_buf, _T(".exe"));

            TCHAR params[128];
            _tcscpy(params, _T("-log="));
			_tcscpy(params, log_port);

			if(!wceRunProcess (T2A(params_buf), T2A(params))) {
				_tprintf( TEXT("FAILED\n"));
				goto stop_emu_deploy;
			}
			_tprintf( TEXT("DONE\n"));
	}

	if (deploy_type == DEPLOY_LOG)
	{
		if (log_file != NULL) {
			startLogServer(log_file, log_port);
		}
	}
	
	return EXIT_SUCCESS;
}
int rapi_run(char *program, char *parameters)
{
	int result = 1;
	HRESULT hr;
	WCHAR* wide_program = NULL;
	WCHAR* wide_parameters = NULL;
	PROCESS_INFORMATION info;
    char *tmpprogram = NULL;

    tmpprogram = (char *) strdup(program);
    
	hr = CeRapiInit();

	if (RAPI_FAILED(hr))
	{
		fprintf(stderr, "Unable to initialize RAPI: %s\n", 
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(tmpprogram);
	wide_program = wstr_from_utf8(tmpprogram);
	if (parameters)
		wide_parameters = wstr_from_utf8(parameters);

	memset(&info, 0, sizeof(info));
	
	if (!CeCreateProcess(
				wide_program,
				wide_parameters,
				NULL,
				NULL,
				false,
				0,
				NULL,
				NULL,
				NULL,
				&info
				))
	{
		fprintf(stderr, "Failed to execute '%s': %s\n", 
				tmpprogram,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	CeCloseHandle(info.hProcess);
	CeCloseHandle(info.hThread);

	result = 0;

exit:
	wstr_free_string(wide_program);
	wstr_free_string(wide_parameters);

	if (tmpprogram)
		free(tmpprogram);

	CeRapiUninit();
	return result;
}
int rapi_copy(char *source, char *dest)
{
	int result = 1;
    HRESULT hr;
    time_t start;
    time_t duration;
    size_t bytes_copied = 0;

    hr = CeRapiInit();

    if (RAPI_FAILED(hr))
    {
        fprintf(stderr, "Unable to initialize RAPI: %s\n",
                synce_strerror(hr));
        goto exit;
    }

    if (!dest)
    {
        char* p;

        if (is_remote_file(source))
        {

            for (p = source + strlen(source); p != source; p--)
            {
                if (*p == '/' || *p == '\\')
                {
                    dest = (char *) strdup(p+1);
                    break;
                }
            }

            if (!dest || '\0' == dest[0])
            {
                fprintf(stderr, "Unable to extract destination filename from source path '%s'\n",
                        source);
                goto exit;
            }
        }
        else
        {
            WCHAR mydocuments[MAX_PATH];
            char* mydocuments_ascii = NULL;
            p = strrchr(source, '/');

            if (p)
                p++;
            else
                p = source;

            if ('\0' == *p)
            {
                fprintf(stderr, "Unable to extract destination filename from source path '%s'\n",
                        source);
                goto exit;
            }

            if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments))
            {
                fprintf(stderr, "Unable to get the \"My Documents\" path.\n");
                goto exit;
            }

            dest = (char *) calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1);

            mydocuments_ascii = wstr_to_ascii(mydocuments);

            strcat(dest, ":");
            strcat(dest, mydocuments_ascii);
            strcat(dest, "\\");
            strcat(dest, p);

            wstr_free_string(mydocuments_ascii);
        }
    }


    if (0 == strcmp(source, dest))
    {
        fprintf(stderr, "You don't want to copy a file to itself.\n");
        goto exit;
    }

    if (is_remote_file(source) && is_remote_file(dest))
    {
        /*
         *          * Both are remote; use CeCopyFile()
         *                   */
        if (!remote_copy(source, dest))
            goto exit;
    }
    else
    {
        start = time(NULL);

        /*
         *          * At least one is local, Use the AnyFile functions
         *                   */
        if (!anyfile_copy(source, dest,  &bytes_copied))
            goto exit;

    }

	result = 0;
exit:

    CeRapiUninit();
    return result;
}
GList* setup_rapi_and_create_list(GList *list, GtkWidget *progressbar) 
{
    HRESULT hr;
    LONG result;
    HKEY parent_key;
    WCHAR* parent_key_name = NULL;
    WCHAR* value_name = NULL;
    DWORD i;
    bool smartphone = false;

    hr = CeRapiInit();

    if (RAPI_FAILED(hr))
    {
        fprintf(stderr, "Unable to initialize RAPI: %s\n", 
                synce_strerror(hr));
        return (list);
    }

    /* Update the progressbar */
    if (progressbar != NULL) {
        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
        while (gtk_events_pending()) {
            gtk_main_iteration();
        }
    }
    /* Path on SmartPhone 2002 */
    parent_key_name = wstr_from_ascii("Security\\AppInstall");

    result = CeRegOpenKeyEx(HKEY_LOCAL_MACHINE, parent_key_name, 0, 0, &parent_key);

    if (ERROR_SUCCESS == result)
    {
        smartphone = true;
    }
    else
    {
        smartphone = false;
        wstr_free_string(parent_key_name);

        /* Path on Pocket PC 2002 */
        parent_key_name = wstr_from_ascii("Software\\Apps");

        result = CeRegOpenKeyEx(HKEY_LOCAL_MACHINE, parent_key_name, 0, 0, &parent_key);

        if (ERROR_SUCCESS != result)
        {
            fprintf(stderr, "Unable to open parent registry key: %s\n", 
                    synce_strerror(result));
            return(list);
        }
    }
    value_name = wstr_from_ascii("Instl");

    /* Update the progressbar */
    if (progressbar != NULL) {
        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
        while (gtk_events_pending()) {
            gtk_main_iteration();
        }
    }

    for (i = 0; ; i++)
    {
        WCHAR wide_name[MAX_PATH];
        DWORD name_size = sizeof(wide_name);
        HKEY program_key;
        DWORD installed = 0;
        DWORD value_size = sizeof(installed);

        result = CeRegEnumKeyEx(parent_key, i, wide_name, &name_size, 
                NULL, NULL, NULL, NULL);

        /* Update the progressbar */
        if (progressbar != NULL) {
            gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
            while (gtk_events_pending()) {
                gtk_main_iteration();
            }
        }
        if (ERROR_SUCCESS != result)
            break;

        if (smartphone)
        {
            char* name = wstr_to_utf8(wide_name);
            list = g_list_append(list,g_strdup(name));
            wstr_free_string(name);
        }
        else
        {
            result = CeRegOpenKeyEx(parent_key, wide_name, 0, 0, &program_key);
            if (ERROR_SUCCESS != result)
                continue;

            result = CeRegQueryValueEx(program_key, value_name, NULL, NULL,
                    (LPBYTE)&installed, &value_size);

            if (ERROR_SUCCESS == result && installed)
            {
                char* name = wstr_to_utf8(wide_name);
                list = g_list_append(list,g_strdup(name));
                wstr_free_string(name);
            }
            CeRegCloseKey(program_key);
        }

    }

    CeRegCloseKey(parent_key);

    return (list);
}
示例#12
0
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* source = NULL;
	char* dest = NULL;
	HRESULT hr;
	time_t start;
	time_t duration;
	size_t bytes_copied = 0;
	
	if (!handle_parameters(argc, argv, &source, &dest))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	if (!dest)
	{
		char* p;

		if (is_remote_file(source))
		{

			for (p = source + strlen(source); p != source; p--)
			{
				if (*p == '/' || *p == '\\')
				{
					dest = strdup(p+1);
					break;
				}
			}

			if (!dest || '\0' == dest[0])
			{
				fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n",
						argv[0], source);
				goto exit;
			}
		}
		else
		{
			WCHAR mydocuments[MAX_PATH];
			char* mydocuments_ascii = NULL;
			p = strrchr(source, '/');

			if (p)
				p++;
			else
				p = source;

			if ('\0' == *p)
			{
				fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n",
						argv[0], source);
				goto exit;
			}

			if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments))
			{
				fprintf(stderr, "%s: Unable to get the \"My Documents\" path.\n",
						argv[0]);
				goto exit;
			}

			dest = calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1);
			
			mydocuments_ascii = wstr_to_current(mydocuments);
			
			strcat(dest, ":");
			strcat(dest, mydocuments_ascii);
			strcat(dest, "\\");
			strcat(dest, p);
			
			wstr_free_string(mydocuments_ascii);
		}
	}

	if (0 == strcmp(source, dest))
	{
		fprintf(stderr, "You don't want to copy a file to itself.\n");
		goto exit;
	}

	if (is_remote_file(source) && is_remote_file(dest))
	{
		/*
		 * Both are remote; use CeCopyFile()
		 */
		if (!remote_copy(source, dest))
			goto exit;
	}
	else
	{
		start = time(NULL);

			/*
		 * At least one is local, Use the AnyFile functions
		 */
		if (!anyfile_copy(source, dest, argv[0], &bytes_copied))
			goto exit;

		duration = time(NULL) - start;

		if (0 == duration)
			printf("File copy took less than one second!\n");
		else
			printf("File copy of %i bytes took %li minutes and %li seconds, that's %li bytes/s.\n",
					bytes_copied, duration / 60, duration % 60, bytes_copied / duration);

	}

	result = 0;

exit:
	if (source)
		free(source);

	if (dest)
		free(dest);

	CeRapiUninit();
	return result;
}
示例#13
0
//ccw 2 aug 2000
//this also now launches the client on the CE device using
//the RAPI.H interface.
remoteDevice::remoteDevice(){
  int index = 0;                      // Integer index
  TCHAR szError[100];                 // Error message string

  SOCKET WinSocket = INVALID_SOCKET;  // Window socket
          // Socket for communicating 
                                      // between the server and client
  SOCKADDR_IN local_sin,              // Local socket address
              accept_sin;             // Receives the address of the 
                                      // connecting entity
  int accept_sin_len;                 // Length of accept_sin

  WSADATA WSAData;                    // Contains details of the Winsock
                                      // implementation


  // Initialize Winsock.
  if (WSAStartup (MAKEWORD(1,1), &WSAData) != 0) 
  {
    /*wsprintf (szError, TEXT("WSAStartup failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }

  // Create a TCP/IP socket, WinSocket.
  if ((WinSocket = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 
  {
    /*wsprintf (szError, TEXT("Allocating socket failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }

 // Fill out the local socket's address information.
  local_sin.sin_family = AF_INET;
  local_sin.sin_port = htons (PORTNUM);  
  local_sin.sin_addr.s_addr = htonl (INADDR_ANY);

  // Associate the local address with WinSocket.
  if (bind (WinSocket, 
            (struct sockaddr *) &local_sin, 
            sizeof (local_sin)) == SOCKET_ERROR) 
  {
    /*wsprintf (szError, TEXT("Binding socket failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);*/
    closesocket (WinSocket);
    success = FALSE;
  }

  // Establish a socket to listen for incoming connections.
  if (listen (WinSocket, MAX_PENDING_CONNECTS) == SOCKET_ERROR) 
  {
    /*wsprintf (szError, 
              TEXT("Listening to the client failed. Error: %d"),
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    closesocket (WinSocket);
    success = FALSE;
  }

  accept_sin_len = sizeof (accept_sin);



	//// ccw 2 aug 2000
	//launch the CE client when we are sure the socket creation has
	//succeded.
	////
	HRESULT hr = CeRapiInit();   
	WCHAR *appName= L"testRemoteCE.exe";
	bool result;
	//PROCESS_INFORMATION  procInfo;
	if ( FAILED(hr) )    {
		cout<<" SPAWN FAILED"<<endl;
		exit(-1);
	}
	
	result = 1;
	if ( result ==0 )    {
		cout<<"ERR--"<< CeGetLastError() <<endl;
		exit(-11);  
	}
	hr = CeRapiGetError();
	if ( FAILED(hr) )    {     
		cout<<"ERR2--"<<endl;
		exit(-11);  
	}
	CeRapiUninit();

  // Accept an incoming connection attempt on WinSocket.
  deviceSocket = accept (WinSocket, 
                       (struct sockaddr *) &accept_sin, 
                       (int *) &accept_sin_len);

  // Stop listening for connections from clients.
  closesocket (WinSocket);

  if (deviceSocket == INVALID_SOCKET) 
  {
    /*wsprintf (szError, TEXT("Accepting connection with client failed.")
              TEXT(" Error: %d"), WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }else{
	//good connection.
	//set up the baseTramp stuff....
	  if(!RemoteGetTrampTemplate()){
		cout <<" ERROR.. GETTING TRAMP ASM"<<endl;
	        exit(-1);
	 }
  }

}
示例#14
0
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* program = NULL;
	char* parameters = NULL;
	HRESULT hr;
	WCHAR* wide_program = NULL;
	WCHAR* wide_parameters = NULL;
	PROCESS_INFORMATION info;

	if (!handle_parameters(argc, argv, &program, &parameters))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(program);
	wide_program = wstr_from_current(program);
	if (parameters)
		wide_parameters = wstr_from_current(parameters);

	memset(&info, 0, sizeof(info));
	
	if (!CeCreateProcess(
				wide_program,
				wide_parameters,
				NULL,
				NULL,
				false,
				0,
				NULL,
				NULL,
				NULL,
				&info
				))
	{
		fprintf(stderr, "%s: Failed to execute '%s': %s\n", 
				argv[0],
				program,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	CeCloseHandle(info.hProcess);
	CeCloseHandle(info.hThread);

	result = 0;

exit:
	wstr_free_string(wide_program);
	wstr_free_string(wide_parameters);

	if (program)
		free(program);

	if (parameters)
		free(parameters);

	CeRapiUninit();
	return result;
}
示例#15
0
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* source = NULL;
	char* dest = NULL;
	HRESULT hr;
	WCHAR* wide_source = NULL;
	WCHAR* wide_dest = NULL;
	
	if (!handle_parameters(argc, argv, &source, &dest))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(source);
	wide_source = wstr_from_current(source);
	wide_source = adjust_remote_path(wide_source, true);

	convert_to_backward_slashes(dest);
	wide_dest   = wstr_from_current(dest);
	wide_dest   = adjust_remote_path(wide_dest, true);

	if (!CeMoveFile(wide_source, wide_dest))
	{
		fprintf(stderr, "%s: Cannot move '%s' to '%s': %s\n", 
				argv[0],
				source,
				dest,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	result = 0;

exit:
	wstr_free_string(wide_source);
	wstr_free_string(wide_dest);

	if (source)
		free(source);

	if (dest)
		free(dest);

	CeRapiUninit();
	return result;
}