Skip to content

Commit

Permalink
Merge pull request #313 from gdt050579/312-bug-incorrect-display-for-…
Browse files Browse the repository at this point in the history
…docx-archives

Fix ZIP display bug
  • Loading branch information
gheorghitamutu authored May 14, 2024
2 parents 2d4f495 + cd2c112 commit 9a934de
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

build-macos:
runs-on: [macos-latest]
runs-on: [macos-13] # avoid ARM for now - https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
retention-days: 1

build-macos:
runs-on: [macos-latest]
runs-on: [macos-13] # avoid ARM for now - https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
steps:
- uses: actions/checkout@v2
with:
Expand Down
29 changes: 29 additions & 0 deletions GViewCore/src/ZIP/zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,35 @@ bool GetInfo(std::u16string_view path, Info& info)
auto& entry = internalInfo->entries.emplace_back();
ConvertZipFileInfoToEntry(zipFile, entry);

std::u8string_view filename = entry.filename;
if (entry.type == EntryType::Directory && filename[filename.size() - 1] == '/') {
filename = { filename.data(), filename.size() - 1 };
}

size_t offset = 0;

while (true) {
size_t pos = filename.find_first_of('/', offset);

CHECKBK(pos != std::string::npos, "");

// add the parent as well if not already present
auto parentFilename = entry.filename.substr(0, pos + 1);

auto it = std::find_if(
internalInfo->entries.begin(), internalInfo->entries.end(), [&](const _Entry& e) -> bool { return e.filename == parentFilename; });
if (it == internalInfo->entries.end()) {
auto& parentEntry = internalInfo->entries.emplace_back();
parentEntry.filename = parentFilename;
parentEntry.filename_size = parentFilename.size();
parentEntry.type = EntryType::Directory;
parentEntry.version_madeby = entry.version_madeby;
parentEntry.version_needed = entry.version_needed;
}

offset = pos + 1;
}

CHECKBK(mz_zip_reader_goto_next_entry(internalInfo->reader.value) == MZ_OK, "");
} while (true);

Expand Down
2 changes: 1 addition & 1 deletion Types/ZIP/src/ZIPFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool ZIPFile::BeginIteration(std::u16string_view path, AppCUI::Controls::TreeVie
CHECK(usb.Set(filename), false, "");

const auto sv = usb.ToStringView();
if (sv.size() != path.size() && sv.starts_with(path)) {
if (sv.size() > path.size() && sv.starts_with(path) && sv[path.size()] == '/') {
const auto tmpSV = std::u16string_view{ sv.data() + path.size(), sv.size() - path.size() };
if (tmpSV.find_first_of('/') == tmpSV.find_last_of('/')) {
curentChildIndexes.push_back(i);
Expand Down

0 comments on commit 9a934de

Please sign in to comment.