int main(int argc, const char* argv[]) { FileInfo info(argv[1]); cout << "1 -- " << endl; cout << " Basename = " << info.Basename() << endl; cout << " dirname = " << info.dirname() << endl; cout << " realpath = " << info.realpath() << endl; cout << endl << "2 -- " << endl; cout << " Basename = " << FileInfo(argv[1]).Basename() << endl; cout << " dirname = " << FileInfo(argv[1]).dirname() << endl; cout << " realpath = " << FileInfo(argv[1]).realpath() << endl; }
bool CModelManager::AddModelReference(const std::string& fileName, bool mirrored, int objRank) { auto it = m_models.find(FileInfo(fileName, mirrored)); if (it == m_models.end()) { if (!LoadModel(fileName, mirrored)) return false; it = m_models.find(FileInfo(fileName, mirrored)); } m_engine->SetObjectBaseRank(objRank, (*it).second.baseObjRank); return true; }
virtual Status GetDirectoryEntries(const VfsPath& path, FileInfos* fileInfos, DirectoryNames* subdirectoryNames) const { ScopedLock s; VfsDirectory* directory; WARN_RETURN_STATUS_IF_ERR(vfs_Lookup(path, &m_rootDirectory, directory, 0)); if(fileInfos) { const VfsDirectory::VfsFiles& files = directory->Files(); fileInfos->clear(); fileInfos->reserve(files.size()); for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it) { const VfsFile& file = it->second; fileInfos->push_back(FileInfo(file.Name(), file.Size(), file.MTime())); } } if(subdirectoryNames) { const VfsDirectory::VfsSubdirectories& subdirectories = directory->Subdirectories(); subdirectoryNames->clear(); subdirectoryNames->reserve(subdirectories.size()); for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it) subdirectoryNames->push_back(it->first); } return INFO::OK; }
bool TPluginSpecPrivate::Read(const QString &SpecFile) { Name = Version = /*CompatVersion =*/ Vendor = Copyright = License = Description = Url = /*Location =*/ ""; State = TPluginSpec::Invalid; HasError = false; ErrorString = ""; Dependencies.clear(); QFile File(SpecFile); if(!File.exists()) return ReportError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): File does not exist: %1").arg(File.fileName())); if(!File.open(QIODevice::ReadOnly)) return ReportError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): Could not open file for read: %1").arg(File.fileName())); QFileInfo FileInfo(File); Location = FileInfo.absolutePath(); //FilePath = fileInfo.absoluteFilePath(); QXmlStreamReader XmlReader(&File); while(!XmlReader.atEnd()) { XmlReader.readNext(); if(XmlReader.tokenType() == QXmlStreamReader::StartElement) ReadPluginSpec(XmlReader); } if(XmlReader.hasError()) return ReportError(QString("TPluginSpecPrivate::Read(const QString &SpecFile): Error parsing file %1: %2, at line %3, column %4") .arg(File.fileName()).arg(XmlReader.errorString()).arg(XmlReader.lineNumber()).arg(XmlReader.columnNumber())); State = TPluginSpec::Read; return true; }
bool DatabaseWrapperBase::LookupAttachment(FileInfo& attachment, int64_t id, FileContentType contentType) { SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?"); s.BindInt64(0, id); s.BindInt(1, contentType); if (!s.Step()) { return false; } else { attachment = FileInfo(s.ColumnString(0), contentType, s.ColumnInt64(1), s.ColumnString(4), static_cast<CompressionType>(s.ColumnInt(2)), s.ColumnInt64(3), s.ColumnString(5)); return true; } }
void getFileListFromZip(VectorFileInfo& _result, const char*_zipfile, const std::string& _folder, const std::string& filename) { unzFile pFile = NULL; std::string path = _folder + filename; bool isDir = false; pFile = unzOpen(_zipfile); if (!pFile) return; do { int nRet = unzLocateFile(pFile, path.c_str(), 1); CC_BREAK_IF(UNZ_OK != nRet); char szFilePathA[260]; unz_file_info unzInfo; nRet = unzGetCurrentFileInfo(pFile, &unzInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0); CC_BREAK_IF(UNZ_OK != nRet); if (szFilePathA[unzInfo.size_filename - 1] == '/' || szFilePathA[unzInfo.size_filename - 1] == '\\') isDir = true; else isDir = false; _result.push_back(FileInfo(filename, isDir)); } while (0); unzClose(pFile); }
void QVolumeSocketData::Send(QBaseSocket* Socket, QByteArray& Data) { QByteArray Voxels((char*)this->Voxels, this->NoBytes); QByteArray ByteArray; QDataStream DataStream(&ByteArray, QIODevice::WriteOnly); DataStream.setVersion(QDataStream::Qt_4_0); QFileInfo FileInfo(this->FileName); DataStream << FileInfo.fileName(); DataStream << this->Resolution[0]; DataStream << this->Resolution[1]; DataStream << this->Resolution[2]; DataStream << this->Spacing[0]; DataStream << this->Spacing[1]; DataStream << this->Spacing[2]; DataStream << Voxels; DataStream << this->NoBytes; QSocketData::Send(Socket, ByteArray); }
bool ListFilesInDirectory(const String & directoryPath, std::vector<FileInfo> & fi) { WIN32_FIND_DATA findData; HANDLE hFind; // "C:\Windows" needs to be "C:\Windows\*" for FindFirstFile to work String workingDirPath = directoryPath; workingDirPath.append(L"\\*"); hFind = FindFirstFile(workingDirPath.c_str(), &findData); if (hFind == INVALID_HANDLE_VALUE) { return false; } do { // exclude '.' & '..' String filename (findData.cFileName); if (filename != L"." && filename != L"..") { fi.push_back(FileInfo(directoryPath, filename)); } } while (FindNextFile(hFind, &findData)); DWORD err = GetLastError(); // no files left, we listed all of them return err == ERROR_NO_MORE_FILES; }
// Calls all writing functions and generates 3D files. void TrackGen::Generate() { PrepareForGeneration(); CreateSegment(); // Decides whether to generate X segments, or keep adding until a minimum length is met. if (_segmentLimit != -1) _totalLength = std::numeric_limits<float>::max(); else _segmentLimit = INT_MAX; CreateSegment(); while (_totalLength < _lengthLowerLimit)// && _sectionNumber < _segmentLimit) { if (rand() % 100 < 70) CreateCurveSegment(); else CreateSegment(); } ConnectToEnd(); if (_returnCode) { std::cout << "Intersection"; return; } // If X position of final segment is not within 0.01 of starting point, the track is deemed to have not connected. if (_segmentList.back()->GetEndPos().x > 0.01 || _segmentList.at(_segmentList.size()-1)->GetEndPos().x < -0.01) { std::cout << "No end meet."; _returnCode = true; return; } WriteSegmentsToXML(); // Generate 3D files and copy files. std::string generateName; // Copy files into track directory. if (_torcsDirectory.length() > 0) { generateName = "\"" + _torcsDirectory + "//trackgen.exe\" -c road -n " + _trackName; system(generateName.c_str()); std::string copyCommand = "copy \"tracks\\road\\" + _trackName + "\" \"" + _torcsDirectory + "\\tracks\\road\\" + _trackName; system(copyCommand.c_str()); // Remove temporary folder from directory. std::string removeFolder = "RD tracks /S /Q"; system(removeFolder.c_str()); } else { generateName = "trackgen.exe -c road -n " + _trackName; system(generateName.c_str()); } FileInfo(); }
int main(int argc, char** argv) { const s_plf_version_info * libplf_version; printf("\n\nplfinfo\n"); printf("****************\n"); printf("2011 & 2015 scorp2kk & @SteveClement\n"); printf("\n\n"); libplf_version = plf_lib_get_version(); printf("libplf Version: %d.%d.%d\n\n", libplf_version->major, libplf_version->minor, libplf_version->bugfix); if (parse_options(argc, argv) < 0 || input_file_name == 0) { print_help("plfinfo"); return 0; } printf("Input file: %s\n", input_file_name); FileInfo(input_file_name); printf("==> DONE <==\n\n"); return 0; }
void CBFileListTable::ReadSetup ( istream& input, const JFileVersion vers ) { RemoveAllFiles(); JSize fileCount; input >> fileCount; StopListening(GetFullNameDataList()); JString fileName; for (JIndex i=1; i<=fileCount; i++) { JFAID_t id; time_t t; input >> fileName >> id >> t; JIndex index; const JBoolean isNew = JXFileListTable::AddFile(fileName, &index); assert( isNew ); itsFileInfo->InsertElementAtIndex(index, FileInfo(id, t)); } ListenTo(GetFullNameDataList()); if (vers >= 80) { input >> itsLastUniqueID; }
void DirectoryNavigation::SetDestinationPath(const string& path) { _currentDirectory = path; _dirName.clear(); DIR *d = opendir(path.c_str()); dirent* dir; if(d) { while((dir = readdir(d)) != NULL) { IconType icon = FindType(dir); _dirName.push_back(FileInfo(dir->d_name, icon)); } closedir(d); } _dirName.pop_front(); _dirName.pop_front(); std::sort(_dirName.begin(), _dirName.end()); }
void Manifest::awaken(Origin origin) const { if (!m_remote.at(origin)) return; const std::size_t chunk(origin / m_chunkSize * m_chunkSize); const auto m(m_endpoint.getSubEndpoint("m")); const auto bytes(io::ensureGet(m, std::to_string(chunk))); const auto json(parse(bytes->data())); std::lock_guard<std::mutex> lock(m_mutex); if (!json.isArray()) { throw std::runtime_error( "Invalid file-info chunk - expected array: " + json.toStyledString()); } else if (json.size() != std::min(m_chunkSize, size() - chunk)) { throw std::runtime_error("Invalid file-info chunk - unexpected size"); } std::size_t i(chunk); for (const auto& f : json) { m_fileInfo.at(i) = FileInfo(f); m_remote.at(i) = false; ++i; } }
// Returns true if the path exists and is a directory bool IsDirectory(const std::string& path) { #ifdef _WIN32 return PathIsDirectory(UTF8ToUTF16(path).c_str()); #else return FileInfo(path).IsDirectory(); #endif }
int CModelManager::GetModelBaseObjRank(const std::string& fileName, bool mirrored) { auto it = m_models.find(FileInfo(fileName, mirrored)); if (it == m_models.end()) return -1; return (*it).second.baseObjRank; }
SourceIndex::FileInfo FileInfo::getFileInfo(ConstStrW fname) { IFileIOServices &svc = IFileIOServices::getIOServices(); PFolderIterator iter = svc.getFileInfo(fname); return FileInfo(FilePath(iter->getFullPath(), false), iter->getModifiedTime()); }
FileInfo RunManager_Util::dirFile(QFileInfo fi) { fi.refresh(); return FileInfo(toString(fi.fileName()), (fi.exists()&&fi.lastModified().isValid())?toDateTime(fi.lastModified()):openstudio::DateTime(), toString(fi.fileName()), /* The default key is the filename */ toPath(fi.absoluteFilePath()), fi.exists()); }
static const FileInfo * getInfo(const char *filename) { set<FileInfo>::iterator it = FileInfo::cActiveFileInfo.find(FileInfo(filename)); if(it != FileInfo::cActiveFileInfo.end()) { return &(*it); } else { return NULL; } }
FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; String tpath( path ); if ( tpath[ tpath.size() - 1 ] == '/' || tpath[ tpath.size() - 1 ] == '\\' ) { tpath += "*"; } else { tpath += "\\*"; } WIN32_FIND_DATAW findFileData; HANDLE hFind = FindFirstFileW( (LPCWSTR)tpath.toWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { std::string name( String( findFileData.cFileName ).toUtf8() ); std::string fpath( path + name ); if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } while( FindNextFileW( hFind, &findFileData ) ) { name = String( findFileData.cFileName ).toUtf8(); fpath = path + name; if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } } FindClose( hFind ); } return files; }
void CModelManager::UnloadModel(const std::string& fileName, bool mirrored) { auto it = m_models.find(FileInfo(fileName, mirrored)); if (it == m_models.end()) return; m_engine->DeleteBaseObject((*it).second.baseObjRank); m_models.erase(it); }
virtual Status GetFileInfo(const VfsPath& pathname, FileInfo* pfileInfo) const { ScopedLock s; VfsDirectory* directory; VfsFile* file; Status ret = vfs_Lookup(pathname, &m_rootDirectory, directory, &file); if(!pfileInfo) // just indicate if the file exists without raising warnings. return ret; WARN_RETURN_STATUS_IF_ERR(ret); *pfileInfo = FileInfo(file->Name(), file->Size(), file->MTime()); return INFO::OK; }
void FileEx::ListDirectory() { pos = 0; topline = 0; std::tstring search(path); search += _T("\\*"); WIN32_FIND_DATA fd; HANDLE hFile = ::FindFirstFile(search.c_str(), &fd); if (hFile == INVALID_HANDLE_VALUE) { DWORD dwError = ::GetLastError(); std::tcerr << _T("::FindFirstFile failed. : ") << dwError << std::endl; path = path.substr(0, path.find_last_of(_T("\\"))); ::FindClose(hFile); return; } filelist.clear(); std::list<FileInfo> dirlist; std::list<FileInfo> normallist; do { if (fd.cFileName == std::tstring(_T("."))) continue; bool bDir = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY); if (bDir) dirlist.push_back(FileInfo(fd.cFileName, bDir)); else normallist.push_back(FileInfo(fd.cFileName, bDir)); } while (::FindNextFile(hFile, &fd)); filelist.insert(filelist.cend(), dirlist.begin(), dirlist.end()); filelist.insert(filelist.cend(), normallist.begin(), normallist.end()); ::FindClose(hFile); }
void visitProduct(const ResolvedProductConstPtr &product) { QBS_CHECK(product->buildData); ArtifactVisitor::visitProduct(product); // For target artifacts, we have to update the on-disk timestamp, because // the executor will look at it. for (Artifact * const targetArtifact : product->targetArtifacts()) { if (FileInfo(targetArtifact->filePath()).exists()) QFile(targetArtifact->filePath()).open(QIODevice::WriteOnly | QIODevice::Append); } }
void FileWatcher :: unwatchfile(const char *filename) { if(!g_filewatcher) g_filewatcher = new FileWatcherImpl(); set<FileInfo>::iterator it = FileInfo::cActiveFileInfo.find(FileInfo(filename)); if(it != FileInfo::cActiveFileInfo.end()) FileInfo::cActiveFileInfo.erase(it); if(!inotifytools_remove_watch_by_filename(filename)) { int err = inotifytools_error(); printf("Error: unwatchingfile %d\n", err); return; } }
const char* FileInfo::realpath() { char* pt = strdup( _path.c_str()); string dir = ::dirname(pt); free(pt); _realpath = _path; if ( dir[0] == '~' ) { // const char* pt = getenv("HOME"); const gchar* pt = g_get_home_dir() ; if ( pt != NULL ) dir = pt + dir.substr(1); } else if ( dir[0] == '$' ) { char varname[80]; const char* pt; int i; for ( i=0, pt = dir.c_str()+1; *pt && *pt != ')' && strncmp(pt,_path_delim,1) ; ++pt ) if ( *pt == '(' ) continue; else varname[i++] = *pt; varname[i] = 0; if ( *pt == ')' ) ++pt; if ( varname[0] ) { const char* pt2 = getenv(varname); if ( pt2 != NULL ) { dir = string(pt2) + string(pt); } else Log::err() << "Error in FileInfo::realpath : undefined environment variable " << varname << endl; } } else if ( dir[0] == '.' ) { char resolved[MAXPATHLEN]; char current[MAXPATHLEN]; if ( getcwd(current, sizeof(current)) == NULL ) return ""; // rep courant indefini if ( chdir(dir.c_str()) != 0 ) return ""; // path invalide getcwd(resolved, sizeof(resolved)); chdir (current); dir=resolved; } _realpath = FileInfo(dir).join(Basename()); return _realpath.c_str(); }
void CrabRibbonBaseUI::dropEvent(QDropEvent *event) { QList<QUrl> urls = event->mimeData()->urls(); if(urls.isEmpty()) {return;} QString FilePath = urls.first().toLocalFile(); QFileInfo FileInfo(FilePath); if(!FileInfo.isFile()) {qDebug() << "CrabRibbonBaseUI::dropEvent() File should be a file!"; return;} if(!FileInfo.isReadable()) {qDebug() << "CrabRibbonBaseUI::dropEvent() Error! File is unreadable!"; return;} //QString FileType = FilePath.section(".",-1); //section separated by ".", and -1 means start from the right end. //if(FileType!="pdf") {qDebug() << "CrabPDFReader::dropEvent() Error! File should be a pdf!"; return;} /* Send open file signal */ emit signal_open_file(FilePath); QWidget::dropEvent(event); }
QScriptValue File::js_lastModified(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(engine); if (Q_UNLIKELY(context->argumentCount() < 1)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("File.lastModified() expects an argument")); } const QString filePath = context->argument(0).toString(); const FileTime timestamp = FileInfo(filePath).lastModified(); const auto se = static_cast<ScriptEngine *>(engine); se->addFileLastModifiedResult(filePath, timestamp); return timestamp.asDouble(); }
bool DlgCompareDir::FetchDir(String dir, VectorMap<String, FileInfo>& files, VectorMap<String, String>& dirs) { FindFile ff; if(!ff.Search(AppendFileName(dir, "*"))) return false; do if(ff.IsFile() && PatternMatchMulti(fm, ff.GetName())) files.Add(NormalizePathCase(ff.GetName()), FileInfo(ff.GetName(), ff.GetLength(), ff.GetLastWriteTime())); else if(ff.IsFolder()) dirs.Add(NormalizePathCase(ff.GetName()), ff.GetName()); while(ff.Next()); return true; }
Job JobFactory::createIdfToModelJob( const openstudio::path &t_idf, const openstudio::path &t_outdir, const boost::optional<openstudio::UUID> &t_uuid) { JobParams params; params.append("outdir", toString(t_outdir)); Files files; files.append(FileInfo(t_idf, "idf")); return createIdfToModelJob(Tools(), params, files, std::vector<openstudio::URLSearchPath>(), t_uuid); }
Files OpenStudioPostProcessJob::outputFilesImpl() const { // Dan: what's the output files generated? if (!boost::filesystem::exists(outdir() / toPath("report.xml"))) { // no output file has been generated yet return Files(); } Files f; f.append(FileInfo(outdir() / toPath("report.xml"), "xml")); return f; }