Recovering a corrupted script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Recovering a corrupted script

Post by mwieder » Wed Jun 05, 2013 7:23 pm

@Richard- the corruption occurred because the stack file was edited with a text editor. The original problem was just an openstack problem - no corruption there.
@MaxV- did your "simple text editor" make a backup file? Something ending with "~"? If so, rename it and try opening it from the IDE.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Recovering a corrupted script

Post by FourthWorld » Wed Jun 05, 2013 7:51 pm

Yes, re-reading the OP it's now become clear that he didn't merely extract the script by copying it, but also saved the LiveCode stack file in that editor.

As a general rule, any time you see binary data in a file made by any program it's safe to assume that editing it in any other program not designed specifically for that format will corrupt it.

In the simplest formats long strings are often length-marked, so that editing something like a script in a LiveCode stack file will later cause the engine to try to grab other elements beyond the script. In more complex formats different sections may also have checksum hashes, which will require that the data they refer to not only be of the same length, but actually remain byte-for-byte intact exactly as is.

If nothing else it's comforting to learn that this corruption wasn't in any way related to anything LiveCode did.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MartinB21
Posts: 1
Joined: Wed Jun 12, 2013 7:20 pm

Re: Recovering a corrupted script

Post by MartinB21 » Wed Jun 12, 2013 7:58 pm

This morning I had an interesting experience...

I was writing a script for a button and was at the point of adding ... with "OK and "Cancel" when strangely Livecode (5.5.5) stopped responding. My typing style is that I look at the keyboard, so I cant be certain of exactly what happened (but I don't recall hitting too many wrong keys either). The script editor just stopped behaving. I could click and change the position of the I-bar but it would not accept keyboard input and it would not allow me to "Apply" the script changes. Anyway after failing to get a proper response for a while I chose to quit Livecode, and as I did I chose to save. Stupid, stupid, STUPID The stupid mistake I had made was not to make a safe copy, and hadn't for a number of hours of development during which time I had broken new ground (for me). When opening the saved file I spotted that the sub stack that I has put the hours into was now named Cancel" - yep, literally Cancel" Humm, Im guessing that the " is not considered a valid character for a stack name as the stack would not respond. I could not get the properties inspector, or script editor to work with it. I tried every which way to recover the situation but without success. I then resorted to Google and came across this thread. Now I have been in the IT industry since 1986 and Yep I have never managed to fix a binary file with a text editor, and to be honest I had not even thought of trying. But I am sure glad I did. I used notepad++ to open (a backup copy) of the problem script search on cancel" and found one entry. I changed cancel" to the original name of the stack and saved it. I was not too shocked when Livecode would not open it at all, reporting it to be corrupt. but after a little bit more experimentation I found that I could change cancel" to cannel" ,save it and Livecode would open it and although the sub stack was still broken I could see that the name had changed. Well, just following the logic a bit further I edited it again in Notepad++ so cancel" now read cannell ------- and I am very, very glad to say that I could then open the sub stack and it is back fully functional again. I renamed the sub stack to the original name and have made a number of backups. I guess there is a checksum on the number of characters in the file so by keeping the name the same length Livecode did not see it as corrupt.

I must assume that whilst typing I hit a key combination that I managed to switch to the stack properties and changed its name.
I have just recreated the situation with a blank stack / sub stack and it seems that as soon as the name is changed to include a " that there is no way back. Even with the properties inspector already open a name change does not take effect.

So, a bunch of babbling to say... Thank you for the inspiration to open the broken stack with a text editor. It saved me hours of recreating, and reminded me to "save as" more regularly.

All the best - Martin

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Recovering a corrupted script

Post by mwieder » Wed Jun 12, 2013 9:38 pm

@Martin- *nice* recovery story.
You're lucky that the stack name was the culprit, that you were able to figure out what the problem was, and that you had the technical savvy to adjust it properly. I don't think there are checksums involved there, but there are lots of pointers to the next item, so the lengths indeed can't change.

And Notepad++ is my editor of choice when I'm forced to use Windows.

Post Reply