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

Clicking the save button when malfunctioning erases the file #208

Open
PaulCauchois opened this issue Jan 29, 2022 · 3 comments
Open

Clicking the save button when malfunctioning erases the file #208

PaulCauchois opened this issue Jan 29, 2022 · 3 comments

Comments

@PaulCauchois
Copy link

PaulCauchois commented Jan 29, 2022

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
Copy link
Author

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
Copy link
Author

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.

@Pulover
Copy link
Owner

Pulover commented Feb 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants