PDA

View Full Version : Check this code for me please.


longedge
01-31-2008, 09:01 AM
Can someone cast an eye over this code.I've looked and looked at it and can't understand why I have a problem namely that the first time the application runs I get an error -

"On Show, Line 10: attempt to call a nil value".

The second and subsequent times I run the app it works fine and does exactly what it's supposed to.

The problem ONLY arises when the "enc" folder is being created.

The confusing thing is that it is enumerating the files in Autoplay\docs folder that appears to fail. I have tried putting a 'sleep' in after creating the folder but that makes no difference.

1 --create folder in users temp directory if it doesn't already exist
2 chk_folder = Folder.DoesExist(_TempFolder.."\\enc");
3 if (chk_folder==false) then
4 Folder.Create(_TempFolder.."\\enc");
5 end
6
7 --decrypt the files
8 while not cryp_files do
9 cryp_files = File.Find("AutoPlay\\Docs", "*", false, false, nil, nil);
10 for index in cryp_files do -- FAILS HERE BUT ONLY ON FIRST RUN!!
11 split_path = String.SplitPath(cryp_files[index]);
12 file_name=split_path.Filename
13 ext=split_path.Extension
14 file=file_name..ext
15 Crypto.BlowfishDecrypt(cryp_files[index], _TempFolder.."\\enc\\"..file, "qdd")
16 end
17 end
18
19 --get the files from temp folder
20 while not decryp_files do
21 decryp_files = File.Find(_TempFolder.."\\enc", "*", false, false, nil, nil);
22 for index in decryp_files do
23 split_path = String.SplitPath(decryp_files[index]);
24 file_name=split_path.Filename
25 add_list = ListBox.AddItem("ListBox1", file_name, decryp_files[index]);
26 end
27 end

Not sure why but the code tag makes backslashes appear as an odd character on this system - don't know if that's the same for everyone else?

holtgrewe
01-31-2008, 09:55 AM
longedge

It worked fine for me.

I copied your code as is:
Placed a txt document in the Docs folder, and a ListBox on the page.
no error message - encrypted file in \temp\enc
...using Win XP Sp2

longedge
01-31-2008, 12:32 PM
Thanks for that Holtgrewe but it still causes the same problem for me.

I emailed the project to myself at home and just tried it with the same error.

So I've abandoned the _TempFolder strategy and have just gone for C:\enc and that now works OK but I don't know why???

Just one thing - do you mean that you were getting an encrypted file from a non-encrypted one using that code?
I was starting with encrypted files in Autoplay\Docs and decrypting them to the enc folder.

holtgrewe
01-31-2008, 05:23 PM
Yea, that's exactly how I tested it. At the time I wasn't concerned about the decrypting aspect. I was thinking it was a timing issue with the folder being created and trying to write to it, but I couldn't get it to fail. So I tested it kind of bass-ackwards. It would be interesting to see if you could duplicate my shenanigans on your system and see if it works for you that way.

You say it worked when you changed the path, so there's nothing wrong with the code. Strange...

holtgrewe
01-31-2008, 05:38 PM
longedge

Forget my previous test. It was on AMS 7 and it worked fine.

On AMS 6 I was able to duplicate your exact problem.
There's an apparent problem in how AMS6 handles this...

Very sorry to mislead you. mea culpa.

RizlaUK
01-31-2008, 06:56 PM
Its because you have a relative file path


Try This: (Tested in AMS 6.0.5.0)
--create folder in users temp directory if it doesn't already exist
chk_folder = Folder.DoesExist(_TempFolder.."\\enc");
if (chk_folder==false) then
Folder.Create(_TempFolder.."\\enc");
end

--decrypt the files
while not cryp_files do
cryp_files = File.Find(_SourceFolder.."\\AutoPlay\\Docs", "*", false, false, nil, nil);
for index in cryp_files do -- FAILS HERE BUT ONLY ON FIRST RUN!!
split_path = String.SplitPath(cryp_files[index]);
file_name=split_path.Filename
ext=split_path.Extension
file=file_name..ext
Crypto.BlowfishDecrypt(cryp_files[index], _TempFolder.."\\enc\\"..file, "qdd")
end
end

--get the files from temp folder
while not decryp_files do
decryp_files = File.Find(_TempFolder.."\\enc", "*", false, false, nil, nil);
for index in decryp_files do
split_path = String.SplitPath(decryp_files[index]);
file_name=split_path.Filename
add_list = ListBox.AddItem("ListBox1", file_name, decryp_files[index]);
end
end

longedge
02-01-2008, 02:43 AM
Rizla and Holtgrewe - Many thanks for your time.

I haven't got time to try it out today but I'll make the change you suggest Rizla :yes.

I got it working by changing to C:\enc but I *also* made the application as an exe whereas before I had been using the standard build. It was probably the change of build type that did it and not the destination. Still can't understand it but that doesn't matter as long as I find a reliable solution :)