wayneh
01-03-2007, 11:10 AM
Hi -
I am evaluating Visual Patch 2.
Is it possible to let the User locate the install/patch directory?
I would like to follow this logic:
1) check the local dir first
2) if not found, check the registry
3) if not found prompt the user to locate the application directory.
Has anyone done something like this?
Can you supply either directions or code?
Thanks.
Lorne
01-05-2007, 11:06 AM
Is it possible to let the User locate the install/patch directory?Yes, definitely. In fact, Visual Patch allows you to completely modify its behaviour through Lua script, so you can make it follow any custom sequence you can think up.
I would like to follow this logic:
1) check the local dir first
2) if not found, check the registry
3) if not found prompt the user to locate the application directory.The first two can be implemented automatically when you start a new project using the project wizard. When you get to the Locate Installed Version step in the wizard, enable the "Current folder" and "Registry key" options. (Disable the "File search" option.) Follow the rest of the project wizard to set up your project however you'd like.
There are a couple different ways you could prompt the user for the application folder: using a Dialog.Input action, or using a Select Folder screen.
Dialog.Input
Using the Dialog.Input action is a bit easier, since you just insert the action in your On Startup script, at the end of the "-- Locate installed version" section (right after the Registry method). Something like this:
-- Location method: Ask the user
-- Prompt the user for a path
if not g_InstalledVersion then
local FolderPath = Dialog.Input("Locate Software", SessionVar.Expand("Where is %ProductName% installed?"));
if FolderPath ~= "CANCEL" then
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", FolderPath);
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", FolderPath);
end
end
end(You could easily modify that code to make it ask for the path in a loop until a recognized folder is provided or the user clicks cancel.)
You can use that dialog method with any interface style...Wizard, Dialog, even Silent if you want (although for silent patches you should really check for a command line argument instead).
Select Folder screen
If you're using a Wizard style install, you'll probably want to use a Select Folder screen. Start by adding the screen to your Before Patching screen list.
In the Select Folder screen, replace the existing On Next script with something like this:
-- These actions are performed when the Next button is clicked.
local SelectedFolder = SessionVar.Expand("%SelectedFolder%");
local FolderExists = Folder.DoesExist(SelectedFolder);
-- If the folder doesn't exist, ask the user if they want to select a different one
if not FolderExists then
local Result = Dialog.Message(VisualPatch.GetLocalizedString("MSG_FOLDER_NOT_EXIST_TITLE"), VisualPatch.GetLocalizedString("ERR_FLD_FOLDER_DOES_NOT_EXIST"), MB_RETRYCANCEL, MB_ICONEXCLAMATION);
if (Result == IDRETRY) then
Application.ExitScript();
else
Screen.Next();
end
end
-- check the provided folder to see if it contains key files
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", SelectedFolder);
--------------------------------------------------------------
-- Set session variables
--------------------------------------------------------------
-- Set session variables that will be used in the log file
-- and in the user interface.
if g_InstalledVersion then
SessionVar.Set("%InstalledVersion%", g_InstalledVersion);
SessionVar.Set("%TargetVersion%", VisualPatch.GetTargetVersion());
end
--------------------------------------------------------------
-- Log result
--------------------------------------------------------------
-- Make a log file entry with the result.
if g_InstalledVersion then
local LogMsg = SessionVar.Expand("Success\tLocated installed version %InstalledVersion%: %AppFolder%\r\n");
VisualPatch.WriteToLogFile(LogMsg);
else
local LogMsg = SessionVar.Expand("Error\tCould not locate software on system\r\n");
VisualPatch.WriteToLogFile(LogMsg);
end
--------------------------------------------------------------
-- Jump to appropriate screen
--------------------------------------------------------------
if g_InstalledVersion then
if g_InstalledVersion == VisualPatch.GetTargetVersion() then
-- The target version was found
Screen.Jump("Software is Current");
else
-- An out-of-date version was found
Screen.Jump("Ready to Patch");
end
else
-- No version was found
Screen.Jump("Cannot Locate Software");
end
Then modify the On Startup script to display that screen if the first two location methods fail (and skip the rest of the On Startup script). To do that, insert something like this at the end of the "-- Locate installed version" section (right after the Registry method).
if not g_InstalledVersion then
Screen.SetStartScreen("Select Folder");
Application.ExitScript();
end
wayneh
01-05-2007, 04:46 PM
Lorne -
Thanks - I figured out some of the code myself, but I really needed the Application.ExitScript() method.
Now, it works like a champ.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.