PDA

View Full Version : removal of legacy folders



jlsf2
03-20-2008, 04:20 PM
My patcher removes legacy files just fine... but it leaves the empty directory structure installed. Anyway to have that removed automatically as well?

Thanks.

Lorne
03-20-2008, 05:01 PM
You could do that from the TrueUpdate server script using Folder.Delete actions.

jlsf2
03-20-2008, 05:11 PM
Yeah, I was hoping to avoid that.

The current scenario where the files just get deleted automatically is the best.

I can use Folder.Delete like you suggested, but that requires me to have knowledge of what is being removed. Unless I just go through and recursively delete any empty folder...

jlsf2
03-20-2008, 05:12 PM
BTW, when do legacy files get deleted? Does it happen before the "On Post Patch" actions?

Thanks.

Lorne
03-20-2008, 05:19 PM
Do you mean with Visual Patch 3.0? (Your original post didn't specify. :))

jlsf2
03-20-2008, 05:22 PM
Ahhh yeah, I posted in the wrong forum.

VP3.

Lorne
03-20-2008, 05:41 PM
No worries...

PATCH_STAGE_REMOVING_LEGACY_FILES happens right after PATCH_STAGE_PATCHING_FILES in the patching sequence.

So, right after all of the files are patched.

(I would have just said so above, but I was checking the source code to make sure. :))

It goes like this:

Initialize some Lua variables (_CommandLineArgs, %SourceFolder%, etc.)
Begin the log file.
Initialize the language support.
Verify the file archive integrity.
Load action plugins.
Do any Global Script includes.
Run the Global Functions script.
Run the On Startup actions.
Show the Before Patching screens.
Run the On Pre Patch actions.
Start writing the log file to disk.
Show While Patching screen.
Patch files.
Remove legacy files.
Handle any files that need to be deleted or moved on reboot.
Destroy the progress screen controller.
Run the On Post Patch actions.
Show the After Patching screens.
Run the On Shutdown actions.
Delete any temp files.
Exit the patch.

jlsf2
03-20-2008, 11:35 PM
In case anyone needs this:

--[[
************************************************** ********************************
Function: RemoveEmptyFolders
Purpose: Recursively remove empty folders starting from the given folder.
Arguments: (string) rootFolder
Returns: nothing
************************************************** ********************************
--]]
function g_RemoveEmptyFolders( rootFolder )

folders = Folder.Find( rootFolder, "*", false, nil );

if ( folders ) then
-- recursively remove empty folders
for i, folderName in folders do
g_RemoveEmptyFolders( folderName );
end
end

-- All of the empty sub-folders have been removed. Do one last check to see
-- if this folder has files or folders in it, if not, then remove it.
folders = Folder.Find( rootFolder, "*", false, nil );
files = File.Find( rootFolder, "*.*", false, false, nil, nil );

if ( (not folders) and (not files) ) then
-- This folder is also empty. Remove it.
Debug.Print( "Folder to be removed: " .. rootFolder .. "\r\n" );
Folder.Delete( rootFolder );
end
end