std::string Manager::init_plugin_path() { char* env = getenv("GSTLAPPLIHOME"); if( env ) { //std::string base_path( env ); //return base_path + "/plugins/"; QString envpath( env ); QDir homedir( envpath ); homedir.cd( "plugins" ); QByteArray tmp = homedir.absolutePath().toAscii(); return tmp.constData(); } else { QDir current_dir; //std::string path( current_dir.absPath().latin1() ); //path += "/plugins/"; //return ( path + "/plugins/" ); current_dir.cd( "plugins" ); QByteArray tmp = current_dir.absolutePath().toAscii(); return tmp.constData(); } }
static WCHAR *GetGhostscriptPath() { WCHAR *gsProducts[] = { L"AFPL Ghostscript", L"Aladdin Ghostscript", L"GPL Ghostscript", L"GNU Ghostscript", }; // find all installed Ghostscript versions WStrVec versions; REGSAM access = KEY_READ | KEY_WOW64_32KEY; TryAgain64Bit: for (int i = 0; i < dimof(gsProducts); i++) { HKEY hkey; ScopedMem<WCHAR> keyName(str::Join(L"Software\\", gsProducts[i])); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, access, &hkey) != ERROR_SUCCESS) continue; WCHAR subkey[32]; for (DWORD ix = 0; RegEnumKey(hkey, ix, subkey, dimof(subkey)) == ERROR_SUCCESS; ix++) versions.Append(str::Dup(subkey)); RegCloseKey(hkey); } if ((access & KEY_WOW64_32KEY)) { // also look for 64-bit Ghostscript versions under 64-bit Windows access = KEY_READ | KEY_WOW64_64KEY; #ifndef _WIN64 // (unless this is 32-bit Windows) if (IsRunningInWow64()) #endif goto TryAgain64Bit; } versions.SortNatural(); // return the path to the newest installation for (size_t ix = versions.Count(); ix > 0; ix--) { for (int i = 0; i < dimof(gsProducts); i++) { ScopedMem<WCHAR> keyName(str::Format(L"Software\\%s\\%s", gsProducts[i], versions.At(ix - 1))); ScopedMem<WCHAR> GS_DLL(ReadRegStr(HKEY_LOCAL_MACHINE, keyName, L"GS_DLL")); if (!GS_DLL) continue; ScopedMem<WCHAR> dir(path::GetDir(GS_DLL)); ScopedMem<WCHAR> exe(path::Join(dir, L"gswin32c.exe")); if (file::Exists(exe)) return exe.StealData(); exe.Set(path::Join(dir, L"gswin64c.exe")); if (file::Exists(exe)) return exe.StealData(); } } // if Ghostscript isn't found in the Registry, try finding it in the %PATH% DWORD size = GetEnvironmentVariable(L"PATH", NULL, 0); ScopedMem<WCHAR> envpath(AllocArray<WCHAR>(size)); if (size > 0 && envpath) { GetEnvironmentVariable(L"PATH", envpath, size); WStrVec paths; paths.Split(envpath, L";", true); for (size_t ix = 0; ix < paths.Count(); ix++) { ScopedMem<WCHAR> exe(path::Join(paths.At(ix), L"gswin32c.exe")); if (file::Exists(exe)) return exe.StealData(); exe.Set(path::Join(paths.At(ix), L"gswin64c.exe")); if (file::Exists(exe)) return exe.StealData(); } } return NULL; }