Ogre::String File::absPath() const { if(isPathAbsolute()) return fullPath(); return File::getCurrentDirectory()/fullPath(); }
/** * Renames the note subfolder in the file system */ bool NoteSubFolder::rename(QString newName) { QDir dir = this->dir(); if (dir.exists() && !newName.isEmpty()) { QString oldPath = fullPath(); setName(newName); QString newPath = fullPath(); // rename the note subfolder return dir.rename(oldPath, newPath); } return false; }
std::shared_ptr<json_object>& ResourceCache::loadAsset(const std::string& name) { std::shared_ptr<json_object> object; if (this->assetCache.find(name) == this->assetCache.end()) { Logger::getInstance().log(Logger::LOG_INFO, "Asset `%s' not in cache, trying to load", name.c_str()); std::string fullPath(this->buildPath(name).c_str()); auto entitySource = this->loadSource(fullPath.c_str()); if (entitySource == nullptr) { Logger::getInstance().log(Logger::LOG_ERROR, "Failed to open `%s'", fullPath.c_str()); return this->assetCache["nullptr"]; } json_tokener_error parseError; object = std::shared_ptr<json_object>( json_tokener_parse_verbose(entitySource.get(), &parseError), json_object_put); if (object == nullptr) { Logger::getInstance().log(Logger::LOG_ERROR, "Failed to parse `%s': %s", fullPath.c_str(), json_tokener_error_desc(parseError)); return this->assetCache["nullptr"]; } this->assetCache.insert(std::make_pair(name, object)); } else { Logger::getInstance().log(Logger::LOG_INFO, "Asset `%s' picked from cache", name.c_str()); } return this->assetCache.at(name); }
/** * Returns the file path of the restored file * * @return */ QString TrashItem::restorationFilePath() { auto noteSubFolder = NoteSubFolder::fetchByPathData(noteSubFolderPathData); QString folderPath = noteSubFolder.fullPath(); QString filePath = folderPath + QDir::separator() + fileName; QFile file(filePath); // prepend the current timestamp if the file already exists if ( file.exists() ) { filePath = folderPath + QDir::separator() + QString::number( QDateTime::currentMSecsSinceEpoch() / 1000) + "_" + fileName; } file.setFileName(filePath); // if the file still exists use a random number if ( file.exists() ) { filePath = folderPath + QDir::separator() + QString::number(qrand()) + "_" + fileName; } file.setFileName(filePath); // if the file still exists quit if ( file.exists() ) { return ""; } return filePath; }
int Simulator::handleAlgorithms() { // handle algorithm files // [exercise says: - in case the directory is defect -> return // - in case the directory is empty -> return // - in case the directory is missing -> search recursively in the working directory for algorithms] int handle = 0; numOfAlgorithms = getNumberOfPotentialAlgorithms(flags[3]); if (numOfAlgorithms == -1 || numOfAlgorithms == 0) { cout << USAGE << endl; cout << ERROR_FIND_ALGORITHM_FILES << fullPath(flags[3]) << endl; return -1; } else if (numOfAlgorithms == -2) { // no usage print is necessary return -1; } handle = handleAlgorithmFiles(handleSlash(flags[3].c_str()), numOfAlgorithms, registrar); if (handle < 0) { if (handle == -1) { cout << USAGE << endl; } return -1; } walkingIntoWallsErrors = make_unique<string[]>(numOfAlgorithms); numOfAlgorithms = registrar.getAlgorithmNames().size(); return 0; }
void OvrSoundManager::LoadSoundAssetsFromJsonObject( const String & url, JSON * dataFile ) { OVR_ASSERT( dataFile ); // Read in sounds - add to map JSON* sounds = dataFile->GetItemByName( "Sounds" ); OVR_ASSERT( sounds ); const unsigned numSounds = sounds->GetItemCount(); for ( unsigned i = 0; i < numSounds; ++i ) { const JSON* sound = sounds->GetItemByIndex( i ); OVR_ASSERT( sound ); String fullPath( url ); fullPath.AppendString( sound->GetStringValue( ) ); // Do we already have this sound? StringHash< String >::ConstIterator soundMapping = SoundMap.Find( sound->Name ); if ( soundMapping != SoundMap.End() ) { LOG( "SoundManger - adding Duplicate sound %s with asset %s", sound->Name.ToCStr( ), fullPath.ToCStr( ) ); SoundMap.Set( sound->Name, fullPath ); } else // add new sound { LOG( "SoundManger read in: %s -> %s", sound->Name.ToCStr( ), fullPath.ToCStr( ) ); SoundMap.Add( sound->Name, fullPath ); } } dataFile->Release(); }
bool U2SearchPath::NextSearchPath(TCHAR* szPath, uint32 len ) { U2Filename fullPath(m_filePath); switch(m_uNextPath) { case 0: break; case 1: fullPath.SetDrive(_T("")); fullPath.SetDir(_T("")); break; case 2: fullPath.SetDrive(_T("")); fullPath.SetDir(m_refPath); break; case 3: if(ms_defPath[0] != _T('\0')) { fullPath.SetDrive(_T("")); fullPath.SetDir(ms_defPath); break; } default: return false; } fullPath.FullPath(szPath, len); m_uNextPath++; return true; }
bool File::readInto(Json::Value &root, bool keepComments) const { if(!exists()) { Ogre::String msg = "could not open :" + fullPath() + ": file not found."; if(Debug::isInit) Debug::error(STEEL_METH_INTRO, msg).endl(); else std::cerr << STEEL_METH_INTRO.c_str() << msg.c_str() << std::endl; return false; } Json::Reader reader; Ogre::String content = read(false); root.clear(); if(!reader.parse(content, root, keepComments)) { Ogre::String msg = "Could not parse content:" + reader.getFormatedErrorMessages() + "\non :" + content; if(Debug::isInit) Debug::error(STEEL_METH_INTRO, msg).endl(); else std::cerr << STEEL_METH_INTRO.c_str() << msg.c_str() << std::endl; return false; } return true; }
gvl::sink toSink() const { auto s = imp->tryToSink(); if (!s) throw std::runtime_error("Could not write " + fullPath()); return std::move(s); }
gvl::source toSource() const { auto s = imp->tryToSource(); if (!s) throw std::runtime_error("Could not read " + fullPath()); return std::move(s); }
// For MacOS CARBON we use other version of the CreateDiskLocation() factory. // I_Disk_Location* CreateDiskLocation( const UChar* inStr ) { if( gUseCarbon ) { String fullPath(inStr); return new Location_Disk_FSSpec( &fullPath ); } else // i.e. we have MACHO { I_Disk_Location_Ptr pLocation = CreateDiskLocationFromFSRef( inStr ); if( !pLocation->get_Exists() ) { I_Location_Ptr pa = I_Disk_Location::GetAppLocation(); I_Location_Ptr pl = pa->get_ChildLocation( inStr ); I_Disk_Location* pdl = dcast<I_Disk_Location*>( pl.get() ); pdl->AddRef(); return pdl; } else { I_Disk_Location* pdl = dcast<I_Disk_Location*>( pLocation.get() ); pdl->AddRef(); return pdl; } } }
void OriginalRecording::openSpikeFile(File rootFolder, SpikeRecordInfo* elec) { FILE* spFile; String fullPath(rootFolder.getFullPathName() + rootFolder.separatorString); fullPath += elec->name.removeCharacters(" "); if (experimentNumber > 1) { fullPath += "_" + String(experimentNumber); } fullPath += ".spikes"; std::cout << "OPENING FILE: " << fullPath << std::endl; File f = File(fullPath); bool fileExists = f.exists(); diskWriteLock.enter(); spFile = fopen(fullPath.toUTF8(),"ab"); if (!fileExists) { String header = generateSpikeHeader(elec); fwrite(header.toUTF8(), 1, header.getNumBytesAsUTF8(), spFile); } diskWriteLock.exit(); spikeFileArray.set(elec->recordIndex,spFile); }
STRING ceefit_call_spec PARSE::Footnote() { if(FootnoteFiles >= 25) { return "[-]"; } else { try { int thisFootnote = ++FootnoteFiles; STRING html(STRING("footnotes/") + thisFootnote + ".html"); STRING fullPath(STRING("Reports/") + html); WRITER* output = new FILEWRITER(fullPath); if(output == null) { throw new IOEXCEPTION("Create Footnote file operation failed"); } Print(output); output->Close(); return (STRING("<a href=/fit/Release/Reports/") + html + "> [" + thisFootnote + "]</a>"); } catch (IOEXCEPTION* e) { delete e; return "[!]"; } } }
FILE* FileSystem::openFile(const char* path, const char* mode) { GP_ASSERT(path); std::string fullPath(__resourcePath); fullPath += resolvePath(path); createFileFromAsset(path); FILE* fp = fopen(fullPath.c_str(), mode); // Win32 doesn't support an asset or bundle definitions. #ifdef WIN32 if (fp == NULL) { fullPath = __resourcePath; fullPath += "../../gameplay/"; fullPath += path; fp = fopen(fullPath.c_str(), mode); } #endif return fp; }
bool FileSystem::fileExists(const char* path) { GP_ASSERT(path); std::string fullPath(__resourcePath); fullPath += resolvePath(path); createFileFromAsset(path); gp_stat_struct s; // Win32 doesn't support an asset or bundle definitions. #ifdef WIN32 if (stat(fullPath.c_str(), &s) != 0) { fullPath = __resourcePath; fullPath += "../../gameplay/"; fullPath += path; return stat(fullPath.c_str(), &s) == 0; } return true; #else return stat(fullPath.c_str(), &s) == 0; #endif }
void MainWindow::on_actionOpen_sample_triggered() { // Get last selected sample auto selected = ui->samplesTreeView->selectionModel()->selectedIndexes(); if (selected.empty()) { return; } for (auto sel : selected) { // Have to map from proxy model to source sel = samplesProxyModel.mapToSource(sel); // Only want to follow selected paths, not ratings, etc. if (sel.column() != 0) { continue; } auto sample = static_cast<Sample*>(sel.internalPointer()); #ifdef Q_OS_WIN QProcess::startDetached( "explorer", QStringList() << "/select," << QDir::toNativeSeparators(sample->fullPath()) ); #endif } }
void ListDir(const std::string& path, bool directories, void (*CallBack)(const std::string& filename, void* param), void* param, std::list<std::string> *liste) { namespace bfs = boost::filesystem; bfs::path fullPath(path); if(!fullPath.has_extension()) return; bfs::path parentPath = fullPath.parent_path(); std::string extension = fullPath.extension().string(); std::transform(extension.begin(), extension.end(), extension.begin(), tolower); for(bfs::directory_iterator it = bfs::directory_iterator(parentPath); it != bfs::directory_iterator(); ++it) { if(bfs::is_directory(it->status()) && !directories) continue; bfs::path curPath = it->path(); curPath.make_preferred(); std::string curExt = curPath.extension().string(); std::transform(curExt.begin(), curExt.end(), curExt.begin(), tolower); if(curExt != extension) continue; if(CallBack) CallBack(curPath.string(), param); if(liste) liste->push_back(curPath.string()); } if(liste) liste->sort(); }
bool CDiskResource::GetFile(std::wstring path,unsigned char** buff,unsigned long* len) { bool result = TRUE; std::wstring fullPath(m_path); fullPath.append(_T("\\")).append(path); /// Open the file. HANDLE hf = ::CreateFile(fullPath.c_str(),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (hf != INVALID_HANDLE_VALUE) { // Allocate a buffer to receive file. *len = ::GetFileSize(hf,NULL); *buff = new unsigned char[(*len)+1]; // Load the data. unsigned long read; ::ReadFile(hf,*buff,*len,&read,NULL); ::CloseHandle(hf); ATLASSERT(read == *len); (*buff)[*len] = 0; } else result = FALSE; return result; }
std::vector<File> File::ls(File::NodeType filter, bool include_hidden) const { if(!(exists() && isDir())) return std::vector<File>(0); std::vector<std::string> files; Poco::File(fullPath()).list(files); std::list<File> nodes; for(auto it = files.begin(); it != files.end(); ++it) { File file = subfile(*it); NodeType nodeType = file.nodeType(); if(nodeType & filter) { if(!include_hidden && (nodeType & HIDDEN)) continue; nodes.push_back(file); } } std::vector<File> vecnodes; for(auto it = nodes.begin(); it != nodes.end(); ++it) vecnodes.push_back(*it); return vecnodes; }
bool EpisodeBox_world::open(QString filePath) { fPath=filePath; FileFormats::OpenWorldFile(filePath, d); qDebug()<< "Opened world, valud=" << d.ReadFileValid << filePath; //Collect music entries! if(d.ReadFileValid) { QDir fullPath(d.path); //From music boxes for(int i=0; i<d.music.size(); i++) { QString &musFile = d.music[i].music_file; if(musFile.isEmpty()) continue; musFile.replace('\\', '/'); musFile.replace("//", "/"); QString mFile = fullPath.absoluteFilePath(musFile); MusicField mus; mus.absolutePath = mFile; mus.field = &musFile; music_entries.push_back(mus); } } return d.ReadFileValid; }
File &File::write(Ogre::String buffer, std::ios_base::openmode mode) { std::ofstream s; s.open(fullPath().c_str(), mode); s.write(buffer.c_str(), buffer.length() * sizeof(char)); return *this; }
TCBitmap* TCBitmap::decodeBitmap(std::string filePath,BitmapFormat format){ std::string fullPath(filePath); TCBitmap* ret=NULL; #if TC_TARGET_PLATFORM==TC_PLATFORM_ANDROID//!android的apk是一个zip文件,必须从apk里读取图片 ret =TCPngUtils::decodePngByFileNameInZip(AndroidSystemInfo::sourceDir().c_str(),fullPath.c_str()); #else ret=TCPngUtils::decodePngByFileName(fullPath.c_str()); #endif if(ret==0){ DebugLog("decode bitmap failed!!!!,%s",filePath.c_str()); return 0; } if(format==RGBA_8888){ return ret; } else if(format==RGBA_4444){ DebugLog("convert bitmap to rgba4444"); ret->convertToRGBA4444(); return ret; } else if(format==RGB_565){ DebugLog("convert bitmap to rgb565"); ret->convertToRGB565(); return ret; } DebugLog("convert bitmap failed:unknown format"); return ret; }
// Return is file exists bool THFileUtil::existFile(const char* fileName) { if(!fileName) { return false; } std::string fullPath(fileName); if(!fileName) { return false; } do { FILE *fp = fopen(fileName, "r"); if(fp != NULL) { fclose(fp); return true; } } while(0); return false; }
bool FileSystem::fileExists(const char* filePath) { GP_ASSERT(filePath); std::string fullPath(__resourcePath); fullPath += resolvePath(filePath); createFileFromAsset(filePath); gp_stat_struct s; #ifdef WIN32 if (stat(fullPath.c_str(), &s) != 0) { fullPath = __resourcePath; fullPath += "../../gameplay/"; fullPath += filePath; int result = stat(fullPath.c_str(), &s); if (result != 0) { fullPath = __resourcePath; fullPath += "../gameplay/"; fullPath += filePath; return stat(fullPath.c_str(), &s) == 0; } } return true; #else return stat(fullPath.c_str(), &s) == 0; #endif }
void Utils::GetModuleFilePath(std::string& path, FCM::PIFCMCallback pCallback) { #ifdef _WINDOWS std::string fullPath; FCM::U_Int16* pFilePath = new FCM::U_Int16[MAX_PATH]; ASSERT(pFilePath); ::GetModuleFileNameW((HINSTANCE)&__ImageBase, pFilePath, MAX_PATH); fullPath = Utils::ToString(pFilePath, pCallback); GetParent(fullPath, path); delete[] pFilePath; #else Dl_info info; if (dladdr((void*)(GetModuleFilePath), &info)) { std::string fullPath(info.dli_fname); GetParent(fullPath, path); GetParent(path, fullPath); GetParent(fullPath, path); GetParent(path, fullPath); path = fullPath; } else{ ASSERT(0); } #endif }
FILE* FileSystem::openFile(const char* path, const char* mode) { GP_ASSERT(path); GP_ASSERT(mode); std::string fullPath(__resourcePath); fullPath += resolvePath(path); createFileFromAsset(path); FILE* fp = fopen(fullPath.c_str(), mode); #ifdef WIN32 if (fp == NULL) { fullPath = __resourcePath; fullPath += "../../gameplay/"; fullPath += path; fp = fopen(fullPath.c_str(), mode); if (!fp) { fullPath = __resourcePath; fullPath += "../gameplay/"; fullPath += path; fp = fopen(fullPath.c_str(), mode); } } #endif return fp; }
void BundleDirectory::List(const std::string& path, std::vector<std::string>& files, bool quiet) const { try { Poco::Path fullPath(m_RootPath); fullPath.append(path); Poco::File file(fullPath); file.list(files); } catch (Poco::FileNotFoundException& exc) { if (!quiet) { BERRY_WARN << "Warning: " << exc.displayText() << std::endl; throw exc; } } catch (const Poco::PathNotFoundException& exc) { if (!quiet) { BERRY_WARN << "Warning: " << exc.displayText() << std::endl; throw exc; } } }
std::string sys::OSUnix::getTempName(const std::string& path, const std::string& prefix) const { std::string name; #if defined(_USE_MKSTEMP) || defined(__linux__) || defined(__linux) || defined(linux__) std::string pathname(path); pathname += "/" + prefix + "XXXXXX"; std::vector<char> fullPath(pathname.size() + 1); strcpy(&fullPath[0], pathname.c_str()); int ret = mkstemp(&fullPath[0]); if (ret == -1) name = ""; else { name = &fullPath[0]; } #else CharWrapper tempname = tempnam(path.c_str(), prefix.c_str()); if (tempname.get() == NULL) name = ""; else { name = tempname.get(); sys::File (name, sys::File::WRITE_ONLY, sys::File::CREATE); } #endif if (name.empty()) { throw except::Exception(Ctxt("Unable to create a temporary file")); } return name; }
void MaterialPrecache::PrecacheMaterial(const char *path) { QString shortPath(path); shortPath.remove(".xml"); if (materials.contains(shortPath)) { DBGWARNING("!! Already precached:" << path); return; } std::string fullPath(PATH_MATERIAL_ROOT); fullPath += shortPath.toStdString(); fullPath += ".xml"; Material *material = ParseMaterial(fullPath.c_str()); if (material == nullptr) { DBGWARNING("!! Failed precaching material:" << path); return; } materials.insert(shortPath, material); }
void getSubDirectories(std::string const & dir, std::list<std::string> & list) { list.clear(); DIR * dirp = NULL; struct dirent * dp = NULL; if (NULL != (dirp = opendir(dir.c_str()))) { do { std::string fullPath(dir); struct stat statBuf; if ((NULL != (dp = readdir(dirp))) && (0 != strcmp(dp->d_name, ".")) && (0 != strcmp(dp->d_name, ".."))) { fullPath.append("/").append(dp->d_name); if ((0 == stat(fullPath.c_str(), &statBuf)) && (S_ISDIR(statBuf.st_mode))) { list.push_back(fullPath); } } } while (NULL != dp); closedir(dirp); } }