Example #1
0
static void getDefaultApp(UT_String &imageApp, bool &bLeaveImageAsPNG)
{
#ifdef WIN32
	bLeaveImageAsPNG = false;
	imageApp.clear();

	char buffer[MAX_PATH];
	// for WinNT mspaint is most likely in the system directory (eg C:\WINNT\SYSTEM32\MSPAINT.EXE)
	if (GetSystemDirectory(buffer, MAX_PATH))
	{
		imageApp = buffer;
		imageApp += "\\MSPAINT.EXE";
		UT_DEBUGMSG(("ABIPAINT: Checking if %s exists\n", imageApp.c_str()));
		if (!UT_isRegularFile(imageApp.c_str()))
			imageApp.clear();
	}
	// if not there, try in Win95b directory (eg %PROGRAMFILES%\ACCESSORIES\MSPAINT.EXE)
	if (imageApp.empty())
	{
		HKEY hKey;
		unsigned long lType;	
		DWORD dwSize;
		unsigned char* szValue = NULL;
		if( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS )
		{
			if( ::RegQueryValueEx( hKey, "ProgramFilesDir", NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS )
			{
				szValue = new unsigned char[dwSize + 1];
				::RegQueryValueEx( hKey, "ProgramFilesDir", NULL, &lType, szValue, &dwSize);
				imageApp = (char*) szValue;
				delete[] szValue;
				imageApp += "\\ACCESSORIES\\MSPAINT.EXE";
				UT_DEBUGMSG(("ABIPAINT: Checking if %s exists\n", imageApp.c_str()));
				if (!UT_isRegularFile(imageApp.c_str()))
					imageApp.clear();
			}
			::RegCloseKey(hKey);
		}
	}
	// if we still haven't found the file, then simply try mspaint.exe
	if (imageApp.empty())
	{
		imageApp = "mspaint.exe";
		UT_DEBUGMSG(("ABIPAINT: Falling back to %s (will probably fail)\n", imageApp.c_str()));
	}
#else
	// for other platforms default to the GIMP, assume in path
	bLeaveImageAsPNG = true;
	imageApp = "gimp";
#endif
}
bool XAP_App::findAbiSuiteLibFile(UT_String & path, const char * filename, const char * subdir)
{
	if (!filename)
	{ 
		return false;
	}

	bool bFound = false;

	const char * dir = getUserPrivateDirectory();
	if (dir)
	{
		path = dir;
		if (subdir)
		{
			path += G_DIR_SEPARATOR;
			path += subdir;
		}
		path += G_DIR_SEPARATOR;
		path += filename;
		bFound = UT_isRegularFile (path.c_str ());
	}
	if (!bFound && (dir = getAbiSuiteLibDir()))
	{
		path = dir;
		if (subdir)
		{
			path += G_DIR_SEPARATOR;
			path += subdir;
		}
		path += G_DIR_SEPARATOR;
		path += filename;
		bFound = UT_isRegularFile (path.c_str ());
	}
	return bFound;
}
/*!
	Localize and URL for help.
	
	\param pathBeforeLang the path for the help file that prefix
	\param pathAfterLang the path inside the localized directory
	\param remoteURLbase remote URL if help files are not found.
	
	Override in subclasses if platform needs specific work
 */
UT_String XAP_AppImpl::localizeHelpUrl (const char * pathBeforeLang, 
										   const char * pathAfterLang,
										   const char * remoteURLbase)
{
	XAP_App* pApp = XAP_App::getApp();

	UT_return_val_if_fail(pApp, "");
	XAP_Prefs* pPrefs = pApp->getPrefs();
	UT_return_val_if_fail(pPrefs, "");

	const char* abiSuiteLibDir = pApp->getAbiSuiteLibDir();
	const gchar* abiSuiteLocString = NULL;
	UT_String url;

	// evil...
	pPrefs->getPrefsValue((gchar*)"StringSet", &abiSuiteLocString);

	// 1st try file on user's computer (local file), if not exist try remote help
	UT_String path(abiSuiteLibDir);
	_catPath(path, pathBeforeLang);

	UT_String localized_path(path);
	_catPath(localized_path, abiSuiteLocString);

	if (UT_directoryExists(localized_path.c_str()))
	{
		// the localised help exists, so use it
		path = localized_path;
	}
	else
	{
		// the localised help directory does not exist, so fall back to the
		// en-US help location, which is the default lang, so usually available
		localized_path = path;
		_catPath(localized_path, "en-US");
	}

	_catPath(localized_path, pathAfterLang);
	localized_path += ".html";

	if (remoteURLbase && !UT_isRegularFile(localized_path.c_str()))
	{
		// not found, so build localized path for remote URL (but we can't verify remote URL)
		url = remoteURLbase;
		
		// HACK: Not all help files are localized. 
		// HACK: Hard code the available translations here instead of 404-ing.
		if (!(
			!strcmp(abiSuiteLocString, "en-US") ||
			!strcmp(abiSuiteLocString, "fr-FR") ||
			!strcmp(abiSuiteLocString, "pl-PL")
			))
			_catPath(url, "en-US");
		else
			_catPath(url, abiSuiteLocString);
		_catPath(url, pathAfterLang);
		url += ".html";
	}
	else
	{
		url = "file://";
		url += localized_path;
	}

	return url;
}