PDA

View Full Version : Number of runs, variables, etc.


rctshine
03-23-2005, 03:46 PM
Hi.

I would like to know if it is possible to make a session variable, such as %install_folder%, and then have its value be changed bythe users input. I need something like a dialog box that has a folder browser for the install directory, and then, when chosen, will change the variable. I also need a way to keep track of how many times it has been run, because I have a script that requires it to know if it has been run before by checking in the registry for the install directory.

I know this is a lot to ask, but thank you.

Jason Pate
03-23-2005, 03:54 PM
This is one easy way,
input = Dialog.Input("TItle", "prompt", "default display text")
SessionVar.Set("%install_folder%", input)


You can also add a second "Select Install Folder" and set its "Store Result in session carable to %install_folder%

And the %install_folder% can be used on a screen to display the value to the user.

rctshine
03-23-2005, 04:09 PM
Thanks.

I used that, and made it into:

target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
strDestinationFile = "target_folder";
elseif(error == 0) then
SessionVar.Set("%install_folder%", target_folder);
end
end


I have found a way around the "keep track of number of installs' thing, but what I now need is a way for the target directory to also set a regisrty value, and each time it runs, it will read of that value.

Adam
03-23-2005, 04:15 PM
rctshine,

Here is some code that may help:


RegRead = Registry.GetValue(HKEY_CURRENT_USER, "Software\\My Application", "MyValue", true);
if RegRead == "" then
-- first time the installer has been run
-- now write out the key that you just looked for
Registry.SetValue(HKEY_CURRENT_USER, "Software\\My Application", "MyValue", "My Data", REG_SZ);
else
-- the Install has been run at least once before
end


you could also make this a numeric value if you would like to know exactly how many times it has been run.

Adam Kapilik

rctshine
03-23-2005, 04:35 PM
I meshed all yours together to make one.

Here is what I put for where to install:
-- Select the directory.
target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
strDestinationFile = "target_folder";
elseif(error == 0) then
SessionVar.Set("%install_folder%", target_folder);
Registry.SetValue(HKEY_LOCAL_MACHINE, "myvalue\\myvalue", "installfolder", "install_folder", REG_SZ);
end
end


And this went into the startup folder:

--check for install folder
regcheck = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "myvalue//myvalue");
if (regcheck) then
regval = Registry.GetValue(HKEY_LOCAL_MACHINE, "myvalue\\myvalue", "installfolder", true);
SessionVar.Set("%install_folder%", regval)
if (Application.GetLastError() ~= 0) then
regcheck = false;
end
end


Will it work?

rctshine
03-23-2005, 05:29 PM
Can you guys help me?

With that code, I get the "argument 1 must be of type string" error.

Here is the complete page:


-- These actions are performed before the screen is shown.

-- Set some variables for the file download...
-- Put your full URL to the file here...
strSourceURL = "http://mypage.com/myfile.grf";
-- Select the directory.
target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
strDestinationFile = "target_folder";
elseif(error == 0) then
SessionVar.Set("%install_folder%", target_folder);
end
end
bIsBinaryFile = true;

-- Set to true is the user presses cancel (see the On Cancel event)
bCancelled = false;

-- Initialize the progress bar...
DlgProgressBar.SetRange(CTRL_PROGRESS_BAR_01,0,100 );
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,0);

rctshine
03-23-2005, 06:15 PM
Hellllppppppp........

Eagle
03-23-2005, 08:38 PM
Hi there..this might make the code more 'logical as far as how to go about it

strSourceURL = "http://mypage.com/myfile.grf";
-- Select the directory.
target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
SessionVar.Set("%install_folder%", target_folder);
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
bCancelled = true; --trigger 'on cancel '
else
strDestinationFile = target_folder;
bIsBinaryFile = true;
-- Set to true is the user presses cancel (see the On Cancel event)
bCancelled = false;
-- Initialize the progress bar...
DlgProgressBar.SetRange(CTRL_PROGRESS_BAR_01,0,100 );
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,0);
end
else
bCancelled = true; --trigger 'on cancel'
end

ps line 18 above move the 'end' back in line with the 'if'

something is wrong with how code is displaying on the forum at the moment.

HTH

Eagle
03-23-2005, 08:55 PM
try this ..

-- Put your full URL to the file here...
strSourceURL = "http://mypage.com/myfile.grf";
-- Select the directory.
target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
SessionVar.Set("%install_folder%", target_folder);
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
bCancelled = true; --cancel the download
else
strDestinationFile = target_folder;
bIsBinaryFile = true;
-- Set to true is the user presses cancel (see the On Cancel event)
bCancelled = false;
-- Initialize the progress bar...
DlgProgressBar.SetRange(CTRL_PROGRESS_BAR_01,0,100 );
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,0);
end
else
bCancelled = true; --cancel the download
end

forum display is fine..(initial formatting was sus)

Eagle
03-23-2005, 09:40 PM
another thought..it may be better to set the destination folder
(folder.browse) on the previous screen's 'on close' event

that way easier to 'control wether to display the 'download screen' at all,
if an error or user selects 'cancel at the folder browse action.

..you could then select which screen to 'jump to' or 'retry' etc

rctshine
03-23-2005, 10:57 PM
Will that solve the "argument 1 must be of type string" error?

Eagle
03-24-2005, 12:34 AM
Hi, what I suggest is you save your current project to a new 'test' project

using 'saveas'

then try out the code suggestions with your saved Test project
and see where you can fit them in, changes, whatever suits you.

these are just suggestions..it is up to you to from then on :),
however from the code you provided, that issue should be gone.

get back if still problems getting what you want to work.