示例#1
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;
}
示例#2
0
文件: AmigaUAE.cpp 项目: emoon/ProDBG
bool AmigaUAE::validateSettings()
{
    readSettings();

    if (m_uaeExe.isEmpty()) {
        QMessageBox::critical(nullptr, QStringLiteral("No UAE executable selected"),
                              QStringLiteral("In order to run Amiga executables you need to select the emulator "
                                             "executable in \"Config -> Amiga UAE..\""));
        return false;
    }

    QFileInfo fileInfo(m_localExeToRun);
    QString filename = fileInfo.fileName();

    m_fileToRun = QStringLiteral("dh0:") + filename;

    if (m_configMode == AmigaUAEConfig::ConfigMode_Manual) {
        if (m_config.isEmpty()) {
            QMessageBox::critical(nullptr, QStringLiteral("No UAE config selected"),
                                  QStringLiteral("In order to run Amiga executables you need to select a configuration "
                                                 "file for UAE in \"Config -> Amiga UAE..\""));
            return false;
        }

        if (m_dh0Path.isEmpty()) {
            QMessageBox::critical(
                nullptr, QStringLiteral("No hard drive path selected"),
                QStringLiteral("In order to run Amiga executables you need to select the directory use "
                               "for the hard drive in \"Config -> Amiga UAE..\""));
            return false;
        }

        // If we aren't going to copy file we have to make sure the path to the file is located in the output
        // hdd directory

        if (!m_copyFiles) {
            if (m_localExeToRun.indexOf(m_dh0Path) != 0) {
                QMessageBox::critical(
                    nullptr, QStringLiteral("Executable not peresent in path"),
                    QStringLiteral(
                        "The executable you are trying to run isn't present in the HDD path."
                        "Either select correct path or the 'Copy files' option in \"Config -> Amiga UAE..\""));
                return false;
            }
        } else {
            return copyExecutable(m_dh0Path, m_localExeToRun);
        }
    } else {
        m_tempDir = new QTemporaryDir();
        m_dh0Path = m_tempDir->path();

        m_config = generateUAEConfig(m_tempDir->path(), m_romPath, m_configMode);
        bool copyRes = copyExecutable(m_dh0Path, m_localExeToRun);

        if (m_config.isEmpty() || !copyRes) {
            delete m_tempDir;
            m_tempDir = nullptr;
            return false;
        }
    }

    return true;
}