Skip to content

SE UI batch convert: add "Try to use source encoding" option - fix #11019#11039

Merged
niksedk merged 1 commit into
mainfrom
batch-convert-source-encoding
May 18, 2026
Merged

SE UI batch convert: add "Try to use source encoding" option - fix #11019#11039
niksedk merged 1 commit into
mainfrom
batch-convert-source-encoding

Conversation

@niksedk
Copy link
Copy Markdown
Member

@niksedk niksedk commented May 18, 2026

Summary

  • Restores the WinForms-era Try to use source encoding entry to the target-encoding dropdown in batch convert — both the settings dialog and the main view (sidenote in Center-aligned, variable width drop-downs should be avoided across the board #11019).
  • Fixes a latent bug where the selected encoding never reached disk: SaveSubtitleFormat was passing _config.TargetEncoding as the title arg to ToText() and writing via File.WriteAllTextAsync without an encoding, so output always landed as UTF-8 without BOM regardless of the user's choice. Encoding is now resolved through EncodingHelper.ResolveEncoding and passed to the write.
  • For the new option, the encoding is detected per-file via LanguageAutoDetect.GetEncodingFromFile(item.FileName).
  • Defaults are pinned to UTF-8 with BOM (rather than "first item in the list") so existing installs without a saved choice don't migrate onto the new option.

Note: this PR doesn't touch the dropdown's center-alignment / variable-width complaint that's the primary topic of #11019 — that's a separate styling change.

Test plan

  • Open Batch convert > Settings — Try to use source encoding appears at the top of the Target encoding dropdown, and the main batch-convert view shows the same option.
  • Convert a UTF-8-with-BOM SRT with target encoding Try to use source encoding → output retains UTF-8 with BOM.
  • Convert a Windows-1252 SRT with Try to use source encoding → output is Windows-1252.
  • Convert with target encoding explicitly UTF-8 without BOM → output has no BOM (regression check of the write-path fix).
  • Convert with target encoding 1252: Western European (Windows) → output bytes match cp1252.
  • Fresh install / wiped Se.Settings.Tools.BatchConvert.TargetEncoding → default is UTF-8 with BOM, not the new option.
  • dotnet test tests/UI/UITests.csproj — 188/188 passing.

🤖 Generated with Claude Code

…1019

Restores the WinForms-era "Try to use source encoding" entry to the
target-encoding dropdown in batch convert (both the settings dialog
and the main view).

Also fixes a latent bug where the selected encoding never reached
disk: SaveSubtitleFormat was passing the encoding string as the
"title" arg to ToText() and then calling File.WriteAllTextAsync
without an encoding, so output always landed as UTF-8 without BOM
regardless of the user's choice. Encoding is now resolved through
EncodingHelper.ResolveEncoding and passed to the write, with the
new sentinel detecting per-file via LanguageAutoDetect.

Defaults are pinned to UTF-8 with BOM (instead of "first item in
the list") so existing installs don't migrate onto the new option.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Restores the Try to use source encoding target-encoding option in the Batch Convert UI and fixes batch-convert output encoding so the user’s selected encoding is actually used when writing converted subtitle files.

Changes:

  • Add a stable sentinel string for “Try to use source encoding” and a new EncodingHelper.ResolveEncoding(...) resolver (including per-file detection via LanguageAutoDetect).
  • Insert the new option into both the Batch Convert main view and Settings dialog encoding dropdowns, and pin the default to UTF-8 with BOM when no saved value exists.
  • Fix the batch-convert save path to pass a real title into ToText(...) and to write output with the resolved Encoding (instead of always defaulting to UTF-8 without BOM).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ui/Logic/EncodingHelper.cs Adds the source-encoding sentinel plus a resolver that maps stored display names to a concrete Encoding.
src/ui/Features/Tools/BatchConvert/BatchConvertViewModel.cs Adds the new dropdown option and ensures default selection remains UTF-8 with BOM when unset/unknown.
src/ui/Features/Tools/BatchConvert/BatchConvertSettingsViewModel.cs Mirrors dropdown option + defaulting logic in the settings dialog and avoids defaulting to the new sentinel.
src/ui/Features/Tools/BatchConvert/BatchConverter.cs Fixes ToText argument usage and writes output using the resolved encoding.

Comment on lines +51 to +52
/// sentinel by detecting the source file's encoding. Falls back to UTF-8 with BOM
/// when the name is empty, unknown, or detection fails.
Comment on lines +76 to +77
var match = GetEncodings().FirstOrDefault(e => e.DisplayName == displayName);
return match?.Encoding ?? new UTF8Encoding(true);
@niksedk niksedk merged commit f536ec9 into main May 18, 2026
5 of 7 checks passed
@niksedk niksedk deleted the batch-convert-source-encoding branch May 18, 2026 19:41
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

Successfully merging this pull request may close these issues.

2 participants