QString config::prefix() { #ifdef Q_OS_WIN32 QDir binaryPath(QCoreApplication::applicationDirPath()); return QDir::toNativeSeparators(binaryPath.canonicalPath()); #endif #ifdef Q_OS_LINUX QString basePath(qgetenv("PLEXYDESK_DIR")); if (basePath.isEmpty() || basePath.isNull()) { return PLEXYPREFIX; } return basePath; #endif #ifdef Q_OS_MAC CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); CFRelease(appUrlRef); CFRelease(macPath); return QLatin1String(pathPtr) + QString("/Contents/"); #endif return QString(); }
bool GetStartOnSystemStartup() { CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl); return !!foundItem; // return boolified object }
// dynamic data path detection onmac bool macSetBundlePath(char* buffer) { // the following code will enable mupen to find its data when placed in an app bundle on mac OS X. // returns true if path is set, returns false if path was not set char path[1024] = { 0 }; CFBundleRef main_bundle = CFBundleGetMainBundle(); assert(main_bundle); CFURLRef main_bundle_URL = CFBundleCopyBundleURL(main_bundle); assert(main_bundle_URL); CFStringRef cf_string_ref = CFURLCopyFileSystemPath( main_bundle_URL, kCFURLPOSIXPathStyle); assert(cf_string_ref); CFStringGetCString(cf_string_ref, path, 1024, kCFStringEncodingASCII); CFRelease(main_bundle_URL); CFRelease(cf_string_ref); if (strstr( path, ".app" ) != 0) { DebugMessage(M64MSG_VERBOSE, "checking whether we are using an app bundle: yes"); // executable is inside an app bundle, use app bundle-relative paths sprintf(buffer, "%s/Contents/Resources/", path); return true; } else { DebugMessage(M64MSG_VERBOSE, "checking whether we are using an app bundle: no"); return false; } }
int main(int argc, char *argv[]) { #ifdef WIN32 qInstallMsgHandler(myMessageOutput); #endif #if defined(Q_OS_MACX) // On Mac, switch working directory to resources folder CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); QString path( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()) ); path += "/Contents/Resources"; QDir::setCurrent( path ); CFRelease(pluginRef); CFRelease(macPath); #elif defined(PO_DATA_REPO) QDir::setCurrent(PO_DATA_REPO); #endif srand(time(NULL)); try { //HotKeyClass HotKeyEvent; QApplication a(argc, argv); //a.installEventFilter(&HotKeyEvent); /* Names to use later for QSettings */ QCoreApplication::setApplicationName("Pokeymon-Online"); QCoreApplication::setOrganizationName("Dreambelievers"); QSettings settings; if (settings.value("language").isNull()) { settings.setValue("language", QLocale::system().name().section('_', 0, 0)); } QString locale = settings.value("language").toString(); QTranslator translator; translator.load(QString("trans/translation_") + locale); a.installTranslator(&translator); /* icon ;) */ #if not defined(Q_OS_MACX) a.setWindowIcon(QIcon("db/icon.png")); #endif MainEngine w; return a.exec(); } /*catch (const std::exception &e) { qDebug() << "Caught runtime " << e.what(); } catch (const QString &s) { qDebug() << "Caught string " << s; } */catch (const char* s) { qDebug() << "Caught const char* " << s; } /*catch (...) { qDebug() << "Caught Exception."; }*/ return 0; }
Bundle::Bundle(CFBundleRef bundle, const char *root /* = NULL */) : mBundle(bundle) { assert(bundle); CFRetain(bundle); mPath = root ? root : cfStringRelease(CFBundleCopyBundleURL(mBundle)); secdebug("bundle", "%p Bundle from bundle %p(%s)", this, bundle, mPath.c_str()); }
static void open_libgl(void) { bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengles")); // we are always linked to OpenGLES.framework statically, so it is already loaded and could be found by id assert(bundle != NULL); CFRetain(bundle); bundleURL = CFBundleCopyBundleURL(bundle); }
void InitDirs(const std::string& argv0) { if (g_initialized) return; // store working dir fs::initial_path(); fs::path bundle_path; fs::path app_path; CFBundleRef bundle = CFBundleGetMainBundle(); char bundle_dir[MAXPATHLEN]; if (bundle) { CFURLRef bundleurl = CFBundleCopyBundleURL(bundle); CFURLGetFileSystemRepresentation(bundleurl, true, reinterpret_cast<UInt8*>(bundle_dir), MAXPATHLEN); } else { // executable is not the main binary in application bundle (i.e. Server or AI) uint32_t size = sizeof(bundle_dir); if (_NSGetExecutablePath(bundle_dir, &size) != 0) { std::cerr << "_NSGetExecutablePath() failed: buffer too small; need size " << size << std::endl; exit(-1); } } bundle_path = fs::path(bundle_dir); // search bundle_path for a directory named "FreeOrion.app", exiting if not found, else constructing a path to application bundle contents fs::path::iterator appiter = std::find(bundle_path.begin(), bundle_path.end(), "FreeOrion.app"); if (appiter == bundle_path.end()) { std::cerr << "Error: Application bundle must be named 'FreeOrion.app' and executables must not be called from outside of it." << std::endl; exit(-1); } else { for (fs::path::iterator piter = bundle_path.begin(); piter != appiter; ++piter) { app_path /= *piter; } app_path /= "FreeOrion.app/Contents"; } s_root_data_dir = app_path / "Resources"; s_user_dir = fs::path(getenv("HOME")) / "Library" / "Application Support" / "FreeOrion"; s_bin_dir = app_path / "Executables"; s_config_path = s_user_dir / "config.xml"; s_python_home = app_path / "Frameworks" / "Python.framework" / "Versions" / "Current"; fs::path p = s_user_dir; if (!exists(p)) fs::create_directories(p); p /= "save"; if (!exists(p)) fs::create_directories(p); // Intentionally do not create the server save dir. // The server save dir is publically accessible and should not be // automatically created for the user. g_initialized = true; }
bool FSGetApplPath(UniString &applPath, bool withPS/* = true*/) { #if defined(WIN32) || defined(_WIN32_WCE) wchar_t Temp[_MAX_PATH+1] = L""; #if defined(_WIN32_WCE) ::GetModuleFileName(NULL, Temp, _MAX_PATH); #else ::GetModuleFileNameW(NULL, Temp, _MAX_PATH); #endif applPath = Temp; STRIndex_t pos = applPath.FindRAt(PATH_SEPARATOR_CHAR); if ( STRING_FOUND(pos) ) applPath.Truncate( withPS ? pos + 1 : pos); return true; #else CFBundleRef bundleRef = CFBundleGetMainBundle(); if ( bundleRef == NULL ) return false; CFURLRef urlRef = CFBundleCopyBundleURL(bundleRef); CFRelease(bundleRef); if ( urlRef ) { CFStringRef stringRef = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); CFRelease(urlRef); if ( stringRef ) { applPath = stringRef; CFRelease(stringRef); STRIndex_t pos = applPath.FindRAt(PATH_SEPARATOR_CHAR); if ( STRING_FOUND(pos) ) { if (!withPS) applPath.Truncate(pos); } else { if (withPS) applPath += PATH_SEPARATOR_CHAR; } return true; } } return false; #endif }
/* ----------------------------------------------------------------------------- plugin entry point, called by vpnd ref is the vpn bundle reference pppref is the ppp bundle reference bundles can be layout in two different ways - As simple vpn bundles (bundle.vpn). the bundle contains the vpn bundle binary. - As full ppp bundles (bundle.ppp). The bundle contains the ppp bundle binary, and also the vpn kext and the vpn bundle binary in its Plugins directory. if a simple vpn bundle was used, pppref will be NULL. if a ppp bundle was used, the vpn plugin will be able to get access to the Plugins directory and load the vpn kext. ----------------------------------------------------------------------------- */ int start(struct vpn_channel* the_vpn_channel, CFBundleRef ref, CFBundleRef pppref, int debug_mode) { char name[MAXPATHLEN]; CFURLRef url; debug = debug_mode; /* first load the kext if we are loaded as part of a ppp bundle */ if (pppref) { while ((listen_sockfd = socket(PF_PPP, SOCK_DGRAM, PPPPROTO_L2TP)) < 0) if (errno != EINTR) break; if (listen_sockfd < 0) { vpnlog(LOG_DEBUG, "first call to socket failed - attempting to load kext\n"); if (url = CFBundleCopyBundleURL(pppref)) { name[0] = 0; CFURLGetFileSystemRepresentation(url, 0, name, MAXPATHLEN - 1); CFRelease(url); strcat(name, "/"); if (url = CFBundleCopyBuiltInPlugInsURL(pppref)) { CFURLGetFileSystemRepresentation(url, 0, name + strlen(name), MAXPATHLEN - strlen(name) - strlen(L2TP_NKE) - 1); CFRelease(url); strcat(name, "/"); strcat(name, L2TP_NKE); if (!load_kext(name)) while ((listen_sockfd = socket(PF_PPP, SOCK_DGRAM, PPPPROTO_L2TP)) < 0) if (errno != EINTR) break; } } if (listen_sockfd < 0) { vpnlog(LOG_ERR, "VPND L2TP plugin: Unable to load L2TP kernel extension\n"); return -1; } } } /* retain reference */ bundle = ref; CFRetain(bundle); pppbundle = pppref; CFRetain(pppbundle); // hookup our socket handlers bzero(the_vpn_channel, sizeof(struct vpn_channel)); the_vpn_channel->get_pppd_args = l2tpvpn_get_pppd_args; the_vpn_channel->listen = l2tpvpn_listen; the_vpn_channel->accept = l2tpvpn_accept; the_vpn_channel->refuse = l2tpvpn_refuse; the_vpn_channel->close = l2tpvpn_close; return 0; }
/* ----------------------------------------------------------------------------- plugin entry point, called by pppd ----------------------------------------------------------------------------- */ int start(CFBundleRef ref) { CFStringRef strref; CFURLRef urlref; bundle = ref; CFRetain(bundle); url = CFBundleCopyBundleURL(bundle); // hookup our handlers old_check_options = the_channel->check_options; the_channel->check_options = serial_check_options; old_connect = the_channel->connect; the_channel->connect = serial_connect; old_process_extra_options = the_channel->process_extra_options; the_channel->process_extra_options = serial_process_extra_options; add_notifier(&connect_fail_notify, serial_connect_notifier, 0); add_notifier(&lcp_lowerdown_notify, serial_lcpdown_notifier, 0); cancelstrref = CFBundleCopyLocalizedString(bundle, CFSTR("Cancel"), CFSTR("Cancel"), NULL); if (cancelstrref == 0) return 1; CFStringGetCString(cancelstrref, (char*)cancelstr, sizeof(cancelstr), kCFStringEncodingUTF8); icstrref = CFBundleCopyLocalizedString(bundle, CFSTR("Network Connection"), CFSTR("Network Connection"), NULL); if (icstrref == 0) return 1; CFStringGetCString(icstrref, (char*)icstr, sizeof(icstr), kCFStringEncodingUTF8); urlref = CFBundleCopyResourceURL(bundle, CFSTR("NetworkConnect.icns"), NULL, NULL); if (urlref == 0 || ((strref = CFURLGetString(urlref)) == 0)) { if (urlref) CFRelease(urlref); return 1; } CFStringGetCString(strref, (char*)iconstr, sizeof(iconstr), kCFStringEncodingUTF8); iconstrref = CFStringCreateCopy(NULL, strref); CFRelease(urlref); urlref = CFBundleCopyBuiltInPlugInsURL(bundle); if (urlref == 0 || ((CFURLGetFileSystemRepresentation(urlref, TRUE, pathccl, sizeof(pathccl))) == FALSE)) { if (urlref) CFRelease(urlref); return 1; } strlcat((char*)pathccl, SUFFIX_CCLENGINE, sizeof(pathccl)); CFRelease(urlref); // add the socket specific options add_options(serial_options); return 0; }
void fill_pathname_application_path(char *buf, size_t size) { size_t i; (void)i; if (!size) return; #ifdef _WIN32 DWORD ret = GetModuleFileName(GetModuleHandle(NULL), buf, size - 1); buf[ret] = '\0'; #elif defined(__APPLE__) CFBundleRef bundle = CFBundleGetMainBundle(); if (bundle) { CFURLRef bundle_url = CFBundleCopyBundleURL(bundle); CFStringRef bundle_path = CFURLCopyPath(bundle_url); CFStringGetCString(bundle_path, buf, size, kCFStringEncodingUTF8); CFRelease(bundle_path); CFRelease(bundle_url); rarch_assert(strlcat(buf, "nobin", size) < size); return; } #elif defined(__HAIKU__) image_info info; int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { if (info.type == B_APP_IMAGE) { strlcpy(buf, info.name, size); return; } } #else *buf = '\0'; pid_t pid = getpid(); char link_path[PATH_MAX]; /* Linux, BSD and Solaris paths. Not standardized. */ static const char *exts[] = { "exe", "file", "path/a.out" }; for (i = 0; i < ARRAY_SIZE(exts); i++) { snprintf(link_path, sizeof(link_path), "/proc/%u/%s", (unsigned)pid, exts[i]); ssize_t ret = readlink(link_path, buf, size - 1); if (ret >= 0) { buf[ret] = '\0'; return; } } RARCH_ERR("Cannot resolve application path! This should not happen.\n"); #endif }
std::string getExecutablePath() { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); FixedStrT<512> buf; CFURLGetFileSystemRepresentation(url, true, (UInt8*) buf.str(), buf.capacity()); return buf.str(); }
QDir lastfm::dir::bundle() { // Trolltech provided example CFURLRef appUrlRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() ); CFStringRef macPath = CFURLCopyFileSystemPath( appUrlRef, kCFURLPOSIXPathStyle ); QString path = CFStringToQString( macPath ); CFRelease(appUrlRef); CFRelease(macPath); return QDir( path ); }
void WindowMenu::onBringAllToFront() { #ifdef Q_WS_MAC CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); if (appUrlRef) { LSOpenCFURLRef(appUrlRef, NULL); CFRelease(appUrlRef); } #endif }
void initialize() { static bool initialized = false; if (initialized) { return; } // Determine path for resources #ifdef TARGET_OSX CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { boost::filesystem::path bundlePath = convertCFUrlToPath(CFBundleCopyBundleURL(mainBundle)); boost::filesystem::path resourcesPath = convertCFUrlToPath(CFBundleCopyResourcesDirectoryURL(mainBundle)); resources = bundlePath / resourcesPath; } #elif TARGET_LINUX resources = boost::filesystem::read_symlink(boost::filesystem::path("/proc/self/exe")).parent_path() / boost::filesystem::path("resources"); #endif if (!valid(resources)) { throw std::runtime_error("Unable to determine resource directory!"); } // Determine data path char const* dataPathEnv = getenv(DATA_DIRECTORY_ENV_NAME.c_str()); if (dataPathEnv) { data = boost::filesystem::path(dataPathEnv); } else { boost::filesystem::path userHome; char const* home = util::coalesce(getenv("HOME"), getenv("USERPROFILE")); if (home) { userHome = boost::filesystem::path(home); } else { char const* homedrive = getenv("HOMEDRIVE"); char const* homepath = getenv("HOMEPATH"); if (homedrive && homepath) { userHome = boost::filesystem::path(std::string(homedrive) + homepath); } } if (!valid(userHome)) { throw std::runtime_error("Unable to determine user home directory!"); } data = userHome / DATA_DIRECTORY_DEFAULT_NAME; ensureDirectoryExists(data); } initialized = true; }
QString ScPaths::bundleDir(void) const { // On MacOS/X, override the compile-time settings with a location // obtained from the system. #ifdef Q_WS_MAC // Set up the various app paths to look inside the app bundle CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); if (pathPtr!=NULL && strlen(pathPtr)>0) { // make sure we get the Scribus.app directory, not some subdir // strip trailing '/': qDebug("Path = %s", pathPtr); char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1); while (*p == '/') --p; ++p; *p = '\0'; if (strcmp("/bin", p-4) == 0) { p -= 4; *p = '\0'; } if (strcmp("/MacOS", p-6) == 0) { p -= 6; *p = '\0'; } if (strcmp("/Contents", p-9) == 0) { p -= 9; *p = '\0'; } CFRelease(pluginRef); CFRelease(macPath); return QString("%1").arg(pathPtr); } else { char buf[2048]; CFStringGetCString (macPath, buf, 2048, kCFStringEncodingUTF8); QString q_pathPtr=QString::fromUtf8(buf); if (q_pathPtr.endsWith("/bin")) q_pathPtr.chop(4); if (q_pathPtr.endsWith("/MacOS")) q_pathPtr.chop(6); if (q_pathPtr.endsWith("/Contents")) q_pathPtr.chop(9); CFRelease(pluginRef); CFRelease(macPath); return q_pathPtr; } #endif return QString::null; }
std::string GetBundleDirectory() { CFURLRef BundleRef; char AppBundlePath[MAXPATHLEN]; // Get the main bundle for the app BundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef BundlePath = CFURLCopyFileSystemPath(BundleRef, kCFURLPOSIXPathStyle); CFStringGetFileSystemRepresentation(BundlePath, AppBundlePath, sizeof(AppBundlePath)); CFRelease(BundleRef); CFRelease(BundlePath); return AppBundlePath; }
QString getMacJackPath(){ QString macPathq; CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); macPathq = QString::fromStdString(pathPtr); CFRelease(appUrlRef); CFRelease(macPath); return macPathq + "/Contents/Resources/JackSms"; }
//-------------------------------------------------------------- void BoxWorldApp::setup(){ ofEnableAlphaBlending(); ofDisableArbTex(); string data_resource_path; #ifdef TARGET_OSX // Get the absolute location of the executable file in the bundle. CFBundleRef appBundle = CFBundleGetMainBundle(); CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle); CFURLRef dataPrefixURL = CFBundleCopyBundleURL(appBundle); char execFile[4096]; if (CFURLGetFileSystemRepresentation(executableURL, TRUE, (UInt8 *)execFile, 4096)) { // Strip out the filename to just get the path string strExecFile = execFile; int found = strExecFile.find_last_of("/"); string strPath = strExecFile.substr(0, found); // Change the working directory to that of the executable if(-1 == chdir(strPath.c_str())) { ofLog(OF_LOG_ERROR, "Unable to change working directory to executable's directory."); } } else { ofLog(OF_LOG_ERROR, "Unable to identify executable's directory."); } CFRelease(executableURL); char dataPrefix[4096]; if (CFURLGetFileSystemRepresentation(dataPrefixURL, TRUE, (UInt8 *)dataPrefix, 4096)) { string strExecFile = dataPrefix; int found = strExecFile.find_last_of("/"); string strPath = strExecFile.substr(0, found); data_resource_path = strPath.append("/data/"); } #endif /* Init according to manifest file. */ ResourceMgrInst::get()->setRootDir(data_resource_path); /* Init connection manager for incoming message handling. */ ConnMgrInst::get()->setCmdReceiver(this); ofSetDataPathRoot(data_resource_path); mShaderExecutor = new ShaderExecutor(BOXWORLD_WIDTH, BOXWORLD_HEIGHT); if(ResourceMgrInst::get()->isDefaultAppValid()) { runAppWithContent(ResourceMgrInst::get()->getDefAppContent()); } }
// This function will locate the path to our application on OS X, // unlike windows you can not rely on the curent working directory // for locating your configuration files and resources. std::string macBundlePath() { char path[1024]; CFBundleRef mainBundle = CFBundleGetMainBundle(); assert(mainBundle); CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); assert(mainBundleURL); CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); assert(cfStringRef); CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); CFRelease(mainBundleURL); CFRelease(cfStringRef); return std::string(path); }
const GHOST_TUns8* GHOST_SystemPathsCarbon::getBinaryDir() const { CFURLRef bundleURL; CFStringRef pathStr; static char path[256]; CFBundleRef mainBundle = CFBundleGetMainBundle(); bundleURL = CFBundleCopyBundleURL(mainBundle); pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII); CFRelease(pathStr); CFRelease(bundleURL); return (GHOST_TUns8*)path; }
void get_my_path(char s[PATH_MAX]) { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle); CFStringRef bundlePathString = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); CFRelease(bundleURL); CFStringGetCString(bundlePathString, s, PATH_MAX - 1, kCFStringEncodingASCII); CFRelease(bundlePathString); char *x; x = strrchr(s, '/'); if(x) x[1] = 0; }
//-------------------------------------------------------------- string osxVoiceOverApp::getAppPathDirectory(){ // Get the path the correct apple way - returns path to inside .app directory CFURLRef mainRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(mainRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); string pathDirectory (pathPtr); size_t found; found=pathDirectory.find_last_of("/\\"); pathDirectory = pathDirectory.substr(0,found+1); return pathDirectory; }
CFStringRef Resources::getResourcesPathFromBundleId() { //@@TODO char buffer[PATH_MAX]; CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("SuperColldierAU") ); if (bundle == NULL) return NULL; CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); CFURLGetFileSystemRepresentation(bundleURL, TRUE, (UInt8*)buffer,PATH_MAX); CFStringRef bundlePath = CFStringCreateWithCString(NULL,buffer, kCFStringEncodingUTF8); CFURLRef bundleResourcesURL = CFBundleCopyResourcesDirectoryURL(bundle); CFStringRef resourcesRelativePath = CFURLGetString(bundleResourcesURL); CFMutableStringRef resourcesPath = CFStringCreateMutable(NULL,0); CFStringAppend(resourcesPath,bundlePath); CFStringAppend(resourcesPath,resourcesRelativePath); return resourcesPath; }
void Autostart::SetActive( bool active ) { #ifdef Q_OS_WIN QString applicationName = QCoreApplication::applicationName(); QString applicationPath = QCoreApplication::applicationFilePath(); QSettings tmpSettings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat ); if( active ) { tmpSettings.setValue( applicationName, QString( "\"%1\"" ).arg( QDir::toNativeSeparators( QFileInfo( applicationPath ).filePath() ) ) ); } else { tmpSettings.remove(applicationName); } #elif defined(Q_OS_MAC) LSSharedFileListRef loginItems = LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL ); if( !loginItems ) return; UInt32 seed = 0U; CFArrayRef currentLoginItems = LSSharedFileListCopySnapshot( loginItems, &seed ); LSSharedFileListItemRef existingItem = FindLoginItemForCurrentBundle( currentLoginItems ); if( active && (existingItem == NULL) ) { CFURLRef mainBundleURL = CFBundleCopyBundleURL( CFBundleGetMainBundle() ); LSSharedFileListInsertItemURL( loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, mainBundleURL, NULL, NULL ); CFRelease( mainBundleURL ); } else if( !active && (existingItem != NULL) ) { LSSharedFileListItemRemove(loginItems, existingItem); } CFRelease( currentLoginItems ); CFRelease( loginItems ); #elif defined Q_OS_LINUX QString homeLocation = QStandardPaths::writableLocation( QStandardPaths::HomeLocation ); QDir* autostartPath = new QDir(homeLocation + "/.config/autostart/"); if( !active ) { QFile* desktopFile = new QFile(autostartPath->filePath("track-o-bot.desktop")); desktopFile->remove(); } else { QFile* srcFile = new QFile( ":/assets/track-o-bot.desktop" ); LOG("source: %s", srcFile->fileName().toStdString().c_str()); LOG("source exists: %s", QString::number(srcFile->exists()).toStdString().c_str()); srcFile->copy(autostartPath->filePath("track-o-bot.desktop")); } #endif }
const char *getPath(const char *filename) { #if defined __IOS__ char *ptr; std::string fnm(filename); if(fnm.find("/") != 0) { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle); CFStringRef str = CFURLCopyFileSystemPath(resourcesURL, kCFURLPOSIXPathStyle); CFRelease(resourcesURL); ptr = new char[CFStringGetLength(str)+1]; CFStringGetCString(str, ptr, FILENAME_MAX, kCFStringEncodingASCII); CFRelease(str); std::string res(ptr); res += std::string("/"); res += std::string(filename); delete[] ptr; ptr = new char[res.length()+1]; strcpy(ptr, res.c_str()); }else { ptr = new char[fnm.length()+1]; strcpy(ptr, fnm.c_str()); } return (const char*)ptr; #else for(int i = 0; i < paths.size(); i++) { std::string str(filename); str = *paths[i]+str; std::ifstream in(str.c_str()); if(in.good()) { char *ptr = new char[str.length()+1]; strcpy(ptr, str.c_str()); return (const char*)ptr; } } char *ptr2 = new char[std::string(filename).length()+1]; strcpy(ptr2, filename); return (const char*)ptr2; #endif }
OSErr GetApplicationPackageFSSpecFromBundle(FSSpecPtr theFSSpecPtr) { OSErr err = fnfErr; CFBundleRef myAppsBundle = CFBundleGetMainBundle(); if (myAppsBundle == NULL) return err; CFURLRef myBundleURL = CFBundleCopyBundleURL(myAppsBundle); if (myBundleURL == NULL) return err; FSRef myBundleRef; Boolean ok = CFURLGetFSRef(myBundleURL, &myBundleRef); CFRelease(myBundleURL); if (!ok) return err; return FSGetCatalogInfo(&myBundleRef, kFSCatInfoNone, NULL, NULL, theFSSpecPtr, NULL); }
bool CFCBundle::GetPath (char *dst, size_t dst_len) { CFBundleRef bundle = get(); if (bundle) { CFCReleaser<CFURLRef> bundle_url (CFBundleCopyBundleURL (bundle)); if (bundle_url.get()) { Boolean resolveAgainstBase = 0; return ::CFURLGetFileSystemRepresentation (bundle_url.get(), resolveAgainstBase, (UInt8 *)dst, dst_len) != 0; } } return false; }
CFStringRef CopyMacBundlePath() { CFBundleRef mainBundle = CFBundleGetMainBundle(); assert(mainBundle); CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); assert(mainBundleURL); CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); assert(cfStringRef); CFRelease(mainBundleURL); return cfStringRef; }
bool EDA_APP::SetBinDir() { // Apple MacOSx #ifdef __APPLE__ // Derive path from location of the app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); if( mainBundle == NULL ) return false; CFURLRef urlref = CFBundleCopyBundleURL( mainBundle ); if( urlref == NULL ) return false; CFStringRef str = CFURLCopyFileSystemPath( urlref, kCFURLPOSIXPathStyle ); if( str == NULL ) return false; char* native_str = NULL; int len = CFStringGetMaximumSizeForEncoding( CFStringGetLength( str ), kCFStringEncodingUTF8 ) + 1; native_str = new char[len]; CFStringGetCString( str, native_str, len, kCFStringEncodingUTF8 ); m_BinDir = FROM_UTF8( native_str ); delete[] native_str; #elif defined(__UNIX__) // Linux and non-Apple Unix m_BinDir = wxStandardPaths::Get().GetExecutablePath(); #else m_BinDir = argv[0]; #endif // Use unix notation for paths. I am not sure this is a good idea, // but it simplify compatibility between Windows and Unices // However it is a potential problem in path handling under Windows m_BinDir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); // Remove file name form command line: while( m_BinDir.Last() != '/' && !m_BinDir.IsEmpty() ) m_BinDir.RemoveLast(); return true; }