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

File extension sanity checks when opening a file #3349

Open
karliss opened this issue May 28, 2024 · 1 comment
Open

File extension sanity checks when opening a file #3349

karliss opened this issue May 28, 2024 · 1 comment
Labels

Comments

@karliss
Copy link
Member

karliss commented May 28, 2024

Is your feature request related to a problem? Please describe.

Certain file types need to be opened in certain mode like ihex:// srec:// jar:// and so on. Opening them as file:// will result in completely wrong result.

Describe the solution you'd like

Create a list of typical extensions for the IO modes where it makes sense. And add some sanity checks or warnings if user tries to do something which is probably wrong.

Keep in mind that

  • not all io modes have meaningful extension
  • and sometimes user might want to open a file as raw file even if there is a suitable IO mode
  • some formats with known extensions, might also be often used with wide range of less common extension or no extension at all

While adding this information it might be also useful to add a flag whether io mode expects file at all.

Describe alternatives you've considered

a) show a warning if there is a more likely IO mode for current file extension
b) After user selects a file, automatically switch to more likely IO mode base on extension if there is one. Don't change anything if extension doesn't have any reasonable guesses. Either way they can still override the IO mode afterwards if guess was wrong or they want to do something unusual.
c) secretly switch the mode under the hood when IO mode is set to file://
d) when opening a file directly without the initial window use the best guess for choosing IO mode.

Additional context

I am unsure about approach c). In ideal world user wouldn't need to manually choose anything, on other hand the file:// IO mode has a specific meaning. Changing the meaning behind the scenes can cause more misunderstandings, and it's less clear how to override things when guesses aren't good enough. b) is probably better as it achieves similar thing while being more explicit to the user of what's happening.

Partially related problem #2204 , but that one might require a more custom solution compared to the file extension check suggested here.

@karliss
Copy link
Member Author

karliss commented Jan 11, 2025

There is a somewhat related problem -> some of the modes like malloc:// null:// self:// and few more don't expect a file at all.

On one hand for those the file selection button could be hidden or disabled completely. On other hand it somewhat inverses the order of steps. Some of approaches described above assume that you might select the file first (not necessarily for the correct mode), and then the mode gets updated automatically or by user.

Potentially more radical approach could be tying the mode selection to what would normally be file extension filter. But that doesn't work at all for nonfile modes.

Maybe have it so that in usual cases file open dialog has 2 filters: default one using extensions relevant for selected mode, wildcard mode in which case activate the extension based input mode guessing. This would cover following usage scenarios:

A:

  1. user chooses file specific input mode
  2. selection of matching file is sped up by having suitable extension filter by default
  3. further extension sanity checks not needed

B:

  1. user chooses to select file first
  2. in file open dialog user chooses to change extension filter to "."
  3. Cutter guesses most suitable input mode based on extension

C:

  1. user chooses non file mode
  2. file selection button gets disabled
  3. user enters the magic string

It doesn't really address one of the main initial cases. When mode is set to file extension could be anything, but the extension based guessing logic should be run. Maybe file:// and other modes without suitable extension filter would always activate guessing logic. In that case the scenario would happen as follows:

  1. user doesn't touch the default mode which is set to "file://"
  2. file open dialog shows all files, no additional filters available
  3. Cutter runs the extension based guessing whether some other mode would be likely more suitable.

@Rot127 Rot127 added the UI label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants