Exemplo n.º 1
0
DWORD WINAPI ThreadProc(LPVOID a)
{
	atexit(lastExit);
	SingleInstanceManager instanceman;

#ifdef EXE_MAKER_DEBUG
	bool dodebug = true;
#else
	bool dodebug = false;
#endif

	if (dodebug)
		DEBUGCONSOLE = new DebugConsole("JSmooth Debug");

	//JVMOptions *options = new JVMOptions();

	bool singleinstance = EXE_MAKER_SINGLE_INSTANCE;
	if (singleinstance)
	{
		if (instanceman.alreadyExists())
		{
			instanceman.sendMessageInstanceShow();
			exit(0);
		}
		else
			instanceman.startMasterInstanceServer();
	}

	DEBUG(string("Main class: ") + EXE_MAKER_MAIN_CLASS);

	char curdir[256];
	GetCurrentDirectory(256, curdir);
	DEBUG(string("Currentdir: ") + curdir);

	HRESULT res = SetCurrentProcessExplicitAppUserModelID(EXE_MAKER_APP_ID);
	if(!SUCCEEDED(res))
	{
		MessageBox(0, "ICustomDestinationList: SetCurrentProcessExplicitAppUserModelID", "seven4idea", 0);
		return -1;
	}

	SetCurrentDirectory(EXE_MAKER_CURRENT_DIR);

	JavaMachineManager man;

	man.setUseConsole(dodebug);

	int retvalue = 0;

	if (man.run() == false)
	{
		DEBUG("Displaying error message to user...");
		if (MessageBox(NULL, EXE_MAKER_ERROR_TEXT, EXE_MAKER_ERROR_CAPTION, MB_OKCANCEL|MB_ICONERROR|MB_APPLMODAL) == IDOK)
			ShellExecute(NULL, "open", EXE_MAKER_DOWNLOAD_URL, NULL, "", 0);
	}
	else
		retvalue = man.getExitCode();

	DEBUG("NORMAL EXIT");
	DEBUGWAITKEY();

	return retvalue;
}
Exemplo n.º 2
0
int WINAPI WinMain(HINSTANCE hThisInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpszArgument,
	int nFunsterStil)
{

	atexit(lastExit);
	SingleInstanceManager instanceman;

	globalResMan = new ResourceManager("JAVA", PROPID, JARID, JNISMOOTHID);

	string silentFile = FileUtils::getExecutablePath() + "setup.silent";
	_silent = FileUtils::fileExists(silentFile);

	// sets up the command line arguments
	// not sure if lpszArgument can be 0 on Windows...
	if ((lpszArgument != 0) && (strlen(lpszArgument) > 0))
	{
		// Note that this overwrites an existing KEY_ARGUMENTS
		std::vector<std::string> args = StringUtils::split(lpszArgument, " \t\n\r", "\"'", false);
		globalResMan->setUserArguments(args);
	}

	loadLanguage(globalResMan->getProperty("minversion"));

	bool dodebug = globalResMan->getBooleanProperty("skel_Debug");

	if (dodebug)
	{
		DEBUGCONSOLE = new DebugConsole("JSmooth Debug");
		globalResMan->printDebug();
	}

	bool singleinstance = globalResMan->getBooleanProperty("skel_SingleInstance");
	if (singleinstance)
	{
		if (instanceman.alreadyExists())
		{
			if (!_silent) {
				instanceman.sendMessageInstanceShow();
			}
			exit(0);
		}
		else
		{
			instanceman.startMasterInstanceServer();
		}
	}

	DEBUG(string("Main class: ") + globalResMan->getMainName());

	char curdir[_MAX_PATH];
	GetCurrentDirectory(_MAX_PATH, curdir);
	DEBUG(string("Currentdir: ") + curdir);

	string newcurdir = globalResMan->getCurrentDirectory();
	SetCurrentDirectory(newcurdir.c_str());

	std::string message = MSG_ERROR_NO_JAVA_FIRST;// globalResMan->getProperty("skel_Message");
	std::string url = globalResMan->getProperty("skel_DownloadURL");
	std::string params = globalResMan->getProperty("skel_DownloadURLParams");
	bool singleProcess = globalResMan->getBooleanProperty("skel_SingleProcess");

	int tries = 0;
	int exitCode = 0;
	while (true) {

		if (tries > 0) {
			DEBUG("try jre again after download...");
		}

		JavaMachineManager *man = new JavaMachineManager(*globalResMan);
		man->setAcceptExe(true);
		man->setAcceptDLL(true);
		man->setUseConsole(dodebug);
		man->setPreferDLL(singleProcess);

		bool ok = man->run();
		exitCode = man->getExitCode();
		delete man;

		if (ok) {
			if (tries > 0) {
				Sleep(2000); // w/o may be the cause for the message 'installer already running'
			}
			break;
		}

		if (tries > 0) {
			if (_silent) {
				DEBUG(MSG_ERROR_NO_JAVA);
			}
			else {
				MessageBox(0, MSG_ERROR_NO_JAVA.c_str(), APP_TITLE.c_str(), MB_OK | MB_APPLMODAL);
			}
			break;
		}

		tries++;

		DEBUG("Displaying message to user...");
		DEBUG("URL=" + url);
		if (url.empty())
		{
			showGenericError();
			break;
		}

		if (!_silent && MessageBox(0, message.c_str(), APP_TITLE.c_str(), MB_OKCANCEL | MB_ICONQUESTION | MB_APPLMODAL) != IDOK) {
			break;
		}

		string adParams = params;
		string file = doDownload(url, adParams);

		if (file.empty())
		{
			showGenericError();
			break;
		}

		string ext = StringUtils::toLowerCase(FileUtils::getFileExtension(file));
		if (ext == "exe")
		{
			makeExecInfoGui(MSG_INSTALLING_JAVA, MSG_INSTALLING_JAVA_WAIT, file + " " + adParams, _silent);
		}
		else // anything else, we try to open it like a document
		{
			ShellExecute(0, "open", file.c_str(), adParams.c_str(), "", 0);
		}
	}

	DEBUG("NORMAL EXIT");
	DEBUGWAITKEY();

	return exitCode;
}