View Full Version : Bonus to SUF70 Installations
csd214
06-14-2005, 11:19 AM
VP20 is not restricted to SUF70 installations; naturally. Could you think of a "bonus" to SUF70 installation offering automatically change of %ProductVer%, adding new folders and files to the uninstall list (and removing legacy files)?
I know that the XML actions are included in VP20 and consequently the designer is capable of modifying the Uninstall Configuration File. Maybe you have a generic script (with parameters 'Uninstall files folder' and 'Configuration filename')?
Brett
06-14-2005, 11:56 AM
I did this exact thing a while back. Here is the code I used. I put it in On Preload. It adds all patched files to the uninstall's XML file.
Debug.ShowWindow();
g_strUninstallXMLFile = "";
g_strUninstallXMLFile = SessionVar.Expand("%AppFolder%");
g_strUninstallXMLFile = String.TrimRight(g_strUninstallXMLFile,"\\");
g_strUninstallXMLFile = g_strUninstallXMLFile.."\\Uninstall\\Uninstall.xml";
Debug.Print("Uninstall file: "..g_strUninstallXMLFile.."\r\n");
g_tblFoldersAdded = {};
if(not File.DoesExist(g_strUninstallXMLFile))then
-- No point in defining the g_OnFileProcessed function
Debug.Print("ERROR: File does not exist\r\n");
Application.ExitScript();
end
function AddFoldertoXML(strFullFilename)
Debug.Print("AddFoldertoXML: "..strFullFilename.."\r\n");
local tblParts = String.SplitPath(strFullFilename);
if(not tblParts)then return false; end
local strFolderPath = tblParts.Drive..tblParts.Folder;
strFolderPath = String.TrimRight(strFolderPath,"\\");
Debug.Print("AddFoldertoXML: strFolderPath:"..strFolderPath.."\r\n");
local bFound = false;
for i,Folder in g_tblFoldersAdded do
if(not bFound)then
if(String.CompareNoCase(Folder,strFolderPath) == 0)then
bFound = true;
end
end
end
if not bFound then
Debug.Print("AddFoldertoXML: folder not found\r\n");
local nNumitems = Table.Count(g_tblFoldersAdded);
g_tblFoldersAdded[nNumitems+1] = strFolderPath;
local nCount = XML.Count("SUF70UninstallData/UninstallFolders","FolderPath");
local nNewElementPos = nCount + 1;
-- We have the XML loaded...
XML.SetValue("SUF70UninstallData/UninstallFolders/FolderPath:"..nNewElementPos,strFolderPath);
local nError = Application.GetLastError();
Debug.Print("XML.SetValue result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
return true;
end
return false;
end
-- Add new files and backup files to the uninstaller for the product:
function g_OnFileProcessed (ResultCode,Filename,BackupFilename)
Debug.Print("OnFileProcessed file: "..ResultCode..", "..Filename..", "..BackupFilename.."\r\n");
local bChangesMade = false;
XML.Load(g_strUninstallXMLFile);
local nError = Application.GetLastError();
Debug.Print("XML Load result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
if(nError ~= 0)then
return;
end
if(ResultCode == 2)then
-- New file added
local nFileCount = XML.Count("SUF70UninstallData/UninstallFiles","File");
local nError = Application.GetLastError();
Debug.Print("XML Count result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
Debug.Print("XML Count: "..nFileCount.."\r\n");
local nNewElementPos = nFileCount + 1;
-- We have the XML loaded...
XML.SetValue("SUF70UninstallData/UninstallFiles/File:"..nNewElementPos.."/Filename",Filename);
local nError = Application.GetLastError();
Debug.Print("XML.SetValue result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
AddFoldertoXML(Filename);
bChangesMade = true;
else
if(File.DoesExist(BackupFilename))then
local nFileCount = XML.Count("SUF70UninstallData/UninstallFiles","File");
local nError = Application.GetLastError();
Debug.Print("XML Count result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
Debug.Print("XML Count: "..nFileCount.."\r\n");
local nNewElementPos = nFileCount + 1;
-- We have the XML loaded...
XML.SetValue("SUF70UninstallData/UninstallFiles/File:"..nNewElementPos.."/Filename",BackupFilename);
local nError = Application.GetLastError();
Debug.Print("XML.SetValue result: "..nError.." - ".._tblErrorMessages[nError].."\r\n");
AddFoldertoXML(BackupFilename);
bChangesMade = true;
end
end
-- Now save the file out
if(bChangesMade)then
XML.Save(g_strUninstallXMLFile);
end
end
csd214
06-14-2005, 03:13 PM
Thanks for the script; for sure, it gave me some ideas.
Allow me to ask, when do you call g_OnFileProcessed(). What values are passed as arguments? Especially I wonder about the ResultCode argument.
Apparently there are some "secrets" (to me) in VP20. I don't want to hardcode new files and folders. Obviously VP20 itself knows what files are successfully patched/backed up.
Lorne
06-14-2005, 04:58 PM
Allow me to ask, when do you call g_OnFileProcessed(). What values are passed as arguments? Especially I wonder about the ResultCode argument.Look up g_OnFileProcessed in the help file. (Typing it into the index is probably the quickest way...) :)
csd214
06-15-2005, 07:13 AM
Thanks, Lorne. I indeed searched the help file; all three tabs. I didn't think of using g_OnFileProcessed as the keyword, because the function is not part of _Global_Functions.lua. I searched for 'result code' (but not 'ResultCode'), got 25 topics, wherein 'Hidden Functions' is found. To all nosy readers, this is exiting: "The following "hidden functions" are available in Visual Patch 2.0: g_OnFileProcessed"
IMHO, the function is a must (personally I'm very focused on a COMPLETE uninstall procedure. (The secret function is needed whatever installer you use).
Quote the help file:
Tip: If you use Setup Factory to build your software installer, you can use actions to add new files to the uninstall control file so they will be removed along with the original files when the user uninstalls your software via the control panel.
It should be to great help if this tip referred to 'Hidden functions' (but the tip is part of the User Guide).
Anyway, the function and Brett's script is a GREAT bonus. It works like a Lamborghini (my car dream). I preferred to check for the uninstall configuration file at an early stage (On Startup), eventually displaying a message like this:
Warning To successfully perform the patch, the %ProductName% configuration file has to be found. We recommend cancelling the execution and contact %CompanyName%.
(Click OK to continue anyway)
In Brett's script (While Patching.On Preload) I replaced the Debug statements with VisualPatch.WriteToLogFile(LogMsg). From SUF70 I have learned to love the write to log feature!
To update the %ProductVer% I added a generic code snippet in On Post Patch (there might be other session variables you want to update too).
If you are interested, my global start-up function and my On Post Patch script can be found in the attached text file.
During a few days I have been devoted to Visual Patch 2. :yes :yes :yes
csd214
06-16-2005, 02:44 AM
Of course, the Warning message should NOT be displayed if the software isn't installed at all. One solution is to modify the suggested global function.
local sMainFile = "<AppDependentFileName>" -- a key file
-- -------------------------------------------------- End of App Dependent Paragraph
-- The WARNING message should NOT be displayed if the %ProductName% isn't found at all...
if not File.DoesExist(SessionVar.Expand("%AppFolder%".."\\"..sMainFile)) then
return; -- VP is going to display the screen 'Cannot Locate Software'
end
Tip The design-time constants #OLDESTVERSION# and #NEWESTVERSION# are very handy for the 'Cannot Locate Software' screen.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.