/* PaletteManager::loadCustomPalettes * Loads any files in the '<userdir>/palettes' directory as palettes, * with names from the files (minus the file extension) *******************************************************************/ bool PaletteManager::loadCustomPalettes() { // If the directory doesn't exist create it if (!wxDirExists(appPath("palettes", DIR_USER))) wxMkdir(appPath("palettes", DIR_USER)); // Open the custom palettes directory wxDir res_dir; res_dir.Open(appPath("palettes", DIR_USER)); // Go through each file in the directory string filename = wxEmptyString; bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES); while (files) { // Load palette data Palette8bit* pal = new Palette8bit(); MemChunk mc; mc.importFile(res_dir.GetName() + "/" + filename); pal->loadMem(mc); // Add the palette wxFileName fn(filename); addPalette(pal, fn.GetName()); // Next file files = res_dir.GetNext(&filename); } return true; }
QString Paths::dataPath() { #ifdef DATA_PATH QString path = QString(DATA_PATH); if (!path.isEmpty()) return path; else return appPath(); #else return appPath(); #endif }
QString Paths::fontPath() { QString path = appPath() + "/mplayer/fonts"; QDir font_dir(path); QStringList files = font_dir.entryList(QStringList() << "*.ttf" << "*.otf", QDir::Files); //qDebug("Paths:fontPath: files in %s: %d", path.toUtf8().constData(), files.count()); if (files.count() > 0) { return path; } else { return appPath() + "/open-fonts"; } }
QString Paths::docPath() { #ifdef DOC_PATH QString path = QString(DOC_PATH); if (!path.isEmpty()) return path; else return appPath() + "/docs"; #else return appPath() + "/docs"; #endif }
QString Helper::docPath() { #ifdef DOC_PATH QString path = QString(DOC_PATH); if (!path.isEmpty()) return path; else return appPath(); #else return appPath(); #endif }
QString Helper::confPath() { #ifdef CONF_PATH QString path = QString(CONF_PATH); if (!path.isEmpty()) return path; else return appPath(); #else return appPath(); #endif }
QString Helper::translationPath() { #ifdef TRANSLATION_PATH QString path = QString(TRANSLATION_PATH); if (!path.isEmpty()) return path; else return appPath() + "/translations"; #else return appPath() + "/translations"; #endif }
QString Helper::themesPath() { #ifdef THEMES_PATH QString path = QString(THEMES_PATH); if (!path.isEmpty()) return path; else return appPath() + "/themes"; #else return appPath() + "/themes"; #endif }
QString Helper::shortcutsPath() { #ifdef SHORTCUTS_PATH QString path = QString(SHORTCUTS_PATH); if (!path.isEmpty()) return path; else return appPath() + "/shortcuts"; #else return appPath() + "/shortcuts"; #endif }
/* MainApp::OnExit * Application shutdown, run when program is closed *******************************************************************/ int MainApp::OnExit() { exiting = true; // Save configuration saveConfigFile(); // Save text style configuration StyleSet::saveCurrent(); // Save colour configuration MemChunk ccfg; ColourConfiguration::writeConfiguration(ccfg); ccfg.exportFile(appPath("colours.cfg", DIR_USER)); // Save game exes wxFile f; f.Open(appPath("executables.cfg", DIR_USER), wxFile::write); f.Write(Executables::writeExecutables()); f.Close(); // Close the map editor if it's open MapEditorWindow::deleteInstance(); // Close all open archives theArchiveManager->closeAll(); // Clean up EntryType::cleanupEntryTypes(); ArchiveManager::deleteInstance(); Console::deleteInstance(); SplashWindow::deleteInstance(); // Clear temp folder wxDir temp; temp.Open(appPath("", DIR_TEMP)); string filename = wxEmptyString; bool files = temp.GetFirst(&filename, wxEmptyString, wxDIR_FILES); while (files) { if (!wxRemoveFile(appPath(filename, DIR_TEMP))) wxLogMessage("Warning: Could not clean up temporary file \"%s\"", filename); files = temp.GetNext(&filename); } // Close lua Lua::close(); return 0; }
/* ColourConfiguration::init * Initialises the colour configuration *******************************************************************/ bool ColourConfiguration::init() { // Load default configuration loadDefaults(); // Check for saved colour configuration if (wxFileExists(appPath("colours.cfg", DIR_USER))) { MemChunk ccfg; ccfg.importFile(appPath("colours.cfg", DIR_USER)); readConfiguration(ccfg); } return true; }
bool MainWindow::serverArgs(QStringList& args, QString& app) { app = appPath(appConfig().synergysName(), appConfig().synergys()); if (!QFile::exists(app)) { if (QMessageBox::warning(this, tr("Synergy server not found"), tr("The executable for the synergy server does not exist. Do you want to browse for the synergy server now?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return false; app = SettingsDialog::browseForSynergys(this, appConfig().synergyProgramDir(), appConfig().synergysName()); if (app.isEmpty()) return false; appConfig().setSynergys(app); } if (appConfig().logToFile()) { appConfig().persistLogDir(); args << "--log" << appConfig().logFilename(); } args << "-c" << configFilename() << "--address" << address(); return true; }
/* Icons::loadIcons * Loads all icons from slade.pk3 (in the icons/ dir) *******************************************************************/ bool Icons::loadIcons() { string tempfile = appPath("sladetemp", DIR_TEMP); // Get slade.pk3 Archive* res_archive = theArchiveManager->programResourceArchive(); // Do nothing if it doesn't exist if (!res_archive) return false; // Get the icons directory of the archive ArchiveTreeNode* dir_icons = res_archive->getDir("icons/"); // Load general icons iconsets_general.push_back("Default"); loadIconsDir(GENERAL, (ArchiveTreeNode*)dir_icons->getChild("general")); // Load entry list icons iconsets_entry.push_back("Default"); loadIconsDir(ENTRY, (ArchiveTreeNode*)dir_icons->getChild("entry_list")); // Load text editor icons loadIconsDir(TEXT_EDITOR, (ArchiveTreeNode*)dir_icons->getChild("text_editor")); return true; }
/* StyleSet::saveCurrent * Writes the current style set to the 'current.sss' file *******************************************************************/ void StyleSet::saveCurrent() { if (!ss_current) return; ss_current->writeFile(appPath("current.sss", DIR_USER)); }
/* StyleSet::initCurrent * Initialises the 'current' style set from the previously saved * 'current.sss' file, or uses the default set if the file does not * exist *******************************************************************/ void StyleSet::initCurrent() { // Create 'current' styleset ss_current = new StyleSet(); ss_current->name = "<current styleset>"; // First up, check if "<userdir>/current.sss" exists string path = appPath("current.sss", DIR_USER); if (wxFileExists(path)) { // Read it in Tokenizer tz; tz.openFile(path); // Parse it ParseTreeNode root; root.allowDup(true); root.parse(tz); // Find definition ParseTreeNode* node = (ParseTreeNode*)root.getChild("styleset"); if (node) { // If found, load it into the current set ss_current->parseSet(node); return; } } // Unable to load from userdir, just load first styleset (should be default) if (style_sets.size() > 0) ss_current->copySet(style_sets[0]); }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QUrl appPath(QString("%1").arg(app.applicationDirPath())); qDebug() << "This is where the application lives " << appPath; engine.rootContext()->setContextProperty("appPath", appPath); QUrl moviesPath; const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation); if (moviesLocation.isEmpty()){ moviesPath = appPath.resolved(QUrl("/home/bps")); } else { moviesPath = QString("%1").arg(moviesLocation.first()); } engine.rootContext()->setContextProperty("moviesPath", moviesPath); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
QStringList DataLocations::getDefaultPluginsPath() { QStringList retval; if(!isRunFromBuildFolder()) { QString appPath(qApp->applicationDirPath()); QString installLocation = appPath; #ifndef CX_WINDOWS installLocation = appPath + "/plugins"; #endif if (QFile(installLocation).exists()) retval << installLocation; QString fallbackInstallLocation = appPath; if (QFile(fallbackInstallLocation).exists()) retval << fallbackInstallLocation; } else { QString bundlePath = DataLocations::getBundlePath(); QString buildLocation = bundlePath; #ifndef CX_WINDOWS buildLocation = bundlePath + "/plugins"; #endif if (QFile(buildLocation).exists()) retval << buildLocation; } return retval; }
void LuaBindingsTest::runXULSample(const std::string & inAppname) { Poco::Path appPath(mPathToXULRunnerSamples, inAppname); Windows::CurrentDirectoryChanger cd(appPath.toString()); #if TEST_WITH_MOZILLA_XULRUNNER ::ShellExecute(NULL, TEXT("open"), TEXT("run.bat"), NULL, NULL, SW_SHOWNORMAL); #endif Lua::XULRunnerWithLua xulRunner(mModuleHandle); ElementPtr rootEl; // Extra scope added to have the ErrorCatcher to do its logging on end of scope { ErrorCatcher errorCatcher; xulRunner.Logger = boost::bind(Lua::showMessage, _1); rootEl = xulRunner.loadApplication("application.ini"); if (!rootEl) { ReportError("Failed to load XUL sample: " + inAppname); return; } } if (XMLWindow * wnd = rootEl->downcast<XMLWindow>()) { wnd->showModal(XMLWindow::CenterInScreen); } }
/* TempFolderWizardPage::canGoNext * Returns true if the wizard page is valid *******************************************************************/ bool TempFolderWizardPage::canGoNext() { #ifdef WIN32 string sep = "\\"; #else string sep = "/"; #endif string testfilename; if (rb_use_system->GetValue()) testfilename = wxStandardPaths::Get().GetTempDir().Append(sep).Append("SLADE3").Append(sep).Append("test.txt"); else if (rb_use_slade_dir->GetValue()) testfilename = appPath("test.txt", DIR_APP); else testfilename = text_custom_dir->GetValue() + sep + "test.txt"; wxFile test; if (test.Open(testfilename, wxFile::write)) { test.Close(); if (wxRemoveFile(testfilename)) return true; } wxMessageBox("The selected folder cannot be written to. Please select a different folder to use.", "", wxICON_ERROR); return false; }
bool MainWindow::clientArgs(QStringList& args, QString& app) { app = appPath(appConfig().synergycName(), appConfig().synergyc()); if (!QFile::exists(app)) { if (QMessageBox::warning(this, tr("Synergy client not found"), tr("The executable for the synergy client does not exist. Do you want to browse for the synergy client now?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return false; app = SettingsDialog::browseForSynergyc(this, appConfig().synergyProgramDir(), appConfig().synergycName()); if (app.isEmpty()) return false; appConfig().setSynergyc(app); } if (m_pLineEditHostname->text().isEmpty()) { QMessageBox::warning(this, tr("Hostname is empty"), tr("Please fill in a hostname for the synergy client to connect to.")); return false; } if (appConfig().logToFile()) { appConfig().persistLogDir(); args << "--log" << appConfig().logFilename(); } args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port()); return true; }
/* MainWindow::saveLayout * Saves the current window layout to a file *******************************************************************/ void MainWindow::saveLayout() { // Open layout file wxFile file(appPath("mainwindow.layout", DIR_USER), wxFile::write); // Write component layout wxAuiManager *m_mgr = wxAuiManager::GetManager(this); // Console pane file.Write("\"console\" "); string pinf = m_mgr->SavePaneInfo(m_mgr->GetPane("console")); file.Write(S_FMT("\"%s\"\n", CHR(pinf))); // Archive Manager pane file.Write("\"archive_manager\" "); pinf = m_mgr->SavePaneInfo(m_mgr->GetPane("archive_manager")); file.Write(S_FMT("\"%s\"\n", CHR(pinf))); // Undo History pane file.Write("\"undo_history\" "); pinf = m_mgr->SavePaneInfo(m_mgr->GetPane("undo_history")); file.Write(S_FMT("\"%s\"\n", CHR(pinf))); // Close file file.Close(); }
/* EntryTreeClipboardItem::EntryTreeClipboardItem * EntryTreeClipboardItem class constructor *******************************************************************/ EntryTreeClipboardItem::EntryTreeClipboardItem(vector<ArchiveEntry*>& entries, vector<ArchiveTreeNode*>& dirs) : ClipboardItem(CLIPBOARD_ENTRY_TREE) { // Create tree tree = new ArchiveTreeNode(); // Copy entries for (unsigned a = 0; a < entries.size(); a++) tree->addEntry(new ArchiveEntry(*(entries[a]))); // Copy entries to system clipboard // (exports them as temp files and adds the paths to the clipboard) if (wxTheClipboard->Open()) { wxTheClipboard->Clear(); wxFileDataObject* file = new wxFileDataObject(); for (unsigned a = 0; a < entries.size(); a++) { // Export to file string filename = entries[a]->getName(true) + "." + entries[a]->getType()->getExtension(); filename = appPath(filename, DIR_TEMP); entries[a]->exportFile(filename); // Add to clipboard file->AddFile(filename); } wxTheClipboard->AddData(file); wxTheClipboard->Close(); } // Copy dirs for (unsigned a = 0; a < dirs.size(); a++) tree->addChild(dirs[a]->clone()); }
static std::wstring GetPathToLiveBrowser() { HKEY hKey; // First, look at the "App Paths" registry key for a "chrome.exe" entry. This only // checks for installs for all users. If Chrome is only installed for the current user, // we fall back to the code below. if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe", 0, KEY_READ, &hKey)) { wchar_t wpath[MAX_PATH] = {0}; DWORD length = MAX_PATH; RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)wpath, &length); RegCloseKey(hKey); return std::wstring(wpath); } // We didn't get an "App Paths" entry. This could be because Chrome was only installed for // the current user, or because Chrome isn't installed at all. // Look for Chrome.exe at C:\Users\{USERNAME}\AppData\Local\Google\Chrome\Application\chrome.exe TCHAR localAppPath[MAX_PATH] = {0}; SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppPath); std::wstring appPath(localAppPath); appPath += L"\\Google\\Chrome\\Application\\chrome.exe"; return appPath; }
/* TranslationEditorDialog::onBtnSave * Called when the 'Save Translation' button is clicked *******************************************************************/ void TranslationEditorDialog::onBtnSave(wxCommandEvent& e) { // If the directory doesn't exist create it string dir = appPath("translations", DIR_USER); if (!wxDirExists(dir)) wxMkdir(dir); // Create save file dialog wxFileDialog dialog_save(this, "Save Translation to File", dir, wxEmptyString, "Text File (*.txt)|*.txt", wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition); // Run the dialog & check that the user didn't cancel if (dialog_save.ShowModal() == wxID_OK) { // Get translation as text string string str = translation.asText(); // Open file for writing wxFile file(dialog_save.GetPath(), wxFile::write); // Write string to file file.Write(str); // Close file file.Close(); } }
void CoreLib::CoreLibInitialize(int argc, char **argv) { boost::filesystem::path path(boost::filesystem::initial_path<boost::filesystem::path>()); if (argc > 0 && argv[0] != NULL) path = boost::filesystem::system_complete(boost::filesystem::path(argv[0])); std::string appId(path.filename().string()); std::string appPath(boost::algorithm::replace_last_copy(path.string(), appId, "")); boost::filesystem::current_path(appPath); }
std::wstring AppPath() { WCHAR szPath[MAX_PATH]; GetModuleFileName(NULL, szPath, FILENAME_MAX); wstring appPath(szPath); appPath = appPath.substr(0, appPath.find_last_of(L"\\")); appPath = appPath.substr(0, appPath.find_last_of(L"\\")); return appPath; }
/* MainWindow::onHTMLLinkClicked * Called when a link is clicked on the HTML Window, so that * external (http) links are opened in the default browser *******************************************************************/ void MainWindow::onHTMLLinkClicked(wxEvent& e) { wxWebViewEvent& ev = (wxWebViewEvent&)e; string href = ev.GetURL(); #ifdef __WXGTK__ href.Replace("file://", ""); #endif if (href.EndsWith("/")) href.RemoveLast(1); if (href.StartsWith("http://")) { wxLaunchDefaultBrowser(ev.GetURL()); ev.Veto(); } else if (href.StartsWith("recent://")) { // Recent file string rs = href.Mid(9); unsigned long index = 0; rs.ToULong(&index); index++; panel_archivemanager->handleAction(S_FMT("aman_recent%lu", index)); createStartPage(); } else if (href.StartsWith("action://")) { // Action if (href.EndsWith("open")) theApp->doAction("aman_open"); else if (href.EndsWith("newwad")) theApp->doAction("aman_newwad"); else if (href.EndsWith("newzip")) theApp->doAction("aman_newzip"); else if (href.EndsWith("newmap")) { theApp->doAction("aman_newmap"); return; } else if (href.EndsWith("reloadstartpage")) createStartPage(); html_startpage->Reload(); } else if (wxFileExists(href)) { // Navigating to file, open it string page = appPath("startpage.htm", DIR_TEMP); if (wxFileName(href).GetLongPath() != wxFileName(page).GetLongPath()) theArchiveManager->openArchive(href); ev.Veto(); } }
bool exportEntry() { wxFileName fn(appPath(entry->getName(), DIR_TEMP)); fn.SetExt("mid"); // Convert to WAV data MemChunk convdata; // Doom Sound if (entry->getType()->getFormat() == "snd_doom" || entry->getType()->getFormat() == "snd_doom_mac") Conversions::doomSndToWav(entry->getMCData(), convdata); // Doom PC Speaker Sound else if (entry->getType()->getFormat() == "snd_speaker") Conversions::spkSndToWav(entry->getMCData(), convdata); // AudioT PC Speaker Sound else if (entry->getType()->getFormat() == "snd_audiot") Conversions::spkSndToWav(entry->getMCData(), convdata, true); // Wolfenstein 3D Sound else if (entry->getType()->getFormat() == "snd_wolf") Conversions::wolfSndToWav(entry->getMCData(), convdata); // Creative Voice File else if (entry->getType()->getFormat() == "snd_voc") Conversions::vocToWav(entry->getMCData(), convdata); // Jaguar Doom Sound else if (entry->getType()->getFormat() == "snd_jaguar") Conversions::jagSndToWav(entry->getMCData(), convdata); // Blood Sound else if (entry->getType()->getFormat() == "snd_bloodsfx") Conversions::bloodToWav(entry, convdata); else { Global::error = S_FMT("Type %s can not be converted to WAV", CHR(entry->getType()->getName())); return false; } // Export file and start monitoring if successful filename = fn.GetFullPath(); if (convdata.exportFile(filename)) { file_modified = wxFileModificationTime(filename); Start(1000); return true; } return false; }
QString PathResolve::resourcesPath() { #ifdef Q_OS_MAC QDir dir(appPath()); dir.cdUp(); dir.cd("Resources"); QString strPath = dir.path(); addBackslash(strPath); return strPath; #elif defined(Q_OS_LINUX) QDir dir(appPath()); dir.cdUp(); dir.cd("share/wiznote"); QString strPath = dir.path(); addBackslash(strPath); return strPath; #else return appPath(); #endif }
String WinFileManager::appDirectory() { TCHAR uAppPathC[MAX_PATH] = L""; DWORD numChars = GetModuleFileName(0, uAppPathC, MAX_PATH - 1); char appPathC[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, uAppPathC, numChars, appPathC, numChars, NULL, NULL); appPathC[numChars] = 0; String appPath(appPathC); return deleteLastPathComponent(appPath); }