static path findUserPath(const char * name, const path & force, const char * registry, const char * prefix, const char * suffix, const path & fallback, bool create) { // Prefer command-line options if(!force.empty()) { path dir = canonical(force); if(create && !create_directories(dir)) { LogCritical << "Could not create " << name << " directory " << dir << '.'; return path(); } else { LogDebug("using " << name << " dir from command-line: " << dir); return dir; } } // Check system settings (windows registry) std::string temp; if(registry && platform::getSystemConfiguration(registry, temp)) { path dir = canonical(temp); if(!create) { return dir; } else if(create_directories(dir)) { LogDebug("got " << name << " dir from registry: \"" << temp << "\" = " << dir); return dir; } else { LogError << "Could not create " << name << " directory " << dir << '.'; LogDebug("ignoring " << name << " dir from registry: \"" << temp << '"'); } } // Search standard locations path to_create; std::vector<path> prefixes = getSearchPaths(prefix); std::vector<path> suffixes = getSearchPaths(suffix); if(prefix || suffix) { bool create_exists = false; BOOST_FOREACH(const path & prefix, prefixes) { BOOST_FOREACH(const path & suffix, suffixes) { path dir = canonical(prefix / suffix); if(is_directory(dir)) { LogDebug("got " << name << " dir from search: " << prefix << " + " << suffix << " = " << dir); return dir; } else { LogDebug("ignoring " << name << " dir from search: " << prefix << " + " << suffix << " = " << dir); } if(to_create.empty() || (!create_exists && is_directory(prefix))) { to_create = dir; create_exists = is_directory(prefix); } }
KDE_EXPORT void kcminit_nsplugin() { KConfigGroup config(KSharedConfig::openConfig( "kcmnspluginrc", KConfig::NoGlobals ), "Misc"); if( config.readEntry( "StartupCheck", true )) { bool update = false; QStringList searchPaths = getSearchPaths(); QStringList lastSearchPaths = config.readEntry( "lastSearchPaths", QStringList()); QStringList lastTimestamps = config.readEntry ( "lastSearchTimestamps", QStringList()); if( searchPaths != lastSearchPaths || lastTimestamps.count() != lastSearchPaths.count()) { // count changed, set empty timestamps, still call checkSearchPathTimestamps() // in order to save the current timestamps for the next time lastSearchPaths = searchPaths; lastTimestamps.clear(); for( int i = 0; i < searchPaths.count(); ++i ) lastTimestamps.append( "N" ); update = true; } if( checkSearchPathTimestamps( lastSearchPaths, lastTimestamps )) update = true; if( update ) KToolInvocation::kdeinitExec("nspluginscan"); } }
void TestResolutionDirectories::onEnter() { FileUtilsDemo::onEnter(); auto sharedFileUtils = FileUtils::getInstance(); std::string ret; sharedFileUtils->purgeCachedEntries(); _defaultSearchPathArray = sharedFileUtils->getSearchPaths(); std::vector<std::string> searchPaths = _defaultSearchPathArray; searchPaths.insert(searchPaths.begin(), "Misc"); sharedFileUtils->setSearchPaths(searchPaths); _defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder(); std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray; resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipadhd"); resolutionsOrder.insert(resolutionsOrder.begin()+1, "resources-ipad"); resolutionsOrder.insert(resolutionsOrder.begin()+2, "resources-widehd"); resolutionsOrder.insert(resolutionsOrder.begin()+3, "resources-wide"); resolutionsOrder.insert(resolutionsOrder.begin()+4, "resources-hd"); resolutionsOrder.insert(resolutionsOrder.begin()+5, "resources-iphone"); sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder); for( int i=1; i<7; i++) { auto filename = StringUtils::format("test%d.txt", i); ret = sharedFileUtils->fullPathForFilename(filename); log("%s -> %s", filename.c_str(), ret.c_str()); } }
HGLOBAL DLL_EXPORT decompress_block(void *data, DWORD dataSize) { #define SEARCHCOUNT 4 //number of paths in search array char *searchPath[SEARCHCOUNT]; // array of paths to search for files int internalSize, externalSize, md5; void *dataStart = data; HGLOBAL block = NULL; //fill searchPath array if (getSearchPaths(searchPath) == 0) { //error filling searchPath array return NULL; } //find size of internal files internalSize = internalFilesSize(data); //skip internal files an null int data += internalSize + 4; //use md5 checksums for external files? md5 = useMd5(data); data += 1; //find size of external files externalSize = externalFilesSize(data, searchPath, md5); if (externalSize == 0) { //external file not found return 0; } //get block block = GlobalAlloc(GMEM_FIXED, internalSize + externalSize); if (block == NULL) { MessageBox(GetActiveWindow(), "GlobalAlloc failed.", "Error!", 16); return block; } //copy internal files to block data = dataStart; CopyMemory(block, data, internalSize); //jump internal files + null int + useMd5 byte data += internalSize + 5; //copy external files to block; if (writeExternalFiles(data, block + internalSize, searchPath, md5) == 0) { //error with external files MessageBox(GetActiveWindow(), "Copy external files failed.", "Error!", 16); return 0; } return block; }
void TestSearchPath::onEnter() { FileUtilsDemo::onEnter(); auto sharedFileUtils = FileUtils::getInstance(); std::string ret; sharedFileUtils->purgeCachedEntries(); _defaultSearchPathArray = sharedFileUtils->getSearchPaths(); std::vector<std::string> searchPaths = _defaultSearchPathArray; std::string writablePath = sharedFileUtils->getWritablePath(); std::string fileName = writablePath+"external.txt"; char szBuf[100] = "Hello Cocos2d-x!"; FILE* fp = fopen(fileName.c_str(), "wb"); if (fp) { size_t ret = fwrite(szBuf, 1, strlen(szBuf), fp); CCASSERT(ret != 0, "fwrite function returned zero value"); fclose(fp); if (ret != 0) log("Writing file to writable path succeed."); } searchPaths.insert(searchPaths.begin(), writablePath); searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1"); searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2"); sharedFileUtils->setSearchPaths(searchPaths); _defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder(); std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray; resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad"); sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder); for( int i=1; i<3; i++) { auto filename = StringUtils::format("file%d.txt", i); ret = sharedFileUtils->fullPathForFilename(filename); log("%s -> %s", filename.c_str(), ret.c_str()); } // Gets external.txt from writable path std::string fullPath = sharedFileUtils->fullPathForFilename("external.txt"); log("external file path = %s", fullPath.c_str()); if (fullPath.length() > 0) { fp = fopen(fullPath.c_str(), "rb"); if (fp) { char szReadBuf[100] = {0}; size_t read = fread(szReadBuf, 1, strlen(szReadBuf), fp); if (read > 0) log("The content of file from writable path: %s", szReadBuf); fclose(fp); } } }
void Mx::initSearchPath(string sysfile){ auto sysImage = Configuration::getInstance()->getValue(sysfile).asValueMap(); auto map = sysImage.at("image_search_path").asValueMap(); auto layer = sysImage.at("image_layer_load").asValueMap(); auto maxWidthByPhone = Configuration::getInstance()->getValue("sys_max_width").asFloat(); auto sharedFileUtils = FileUtils::getInstance(); Size winSize = Director::getInstance()->getWinSize(); std::vector<std::string> searchPath = sharedFileUtils->getSearchPaths(); { string dpi = ""; if (winSize.width <= maxWidthByPhone) { dpi = imageFolder.mdpi; }else{ dpi = imageFolder.hdpi; } if (!factory->checkElement(searchPath, dpi + "/")) { searchPath.push_back(dpi); } auto array = map.at(dpi).asValueVector(); for (auto value : array) { string path = dpi + "/" + value.asString(); if (!factory->checkElement(searchPath, path)) { searchPath.push_back(path); } } } for (auto key : layer) { std::string folder = key.first; auto folderMap = key.second.asValueMap(); for (auto key2 : folderMap) { std::string path = imageFolder.mdpi + "/" + imageFolder.layer + "/" + folder + "/" + key2.first; if (!factory->checkElement(searchPath, path)) { searchPath.push_back(path); } } } // for (auto str : searchPath) { // log("-------%s-------", str.c_str()); // } sharedFileUtils->setSearchPaths(searchPath); }
void FileUtilsLayer::OnClickMenu6(Ref* pSender) { auto sharedFileUtils = FileUtils::getInstance(); sharedFileUtils->purgeCachedEntries(); std::vector<std::string> searchPaths = sharedFileUtils->getSearchPaths(); std::string writablePath = sharedFileUtils->getWritablePath(); searchPaths.insert(searchPaths.begin(), "dir1"); searchPaths.insert(searchPaths.begin()+1, writablePath); sharedFileUtils->setSearchPaths(searchPaths); std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("test.txt"); log("test.txt 's fullPathForFilename is : %s",fullPathForFilename.c_str()); Data data = sharedFileUtils->getDataFromFile(fullPathForFilename); std::string content = sharedFileUtils->getStringFromFile(fullPathForFilename); log("File content is : %s",content.c_str()); }
KDbool AppDelegate::applicationDidFinishLaunching ( KDvoid ) { // initialize director auto pDirector = Director::getInstance ( ); pDirector->setOpenGLView ( EGLView::getInstance ( ) ); // turn on display FPS pDirector->setDisplayStats ( true ); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval ( 1.0 / 60 ); auto tScreenSize = EGLView::getInstance ( )->getFrameSize ( ); auto tDesignSize = Size ( 480, 320 ); auto pFileUtils = FileUtils::getInstance ( ); if ( tScreenSize.height > 320 ) { auto tResourceSize = Size ( 960, 640 ); std::vector<std::string> aSearchPaths; aSearchPaths.push_back ( "hd" ); pFileUtils->setSearchPaths ( aSearchPaths ); pDirector->setContentScaleFactor ( tResourceSize.height / tDesignSize.height ); } EGLView::getInstance ( )->setDesignResolutionSize ( tDesignSize.width, tDesignSize.height, ResolutionPolicy::FIXED_HEIGHT ); // register lua engine LuaEngine* pEngine = LuaEngine::getInstance ( ); ScriptEngineManager::getInstance ( )->setScriptEngine ( pEngine ); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) LuaStack* pStack = pEngine->getLuaStack ( ); register_assetsmanager_test_sample ( pStack->getLuaState ( ) ); #endif std::vector<std::string> aSearchPaths = pFileUtils->getSearchPaths ( ); aSearchPaths.insert ( aSearchPaths.begin(), "Images" ); aSearchPaths.insert ( aSearchPaths.begin(), "cocosbuilderRes" ); if ( tScreenSize.height > 320 ) { aSearchPaths.insert ( aSearchPaths.begin ( ), "hd/scenetest" ); } else { aSearchPaths.insert ( aSearchPaths.begin ( ), "scenetest" ); } #if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY aSearchPaths.push_back ( "TestCppResources" ); aSearchPaths.push_back ( "script" ); #endif FileUtils::getInstance ( )->setSearchPaths ( aSearchPaths ); pEngine->executeScriptFile ( "luaScript/controller.lua" ); return true; }
int main( int argc, char **argv ) { KAboutData aboutData( "nspluginscan", "nsplugin", ki18n("nspluginscan"), "0.3", ki18n("nspluginscan"), KAboutData::License_GPL, ki18n("(c) 2000,2001 by Stefan Schimanski") ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineOptions options; options.add("verbose", ki18n("Show progress output for GUI")); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); showProgress = args->isSet("verbose"); if (showProgress) { printf("10\n"); fflush(stdout); } KApplication app(false); // Set up SIGCHLD handler struct sigaction act; act.sa_handler=sigChildHandler; sigemptyset(&(act.sa_mask)); sigaddset(&(act.sa_mask), SIGCHLD); // Make sure we don't block this signal. gdb tends to do that :-( sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); act.sa_flags = SA_NOCLDSTOP; // CC: take care of SunOS which automatically restarts interrupted system // calls (and thus does not have SA_RESTART) #ifdef SA_RESTART act.sa_flags |= SA_RESTART; #endif struct sigaction oldact; sigaction( SIGCHLD, &act, &oldact ); // set up the paths used to look for plugins QStringList searchPaths = getSearchPaths(); QStringList mimeInfoList; infoConfig = new KConfig( KGlobal::dirs()->saveLocation("data", "nsplugins") + "/pluginsinfo" ); infoConfig->group("<default>").writeEntry( "number", 0 ); // open the cache file for the mime information QString cacheName = KGlobal::dirs()->saveLocation("data", "nsplugins")+"/cache"; kDebug(1433) << "Creating MIME cache file " << cacheName; QFile cachef(cacheName); if (!cachef.open(QIODevice::WriteOnly)) return -1; QTextStream cache(&cachef); if (showProgress) { printf("20\n"); fflush(stdout); } // read in the plugins mime information kDebug(1433) << "Scanning directories" << searchPaths; int count = searchPaths.count(); int i = 0; for ( QStringList::const_iterator it = searchPaths.constBegin(); it != searchPaths.constEnd(); ++it, ++i) { if ((*it).isEmpty()) continue; scanDirectory( *it, mimeInfoList, cache ); if (showProgress) { printf("%d\n", 25 + (50*i) / count ); fflush(stdout); } } if (showProgress) { printf("75\n"); fflush(stdout); } // We're done with forking, // KProcess needs SIGCHLD to be reset to what it was initially sigaction( SIGCHLD, &oldact, 0 ); // delete old mime types kDebug(1433) << "Removing old mimetypes"; const QStringList oldMimes = deletePluginMimeTypes(); bool mimeTypesChanged = !oldMimes.isEmpty(); if (showProgress) { printf("80\n"); fflush(stdout); } // write mimetype files kDebug(1433) << "Creating MIME type descriptions"; QStringList mimeTypes; for ( QStringList::const_iterator it=mimeInfoList.constBegin(); it!=mimeInfoList.constEnd(); ++it) { kDebug(1433) << "Handling MIME type " << *it; QStringList info = (*it).split(':', QString::KeepEmptyParts); if ( info.count()==4 ) { QString pluginName = info[0]; QString type = info[1].toLower(); QString extension = info[2]; QString desc = info[3]; // append to global mime type list if ( !mimeTypes.contains(type) ) { kDebug(1433) << " - mimeType=" << type; mimeTypes.append( type ); // write or update mime type file, if // 1) it doesn't exist in ksycoca (meaning we never heard of it) // 2) or we just deleted it [it's still in ksycoca though] // This prevents noticing that a shared-mime-info upgrade brought // us a mimetype we needed; but doing this right requires launching // kbuildsycoca4 after removing mimetypes above, and that's really slow bool mustWriteMimeType = KMimeType::mimeType(type).isNull(); if (!mustWriteMimeType) mustWriteMimeType = oldMimes.contains(type); if ( mustWriteMimeType ) { kDebug(1433) << " - creating MIME type description"; removeExistingExtensions( extension ); generateMimeType( type, extension, pluginName, desc ); mimeTypesChanged = true; } else { kDebug(1433) << " - already exists"; } } } } // done with new mimetypes, run update-mime-database if (mimeTypesChanged) { MimeTypeWriter::runUpdateMimeDatabase(); // note that we'll run kbuildsycoca below anyway } if (showProgress) { printf("85\n"); fflush(stdout); } // close files kDebug(1433) << "Closing cache file"; cachef.close(); infoConfig->sync(); delete infoConfig; // write plugin lib service file writeServicesFile( mimeTypes ); if (showProgress) { printf("90\n"); fflush(stdout); } if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kded")) { // Tell kded to update sycoca database. QDBusInterface kbuildsycoca("org.kde.kded", "/kbuildsycoca", "org.kde.kded"); kbuildsycoca.call("recreate"); } else { // kded not running? fallback to calling kbuildsycoca directly: KProcess proc; proc << KStandardDirs::findExe(KBUILDSYCOCA_EXENAME); proc.setOutputChannelMode(KProcess::MergedChannels); // silence kbuildsycoca output proc.execute(); } }