Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract 7z archive with UTF-8 filename #103

Open
hexabyte23 opened this issue Dec 14, 2024 · 5 comments
Open

Extract 7z archive with UTF-8 filename #103

hexabyte23 opened this issue Dec 14, 2024 · 5 comments

Comments

@hexabyte23
Copy link

hexabyte23 commented Dec 14, 2024

Hi all,

For win10, Is there a parameter to set to extract an 7z archive with UTF8 filenames ?

short ExtractorPrivate::writeData(struct archive_entry* entry) {
...
// UTF-8 in archive entry messes up when extracting under Windows
   // when UTF-8 is not set, to fix this we first get the archive
   // entry pathname in raw bytes then convert it to wide characters
   // and set it has the new pathname which should make libarchive
   // handle it better.
...
}

UTF-8 is not set where ?

When debugging

Capture d’écran 2024-12-14 à 10 53 58

Not sure that at line 902

auto wstr = ptname.toStdWString();

fix the problem, as wstr still showing bad characters

Capture d’écran 2024-12-14 à 11 05 58

As always in macOS, its working like a charm.

Thanks

@hexabyte23
Copy link
Author

on Master branch, this should fix the problem. Its working for me on macOS and Win10 :


      // UTF-8 in archive entry messes up when extracting under Windows
      // when UTF-8 is not set, to fix this we first get the archive
      // entry pathname in raw bytes then convert it to wide characters
      // and set it has the new pathname which should make libarchive
      // handle it better.

      // Get current pathname
      auto ptname_cstr = archive_entry_pathname(entry);

      // Check if UTF-8
      if (isUTF8(ptname_cstr)) {
         auto w = archive_entry_pathname_w(entry);
         archive_entry_copy_pathname_w(entry, w);
/*
        auto ptname = QString::fromUtf8(ptname_cstr);

        auto wstr = ptname.toStdWString();
        archive_entry_copy_pathname_w(entry, wstr.c_str());*/
      }

      ret = archive_write_header(m_ArchiveWrite.data(), entry);
    } else {

@antony-jr
Copy link
Owner

antony-jr commented Dec 15, 2024

This is really weird @hexabyte23. What standard of C++ are you using. Anyhow I need to look into this.

archive_entry_copy_pathname_w(entry, wstr.c_str());*/

I don't know how this works with this line commented out.

@antony-jr
Copy link
Owner

btw this is definitely again related to libarchive/libarchive#587

@hexabyte23
Copy link
Author

hexabyte23 commented Dec 15, 2024

Sorry , to clarify, I just comment out your fix of 2023

auto ptname = QString::fromUtf8(ptname_cstr);
auto wstr = ptname.toStdWString();
archive_entry_copy_pathname_w(entry, wstr.c_str());

that seems not working properly with VC2019 compiler, by mine:

auto w = archive_entry_pathname_w(entry);
archive_entry_copy_pathname_w(entry, w);

@antony-jr
Copy link
Owner

Okay, this makes sense. Let me test this on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants