/*! Create a sandbox install directory on the media card for this package and if necessary create the media card "package" directory parent. The sandbox install directory is symlinked to the main package root. */ void SandboxInstallJob::mediaSandboxRoot() { QDir mediaSandbox( media + "/" + PACKAGE_DIRECTORY ); if ( !mediaSandbox.exists() ) // try creating it from parent { QDir mediaDir( media ); if ( !mediaDir.exists() ) { //TODO: Proper error reporting for media card errors qWarning( "### %s (the media path) doesnt exist! ###", qPrintable( media )); abort = true; return; } qLog(Package) << "Creating directory" << mediaSandbox.path() << "in path" << media; if ( !mediaDir.mkdir( PACKAGE_DIRECTORY )) { //TODO: Proper error reporting for media card errors qWarning( "mkdir failed : %s", strerror( errno )); abort = true; return; } } QString linkTarget = mediaSandbox.path() + "/" + package->md5Sum; QFile::link( linkTarget, destination ); destination = linkTarget; if ( mediaSandbox.exists( package->md5Sum )) { // overwriting with reinstalled package removeDestination(); } mediaSandbox.mkdir( package->md5Sum ); }
OrphanedImagesDialog::OrphanedImagesDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::OrphanedImagesDialog) { ui->setupUi(this); ui->fileTreeWidget->installEventFilter(this); QDir mediaDir(NoteFolder::currentMediaPath()); if (!mediaDir.exists()) { ui->progressBar->setValue(ui->progressBar->maximum()); return; } QStringList orphanedFiles = mediaDir.entryList( QStringList("*"), QDir::Files, QDir::Time); orphanedFiles.removeDuplicates(); QList<Note> noteList = Note::fetchAll(); int noteListCount = noteList.count(); ui->progressBar->setMaximum(noteListCount); ui->progressBar->show(); Q_FOREACH(Note note, noteList) { QString text = note.getNoteText(); // match image links like ![media-qV920](file://media/608766373.gif) QRegularExpression re( "!\\[.*?\\]\\(file:\\/\\/media/(.+?)\\)"); QRegularExpressionMatchIterator i = re.globalMatch(text); // remove all found images from the orphaned files list while (i.hasNext()) { QRegularExpressionMatch match = i.next(); QString fileName = match.captured(1); orphanedFiles.removeAll(fileName); } ui->progressBar->setValue(ui->progressBar->value() + 1); }