Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    if (3 != argc) {
        fprintf(stderr, "usage: %s archive_name directory_name\n",
                argv[0]);
        return -1;
    }

    Zip *pZip = new Zip(argv[1]);

    int rt = 0;

    rt = pZip->uncompress(argv[2]);

    delete pZip;
    pZip = NULL;

    if (-1 == rt) {
        fprintf(stderr, "uncompress failed\n");
        return -1;
    }
        
    fprintf(stderr, "uncompress successfully\n");

    return 0;
}
Exemplo n.º 2
0
jobject MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_NativeZip__1getInputStream(JNIEnv *jenv, jobject jzip, jlong obj, jstring path)
{
    Zip *zip = (Zip *)obj;
    const char* str;
    str = jenv->GetStringUTFChars(path, nullptr);

    Zip::Stream stream;
    bool res = zip->GetStream(str, &stream);
    jenv->ReleaseStringUTFChars(path, str);
    if (!res) {
        return nullptr;
    }
    jobject buf = jenv->NewDirectByteBuffer(const_cast<void *>(stream.GetBuffer()), stream.GetSize());
    if (!buf) {
        JNI_Throw(jenv, "java/lang/RuntimeException", "Failed to create ByteBuffer");
        return nullptr;
    }
    jclass nativeZip = jenv->GetObjectClass(jzip);
    jmethodID method = jenv->GetMethodID(nativeZip, "createInputStream", "(Ljava/nio/ByteBuffer;I)Ljava/io/InputStream;");
    // Since this function is only expected to be called from Java, it is safe
    // to skip exception checking for the method call below, as long as no
    // other Native -> Java call doesn't happen before returning to Java.
    return jenv->CallObjectMethod(jzip, method, buf, (jint) stream.GetType());
}
Exemplo n.º 3
0
int FSZip::load(string backfile, string filename, FileBuffer *p, bool async)
{
	Zip zip;

	if (zip.Open(backfile.substr(1)))
		return -1;

	if (!zip.check_file_exist(filename))
		return -1;

	if (async)
	{
		p->m_aync_thread = thread(zip_async_load, backfile, filename, p);
	}
	else
	{
		shared_ptr<FileBuffer> pzip = zip.get_file_buff(filename);
		if (pzip == NULL)
			return -1;

		p->swap(*pzip);
		p->m_loaded = true;
	}
	return 0;
}
Exemplo n.º 4
0
bool FSZip::exist(string backfile, string filename)
{
	Zip zip;
	if (zip.Open(backfile.substr(1)))
		return false;

	return zip.check_file_exist(filename);
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
QScriptValue ScriptEngine::extractZip(const QString &zipName, const QString &targetDir)
{
    if (safeScripts) {
        warn("extract(zipName, targetDir)", "Safe scripts is on.");
        return "";
    }
    Zip zip;
    if (!zip.open(zipName)) {
        return myengine.undefinedValue();
    }
    zip.extractTo(targetDir);
    return targetDir;
}
Exemplo n.º 7
0
QScriptValue ScriptEngine:: extractZip(const QString &zipName)
{
    if (safeScripts) {
        warn("extractZip(zipName)", "Safe scripts is on.");
        return "";
    }
    Zip zip;
    if (!zip.open(zipName)) {
        return myengine.undefinedValue();
    }
    QDir directory;
    QString current=directory.currentPath();
    zip.extractTo(current);
    return zipName;
}
Exemplo n.º 8
0
int zip_async_load(string zipfile, string fn, FileBuffer * buff)
{
	std::lock_guard<mutex> lock(buff->m_async_mutex);

	Zip zip;
	if (zip.Open(zipfile.substr(1)))
		return -1;

	shared_ptr<FileBuffer> p = zip.get_file_buff(fn);
	if (p == NULL)
		return -1;

	buff->swap(*p);
	buff->m_loaded = true;
	return 0;
}
Exemplo n.º 9
0
    void AppendUserInfo(const CStringW& dumpFile, Zip& zip)
    {
        CStringW crashInfoFile = m_workingFolder + L"\\crashinfo.xml";
        if (m_crashInfo->GetCrashInfoFile(crashInfoFile))
            m_config.FilesToAttach.push_back(std::make_pair<CStringW, CStringW>(CStringW(crashInfoFile), L"crashinfo.xml"));

        CStringW crashUserInfoFile = m_workingFolder + L"\\crashuserinfo.xml";
        if (m_config.UserInfo.size())
        {
            FILE* f = NULL;
            if (0 == _wfopen_s(&f, crashUserInfoFile, L"wt,ccs=UTF-8"))
            {
                fwprintf_s(f, L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<UserInfo>\n");
                for (auto it = m_config.UserInfo.cbegin(), end = m_config.UserInfo.cend(); it != end; ++it)
                {
                    m_log.Info(_T("Adding UserInfo \"%ls\" as \"%ls\"..."), static_cast<LPCWSTR>(it->first), static_cast<LPCWSTR>(it->second));
                    fwprintf_s(f,
                        L"<%ls>%ls</%ls>\n",
                        static_cast<LPCWSTR>(it->first),
                        static_cast<LPCWSTR>(it->second),
                        static_cast<LPCWSTR>(it->first));
                }
                fwprintf_s(f, L"</UserInfo>");
                fclose(f);
                m_config.FilesToAttach.push_back(std::make_pair<CStringW, CStringW>(CStringW(crashUserInfoFile), L"crashuserinfo.xml"));
            }
        }

        WIN32_FIND_DATAW ff;
        FindClose(FindFirstFileW(dumpFile, &ff));
        __int64 attachedSizeLimit = max(1024*1024I64, (static_cast<__int64>(ff.nFileSizeHigh) << 32) | ff.nFileSizeLow);

        m_log.Info(_T("Adding %d attaches..."), m_config.FilesToAttach.size());
        for (auto it = m_config.FilesToAttach.begin(), end = m_config.FilesToAttach.end(); it != end; ++it)
        {
            m_log.Info(_T("Adding \"%ls\" as \"%ls\"..."), static_cast<LPCWSTR>(it->first), static_cast<LPCWSTR>(it->second));
            WIN32_FIND_DATAW ff;
            HANDLE hFind = FindFirstFileW(it->first, &ff);
            if (hFind == INVALID_HANDLE_VALUE)
            {
                m_log.Warning(_T("File \"%ls\" not found..."), static_cast<LPCWSTR>(it->first));
                continue;
            }
            FindClose(hFind);
            __int64 size = (static_cast<__int64>(ff.nFileSizeHigh) << 32) | ff.nFileSizeLow;
            if (size > attachedSizeLimit)
            {
                m_log.Warning(_T("File \"%ls\" not skipped by size..."), static_cast<LPCWSTR>(it->first));
                continue;
            }
            attachedSizeLimit -= size;

            zip.AddFile(it->first, it->second, &g_cancel);
            m_log.Info(_T("Done."));
        }
        DeleteFile(crashInfoFile);
    }
Exemplo n.º 10
0
int FSZip::for_each_ls(uuu_ls_file fn, string backfile, string filename, void *p)
{
	Zip zip;

        if (zip.Open(backfile.substr(1)))
                return -1;

	for(auto it = zip.m_filemap.begin(); it!=zip.m_filemap.end(); ++it)
	{
		if(it->first.substr(0, filename.size()) == filename || filename.empty())
		{
			string name = backfile;
			name += "/";
			name += it->first;
			fn(name.c_str()+1, p);
		}
	}

	return 0;
}
Exemplo n.º 11
0
QScriptValue ScriptEngine::zip(const QString &path, const QString &dir)
{
    if (safeScripts) {
        warn("zip(path, dir)", "Safe scripts is on.");
        return "";
    }
    Zip zip;
    QDir directory(dir);
    if(!zip.open(path)){
        zip.create(path);
    }
    if(!directory.exists()) {
        zip.addFile(dir); //adds the file normally if it's not a directory
        zip.writeArchive();
        return path;
    }
    QStringList files = directory.entryList(QDir::Files, QDir::Name);
    foreach(QString file, files){ //goes through the folder and adds each file to the zip file
        zip.addFile(dir+"/"+file);
    }
Exemplo n.º 12
0
void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_NativeZip__1release(JNIEnv *jenv, jclass, jlong obj)
{
    Zip *zip = (Zip *)obj;
    zip->Release();
}
Exemplo n.º 13
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;
  }