IconFactory::IconFactory() { if(m_cursor_watch == NULL) { m_cursor_watch = new Gdk::Cursor(Gdk::WATCH); } if(m_datadir.empty()) { m_datadir = br_find_data_dir(AESKULAP_DATADIR); m_imagesdir = m_datadir + "/aeskulap/images"; } add(Stock::GRID_1X1, "grid-1.png"); add(Stock::GRID_1X2, "grid-2h.png"); add(Stock::GRID_2X1, "grid-2v.png"); add(Stock::GRID_2X2, "grid-4.png"); add(Stock::GRID_4X4, "grid-16.png"); add(Stock::SERIES_SINGLE, "stock-tool-scale-22.png"); add(Stock::SERIES_ALL, "stock-layers-24.png"); add(Stock::SERIES_1X1, "series-1x1.png"); add(Stock::SERIES_2X1, "series-2x1.png"); add(Stock::SERIES_2X2, "series-2x2.png"); add(Stock::SERIES_3X2, "series-3x2.png"); add(Stock::SERIES_3X3, "series-3x3.png"); add(Stock::SERIES_4X4, "series-4x4.png"); add(Stock::REFFRAME, "stock-layers-24.png"); add(Stock::DRAW_ERASER, "stock-tool-eraser-22.png"); add(Stock::THREEDEE_CURSOR, "cursor_pan.png"); add(Stock::VALUE_CURSOR, "stock-tool-color-picker-22.png"); add(Stock::MEASURE, "stock-tool-measure-22.png"); Stock::init_stock_items(); Gtk::IconFactory::add_default(); }
const fs::path GetRootDataDir() { if (!g_initialized) InitDirs(""); char* dir_name = br_find_data_dir("/usr/local/share"); fs::path p(dir_name); std::free(dir_name); p /= "freeorion"; // if the path does not exist, we fall back to the working directory if (!exists(p)) { return fs::initial_path(); } else { return p; } }
int setTranslator(QString lang) { QString langdir; #ifdef _Windows langdir = qApp->applicationDirPath()+"/translations/"; #else langdir = QString(br_find_data_dir("/usr/share")) + QString("/ananas/translations/"); #endif tr_app.load( langdir+"ananas-engine-"+lang.lower()+".qm","."); tr_lib.load( langdir+"ananas-lib-"+lang.lower()+".qm","."); tr_plugins.load( langdir+"ananas-plugins-"+lang.lower()+".qm","."); return 0; }
const char * elicit_data_file_find(const char *file) { static char buf[PATH_MAX]; char *datadir; datadir = br_find_data_dir(DATADIR); snprintf(buf, sizeof(buf), "%s/%s/%s", datadir, PACKAGE, file); free(datadir); if (ecore_file_exists(buf)) return buf; snprintf(buf, sizeof(buf), "%s/%s/%s", DATADIR, PACKAGE, file); if (ecore_file_exists(buf)) return buf; return NULL; }
/** Locate the application's localization folder. * * The path is generated by the following pseudo-code evaluation: * \code * prefix + "/share/locale" * \endcode * * @param default_locale_dir A default path which will used as fallback. * @return A string containing the localization folder's path, which must be freed when * no longer necessary. If BinReloc is not initialized, or if the * initialization function failed, then a copy of default_locale_dir will be returned. * If default_locale_dir is NULL, then NULL will be returned. */ char * br_find_locale_dir (const char *default_locale_dir) { char *data_dir, *dir; data_dir = br_find_data_dir ((const char *) NULL); if (data_dir == (char *) NULL) { /* BinReloc not initialized. */ if (default_locale_dir != (const char *) NULL) return strdup (default_locale_dir); else return (char *) NULL; } dir = br_build_path (data_dir, "locale"); free (data_dir); return dir; }
int setTranslator(QString lang) { QString langdir; #ifdef _Windows langdir = qApp->applicationDirPath()+"/translations/"; #else BrInitError error; if (br_init_lib(&error) == 0 && error != BR_INIT_ERROR_DISABLED) { aLog::print(aLog::MT_INFO, QObject::tr("Warning: BinReloc failed to initialize (error code %1)\n").arg(error)); aLog::print(aLog::MT_INFO, QObject::tr("Will fallback to hardcoded default path.\n")); } aLog::print(aLog::MT_DEBUG, QObject::tr("setTranslator - BinReloc path to data dir is %1.\n").arg( br_find_data_dir("/usr/share") )); langdir = QString(br_find_data_dir("/usr/share")) + QString("/ananas/translations/"); #endif tr_app.load( langdir+"ananas-engine-"+lang.lower()+".qm","."); tr_lib.load( langdir+"ananas-lib-"+lang.lower()+".qm","."); tr_plugins.load( langdir+"ananas-plugins-"+lang.lower()+".qm","."); return 0; }
void getinstallprefix() { #ifdef HAVE_WINDOWS_H HKEY hKey; long res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\WorldForge\\Cyphesis\\Settings", 0, KEY_READ, &hKey); if (res != ERROR_SUCCESS) { log(CYLOG_ERROR, "No install key for cyphesis"); return; } unsigned long type=REG_SZ, size=1024; char path[1024]=""; res = RegQueryValueEx(hKey, "Path", NULL, &type, (LPBYTE)&path[0], &size); if (res != ERROR_SUCCESS) { log(CYLOG_ERROR, "No install key for cyphesis"); } else { etc_directory = String::compose("%1/etc", path); var_directory = String::compose("%1/var", path); share_directory = String::compose("%1/share", path); } RegCloseKey(hKey); #else // HAVE_WINDOWS_H BrInitError error; if (br_init (&error) == 0) { return; } etc_directory = br_find_etc_dir(""); share_directory = br_find_data_dir("data"); var_directory = String::compose("%1/var", br_find_prefix("")); #endif // HAVE_WINDOWS_H }
/*! * \en * Return path to working dir. * \_en * \ru * Возвращает путь к рабочей директории. * \_ru * \see setTable( const QString &name ) */ QString aReport::path2workdir() { QString res; #ifndef Q_OS_WIN32 BrInitError error; if (br_init_lib(&error) == 0 && error != BR_INIT_ERROR_DISABLED) { aLog::print(aLog::MT_INFO, tr("Warning: BinReloc failed to initialize (error code %1)\n").arg(error)); aLog::print(aLog::MT_INFO, tr("Will fallback to hardcoded default path.\n")); } aLog::print(aLog::MT_DEBUG, tr("aReport::path2workdir BinReloc path to data dir is %1.\n").arg( br_find_data_dir("/usr/share") )); res = QString(br_find_data_dir("/usr/share")) + QString("/ananas/"); #else res = ""; #endif if(md!=NULL) { res = md->rc.value("workdir"); } aLog::print(aLog::MT_DEBUG, tr("aReport working dir = %1").arg(res)); return res; }
int main( int argc, char ** argv ) { QApplication a( argc, argv ); // dSelectDB dselectdb; dLogin dlogin; // application = &a; int rc = 1; bool ok; QPixmap pixmap; BrInitError error; QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF8") ); aLog::init("",aLog::MT_DEBUG); #ifndef _Windows if (br_init_lib(&error) == 0 && error != BR_INIT_ERROR_DISABLED) { aLog::print(aLog::MT_INFO, QObject::tr("Warning: BinReloc failed to initialize (error code %1)\n").arg(error)); aLog::print(aLog::MT_INFO, QObject::tr("Will fallback to hardcoded default path.\n")); } aLog::print(aLog::MT_DEBUG, QObject::tr("main - BinReloc path to data dir is %1.\n").arg( br_find_data_dir("/usr/share") )); aLog::print(aLog::MT_DEBUG, QObject::tr("main - BinReloc path to lib dir is %1.\n").arg( br_find_data_dir("/usr/lib") )); #endif if ( parseCommandLine( qApp->argc(), qApp->argv() ) ) return 1; qApp->installTranslator( &tr_app ); qApp->installTranslator( &tr_lib ); qApp->installTranslator( &tr_plugins ); pixmap = QPixmap::fromMimeSource( "engine-splash-"+lang+".png" ); if ( pixmap.isNull() ) #ifdef _Windows pixmap = QPixmap::fromMimeSource( qApp->applicationDirPath()+"/engine-splash-"+lang+".png" ); qApp->addLibraryPath( qApp->applicationDirPath() ); #else pixmap = QPixmap::fromMimeSource( QString(br_find_data_dir("/usr/share") ) + "/ananas/designer/locale/engine-splash-"+lang+".png"); qApp->addLibraryPath( QString( br_find_lib_dir("/usr/lib")) + "/ananas/qt3plugins" ); QStringList list = a.libraryPaths(); QString libPath = ""; QStringList::Iterator it = list.begin(); while( it != list.end() ) { libPath += *it+":"; ++it; } aLog::print(aLog::MT_DEBUG, QString("main - qt library path is '%1'\n").arg( libPath)); #endif printf("extensions: \n%s\n",( const char *) AExtensionFactory::keys().join("\n") ); // Test create extension // AExtension *e = AExtensionFactory::create("AExtTest"); // if (e) printf("EXT OK\n"); else printf("NO EXT OK\n"); if ( pixmap.isNull() ) pixmap = QPixmap::fromMimeSource( "engine-splash-en.png" ); QSplashScreen *splash = new QSplashScreen( pixmap ); if ( ananas_login( rcfile, username, userpassword ) ){ // if ( rcfile.isEmpty() ) { // if (dselectdb.exec()==QDialog::Accepted) rcfile = dselectdb.rcfile; // } // if ( !rcfile.isEmpty() ) { // if (dlogin.exec()==QDialog::Accepted) { // username = dlogin.username; // userpassword = dlogin.password; // } // if (dselectdb.rcfile.isEmpty()) return 0; splash->show(); splash->message( QObject::tr("Init application"), Qt::AlignBottom, Qt::white ); MainForm *w = new MainForm( 0, "MainForm"); mainform = w; mainformws = mainform->ws; mainformwl = mainform->wl; qApp->setMainWidget( w ); w->rcfile = rcfile; // printf( "rcfile = %s\n", rcfile.ascii() ); w->show(); ok = w->init(); splash->clear(); splash->finish( w ); delete splash; if ( ok ) { qApp->connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) ); rc = qApp->exec(); if( w ) delete w; w=0; } else { QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Ananas runtime init error. See message window and log file for details.")); } aLog::close(); return rc; } else { aLog::close(); return 0; } }
void initPhysfs(const char* argv0) { if(!PHYSFS_init(argv0)) { std::stringstream msg; msg << "Couldn't initialize physfs: " << PHYSFS_getLastError(); throw std::runtime_error(msg.str()); } // Initialize physfs (this is a slightly modified version of // PHYSFS_setSaneConfig const char* application = /* PACKAGE_NAME */ "lincity"; const char* userdir = PHYSFS_getUserDir(); const char* dirsep = PHYSFS_getDirSeparator(); char* writedir = new char[strlen(userdir) + strlen(application) + 2]; // Set configuration directory sprintf(writedir, "%s.%s", userdir, application); if(!PHYSFS_setWriteDir(writedir)) { // try to create the directory char* mkdir = new char[strlen(application) + 2]; sprintf(mkdir, ".%s", application); if(!PHYSFS_setWriteDir(userdir) || !PHYSFS_mkdir(mkdir)) { std::ostringstream msg; msg << "Failed creating configuration directory '" << writedir << "': " << PHYSFS_getLastError(); delete[] writedir; delete[] mkdir; throw std::runtime_error(msg.str()); } delete[] mkdir; if(!PHYSFS_setWriteDir(writedir)) { std::ostringstream msg; msg << "Failed to use configuration directory '" << writedir << "': " << PHYSFS_getLastError(); delete[] writedir; throw std::runtime_error(msg.str()); } } PHYSFS_addToSearchPath(writedir, 0); delete[] writedir; // Search for archives and add them to the search path const char* archiveExt = "zip"; char** rc = PHYSFS_enumerateFiles("/"); size_t extlen = strlen(archiveExt); for(char** i = rc; *i != 0; ++i) { size_t l = strlen(*i); if((l > extlen) && ((*i)[l - extlen - 1] == '.')) { const char* ext = (*i) + (l - extlen); if(strcasecmp(ext, archiveExt) == 0) { const char* d = PHYSFS_getRealDir(*i); char* str = new char[strlen(d) + strlen(dirsep) + l + 1]; sprintf(str, "%s%s%s", d, dirsep, *i); PHYSFS_addToSearchPath(str, 1); delete[] str; } } } PHYSFS_freeList(rc); // when started from source dir... std::string dir = PHYSFS_getBaseDir(); dir += "/data"; std::string testfname = dir; testfname += "/images/tiles/images.xml"; FILE* f = fopen(testfname.c_str(), "r"); if(f) { fclose(f); if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) { #ifdef DEBUG std::cout << "Warning: Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n"; #endif } } #if defined(APPDATADIR) || defined(ENABLE_BINRELOC) std::string datadir; #ifdef ENABLE_BINRELOC BrInitError error; if (br_init (&error) == 0 && error != BR_INIT_ERROR_DISABLED) { printf ("Warning: BinReloc failed to initialize (error code %d)\n", error); printf ("Will fallback to hardcoded default path.\n"); } char* brdatadir = br_find_data_dir("/usr/local/share"); datadir = brdatadir; datadir += "/" PACKAGE_NAME; free(brdatadir); #else datadir = APPDATADIR; #endif if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) { std::cout << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n"; } #endif // allow symbolic links PHYSFS_permitSymbolicLinks(1); //show search Path for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++) printf("[%s] is in the search path.\n", *i); // ugly: set LINCITY_HOME environment variable const char* lincityhome = PHYSFS_getRealDir("colour.pal"); if(lincityhome == 0) { throw std::runtime_error("Couldn't locate lincity data (colour.pal)."); } std::cout << "LINCITY_HOME: " << lincityhome << "\n"; char tmp[256]; snprintf(tmp, sizeof(tmp), "LINCITY_HOME=%s", lincityhome); putenv(tmp); }
Elicit * elicit_new() { Elicit *el; char buf[PATH_MAX]; char *dir; el = calloc(sizeof(Elicit), 1); el->ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 500, 500); if (!el->ee) { fprintf(stderr, "[Elicit] Error creating new ecore evas\n"); free(el); return NULL; } el->evas = ecore_evas_get(el->ee); ecore_evas_title_set(el->ee, "Elicit"); ecore_evas_name_class_set(el->ee, "Elicit", "Elicit"); ecore_evas_borderless_set(el->ee, 1); // XXX get correct screen number if (ecore_x_screen_is_composited(0)) ecore_evas_alpha_set(el->ee, 1); else ecore_evas_shaped_set(el->ee, 1); ecore_evas_data_set(el->ee, "Elicit", el); ecore_evas_callback_resize_set(el->ee, cb_ee_resize); ecore_evas_callback_mouse_in_set(el->ee, cb_ee_mouse_in); ecore_evas_callback_mouse_out_set(el->ee, cb_ee_mouse_out); ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE, cb_x_configure, el); el->obj.main = edje_object_add(el->evas); /* setup paths */ dir = br_find_data_dir(DATADIR); snprintf(buf, sizeof(buf), "%s/%s/", dir, PACKAGE); if (!ecore_file_exists(buf)) { fprintf(stderr, "[Elicit] Warning: falling back to hardcoded data dir.\n"); snprintf(buf, sizeof(buf), "%s/%s/", DATADIR, PACKAGE); } el->path.datadir = strdup(buf); free(dir); if (getenv("HOME")) { snprintf(buf, sizeof(buf), "%s/.e/apps/elicit/", getenv("HOME")); if (!ecore_file_is_dir(buf)) ecore_file_mkpath(buf); el->path.confdir = strdup(buf); snprintf(buf, sizeof(buf), "%s/.e/apps/elicit/elicit.conf", getenv("HOME")); el->path.conffile = strdup(buf); snprintf(buf, sizeof(buf), "%s/.e/apps/elicit/elicit.gpl", getenv("HOME")); el->path.palette = strdup(buf); } /* color */ el->color = color_new(); color_callback_changed_add(el->color, cb_color_changed, el); /* palette */ el->palette = palette_new(); palette_load(el->palette, el->path.palette); return el; }