Skip to content

Feature: Add ZIP encoding selection support for browsing archives with non-UTF-8 filenames#18529

Open
oxygen-dioxide wants to merge 18 commits into
files-community:mainfrom
oxygen-dioxide:zip-encoding-oc
Open

Feature: Add ZIP encoding selection support for browsing archives with non-UTF-8 filenames#18529
oxygen-dioxide wants to merge 18 commits into
files-community:mainfrom
oxygen-dioxide:zip-encoding-oc

Conversation

@oxygen-dioxide

Copy link
Copy Markdown
Contributor

Problem
When opening a ZIP archive whose filenames use an encoding other than the user's OS encoding, the filenames appear garbled

Solution
Added a ComboBox in the navigation toolbar that appears when browsing a ZIP archive with undetermined encoding, allowing the user to select the appropriate character encoding. When a custom encoding is selected, the app switches from SevenZipSharp to SharpZipLib to read filenames and file contents.

Resolved / Related Issues

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. Download this zip file: japanese-example.zip
  2. In Files, double click this file to open it
  3. Select "Japanese (Shift-JIS)" encoding

previous behaviour:
image

current behaviour:
image

@oxygen-dioxide

oxygen-dioxide commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Problem: users still can't double-click a file in the archive to open it because process.Start() doesn't support custom zip encoding. (However, this bug also occurs for 7z files, so I may create another PR to fix it.)

Comment thread src/Files.App/UserControls/NavigationToolbar.xaml Outdated
@oxygen-dioxide

Copy link
Copy Markdown
Contributor Author

moved the combobox to bottom right corner
image

@yair100

yair100 commented Jun 1, 2026

Copy link
Copy Markdown
Member

Thanks! I'd like to take a closer look and get some feedback from @mdtauk but I can already tell that the overall location looks a lot better in that screenshot.

@yair100

yair100 commented Jun 4, 2026

Copy link
Copy Markdown
Member

What do you think about replacing the ComboBox with a Button and Flyout like we do for git branches? Please let me know if you want me to push a commit.
image

@oxygen-dioxide

Copy link
Copy Markdown
Contributor Author

What do you think about replacing the ComboBox with a Button and Flyout like we do for git branches? Please let me know if you want me to push a commit. image

Looks good to me

Comment thread src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs
@yair100

yair100 commented Jun 4, 2026

Copy link
Copy Markdown
Member

What's the expected behavior when opening a regular zip file?

@oxygen-dioxide

oxygen-dioxide commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author
  • src/Files.App/Data/Items/EncodingItem.cs — Changed the built-in Chinese encoding from gb2312 to gb18030, which is a strict superset and matches the encoding name returned by DetectEncodingAsync.
  • src/Files.App/Services/Storage/StorageArchiveService.cs — In IsEncodingUndeterminedAsync, entries whose names consist entirely of ASCII characters are now considered determined (not undetermined), even if they don't declare Unicode. This avoids showing the encoding picker when the zip content is pure ASCII and doesn't need a specific non-UTF-8 encoding.
  • src/Files.App/Data/Models/DirectoryPropertiesViewModel.cs (the StatusBarViewModel) — When auto-detect finds an encoding not present in the built-in list, it dynamically creates an EncodingItem for it and appends it to the options, ensuring the detected encoding always appears in the dropdown.

@oxygen-dioxide

Copy link
Copy Markdown
Contributor Author

What's the expected behavior when opening a regular zip file?

For ascii or utf-8 zip file, the encoding selector shouldn't show up. I've fixed my code.

yair100
yair100 previously approved these changes Jun 7, 2026
@yair100 yair100 requested a review from 0x5bfa June 7, 2026 15:00
@yair100 yair100 added the ready for review Pull requests that are ready for review label Jun 7, 2026
Comment thread src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these newly added methods support password requesting? Apparently, it silently fails?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Comment thread src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs
Comment thread src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs
@0x5bfa

0x5bfa commented Jun 8, 2026

Copy link
Copy Markdown
Member

CI is now failing and most of my reviews are still present.

@yair100

yair100 commented Jun 18, 2026

Copy link
Copy Markdown
Member

@oxygen-dioxide fyi

IsItemClickEnabled="True"
ItemClick="ZipEncodingList_ItemClick"
ItemsSource="{x:Bind StatusBarViewModel.ZipEncodingOptions, Mode=OneWay}"
SelectedItem="{x:Bind StatusBarViewModel.SelectedZipEncoding, Mode=OneWay}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be TwoWay?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a ListView's ItemsSource is replaced (which happens every time StatusBarViewModel is reassigned during a tab switch), the ListView internally resets SelectedItem = null. With a TwoWay binding, this null propagates back to the ViewModel property, overwriting the previously selected encoding:

UpdateStatusBarProperties()
  → StatusBarViewModel DP set → DataContext changes
    → ItemsSource binding evaluates → ListView resets SelectedItem = null
    → SelectedItem TwoWay binding writes null → SelectedZipEncoding = null  ← bug

This happens despite UpdateZipEncodingStateAsync() already having restored the correct encoding synchronously earlier in the same UI cycle.

Changing to Mode=OneWay breaks the ListView → ViewModel propagation path, preventing the spurious null write. The user's selection is still synced to the ViewModel via the existing ItemClick handler (called when the user picks an encoding from the flyout):

https://github.com/oxygen-dioxide/Files/blob/3d0b867e34da179111a34691291fe28cf962d0d1/src/Files.App/UserControls/StatusBar.xaml.cs#L71-L77

ItemClickSelectedZipEncoding.set → triggers OnZipEncodingChangedAsync() → stores the encoding and refreshes the view, just as before.

The ViewModel → ListView direction (OneWay) still works, so on tab switch or encoding restore, the ListView correctly highlights the matching item from the ViewModel's SelectedZipEncoding value.

There is still a problem: when a zip file is opened, the detected zip encoding is shown on the button, but isn't shown as selected in the flyout menu. Let me fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should find the root cause and fix this to use the TwoWay binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Pull requests that are ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: File names for Japanese zips aren't shown correctly on Chinese language

3 participants