From 946376cd67d5aaa2228518971d671b1af9829ec4 Mon Sep 17 00:00:00 2001 From: FromDarkHell Date: Tue, 6 Jan 2026 11:34:02 -0600 Subject: [PATCH 1/2] Add TitleUpdateEnabler --- UtilityScripts/TitleUpdateEnabler/Main.lua | 104 +++++++++++++++++++++ UtilityScripts/TitleUpdateEnabler/icon.png | Bin 0 -> 1568 bytes 2 files changed, 104 insertions(+) create mode 100644 UtilityScripts/TitleUpdateEnabler/Main.lua create mode 100644 UtilityScripts/TitleUpdateEnabler/icon.png diff --git a/UtilityScripts/TitleUpdateEnabler/Main.lua b/UtilityScripts/TitleUpdateEnabler/Main.lua new file mode 100644 index 0000000..845f62f --- /dev/null +++ b/UtilityScripts/TitleUpdateEnabler/Main.lua @@ -0,0 +1,104 @@ +scriptTitle = "Title Update Enabler" +scriptAuthor = "FDH" +scriptVersion = 1.0 +scriptDescription = "Automatically enables all cached title updates" +scriptIcon = "icon.png" +scriptPermissions = { "sql" } + +MainMenu = { + "Enable All", + "Disable All" +} + +MainMenuOption_EnableAll = 1 +MainMenuOption_DisableAll = 2 + +-- Main entry point to script +function main() + ResetToMainMenu() +end + +-- Return to start of the application +function ResetToMainMenu() + -- Show Main Menu + local selectedMenuOption = ShowMainMenu() + + if selectedMenuOption == MainMenuOption_EnableAll then + EnableAllTitleUpdates() + elseif selectedMenuOption == MainMenuOption_DisableAll then + DisableAllTitleUpdates() + end +end + +-- Display Main Menu and return selected option's index, or -1 if cancelled +function ShowMainMenu() + local dialogBox = Script.ShowPopupList(scriptTitle, "Select an option", MainMenu) + if not dialogBox.Canceled then + return dialogBox.Selected.Key + end + + return -1 +end + +-- Enable all title updates +function EnableAllTitleUpdates() + -- First, clear any existing active title updates + Sql.Execute("DELETE FROM ActiveTitleUpdates") + + -- Get all title updates from ContentItems.db + local titleUpdates = Sql.ExecuteFetchRows("SELECT Id FROM TitleUpdates") + + if #titleUpdates == 0 then + Script.ShowMessageBox("No Title Updates", "No title updates found in database.", "OK") + ResetToMainMenu() + return + end + + -- Add each title update to ActiveTitleUpdates + local successCount = 0 + for i, titleUpdate in ipairs(titleUpdates) do + local titleUpdateId = titleUpdate.Id + + -- Insert into ActiveTitleUpdates table + local success = Sql.Execute("INSERT INTO ActiveTitleUpdates (TitleUpdateId) VALUES (" .. titleUpdateId .. ")") + + if success then + successCount = successCount + 1 + end + end + + if successCount >= 1 then + local ret = Script.ShowMessageBox("Title Updates Enabled", "Successfully enabled " .. successCount .. " of " .. #titleUpdates .. " title updates.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "No", "Yes") + + if ret.Button == 2 then + Aurora.Restart(); + end + else + Script.ShowMessageBox( + "Title Updates Enabled", + "Enabled " .. successCount .. " of " .. #titleUpdates .. " title updates.", + "OK" + ) + end + + ResetToMainMenu() +end + +-- Disable all title updates +function DisableAllTitleUpdates() + -- Clear all entries from ActiveTitleUpdates + local success = Sql.Execute("DELETE FROM ActiveTitleUpdates") + + if success then + local ret = Script.ShowMessageBox("Title Updates Disabled", "All title updates have been disabled.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "No", "Yes") + + if ret.Button == 2 then + Aurora.Restart(); + end + + else + Script.ShowMessageBox("Error", "Failed to disable title updates.", "OK") + end + + ResetToMainMenu() +end \ No newline at end of file diff --git a/UtilityScripts/TitleUpdateEnabler/icon.png b/UtilityScripts/TitleUpdateEnabler/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b5eeb457f9c6453da11886f789a74cc06a9955e1 GIT binary patch literal 1568 zcmV+*2H*LKP)gDiUMh&4HVMaR;gAXM5NS8TB?%L1=^}zSh}RHv~dB`qOl~nfQ{NJ z#X`iphg0Cn7e*K zUGSqneYEdJSy1{Z0mg=_QI|x*2CI{($57`u4F%Blnp?ZJK!CTncO*};LhS6hpj-72 z=&Q>hWy?CyKUoUe;s+r%dk+0y79TR;%c##n&<}~SR^h-J6DZPMpjo;YQX4mb`NUSp zINJh_kN1J|{7YcRU)!0TVCrmul=?NG$yC$HPH&ZOJ&c3r1iyM z>D~^m;Uiu_Jv4Hh-e-AZ8|W$uL1}UY13Z9wJp`~V|`=x^G=uyYfroY}!7vUZdU^^SpzUg!&#l47?*Qb zx3RSbJ=ev7vR9|LQ56C@NY1%=TG>V@;cfbE>0zs#;>3~S@wYEY4k9bDoW zM5UrssEeq7C%NxOnUDm<13pbQ5$T8O#^IPNU0~~JhP3A&2m2@c>2>D2qhRmf3z}t1 zK#`mQadYnm!=7rkbh%9kDQBw8S-}Dm4Wr^vw{s!;H}8M4hc6EZ)&uzP)4*`R4unju zEk`dpK)ZYy4OQE_FF^c~MKlYO#AG`53=MCOkSD-h4WR-i8s&gvIOspzB=83uMXcxP8h-&AMA#t%9Vgwob~LCSu{HnFmDOX@#z8FZmy;4J4C=^ z(4&(mu#mkDc2Q4TFgw!-@Z#CA-Iifb6{wh*p*%r_30Tb@1+^u(wLH}{ zAsI2aruh@WpA_>ejkH{GTg&JNCL#$bY26CkG3~%LJUO5TEUtAcP7>Lvxg8#E4q$S; zQ#rChS6Tq+2cM$lh-7T9pjWUi547QZb@T;+(wa$^#?1xHK`YW6xQkkVwYY-TXR>u9 zaAX4P1Fc|tubE!gSCv8hq6PH+DFzK8@YtHxnrVot=gp(9bdoldfPPac{ubj}&&Rr) z3rY(E@PIO;1hD?tey+ccCj)WGB`U7weZ$XC3?FtG$O zzG Date: Wed, 7 Jan 2026 17:17:05 -0600 Subject: [PATCH 2/2] Update SQL + Add Mass Apply function --- UtilityScripts/TitleUpdateEnabler/Main.lua | 151 +++++++++++++++------ 1 file changed, 112 insertions(+), 39 deletions(-) diff --git a/UtilityScripts/TitleUpdateEnabler/Main.lua b/UtilityScripts/TitleUpdateEnabler/Main.lua index 845f62f..897c35d 100644 --- a/UtilityScripts/TitleUpdateEnabler/Main.lua +++ b/UtilityScripts/TitleUpdateEnabler/Main.lua @@ -1,17 +1,19 @@ scriptTitle = "Title Update Enabler" scriptAuthor = "FDH" scriptVersion = 1.0 -scriptDescription = "Automatically enables all cached title updates" +scriptDescription = "Lets you manage the Aurora-cached title updates" scriptIcon = "icon.png" -scriptPermissions = { "sql" } +scriptPermissions = { "sql", "filesystem" } MainMenu = { - "Enable All", - "Disable All" + "Enable Latest Updates", + "Disable Latest Updates", + "Mass Apply Latest Updates" } -MainMenuOption_EnableAll = 1 -MainMenuOption_DisableAll = 2 +MainMenuOption_EnableLatest = 1 +MainMenuOption_DisableLatest = 2 +MainMenuOption_ApplyLatest = 3 -- Main entry point to script function main() @@ -23,10 +25,12 @@ function ResetToMainMenu() -- Show Main Menu local selectedMenuOption = ShowMainMenu() - if selectedMenuOption == MainMenuOption_EnableAll then + if selectedMenuOption == MainMenuOption_EnableLatest then EnableAllTitleUpdates() - elseif selectedMenuOption == MainMenuOption_DisableAll then + elseif selectedMenuOption == MainMenuOption_DisableLatest then DisableAllTitleUpdates() + elseif selectedMenuOption == MainMenuOption_ApplyLatest then + InstallAllTitleUpdates() end end @@ -42,41 +46,44 @@ end -- Enable all title updates function EnableAllTitleUpdates() - -- First, clear any existing active title updates - Sql.Execute("DELETE FROM ActiveTitleUpdates") - - -- Get all title updates from ContentItems.db - local titleUpdates = Sql.ExecuteFetchRows("SELECT Id FROM TitleUpdates") + -- Check if there are any title updates + local countResult = Sql.ExecuteFetchRows("SELECT COUNT(*) as Count FROM TitleUpdates") + local totalTitleUpdates = countResult[1].Count - if #titleUpdates == 0 then + if totalTitleUpdates == 0 then Script.ShowMessageBox("No Title Updates", "No title updates found in database.", "OK") ResetToMainMenu() return end - -- Add each title update to ActiveTitleUpdates - local successCount = 0 - for i, titleUpdate in ipairs(titleUpdates) do - local titleUpdateId = titleUpdate.Id - - -- Insert into ActiveTitleUpdates table - local success = Sql.Execute("INSERT INTO ActiveTitleUpdates (TitleUpdateId) VALUES (" .. titleUpdateId .. ")") - - if success then - successCount = successCount + 1 - end - end + -- First, clear any existing active title updates + Sql.Execute("DELETE FROM ActiveTitleUpdates") - if successCount >= 1 then - local ret = Script.ShowMessageBox("Title Updates Enabled", "Successfully enabled " .. successCount .. " of " .. #titleUpdates .. " title updates.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "No", "Yes") + -- Insert only the latest title update per game (highest `Version` per TitleId) + -- Assumes higher `Version` = newer version for the same title + Sql.Execute([[ + INSERT INTO ActiveTitleUpdates (TitleUpdateId) + SELECT Id FROM TitleUpdates t1 + WHERE Version = ( + SELECT MAX(Version) FROM TitleUpdates t2 + WHERE t1.TitleId = t2.TitleId + ) + ]]) + + -- Count how many were successfully enabled + local enabledResult = Sql.ExecuteFetchRows("SELECT COUNT(*) as Count FROM ActiveTitleUpdates") + local enabledCount = enabledResult[1].Count + + if enabledCount >= 1 then + local ret = Script.ShowMessageBox("Title Updates Enabled", "Successfully enabled " .. enabledCount .. " (" .. totalTitleUpdates .. " total) latest title updates.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "Yes", "No") - if ret.Button == 2 then + if ret.Button == 1 then Aurora.Restart(); end else Script.ShowMessageBox( "Title Updates Enabled", - "Enabled " .. successCount .. " of " .. #titleUpdates .. " title updates.", + "Enabled " .. enabledCount .. " of " .. totalTitleUpdates .. " title updates.", "OK" ) end @@ -86,19 +93,85 @@ end -- Disable all title updates function DisableAllTitleUpdates() + -- Check current count before deleting + local countResult = Sql.ExecuteFetchRows("SELECT COUNT(*) as Count FROM ActiveTitleUpdates") + local disabledCount = countResult[1].Count + -- Clear all entries from ActiveTitleUpdates - local success = Sql.Execute("DELETE FROM ActiveTitleUpdates") + Sql.Execute("DELETE FROM ActiveTitleUpdates") - if success then - local ret = Script.ShowMessageBox("Title Updates Disabled", "All title updates have been disabled.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "No", "Yes") + local ret = Script.ShowMessageBox("Title Updates Disabled", disabledCount .. " title updates have been disabled.\nIn order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "Yes", "No") - if ret.Button == 2 then - Aurora.Restart(); - end + if ret.Button == 1 then + Aurora.Restart(); + else + ResetToMainMenu() + end +end + +function InstallAllTitleUpdates() + local ret = Script.ShowMessageBox("Are you sure?", "This will apply the latest enabled title updates. This will clear the title update cache.\nIf you want to use Aurora to manage title updates, you probably shouldn't be doing this!\nAre you sure you want to do this?", "No", "Yes") + + if ret.Button == 2 then + -- Get all active title updates with their details + local activeTitleUpdates = Sql.ExecuteFetchRows([[ + SELECT tu.Id, tu.FileName, tu.LiveDeviceId, tu.LivePath, tu.TitleId, tu.BackupPath + FROM TitleUpdates tu + INNER JOIN ActiveTitleUpdates atu ON tu.Id = atu.TitleUpdateId + ]]) + + if #activeTitleUpdates == 0 then + Script.ShowMessageBox("No Active Title Updates", "No active title updates found to install.", "OK") + ResetToMainMenu() + return + end + + -- Get an array that's serial -> mount point + local matchingDrives = {} + for i, drives in ipairs(FileSystem.GetDrives(false)) do + matchingDrives[drives["Serial"]] = drives["MountPoint"] + end + + local total = #activeTitleUpdates + local successes = 0 + local failures = 0 + + -- Loop through every currently active title update + for i, tu in ipairs(activeTitleUpdates) do + Script.SetStatus("Applying: " .. tu.FileName) + Script.SetProgress(i, total) + local destinationPath = (matchingDrives[tu.LiveDeviceId] .. tu.LivePath) .. tu.FileName + local srcPath = tu.BackupPath + + -- Move it from the backup path to the destination path. + local success = FileSystem.MoveFile(srcPath, destinationPath, true) + + -- If we moved the file successfully, clean it from the database to avoid wonkiness. + if success then + Sql.Execute("DELETE FROM TitleUpdates WHERE Id = " .. tu.Id) + Sql.Execute("DELETE FROM ActiveTitleUpdates WHERE TitleUpdateId = " .. tu.Id) + successes = successes + 1 + else + failures = failures + 1 + end + end + + ret = Script.ShowMessageBox( + "Mass Apply Complete", + ("Successfully applied: " .. successes .. "\n" .. + "Failed: " .. failures .. "\n" .. + "Total: " .. total .. "\n" .. + "In order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?"), + "Yes", "No" + ) + + if ret.Button == 1 then + Aurora.Restart(); + else + ResetToMainMenu() + end else - Script.ShowMessageBox("Error", "Failed to disable title updates.", "OK") + ResetToMainMenu() end - - ResetToMainMenu() end \ No newline at end of file