PuloversMacroCreator icon indicating copy to clipboard operation
PuloversMacroCreator copied to clipboard

Clicking the save button when malfunctioning erases the file

Open PaulCauchois opened this issue 3 years ago • 3 comments

It's rather ironical for a save button to literally delete your file, but that's what happens here. If the application is malfunctioning in some way, and the macro part of the app is frozen while the toolbar is still functioning, then clicking the save button (as one might be tempted to do before restarting the app) will result in your file being deleted.

Steps to reproduce the error :

  1. Get the app in the aforementioned state, where the macro part is frozen but the toolbar is still responsive. For me, this can be reproduced pretty consistently by trying to insert a comment using the button.
  2. Check in your file explorer to make sure the file is still there, and maybe copy it somewhere else so you don't lose your work.
  3. Click the "save" or "save as" buttons. The latter won't actually open the save window, by the way.
  4. Check the file explorer, and notice that the file you were working on has disappeared.

As you can imagine, this is a very problematic issue, as "Save your file and restart the app" is one of the most common ways, if not the most common way to deal with errors. If doing this ends up deleting your file for good, it makes other errors that much more dangerous. Instead of losing the progress you've made since you last saved, you end up losing hours if not tens of hours of work.

PaulCauchois avatar Jan 29 '22 19:01 PaulCauchois

An helpful but imperfect fix is to copy and paste the ahk script window (if responsive) into another ahk script file. However, as there is, to my knowledge, no way to import an ahk script back into PMC, the recovered script can only be opened using AutoHotKey.

PaulCauchois avatar Jan 29 '22 19:01 PaulCauchois

Having looked at the code for a while, I believe that the error comes from the Save subroutine (as obvious as it sounds), more specifically line 2164. The subroutine starts by checking if a file of that name exists, if so it deletes it, and creates a new file with that name. However, if for whatever reason the subroutine cannot complete after that, the end result is that the file you were working on is simply deleted, gone for good. My solution would be creating a backup of the existing file with a different name, only then deleting the existing file, and checking if the rest of the subroutine completes without error, in which case the extraneous file can be safely discarded. If there is an error, however, the backup can be renamed and an error message can be shown to the user. However, this solution comes from a Python programmer with very little knowledge of AHK, so I may be blind to obvious flaws created by this method. It does seem like the safest solution to me, though, so I hope it will be of use in fixing this problem.

PaulCauchois avatar Feb 17 '22 22:02 PaulCauchois

Thanks. I'm out of time now but I'll see if I can work on that sometime soon.

Pulover avatar Feb 18 '22 12:02 Pulover