Checking a file for corruption before "loading"?

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rayjbenet
Posts: 26
Joined: Tue Feb 10, 2009 2:35 pm
Contact:

Checking a file for corruption before "loading"?

Post by rayjbenet » Fri Feb 20, 2009 2:47 pm

When someone creates a "tournament" using our standalone application, we create two files that make up that tournament - one for participants, one for brackets. We save them both as ".rev" files. This is the method we've used since 2003, and it seems to work fine.

Recently, there have been a couple of instances of these tournament files becoming corrupted, either when being sent via email, or when someone makes a "backup copy" and moves it to another machine.

The challenge this creates is the standalone built with Rev 3.0 can't proceed with a file corrupted like this, it just hangs, or worse, crashes (but the "hang" seems more common).

Opening the stack directly (not via my application) in the development environment for 3.0 produces a Rev crash. Opening the stack directly in the devlopment environment for 3.5 produces the error dialog "this file is corrupted, please check for a ~ file". These files have cleared all virus scanners successfully.

So, to the question: is there a way for me to open a file as binary, checksum it, verify that it is okay, and then either report it as corrupt or proceed? These crashes make people believe my program is misbehaving, when it _seems_ to me that it's out of my control.

Thanks in advance.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Feb 27, 2009 12:37 am

Dear rayjbenet,

There are several ways to do this. You might want to use one, some or all of them, depending on the expertise of your public/customers and the level of reliability you want to provide.

You can use the "there is a stack" syntax:

Code: Select all

put (there is a stack "~/desktop/crash log.txt.zip") into myVar  --> false
put (there is a stack "~/desktop/a real stack.rev") into myVar --> true
You could store a file hash somewhere and include that with the actual files on the server or send it by e-mail along with the stacks.

Code: Select all

get binarydecode("h*",md5digest(url ("binfile:~/desktop/a real stack.rev")),myHash) 
put myHash into url "binfile:~/desktop/a real stack.md5"
You could provide people with a little utility that calculates the md5 hash of a file and compares it with the hash stored in an md5 file.

Of course, you could also tell people how many bytes a file has and tell them to check the file size when they receive the file.

You might want to check that people are able to read your stack. People with older versions of Revolution need stacks to be saved in legacy format.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Post by paul_gr » Fri Feb 27, 2009 1:57 am

Another way is to zip them before sending. Zip files seem to pass across the internet better than raw files. This applies to all sorts of file formats, not just Rev ones.

Paul

rayjbenet
Posts: 26
Joined: Tue Feb 10, 2009 2:35 pm
Contact:

thanks - all good advice

Post by rayjbenet » Fri Feb 27, 2009 5:14 pm

Thanks for your feedback. I have already added a "Create ZIP Archive" feature that we'll recommend they use before shipping around.

Wouldn't have thought of the "there is a stack" - very clever. What you're saying is that it returns FALSE unless the item is a valid REV stack. This is exactly, I think, what I was looking for. Some easy ability to say "I'm gonna choke on this sucker - please don't make me open it."

The md5 concept I like for other applications within our domain, so am grateful for that advice as well.

Thanks!
Ray

Post Reply