fadden / CiderPress2

Tool for working with Apple II and vintage Mac disk images and file archives.
https://ciderpress2.com/
Apache License 2.0
44 stars 7 forks source link

Cannot Open An Image That is "In-Use" #16

Closed paulhlee1967 closed 6 months ago

paulhlee1967 commented 6 months ago

CiderPress 1 allows me to open up a disk image that is in use (for example in AppleWin) in a READ-ONLY mode. CiderPress2 fails to open the image at all with an error that the file is in use.

fadden commented 6 months ago

That is supposed to work, though you have to do it with the understanding that AppleWin is allowed to cache data in memory, and as a result the disk image file may not be consistent.

The .NET file sharing flags are supposed to allow you to open the file for read-only or read-write, and then control how the file is shared (i.e. how it can be opened by other processes). If I open it read-write and share read-write, the other process can open it read-write. If I open it read-only and share read-only, the other process can open it read-only. If I open it read-write and share read-only, the other process can't open it at all. So either I'm doing something wrong or .NET / Windows is misbehaving. I'll need to dig into it more. (The above tests were done with two copies of CiderPress2 opening the same file, so it's entirely under app control.)

fadden commented 6 months ago

Answer: I'm doing something wrong.

When you open a file read-write, you specify FileShare.Read to allow others to read from it but not write. The part I missed is that, when you open a file read-only, you want to specify FileShare.ReadWrite instead, to say that it's okay if somebody else is writing to it.

Fixing the Open calls is easy. I think I want to add a note explaining to the user why it's read-only though.

fadden commented 6 months ago

This appears to work correctly now. I also updated the command-line tool, so it's possible to e.g. get a catalog from a disk image open in an emulator. The info panel for the top-level entity has an added message.

paulhlee1967 commented 6 months ago

Nice. TY. Is it published in any of the DEV releases ye?

fadden commented 6 months ago

It's now available as https://github.com/fadden/CiderPress2/releases/tag/v1.0.1-dev3

fadden commented 6 months ago

Available in v1.0.1.