Example #1
0
bool compress(const QString& zip, const QString& dir, const QString& pwd)
{
	QFileInfo fi(dir);
	if (!fi.isDir()) {
		cout << "Directory does not exist." << endl << endl;
		return false;
	}

	Zip::ErrorCode ec;
	Zip uz;

	ec = uz.createArchive(zip);
	if (ec != Zip::Ok) {
		cout << "Unable to create archive: " << uz.formatError(ec).toLatin1().data() << endl << endl;
		return false;
	}

    uz.setPassword(pwd);
    ec = uz.addDirectory(dir);
	if (ec != Zip::Ok) {
		cout << "Unable to add directory: " << uz.formatError(ec).toLatin1().data() << endl << endl;
	}

	uz.setArchiveComment("This archive has been created using OSDaB Zip (http://osdab.42cows.org/).");

	if (uz.closeArchive() != Zip::Ok) {
		cout << "Unable to close the archive: " << uz.formatError(ec).toLatin1().data() << endl << endl;
	}

	return ec == Zip::Ok;
}
Example #2
0
  bool ConfigBase::exportConfiguration( const QString &name, const Configuration  &config ) {

    if ( name.isNull() || name.isEmpty() ) {
      return false;
    }

    QString homePath = QDir::homePath();

    homePath.append( "/.dboxfe" );

    QDir exportDir( homePath + "/export/" + name );

    if ( exportDir.exists() ) {
      exportDir.mkpath( homePath + "/export/" + name );
    }

    writeConfiguration( homePath + "/export/" + name + "/" + name + ".conf", config );

    QSettings exportConf( homePath + "/export/" + name + "/" + name + ".conf", QSettings::IniFormat );
    exportConf.beginGroup( "dosbox" );
    QString language = exportConf.value( "language" ).toString();
    QString captures = exportConf.value( "captures" ).toString();
    exportConf.endGroup();

    // autoexec
    QFile configFile( homePath + "/export/" + name + "/" + name + ".conf" );

    if ( !configFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
      return false;
    }

    QTextStream in( &configFile );

    QString line = QString( "" );
    QString autoexec = QString( "" );
    QString mountDirectory = QString( "" );

    while ( !in.atEnd() ) {
      line = in.readLine();

      if ( line == "[autoexec]" ) {
        while ( !in.atEnd() ) {
          autoexec = in.readAll();
          mountDirectory = autoexec.split( " " ).value( 2 );

          QMap< QString, QString> zipData = exportDatas( mountDirectory );
          QMap< QString, QString>::const_iterator zipDataIt = zipData.constBegin();

          while ( zipDataIt != zipData.end() ) {
            QString fileDirectory = zipDataIt.key();
            QString fileName = zipDataIt.value();
            QString file = fileDirectory + fileName;

            // TODO make sure that you create directory before you create/copy file
            // insert code here ...

            QFile copyFile( file );

            if ( copyFile.exists() ) {
              QFileInfo copyFileInfo( copyFile );
              bool ok = copyFile.copy( homePath + "/export/" + name + "/" + fileName );

              if ( !ok ) {
                ++zipDataIt;
              }
            }

            ++zipDataIt;
          }

          if ( line.startsWith( "[" ) && line.endsWith( "]" ) )
            break;
        }
      }
    }

    configFile.close();

    // Create Ziparchive for D-Fend Reloaded
    Zip::ErrorCode ec;
    Zip iz;

    ec = iz.createArchive( homePath + "/export/" + name + ".zip" );

    if ( ec != Zip::Ok ) {

      qDebug() << QDateTime::currentDateTime().toString( Qt::LocaleDate ) << tr( " - [ERROR] Unable to create archive: " ) << iz.formatError( ec ).toAscii().data() << endl;
      return false;
    }

    ec = iz.addDirectory( homePath + "/export/" + name );

    if ( ec != Zip::Ok ) {

      qDebug() << QDateTime::currentDateTime().toString( Qt::LocaleDate ) << tr( " - [ERROR] Unable to add directory: " ) << iz.formatError( ec ).toAscii().data() << endl;
      return false;
    }

    QString zipComment = QString( "" );

    zipComment += tr( "This archive has been created using OSDaB Zip (http://osdab.sourceforge.net/)." ) + "\n";
    zipComment += tr( "This archive was created by DBoxFE." );

    iz.setArchiveComment( zipComment );

    if ( iz.closeArchive() != Zip::Ok ) {

      qDebug() << QDateTime::currentDateTime().toString( Qt::LocaleDate ) << tr( " - [ERROR] Unable to close the archive: " ) << iz.formatError( ec ).toAscii().data() << endl;
      return false;
    }

    return true;
  }