nspire-emus / firebird

Multi-platform emulator of TI Nspire calculators
GNU General Public License v3.0
692 stars 68 forks source link

File issue on Firebird v1.6 iOS version #336

Open KusakabeShi opened 6 months ago

KusakabeShi commented 6 months ago
  1. Saved files are stored in the internal storage of the app, which can't be accessed by Files app in iOS. And I can't save files to external folders either.
  2. "Save" function are not work at iOS app. It shows Flash and snapshot saved, but actually not. The md5sum of the flash files are not changed.
  3. Can't access boot/flash files at the app initialize. It turnd red if I close and restart the app. I have to select these files again.
KusakabeShi commented 6 months ago

For the issue 3 Can't access boot/flash files at the app initialize. It turnd red if I close and restart the app., this only happens if I have multiple profiles/kits, like this:

  1. Kit454:
    • boot: ti/454/boot1
    • flash: ti/454/flash
  2. Kit455:
    • boot: ti/455/boot1
    • flash: ti/455/flash

Everytime I restart the whole app, the boot1 and flash becomes red and unavailable, I have to select it again.

It seems the file selector makes a copy of the selected to the tmp folder, and both file are called boot1 and they overwrite it each other. That's why it behaves weird if I have multiple kits with flash/boot files with same filename.

And it explains why the "Save" function not works. It saved to the copy in the tmp folder, but while I reselect the flash file, the changes got lost.

KusakabeShi commented 6 months ago

This is my assumption, all issues above are caused by one reason: tmp folder.

The file selector doesn't "select" a file, it copy the file to tmp folder instead. So any write operation are operates to the tmp file, the real file doesn't affected.

And the tmp file got removed somehow by some iOS cleanup mechanism, that causes boot/flash turns to red and asks users to select again. Meanwhile lost all change to the flash.

A potential fix may adding UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace to Info.plist

Once developer enable this, you can open Files app, navigate to the "On My iPhone" section and if you have any files inside Documents directory, you will se directory with your app name with these files inside.

Asks users to place image and flash and snapshot in it.

And then write a simple GUI allow users select the file in Document folder. Or put a textbox to ask users type the file path directly(relation path from Document folder) instead of using a file selector.

adriweb commented 6 months ago

A potential fix may adding UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace to Info.plist

Well the first one is already there in https://github.com/nspire-emus/firebird/blob/master/Info.plist#L58-L59

I suppose we could try adding the other one...

KusakabeShi commented 6 months ago

According to this thread: https://stackoverflow.com/questions/66678061/why-does-uifilesharingenabled-lssupportsopeningdocumentsinplace-behave-like-ui

If you want to expose the Documents folder of an iOS app in iTunes/Music, you need to set UIFileSharingEnabled in your Info.plist file.

If you want to expose the Documents folder in the Files app in iOS, you need to set UISupportsDocumentBrowser in your Info.plist file.

If you set both, you expose it both ways.

Finally, if you set UISupportsDocumentBrowser in your Info.plist file, you can also set LSSupportsOpeningDocumentsInPlace in case you want to directly work with the original files, which means you have to explicitly coordinate file access. Without that flag you are working with copies.

It seems the UISupportsDocumentBrowser + LSSupportsOpeningDocumentsInPlace is enough, a simple GUI to allow users to select files in Document folder is unnecessary.

By the way, the "Save file" GUI are basically unuseable. It would be better if we can rewrite a GUI for that. Even a textbox allows user to fill a file path(relative to Document folder) will better than current one I think.

KusakabeShi commented 1 week ago

Any progress on adding UISupportsDocumentBrowser / LSSupportsOpeningDocumentsInPlace to the Info.plist?

adriweb commented 1 week ago

Not really, I haven't taken the time to do any firebird testing on iOS anymore, just macOS I guess. If you can test it and it works, feel free to make a PR and it can be merged.

(This won't solve the UI picker issues though, but that's more on the Qt side itself anyway)