Exemplo n.º 1
0
generic_string getLocalizationPathFromParam(ParamVector & params)
{
	generic_string locStr;
	if (!getParamVal('L', params, locStr))
		return TEXT("");
	return NppParameters::getLocPathFromStr(locStr.c_str());
}
Exemplo n.º 2
0
LangType getLangTypeFromParam(ParamVector & params)
{
	generic_string langStr;
	if (!getParamVal('l', params, langStr))
		return L_EXTERNAL;
	return NppParameters::getLangIDFromStr(langStr.c_str());
}
Exemplo n.º 3
0
int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent) {
	generic_string numStr;
	if (!getParamVal(paramName, params, numStr))
	{
		isParamePresent = false;
		return -1;
	}
	isParamePresent = true;
	return generic_atoi(numStr.c_str());
};
TransformErrFunction::cParamVals * TransformErrFunction::getVals() const
{
    cParamVals * vals = new cParamVals(indexedParamLocations_.size());

    size_t paramCount = indexedParamLocations_.size();
    for(size_t i=0; i < paramCount; i++)
    {
        (*vals)[i] = getParamVal(i);
    }
    return vals;
}
double TransformErrFunction::pd(int idx)
{
    if(!RECalculated_)
        throw new GRCException("TransformErrFunction::pd: Reproj. Err. not calculated");
    if(idx < 0 || idx >= (int)indexedParamLocations_.size())
        throw new GRCException("TransformErrFunction::pd: Idx OOB");

    /*double * param = indexedParamLocations_[idx];

    double paramFactor = getParamFactor(idx); //Scale

    double paramVal = *param;
	double delta_inv, delta = 1e-4*fabs(paramVal); //Todo: constants...
	if (delta < 1e-6) {
		delta = 1e-6;
        delta_inv = 1e+6;
	}
    else
        delta_inv = 1.0/delta;

    *param = paramVal + delta;
    double f_x_plus_delta = evaluateReprojErrInt(); //Todo: only need to measure change in reproj error--look only at the few transforms this val affects (all transforms including the image containing this point)
    *param = paramVal;

    return (f_x_plus_delta - reprojErrVal_) * delta_inv * paramFactor;*/

    double paramVal = getParamVal(idx);

	double delta_inv, delta = 1e-4*fabs(paramVal); //Todo: constants...
	if (delta < 1e-6) {
		delta = 1e-6;
        delta_inv = 1e+6;
	}
    else
        delta_inv = 1.0/delta;

    setParamVal(idx, paramVal + delta);
    double f_x_plus_delta = evaluateReprojErrInt(); //Todo: only need to measure change in reproj error--look only at the few transforms this val affects (all transforms including the image containing this point)
    setParamVal(idx, paramVal);

    return (f_x_plus_delta - reprojErrVal_) * delta_inv;
};
Exemplo n.º 6
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow)
{
	bool isSilentMode = false;
	FILE *pFile = NULL;

	bool launchSettingsDlg = false;
	bool isVerbose = false;
	string version = "";

	if (lpszCmdLine && lpszCmdLine[0])
	{
		launchSettingsDlg = isInList(FLAG_OPTIONS, lpszCmdLine);
		isVerbose = isInList(FLAG_VERBOSE, lpszCmdLine);
		version = getParamVal('v', lpszCmdLine);
	}
	hInst = hInstance;
	try {
		GupParameters gupParams("gup.xml");
		GupExtraOptions extraOptions("gupOptions.xml");
		GupNativeLang nativeLang("nativeLang.xml");

		if (launchSettingsDlg)
		{
			if (extraOptions.hasProxySettings())
			{
				proxySrv = extraOptions.getProxyServer();
				proxyPort = extraOptions.getPort();
			}
			if (::DialogBox(hInst, MAKEINTRESOURCE(IDD_PROXY_DLG), NULL, reinterpret_cast<DLGPROC>(proxyDlgProc)))
				extraOptions.writeProxyInfo("gupOptions.xml", proxySrv.c_str(), proxyPort);

			return 0;
		}

		msgBoxTitle = gupParams.getMessageBoxTitle();
		abortOrNot = nativeLang.getMessageString("MSGID_ABORTORNOT");

		std::string updateInfo;
		char errorBuffer[CURL_ERROR_SIZE];

		// Get your software's current version.
		// If you pass the version number as the argument
		// then the version set in the gup.xml will be overrided
		if (lpszCmdLine && lpszCmdLine[0])
			gupParams.setCurrentVersion(lpszCmdLine);

		// override silent mode if "-isVerbose" is passed as argument
		if (isVerbose)
			gupParams.setSilentMode(false);

		isSilentMode = gupParams.isSilentMode();

		// Check on the web the availibility of update
		// Get the update package's location
		CURL *curl;
		CURLcode res;

		curl = curl_easy_init();
		if(curl) 
		{
			std::string urlComplete = gupParams.getInfoLocation() + "?version=";
			if (version != "")
				urlComplete += version;
			else
				urlComplete += gupParams.getCurrentVersion();

			curl_easy_setopt(curl, CURLOPT_URL, urlComplete.c_str());
            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE);

			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getUpdateInfo);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, &updateInfo);
			curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);

			if (extraOptions.hasProxySettings())
			{
				curl_easy_setopt(curl, CURLOPT_PROXY, extraOptions.getProxyServer().c_str());
				curl_easy_setopt(curl, CURLOPT_PROXYPORT, extraOptions.getPort());
			}

			res = curl_easy_perform(curl);

			curl_easy_cleanup(curl);
		}

		if (res != 0)
		{
			if (!isSilentMode)
				::MessageBoxA(NULL, errorBuffer, "curl error", MB_OK);
			return -1;
		}

		GupDownloadInfo gupDlInfo(updateInfo.c_str());

		if (!gupDlInfo.doesNeed2BeUpdated())
		{
			if (!isSilentMode)
			{
				string noUpdate = nativeLang.getMessageString("MSGID_NOUPDATE");
				if (noUpdate == "")
					noUpdate = MSGID_NOUPDATE;
				::MessageBoxA(NULL, noUpdate.c_str(), gupParams.getMessageBoxTitle().c_str(), MB_OK);
			}
			return 0;
		}

		string updateAvailable = nativeLang.getMessageString("MSGID_UPDATEAVAILABLE");
		if (updateAvailable == "")
			updateAvailable = MSGID_UPDATEAVAILABLE;
		
		int thirdButtonCmd = gupParams.get3rdButtonCmd();
		int buttonStyle = thirdButtonCmd?MB_YESNOCANCEL:MB_YESNO;
		int dlAnswer = ::MessageBoxA(NULL, updateAvailable.c_str(), gupParams.getMessageBoxTitle().c_str(), buttonStyle);

		if (dlAnswer == IDNO)
		{
			return 0;
		}
		
		if (dlAnswer == IDCANCEL)
		{
			if (gupParams.getClassName() != "")
			{
				HWND h = ::FindWindowExA(NULL, NULL, gupParams.getClassName().c_str(), NULL);

				if (h)
				{
					::SendMessage(h, thirdButtonCmd, gupParams.get3rdButtonWparam(), gupParams.get3rdButtonLparam());
				}
			}
			return 0;
		}
		
		::CreateThread(NULL, 0, launchProgressBar, NULL, 0, NULL);
		
		std::string dlDest = std::getenv("TEMP");
		dlDest += "\\";
		dlDest += ::PathFindFileNameA(gupDlInfo.getDownloadLocation().c_str());

        char *ext = ::PathFindExtensionA(gupDlInfo.getDownloadLocation().c_str());
        if (strcmp(ext, ".exe") != 0)
            dlDest += ".exe";

		pFile = fopen(dlDest.c_str(), "wb");

		//  Download the install package from indicated location
		curl = curl_easy_init();
		if(curl) 
		{
			curl_easy_setopt(curl, CURLOPT_URL, gupDlInfo.getDownloadLocation().c_str());
            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE);

			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getDownloadData);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, pFile);

			curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
			curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, setProgress);
			curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, hProgressBar);
			
			curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
			
			if (extraOptions.hasProxySettings())
			{
				curl_easy_setopt(curl, CURLOPT_PROXY, extraOptions.getProxyServer().c_str());
				curl_easy_setopt(curl, CURLOPT_PROXYPORT, extraOptions.getPort());
			}
			res = curl_easy_perform(curl);

			curl_easy_cleanup(curl);
		}

		if (res != 0)
		{
			if (!isSilentMode)
				::MessageBoxA(NULL, errorBuffer, "curl error", MB_OK);
			if (doAbort)
			{
				string dlStopped = nativeLang.getMessageString("MSGID_DOWNLOADSTOPPED");
				if (dlStopped == "")
					dlStopped = MSGID_DOWNLOADSTOPPED;
				::MessageBoxA(NULL, dlStopped.c_str(), gupParams.getMessageBoxTitle().c_str(), MB_OK);
			}
			return -1;
		}

		fflush(pFile);
		fclose(pFile);
		pFile = NULL;

		if (gupParams.getClassName() != "")
		{
			HWND h = ::FindWindowExA(NULL, NULL, gupParams.getClassName().c_str(), NULL);

			if (h)
			{
				string msg = gupParams.getClassName();
				string closeApp = nativeLang.getMessageString("MSGID_CLOSEAPP");
				if (closeApp == "")
					closeApp = MSGID_CLOSEAPP;
				msg += closeApp;

				int installAnswer = ::MessageBoxA(NULL, msg.c_str(), gupParams.getMessageBoxTitle().c_str(), MB_YESNO);

				if (installAnswer == IDNO)
				{
					return 0;
				}
			}
			// kill all process of binary needs to be updated.
			while (h)
			{
				::SendMessage(h, WM_CLOSE, 0, 0);
				h = ::FindWindowExA(NULL, NULL, gupParams.getClassName().c_str(), NULL);
			}
		}

		// execute the installer
		HINSTANCE result = ::ShellExecuteA(NULL, "open", dlDest.c_str(), "", ".", SW_SHOW);
        
        if ((unsigned long)result <= 32) // There's a problem (Don't ask me why, ask Microsoft)
        {
            return -1;
        }   
		return 0;

	} catch (exception ex) {
		if (!isSilentMode)
			::MessageBoxA(NULL, ex.what(), "Xml Exception", MB_OK);

		if (pFile != NULL)
			fclose(pFile);

		return -1;
	}
	catch (...)
	{
		if (!isSilentMode)
			::MessageBoxA(NULL, "Unknown", "Unknown Exception", MB_OK);

		if (pFile != NULL)
			fclose(pFile);

		return -1;
	}
}