Esempio n. 1
0
void ArchiveList::updateArchives(QList<Archive *> archivesOrig)
{
    QSet<QString> expandedLanguages;
    QSet<QString> knownLanguages;
    QSet<ArchiveID> expandedItems;

    for (int i = 0; i < topLevelItemCount(); i ++) {
        QTreeWidgetItem *langItem = topLevelItem(i);
        const QString &lang = langItem->text(0);
        if (langItem->isExpanded())
            expandedLanguages += lang;
        knownLanguages += lang;
        for (int j = 0; j < langItem->childCount(); j ++) {
            QTreeWidgetItem *dateItem = langItem->child(j);
            if (dateItem->isExpanded())
                expandedItems += ArchiveID(lang, dateItem->text(0));
        }
    }

    clear();

    QList<Archive *> archives(archivesOrig);
    qSort(archives.begin(), archives.end(), Archive::comparePointers);

    QTreeWidgetItem *topItem(0);
    QString lastLanguage;

    foreach (Archive *a, archives) {
        if (lastLanguage != a->getLanguage() || a->getLanguage().isEmpty()) {
            lastLanguage = a->getLanguage();
            topItem = new QTreeWidgetItem(this, QStringList() << lastLanguage);
            addTopLevelItem(topItem);
            if (expandedLanguages.contains(lastLanguage))
                topItem->setExpanded(true);
        }
        QTreeWidgetItem *item = new QTreeWidgetItem(topItem);
        item->setText(0, a->getDate());

        if (expandedItems.contains(a->getID()))
            item->setExpanded(true);

        if (qobject_cast<DownloadableArchive *>(a)) {
            fillDownloadableArchiveItem(static_cast<DownloadableArchive *>(a), item);
        } else if (qobject_cast<PartialArchive *>(a)) {
            if (!knownLanguages.contains(a->getLanguage()))
                topItem->setExpanded(true);
            fillPartialArchiveItem(static_cast<PartialArchive *>(a), item);
        } else if (qobject_cast<LocalArchive *>(a)) {
            if (!knownLanguages.contains(a->getLanguage()))
                topItem->setExpanded(true);
            fillLocalArchiveItem(static_cast<LocalArchive *>(a), item);
        }
    }
    resizeColumnToContents(0);
    resizeColumnToContents(1);
    resizeColumnToContents(2);
    resizeColumnToContents(3);
}
Esempio n. 2
0
void attach_sfx_module(const wstring& file_path, const SfxOptions& sfx_options) {
  AttachSfxModuleProgress progress(file_path);

  {
    OpenOptions options;
    options.arc_path = file_path;
    options.detect = false;
    options.arc_types.push_back(c_7z);
    unique_ptr<Archives> archives(Archive::open(options));
    if (archives->empty())
      FAIL_MSG(Far::get_msg(MSG_ERROR_SFX_CONVERT));
    if (!archives->front()->is_pure_7z())
      FAIL_MSG(Far::get_msg(MSG_ERROR_SFX_CONVERT));
  }

  FindData file_data = File::get_find_data(file_path);
  progress.set_total(file_data.size());
  wstring dst_path = file_path + c_sfx_ext;
  try {
    create_sfx_module(dst_path, sfx_options);

    File dst_file(dst_path, FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, OPEN_EXISTING, 0);
    dst_file.set_pos(0, FILE_END);

    File src_file(file_path, FILE_READ_DATA, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN);
    Buffer<char> buf(1024 * 1024);
    while (true) {
      unsigned size_read = src_file.read(buf.data(), static_cast<unsigned>(buf.size()));
      if (size_read == 0)
        break;
      CHECK(dst_file.write(buf.data(), size_read) == size_read);
      progress.update_completed(size_read);
    }

    File::set_attr(file_path, file_data.dwFileAttributes);
    dst_file.set_time(file_data.ftCreationTime, file_data.ftLastAccessTime, file_data.ftLastWriteTime);
  }
  catch (...) {
    File::delete_file_nt(dst_path);
    throw;
  }
  File::delete_file_nt(file_path);
}