Skip to content

Commit

Permalink
Make MAD process cancellable (#865)
Browse files Browse the repository at this point in the history
Mod counterpart to the launcher PR that makes a mod download via MAD cancellable.
  • Loading branch information
Alystrasz authored Nov 22, 2024
1 parent e7aa1c2 commit aba62bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/nativefuncs.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@
"returnTypeString": "void",
"argTypes": "string name, string version"
},
{
"name": "NSCancelModDownload",
"helpText": "prevents installation of the mod currently being installed",
"returnTypeString": "void",
"argTypes": ""
},
{
"name": "NSGetModInstallState",
"helpText": "get status of the mod currently being installed",
Expand Down
19 changes: 19 additions & 0 deletions Northstar.Client/mod/scripts/vscripts/ui/menu_ns_moddownload.nut
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ global enum eModInstallStatus
CHECKSUMING,
EXTRACTING,
DONE,
ABORTED,
FAILED,
FAILED_READING_ARCHIVE,
FAILED_WRITING_TO_DISK,
Expand Down Expand Up @@ -57,6 +58,11 @@ bool function DownloadMod( RequiredModInfo mod )
dialogData.message = Localize( "#DOWNLOADING_MOD_TEXT", mod.name, mod.version )
dialogData.showSpinner = true;

// Prevent download button
AddDialogButton( dialogData, "#CANCEL", void function() {
NSCancelModDownload()
})

// Prevent user from closing dialog
dialogData.forceChoice = true;
OpenDialog( dialogData )
Expand All @@ -77,6 +83,13 @@ bool function DownloadMod( RequiredModInfo mod )
WaitFrame()
}

// If download was aborted, don't close UI since it was closed by clicking cancel button
if ( state.status == eModInstallStatus.ABORTED )
{
print("Mod download was cancelled by the user.")
return false;
}

printt( "Mod status:", state.status )

// Close loading dialog
Expand Down Expand Up @@ -114,6 +127,12 @@ void function DisplayModDownloadErrorDialog( string modName )
{
ModInstallState state = NSGetModInstallState()

// If user cancelled download, no need to display an error message
if ( state.status == eModInstallStatus.ABORTED )
{
return
}

DialogData dialogData
dialogData.header = Localize( "#FAILED_DOWNLOADING", modName )
dialogData.image = $"ui/menu/common/dialog_error"
Expand Down

0 comments on commit aba62bf

Please sign in to comment.