View Full Version : Finction Help Please!!!
thetford
02-07-2008, 06:33 PM
ok, I have saved files which are blowfish encrypted. To open them, I populate them from the saved folder in a tree object. All that works, I'm just having a problem actually opening them. On my tree objects "On Double Click" event, I have this fuction (well, the actual function is in the GLOBALS)
function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree1");
node = Tree.GetNode("Tree1", sel_node);
node_data = node.Data
Crypto.BlowfishDecrypt(node_data, _TempFolder..node_data..".txt", "trustno1withthispassword"); --trustno1withthispassword
OPEN_TXT = TextFile.ReadToString(_TempFolder..node_data..".txt");
Page.Jump("forms");
--File.Open(node_data, "", SW_SHOWNORMAL);
end
Page jumps, but there is no text file created in the Temp Folder, and thus no text displayed in the paragraph object. I think it's just how I have the file concatenated.
RizlaUK
02-07-2008, 07:45 PM
you need to add a backslash to the filepaths
function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree1");
node = Tree.GetNode("Tree1", sel_node);
node_data = node.Data
Crypto.BlowfishDecrypt(node_data, _TempFolder.."\\"..node_data..".txt", "trustno1withthispassword"); --trustno1withthispassword
OPEN_TXT = TextFile.ReadToString(_TempFolder.."\\"..node_data..".txt");
Page.Jump("forms");
--File.Open(node_data, "", SW_SHOWNORMAL);
end
thetford
02-09-2008, 09:37 AM
I tried it, still no text displayed in paragraph object. Also, no text file created in the temp folder. Any other thoughts? Oh.. thanks for looking.
RizlaUK
02-09-2008, 10:52 AM
sorry, i was in a rush and dident even read the code properly
if the file is already encrypted then no need to create a decrypted version, just use the decrypted string
heres how i would have done it
fill the tree node data with the full path to the file
put the function in globals
function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree1");
node = Tree.GetNode("Tree1", sel_node);
EncryptedString = TextFile.ReadToString(node.Data);
OPEN_TXT = Crypto.BlowfishDecryptString(EncryptedString, "trustno1withthispassword");--trustno1withthispassword
return OPEN_TXT
end
and call like this, so it will only jump if the global "OPEN_TXT" contains some text
if RunNodeFile() ~= "" then then
Page.Jump("forms");
end
as long as "node_data" holds the full path to the file then the above should work
thetford
02-16-2008, 01:07 PM
nothing happens........................
here is my tree object population code (GLOBAL):function GetFolderContents()
ENC = File.Find(_ProgramFilesFolder.."\\Credit Mechanic\\Saved", "*.enc", true, false, ShowSearchProgress, nil);
if ENC then
for i,v in ENC do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree_files", "3", tblNodeData);
end
end
end
here is the on double click function (GLOBAL):function RunNodeFile()
sel_node = Tree.GetSelectedNode("Tree_files");
node = Tree.GetNode("Tree_files", sel_node);
EncryptedString = TextFile.ReadToString(node.Data);
OPEN_TXT = Crypto.BlowfishDecryptString(EncryptedString, "trustno1withthispassword");--trustno1withthispassword
return OPEN_TXT
end
here is my evaluation statement on the forms page:if OPEN_TXT == "" then
else
Paragraph.SetText("form", OPEN_TXT);
end
I'm stupted dean.......... also, how can I keep the tree object from duplicate population when the user re-visits the OPEN page?
RizlaUK
02-16-2008, 04:11 PM
mmm, i cant see any problem with the code
is "RunNodeFile()" being called from the global area if it is then "OPEN_TXT" would contain the decrypted text
well, i put you code in a example and i couldent get it to work either, it seems the tree functions was causeing some weird erros coz when i moved them to the listbox it worked
so heres a version of the above that works ;)
put this in your global functions
function GetFolderContents()
--ENC = File.Find(_ProgramFilesFolder.."\\Credit Mechanic\\Saved", "*.enc", true, false, ShowSearchProgress, nil);
ENC = File.Find("AutoPlay\\Docs\\Saved", "*.enc", true, false, nil, nil);
if ENC then
for i,v in ENC do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree_files", "3", tblNodeData);
end
end
-- set a variable here so the tree dose not fill everytime we enter the page
blnTreeFilled=true
end
function RunNodeFile(strFilePath)
-- this var is local
local EncryptedString = TextFile.ReadToString(strFilePath);
-- leave this var global for use on the next page
strText = Crypto.BlowfishDecryptString(EncryptedString, "trustno1withthispassword");--trustno1withthispassword
-- now jump to page
Page.Jump("Page2")
end
page on show (tree page)
-- if tree has not been filled then fill it now
if not blnTreeFilled then
GetFolderContents()
end
page on show (text page)
-- check the the var has some value
if strText ~= "" then
Paragraph.SetText("Paragraph1", strText);
else
Paragraph.SetText("Paragraph1", "No File Found");
end
heres a example of it working
thetford
02-16-2008, 05:22 PM
OK it's working!!!! thanks...... :yes
RizlaUK
02-16-2008, 05:48 PM
no problem, glad to help
thetford
02-16-2008, 06:40 PM
one more quick question......... how are you encrypting your text? Your text files open in the example, but mine do not.
Here is my original "Save" code:save_text = Paragraph.GetText("form");
SA_NAME = Dialog.Input("Save As", "File Name:", "", MB_ICONQUESTION);
if SA_NAME == "" then
result = Dialog.Message("Notice", "You must enter a name.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
elseif SA_NAME == "CANCEL" then
result = Dialog.Message("Cancelled", "File save cancelled.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
TextFile.WriteFromString(_TempFolder.."\\cmsave.txt", save_text, false);
Crypto.BlowfishEncrypt(_TempFolder.."\\cmsave.txt", _ProgramFilesFolder.."\\Credit Mechanic\\Saved\\"..SA_NAME..".enc", "trustno1withthispassword");
File.Delete(_TempFolder.."\\cmsave.txt", false, false, true, nil);
end
Found = File.Find(_ProgramFilesFolder.."\\Credit Mechanic\\Saved\\", SA_NAME..".enc", false, false, nil, nil);
if Found == true then
result = Dialog.Message("File Saved", "Your file has been successfully saved!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else -- file not found
--do something here
end
The above code worked.... well it did save files. I changed my "Save" code to this, put it does not work:
save_text = Paragraph.GetText("form");
SA_NAME = Dialog.Input("Save As", "File Name:", "", MB_ICONQUESTION);
if SA_NAME == "" then
result = Dialog.Message("Notice", "You must enter a name.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
elseif SA_NAME == "CANCEL" then
result = Dialog.Message("Cancelled", "File save cancelled.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
Crypto.BlowfishEncrypt(save_text, _ProgramFilesFolder.."\\Credit Mechanic\\Saved\\"..SA_NAME..".enc", "trustno1withthispassword");
end
Found = File.Find(_ProgramFilesFolder.."\\Credit Mechanic\\Saved\\", SA_NAME..".enc", false, false, nil, nil);
if Found == true then
result = Dialog.Message("File Saved", "Your file has been successfully saved!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else -- file not found
--do something here
end
What am I missing here?
--EDIT nevermind, I got it........
thetford
02-16-2008, 07:10 PM
ok, ok, ONE more thing....... (yeah right - LOL)
Your function works for only populating the tree once per session, but what if you save a file and want to open it in the same session. I think the answer is to clear the tree every time the Open page (where the tree object is locted) is navigated away from, that way it popultes fresh everytime the Open page is accessed.
But I don't even know how to start writing a function to clear a tree object?
RizlaUK
02-16-2008, 07:40 PM
no problem, after your save code make the tree populate again and put this in the top of the populate code
Tree.RemoveNode("Tree1", "0");
function GetFolderContents()
Tree.RemoveNode("Tree_files", "0");
--ENC = File.Find(_ProgramFilesFolder.."\\Credit Mechanic\\Saved", "*.enc", true, false, ShowSearchProgress, nil);
ENC = File.Find("AutoPlay\\Docs\\Saved", "*.enc", true, false, nil, nil);
if ENC then
for i,v in ENC do
tbSplit = String.SplitPath(v);
name = tbSplit.Filename
tblNodeData = {};
tblNodeData.Text = name;
tblNodeData.Data = v;
Tree.InsertNode("Tree_files", "3", tblNodeData);
end
end
-- set a variable here so the tree dose not fill everytime we enter the page
blnTreeFilled=true
end
that way the tree will only populate only when it needs to, i always do this with trees and list/combo box, no need to waist time and cpu/memory running functions that have no current use or do not need to be run, on small projects it dosent really matter but on big projects.....boy......it matters, lol
EDIT: if saving the file on another page then all you need to do is set "blnTreeFilled=true" to "blnTreeFilled=false" and the tree will update when the page next shows
thetford
02-17-2008, 09:51 AM
Well, i'm not sure why, but the "saved" files always open as the last saved file, reguardless of the file selected in the tree object.
Do you want to demo what I'm doing?
thetford
02-17-2008, 10:21 AM
If you want to download the demo - and it's just a work in progress.... not near completion, but you will see what I'm talking about the saved files.
Anyway, go to my website http://www.mtplans.com
Login, Username - irforums
Password - password
GO to software, Beta Testing & download credit mechanic 3.0
RizlaUK
02-17-2008, 10:56 AM
sure ill take a look
EDIT:
cant login, incorrect username or passowrd
thetford
02-18-2008, 02:32 PM
ok, try this:
username - irforum
password - password
Both are lower case.............. I just tried it, it works.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.