Example #1
0
filesys::Node const *LinkFile::tryGetChild(String const &name) const
{
    if (Folder const *folder = targetFolder())
    {
        return folder->tryGetChild(name);
    }
    return nullptr;
}
Example #2
0
filesys::Node const *LinkFile::tryFollowPath(PathRef const &path) const
{
    if (Folder const *folder = targetFolder())
    {
        return folder->tryFollowPath(path);
    }
    return nullptr;
}
Example #3
0
/*! DELETE (delete a file/folder)
*/
void QwsClientSocket::handleMessageDELETE(const QwMessage &message)
{
    resetIdleTimer();
    if (!user.privileges().testFlag(Qws::PrivilegeDeleteFiles)) {
        sendError(Qw::ErrorPermissionDenied); return; }

    QString folderBasePath = message.stringArg(0).section('/', 0, -2, QString::SectionSkipEmpty);
    QString folderBaseName = message.stringArg(0).section('/', -1, -1, QString::SectionSkipEmpty);

    qDebug() << this << "Path=" << folderBasePath << "Item=" << folderBaseName;

    QwsFile targetBase;
    targetBase.setRemotePath(message.stringArg(0));
    targetBase.localFilesRoot = filesRootPath;
    if (!targetBase.loadFromLocalPath(true)) {
        sendError(Qw::ErrorFileOrDirectoryNotFound);
        return;
    }

    if (targetBase.localPath() == filesRootPath) {
        sendError(Qw::ErrorFileOrDirectoryNotFound);
        return;
    }

    QFileInfo targetInfo(targetBase.localPath());
    QDir targetFolder(targetBase.localPath());
    if (targetInfo.isDir()) {
        // Directory
        qDebug() << "Deleting a directory.";
        deleteDirRecursive(targetInfo.absoluteFilePath());

    } else {
        // File
        QDir parentDir(targetBase.localPath());
        if (!parentDir.cdUp()) {
            sendError(Qw::ErrorFileOrDirectoryNotFound);
            return;
        }
        if (!parentDir.remove(folderBaseName)) {
            qDebug() << this << "Unable to delete file" << targetBase.localPath();
            sendError(Qw::ErrorFileOrDirectoryNotFound);
            return;
        }
    }

}
bool FileSystemManager::copyFolder(QString source, QString target, qint64 total, bool cut)
{
    QDir sourceFolder(source);
    QDir targetFolder(QFileInfo(target).path());
    QString folderName = QFileInfo(target).fileName();

    bool ok = true;

    if(!QFileInfo(target).exists())
        targetFolder.mkdir(folderName);

    targetFolder = QDir(target);

    QStringList files = sourceFolder.entryList(QDir::Files
                                               | QDir::NoDotAndDotDot | QDir::Hidden);

    for(int i = 0; i < files.count(); i++)
    {
        QString srcName = sourceFolder.path() + "/" + files[i];
        QString destName = targetFolder.path() + "/" + files[i];
        if(!copyFile(srcName, destName, total, cut))
            ok = false;     //don't remove source folder if all files not cut

        if(m_cancel == true)
            return false;                           //cancelled
    }

    files.clear();
    files = sourceFolder.entryList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);

    for(int i = 0; i < files.count(); i++)
    {
        if(m_cancel)
            return false;    //cancelled

        QString srcName = sourceFolder.path() + "/" + files[i];
        QString destName = targetFolder.path() + "/" + files[i];
        copyFolder(srcName, destName, total, cut);
    }

    //remove source folder if all files moved ok
    if(cut && ok)
        sourceFolder.rmdir(source);
    return ok;
}
Example #5
0
void Cconfig::save() //saves to ~/.gnurpgm/config
{
    QDir targetFolder( QDir::homePath() + "/.gnurpgm" );

    if (!targetFolder.exists())
        targetFolder.mkdir( QDir::homePath() + "/.gnurpgm" );

    //writing the lines
    QFile target( QDir::homePath() + "/.gnurpgm/config" );
//    if (target.exists())
//        target.remove();
    if ( !target.exists() )
    {
//        target.
    }
    if (!target.open(QIODevice::WriteOnly))
    {
//        QMessageBox::information(this,tr("File Error"),tr("Could not write config File:\n") + this->targetConfigFile);
    }
    //now write those bastards!
    QTextStream boss(&target);
//    QString bla;
    boss << tr("#Notice, that changing things in here may eat your toaster *dump*") << "\r\n";
    boss << "mainwindow_x=" << this->config_file_system->mainWindowX << "\r\n";
    boss << "mainwindow_y=" << this->config_file_system->mainWindowY << "\r\n";
    boss << "mainwindow_width=" << this->config_file_system->mainWindowWidth << "\r\n";
    boss << "mainwindow_height=" << this->config_file_system->mainWindowHeight << "\r\n";
    boss << "guistyle=" << QString::number(this->config_file_system->guiStyle)  << "\r\n"; //see *.h for 0=..
    boss << "guitype=" << QString::number(this->config_file_system->guiType)  << "\r\n"; //see *.h for 0=..
    boss << "lastprojectpath=" << this->config_file_system->lastProjectFilePath << "\r\n";
    //boss << "updatetype=" << QString::number( this->config_file_system->updateCycle ) << "\r\n";
    boss << "lastupdate=" << this->config_file_system->updateLastUpdateDate.toString( "dd.MM.yyyy" ) << "\r\n";
    boss << "language=" <<this->config_file_system->language << "\r\n";
    boss << "autosave_delay=" << QString::number(this->config_file_system->autosave_delay) << "\r\n";
    if ( this->config_file_system->checkForUpdateOnStartup )
        boss << "updateautocheck=true" << "\r\n";
    else
        boss << "updateautocheck=false" << "\r\n";

    if ( this->config_file_system->showTutorials )
        boss << "showtutorials=true" << "\r\n";
    else
        boss << "showtutorials=false" << "\r\n";

    if ( this->config_file_system->acceptedLicense )
        boss << "accepted_license=true" << "\r\n";
    else
        boss << "accepted_license=false" << "\r\n";

    if ( this->config_file_system->useKicon )
        boss << "kicon=true" << "\r\n";
    else
        boss << "kicon=false" << "\r\n";

    if ( this->config_file_system->depug )
        boss << "debug=true" << "\r\n";
    else
        boss << "debug=false" << "\r\n";
    boss << "main_menu_buttons_style=" <<this->config_file_system->main_menu_buttons_style << "\r\n";
    if ( this->config_file_system->main_menu_buttons_show_text )
        boss << "main_menu_buttons_show_text=true" << "\r\n";
    else
        boss << "main_menu_buttons_show_text=false" << "\r\n";
    if ( this->config_file_system->main_menu_buttons_show_icons )
        boss << "main_menu_buttons_show_icons=true" << "\r\n";
    else
        boss << "main_menu_buttons_show_icons=false" << "\r\n";
//    boss << "current_version=" <<this->config_file_system->current_version << "\r\n";
    target.close();
}
/*! \brief Extracts the selected .tar.gz archive to the selected folder, will try to create the target folder if it does not exist.
* @param filePath Full path to selected archive.
* @param targetFolderPath Full path to target folder.
* @return Returns full path to the extracted archive, or empty QString if failed.
*/
QString ArchiveExtractor::extractFileToTargetFolder(QString filePath, QString targetFolderPath){
  //check if the selected archive file exist
  QFile *selectedFile = new QFile(filePath);
  if(!selectedFile->exists()){
    qDebug()<<"ERROR: File marked for decompression does not exist!";
    delete selectedFile;
    return QString("");
  }
  delete selectedFile;
  struct archive *a;
  struct archive *ext;
  struct archive_entry *entry;
  int r;
  //  /* The "flags" argument selects optional behavior, 'OR' the flags you want. */
  //  /* Default: Do not try to set owner/group. */
  //#define	ARCHIVE_EXTRACT_OWNER			(0x0001)
  //  /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
  //#define	ARCHIVE_EXTRACT_PERM			(0x0002)
  //  /* Default: Do not restore mtime/atime. */
  //#define	ARCHIVE_EXTRACT_TIME			(0x0004)
  //  /* Default: Replace existing files. */
  //#define	ARCHIVE_EXTRACT_NO_OVERWRITE 		(0x0008)
  //  /* Default: Try create first, unlink only if create fails with EEXIST. */
  //#define	ARCHIVE_EXTRACT_UNLINK			(0x0010)
  //  /* Default: Do not restore ACLs. */
  //#define	ARCHIVE_EXTRACT_ACL			(0x0020)
  //  /* Default: Do not restore fflags. */
  //#define	ARCHIVE_EXTRACT_FFLAGS			(0x0040)
  //  /* Default: Do not restore xattrs. */
  //#define	ARCHIVE_EXTRACT_XATTR 			(0x0080)
  //  /* Default: Do not try to guard against extracts redirected by symlinks. */
  //  /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
  //#define	ARCHIVE_EXTRACT_SECURE_SYMLINKS		(0x0100)
  //  /* Default: Do not reject entries with '..' as path elements. */
  //#define	ARCHIVE_EXTRACT_SECURE_NODOTDOT		(0x0200)
  //  /* Default: Create parent directories as needed. */
  //#define	ARCHIVE_EXTRACT_NO_AUTODIR		(0x0400)
  //  /* Default: Overwrite files, even if one on disk is newer. */
  //#define	ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER	(0x0800)
  //  /* Detect blocks of 0 and write holes instead. */
  //#define	ARCHIVE_EXTRACT_SPARSE			(0x1000)
  //  /* Default: Do not restore Mac extended metadata. */
  //  /* This has no effect except on Mac OS. */
  //#define	ARCHIVE_EXTRACT_MAC_METADATA		(0x2000)
  int flags = 0;
  //      flags |= ARCHIVE_EXTRACT_TIME;
  //      flags |= ARCHIVE_EXTRACT_NO_AUTODIR;
  //      flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;

  QFileInfo *fileInfo = new QFileInfo(filePath);
//  qDebug()<<"resolved filename: "<<fileInfo->fileName();
  delete fileInfo;

  //MEMORY LEAK!!! (Pointers be dangerous, man. :)
  //  const char *filename = fileInfo->fileName().toUtf8().constData();
  //AVOID IT BY CONVERTING TO A QBYTEARRAY FIRST!
  QByteArray byteArray = filePath.toUtf8();
  const char *filename = byteArray.constData();
  //That's better :D

  //toggle extraction
  bool do_extract = true;

  a = archive_read_new();
  ext = archive_write_disk_new();
  archive_write_disk_set_options(ext, flags);

  //tuned for .tar.gz
  archive_read_support_filter_gzip(a);
  archive_read_support_format_gnutar(a);

  if((r = archive_read_open_filename(a, filename, 10240)) ){
    errmsg(archive_error_string(a));
  }
  for(;;){
    r = archive_read_next_header(a, &entry);
    if(r == ARCHIVE_EOF) break;
    if(r != ARCHIVE_OK){
      errmsg(archive_error_string(a));
    }
    if (verbose || !do_extract){
      qDebug()<<"Detected files in archive: ";
      msg(archive_entry_pathname(entry));
    }
    QString currentPath(archive_entry_pathname( entry ));
    qDebug()<<currentPath;

    QDir targetFolder(targetFolderPath);
    if(!targetFolder.exists()){//target folder does not exist
      //attempt to create it
      if(!targetFolder.mkpath(targetFolderPath)){//failed to create target folder
        //break procedure
        qDebug()<<"ERROR: Target folder does not exist and cannot be created";
        return QString("");
      }
    }

    QString newPath = targetFolderPath + currentPath;
    qDebug()<<"newPath: " << newPath;

    archive_entry_set_pathname( entry, newPath.toUtf8().constData() );
    if (verbose && do_extract){
//      msg("About to start extracting\n");
    }
    if (do_extract){
      qDebug()<<"Extracting...";
      r = archive_write_header(ext, entry);
      if (r != ARCHIVE_OK) errmsg(archive_error_string(a));
      else copy_data(a, ext);
      std::string returnPath;
      returnPath = archive_entry_pathname(entry);
      qDebug()<<"File extracted: " << QString::fromStdString(returnPath);
      archive_read_close(a);
      archive_read_free(a);
      archive_write_close(ext);
      archive_write_free(ext);
      return QString::fromStdString( returnPath );
    }
  }
  archive_read_close(a);
  archive_read_free(a);
  archive_write_close(ext);
  archive_write_free(ext);
  return QString("");
}