void UninstallAllThread::removeDesuraCache() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_CACHE")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); UTIL::FS::Path path(getCachePath(), "", false); std::vector<std::string> extList; extList.push_back("mcf"); for (size_t x=0; x<20; x++) extList.push_back(gcString("part_{0}", x)); UTIL::FS::Path dbDir(UTIL::OS::getAppDataPath(), L"", false); delLeftOverMcf(path, extList); delLeftOverMcf(dbDir, extList); UTIL::FS::Path mcfUploads = dbDir; UTIL::FS::Path mcfStore = dbDir; mcfUploads += UTIL::FS::File("mcf_uploads.sqlite"); mcfStore += UTIL::FS::File("mcfstoreb.sqlite"); UTIL::FS::delFile(mcfUploads); UTIL::FS::delFile(mcfStore); }
void ManageBDD::copyDatabaseToWritableDirectory(const QString &dbName) { if (this->databasePath.isEmpty()) { QDir dbDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); this->databasePath = dbDir.absolutePath(); qDebug() << this->databasePath; if (!dbDir.exists()) dbDir.mkpath(dbDir.absolutePath()); qDebug() << "Data dir exists : " << dbDir.exists(); } QFile dbFile(this->databasePath + "/" + dbName); qDebug() << dbFile.fileName(); if (!dbFile.exists()) { qDebug() << "File doesn't exist"; QFile dbTemplate(this->applicationPath + "/databases/" + dbName); qDebug() << "Trying to copy " << dbTemplate.fileName(); if (dbTemplate.exists()) dbTemplate.copy(dbFile.fileName()); } else qDebug() << "File already exists"; dbFile.setPermissions(QFile::ReadOwner|QFile::WriteOwner); // OPENED DB PATH IS SAVED IN HASH this->nameToPathHash[dbName] = dbFile.fileName(); this->localDBName = this->nameToPathHash[dbName]; }
void ChangeDirThread::updateDb(FileList &list) { if (isStopped()) return; uint32 prog = 0; onProgressEvent(prog); uint32 stage = 1; onStageEvent(stage); gcString path = UTIL::OS::getAppDataPath(); UTIL::FS::Path dbDir(path, "", false); fixMcfUploads(dbDir, list); fixMcfStore(dbDir, list); }
QSqlDatabase QMail::createDatabase() { if (!databaseDataInstance()->hasLocalData()) { databaseDataInstance()->setLocalData(new QDatabaseInstanceData); } QDatabaseInstanceData* instance = databaseDataInstance()->localData(); QSqlDatabase db; if (instance->init) { db = QSqlDatabase::database("qmailstore_sql_connection"); } else { qMailLog(Messaging) << "opening database"; db = QSqlDatabase::addDatabase("QSQLITE", "qmailstore_sql_connection"); QDir dbDir(dataPath() + "database"); if (!dbDir.exists()) { #ifdef Q_OS_UNIX QString path = dataPath(); if (path.endsWith('/')) path = path.left(path.length() - 1); if (!QDir(path).exists() && ::mkdir(QFile::encodeName(path), S_IRWXU) == -1) qCritical() << "Cannot create database directory: " << errno; #endif if (!dbDir.mkpath(dataPath() + "database")) qCritical() << "Cannot create database path"; } db.setDatabaseName(dataPath() + "database/qmailstore.db"); #endif if(!db.open()) { QSqlError dbError = db.lastError(); qCritical() << "Cannot open database: " << dbError.text(); } QDir tp(tempPath()); if(!tp.exists()) if(!tp.mkpath(tempPath())) qCritical() << "Cannot create temp path"; instance->init = true; } return db; }
QString PHIParent::tempDir( const QString &domain, const QString &def ) { QString tmp; _lock.lockForRead(); if ( _tmpDirs.contains( domain ) ) { tmp=_tmpDirs.value( domain ); _lock.unlock(); if ( _internalApp ) { QFileInfo info( tmp+QDir::separator()+QLatin1String( ".invalidate" ) ); if ( info.exists() ) { if ( _invalidateTouch < info.lastModified() ) { invalidate( domain ); _invalidateTouch=info.lastModified(); } } } return tmp; } _lock.unlock(); QWriteLocker l( &_lock ); QSettings *s=PHI::globalSettings(); s->beginGroup( def ); s->beginGroup( domain ); tmp=PHI::stdTmpPath()+QDir::separator()+domain; tmp=s->value( QStringLiteral( "TempDir" ), tmp ).toString(); s->setValue( QStringLiteral( "TempDir" ), tmp ); s->endGroup(); s->endGroup(); if ( !tmp.isEmpty() ) _tmpDirs.insert( domain, tmp ); else return tmp; QDir imgDir( tmp+QDir::separator()+QLatin1String( "img" ) ); imgDir.mkpath( tmp+QDir::separator()+QLatin1String( "img" ) ); QDir cssDir( tmp+QDir::separator()+QLatin1String( "css" ) ); cssDir.mkpath( tmp+QDir::separator()+QLatin1String( "css" ) ); QDir dbDir( tmp+QDir::separator()+QLatin1String( "db" ) ); dbDir.mkpath( tmp+QDir::separator()+QLatin1String( "db" ) ); QDir jsDir( tmp+QDir::separator()+QLatin1String( "js" ) ); jsDir.mkpath( tmp+QDir::separator()+QLatin1String( "js" ) ); return tmp; }
QFileInfo MainWindow::dbFile() { QDir dbDir(qApp->applicationDirPath()); #if defined(Q_OS_WIN) #elif defined(Q_OS_MAC) if (dbDir.dirName() == "MacOS") { dbDir.cdUp(); } else{ dbDir.cd(qApp->applicationName()+".app"); dbDir.cd("Contents"); } #endif if(!dbDir.cd("tools")) dbDir.mkdir("tools"); dbDir.cd("tools"); return QFileInfo (dbDir, "Database.db"); }
bool QrSqlHelper::makesureDbExist(QrSqlDatabase *database) { if (nullptr == database) { qDebug() << "database is nullptr"; return false; } const QString dbPath = database->getDatabasePath(); qDebug() << "check database " << dbPath; if (! QrCommon::QrFiler::fileExists (dbPath)) { qDebug() << "database is not exist"; return false; } QDir dbDir(database->getParams().folder); if (! dbDir.exists()) { QString parentFolder = QApplication::applicationDirPath (); if (parentFolder.isEmpty()) { parentFolder = "."; } QDir().mkdir( parentFolder + "/" + database->getParams().folder); } QSqlDatabase newDatabase = QSqlDatabase::addDatabase("QSQLITE"); newDatabase.setDatabaseName(dbPath); qDebug() << "open database..."; bool success = false; if (newDatabase.open()) { success = true; } else { qDebug() << "Database create fail:" << newDatabase.lastError().text(); } newDatabase.close(); return success; }
void UninstallAllThread::removeDesuraSettings() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_SETTINGS")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); UTIL::FS::Path dbDir(UTIL::OS::getAppDataPath(), L"", false); std::vector<UTIL::FS::Path> fileList; std::vector<UTIL::FS::Path> folderList; UTIL::FS::getAllFiles(dbDir, fileList, nullptr); UTIL::FS::getAllFolders(dbDir, folderList); for (size_t x=0; x<fileList.size(); x++) { std::string fileName = fileList[x].getFile().getFile(); if (fileName == "mcfstoreb.sqlite" || fileName == "mcf_uploads.sqlite") continue; UTIL::FS::delFile(fileList[x]); } for (size_t x=0; x<folderList.size(); x++) { std::string folderName = folderList[x].getLastFolder(); if (folderName == "mods" || folderName == "games" || folderName == "GDF") continue; UTIL::FS::delFolder(folderList[x]); } }
Foam::fileName Foam::surfMesh::meshDir() const { return dbDir()/meshSubDir; }
static INT32 _ossEnumSubDirs( const string &dirPath, const string &parentSubDir, vector< string > &subDirs, UINT32 deep ) { INT32 rc = SDB_OK ; try { fs::path dbDir ( dirPath ) ; fs::directory_iterator end_iter ; string subDir ; if ( 0 == deep ) { goto done ; } if ( fs::exists ( dbDir ) && fs::is_directory ( dbDir ) ) { for ( fs::directory_iterator dir_iter ( dbDir ); dir_iter != end_iter; ++dir_iter ) { try { if ( fs::is_directory( dir_iter->path() ) ) { if ( parentSubDir.empty() ) { subDir = dir_iter->path().leaf().string() ; } else { string subDir = parentSubDir ; subDir += OSS_FILE_SEP ; subDir += dir_iter->path().leaf().string() ; } subDirs.push_back( subDir ) ; if ( deep > 1 ) { _ossEnumSubDirs( dir_iter->path().string(), subDir, subDirs,deep - 1 ) ; } } } catch( std::exception &e ) { PD_LOG( PDWARNING, "File or dir[%s] occur exception: %s", dir_iter->path().string().c_str(), e.what() ) ; } } } else { rc = SDB_INVALIDARG ; goto error ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
static INT32 _ossEnumFiles( const string &dirPath, map<string, string> &mapFiles, const CHAR *filter, UINT32 filterLen, OSS_MATCH_TYPE type, UINT32 deep ) { INT32 rc = SDB_OK ; const CHAR *pFind = NULL ; try { fs::path dbDir ( dirPath ) ; fs::directory_iterator end_iter ; if ( 0 == deep ) { goto done ; } if ( fs::exists ( dbDir ) && fs::is_directory ( dbDir ) ) { for ( fs::directory_iterator dir_iter ( dbDir ); dir_iter != end_iter; ++dir_iter ) { try { if ( fs::is_regular_file ( dir_iter->status() ) ) { const std::string fileName = dir_iter->path().filename().string() ; if ( ( OSS_MATCH_NULL == type ) || ( OSS_MATCH_LEFT == type && 0 == ossStrncmp( fileName.c_str(), filter, filterLen ) ) || ( OSS_MATCH_MID == type && ossStrstr( fileName.c_str(), filter ) ) || ( OSS_MATCH_RIGHT == type && ( pFind = ossStrstr( fileName.c_str(), filter ) ) && pFind[filterLen] == 0 ) || ( OSS_MATCH_ALL == type && 0 == ossStrcmp( fileName.c_str(), filter ) ) ) { mapFiles[ fileName ] = dir_iter->path().string() ; } } else if ( fs::is_directory( dir_iter->path() ) && deep > 1 ) { _ossEnumFiles( dir_iter->path().string(), mapFiles, filter, filterLen, type, deep - 1 ) ; } } catch( std::exception &e ) { PD_LOG( PDWARNING, "File or dir[%s] occur exception: %s", dir_iter->path().string().c_str(), e.what() ) ; } } } else { rc = SDB_INVALIDARG ; goto error ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
int main( int argc, char **argv ) { QApplication a( argc, argv ); // QApplication required! Q_UNUSED( argc ); Q_UNUSED( argv ); QTime t; t.start(); QDir dbDir( QStringLiteral( "./pdfdb" ) ); if ( !dbDir.exists() ) { qWarning() << "Database directory does not exist"; } QStringList excludeSubDirs; excludeSubDirs << QStringLiteral("000048") << QStringLiteral("000607"); const QStringList dirs = dbDir.entryList(QStringList() << QStringLiteral("0000*"), QDir::Dirs); foreach ( const QString &subdir, dirs ) { if ( excludeSubDirs.contains(subdir) ) { // then skip it } else { QString path = "./pdfdb/" + subdir + "/data.pdf"; std::cout <<"Doing " << path.toLatin1().data() << " :"; Poppler::Document *doc = Poppler::Document::load( path ); if (!doc) { qWarning() << "doc not loaded"; } else { int major = 0, minor = 0; doc->getPdfVersion( &major, &minor ); doc->info(QStringLiteral("Title")); doc->info(QStringLiteral("Subject")); doc->info(QStringLiteral("Author")); doc->info(QStringLiteral("Keywords")); doc->info(QStringLiteral("Creator")); doc->info(QStringLiteral("Producer")); doc->date(QStringLiteral("CreationDate")).toString(); doc->date(QStringLiteral("ModDate")).toString(); doc->numPages(); doc->isLinearized(); doc->isEncrypted(); doc->okToPrint(); doc->okToCopy(); doc->okToChange(); doc->okToAddNotes(); doc->pageMode(); for( int index = 0; index < doc->numPages(); ++index ) { Poppler::Page *page = doc->page( index ); page->renderToImage(); page->pageSize(); page->orientation(); delete page; std::cout << "."; std::cout.flush(); } std::cout << std::endl; delete doc; } } } std::cout << "Elapsed time: " << (t.elapsed()/1000) << std::endl; }