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

Correctly use the selected file type after asking save path #18645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbjeukendrup
Copy link
Contributor

@cbjeukendrup cbjeukendrup commented Jul 16, 2023

Should resolve: #18321
Should resolve: #11615
Should resolve: #17563
Closes: #14365

Before, we determined the selected file type by looking at the path that the user entered in the file dialog. This is unreliable, since some OSs don't check if the entered filename extension matches the selected file type; if it didn't match, MuseScore would create a file of a different type from what was selected in the file dialog (in the dropdown).
Now, we will use the available APIs to check the actually selected file type. Then, we adjust the name based on the selected file type. It may happen that we end up writing to a different path from what was selected in the file dialog, for example when an extension needs to be added or removed.
In that case, the file dialog will not have had the ability to ask the user whether to replace the file that will actually be replaced, because the file dialog only knows what the user has entered, not what we will make of it. In this situation, to be on the safe side, we ourselves check if the file exists and ask the user about replacing it.
In the worst case, the user will see two "replace file?" dialogs, namely the one from the file dialog about what the user has entered there, and the one from us about what we will make of that, but that's still better than overwriting a file when the user didn't want that.
(Telling the file dialog that it should not show its own dialog is no option, because that needs to be told before the dialog is opened, and we only know whether we will show our own dialog after the dialog is closed. And on macOS, disabling the native "replace file?" dialog is not supported anyway.)

Testing checklist:

  • all kinds of combinations of filenames+extensions and file types, on all OSs:
    • macOS
      On macOS, there is a preference in Finder that influences the behaviour: Finder > Preferences (or "Settings", nowadays) > Advanced > Show all file extensions (topmost option)
      • with the option disabled (default)
      • with the option enabled
    • Windows
    • Linux

I've already tested it on macOS, but not very systematically.

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