fix: windows save dialog extension bug (#44770)

* fix: windows save dialog extension bug

* refactor: simplify firstSpec extraction



* refactor: split when necessary



---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: nilaoda <nilaoda@live.com>
This commit is contained in:
trop[bot] 2024-11-21 22:36:31 +01:00 committed by GitHub
parent 787d4c3859
commit b6f97b7952
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -144,10 +144,14 @@ static void ApplySettings(IFileDialog* dialog, const DialogSettings& settings) {
// We set file extension to the first none-wildcard extension to make // We set file extension to the first none-wildcard extension to make
// sure the dialog will update file extension automatically. // sure the dialog will update file extension automatically.
for (size_t i = 0; i < filterspec.size(); ++i) { for (size_t i = 0; i < filterspec.size(); ++i) {
if (std::wstring(filterspec[i].pszSpec) != L"*.*") { std::wstring spec(filterspec[i].pszSpec);
if (spec != L"*.*") {
// SetFileTypeIndex is regarded as one-based index. // SetFileTypeIndex is regarded as one-based index.
dialog->SetFileTypeIndex(i + 1); dialog->SetFileTypeIndex(i + 1);
dialog->SetDefaultExtension(filterspec[i].pszSpec); // "*.jpg;*.png" => "*.jpg"
std::wstring first_spec = spec.substr(0, spec.find(L';'));
// "*.jpg" => "jpg"
dialog->SetDefaultExtension(first_spec.substr(2).c_str());
break; break;
} }
} }