forked from modio/modio-ue4-legacy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added UninstallUnavailableMods to both C++ and BP layers
- Loading branch information
Showing
8 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
Source/modio/Private/AsyncRequest/ModioAsyncRequest_UninstallUnavailableMods.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2019 modio. All Rights Reserved. | ||
// Released under MIT. | ||
|
||
#include "AsyncRequest/ModioAsyncRequest_UninstallUnavailableMods.h" | ||
#include "ModioUE4Utility.h" | ||
|
||
FModioAsyncRequest_UninstallUnavailableMods::FModioAsyncRequest_UninstallUnavailableMods( FModioSubsystem *Modio, FModioGenericDelegate Delegate, int32 PendingCalls ) : | ||
FModioAsyncRequest( Modio ), | ||
ResponseDelegate( Delegate ) | ||
{ | ||
this->PendingCalls = PendingCalls; | ||
} | ||
|
||
TArray<int32> getInstalledMods() | ||
{ | ||
TArray<int32> InstalledMods; | ||
u32 installed_mods_count = modioGetAllInstalledModsCount(); | ||
ModioInstalledMod *modio_installed_mods = (ModioInstalledMod *)malloc(installed_mods_count * sizeof(*modio_installed_mods)); | ||
modioGetAllInstalledMods(modio_installed_mods); | ||
for (u32 i = 0; i < installed_mods_count; i++) | ||
{ | ||
InstalledMods.Add(modio_installed_mods[i].mod.id); | ||
modioFreeInstalledMod(&modio_installed_mods[i]); | ||
} | ||
free(modio_installed_mods); | ||
return InstalledMods; | ||
} | ||
|
||
void FModioAsyncRequest_UninstallUnavailableMods::Response(void *Object, ModioResponse ModioResponse, ModioMod *ModioMods, u32 ModioModsSize) | ||
{ | ||
UE_LOG(LogTemp, Warning, TEXT("[mod.io] FModioAsyncRequest_UninstallUnavailableMods response returned")); | ||
FModioAsyncRequest_UninstallUnavailableMods* ThisPointer = (FModioAsyncRequest_UninstallUnavailableMods*)Object; | ||
|
||
ThisPointer->PendingCalls--; | ||
for(int32 i=0; i<(int32)ModioModsSize; i++) | ||
{ | ||
ThisPointer->AvailableMods.Push(ModioMods[i].id); | ||
} | ||
|
||
if(ThisPointer->PendingCalls == 0) | ||
{ | ||
UE_LOG(LogTemp, Warning, TEXT("[mod.io] FModioAsyncRequest_UninstallUnavailableMods response returned")); | ||
for(auto InstalledMod : getInstalledMods()) | ||
{ | ||
bool IsAvailable = false; | ||
for(auto AvailableMod : ThisPointer->AvailableMods) | ||
{ | ||
if(InstalledMod == AvailableMod) | ||
IsAvailable = true; | ||
} | ||
if(!IsAvailable) | ||
{ | ||
UE_LOG(LogTemp, Warning, TEXT("[mod.io] Mod %i is unavailable, will be uninstalled"), InstalledMod); | ||
modioUninstallMod((u32)InstalledMod); | ||
}else | ||
{ | ||
UE_LOG(LogTemp, Warning, TEXT("[mod.io] Mod %i is available"), InstalledMod); | ||
} | ||
} | ||
FModioResponse Response; | ||
InitializeResponse( Response, ModioResponse ); | ||
|
||
ThisPointer->ResponseDelegate.ExecuteIfBound( Response ); | ||
|
||
ThisPointer->Done(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Source/modio/Private/BlueprintCallbackProxies/CallbackProxy_UninstallUnavailableMods.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2019 modio. All Rights Reserved. | ||
// Released under MIT. | ||
|
||
#include "BlueprintCallbackProxies/CallbackProxy_UninstallUnavailableMods.h" | ||
#include "ModioSubsystem.h" | ||
#include "Engine/Engine.h" | ||
|
||
UCallbackProxy_UninstallUnavailableMods::UCallbackProxy_UninstallUnavailableMods(const FObjectInitializer &ObjectInitializer) | ||
: Super(ObjectInitializer) | ||
{ | ||
} | ||
|
||
UCallbackProxy_UninstallUnavailableMods *UCallbackProxy_UninstallUnavailableMods::UninstallUnavailableMods(UObject *WorldContext) | ||
{ | ||
UCallbackProxy_UninstallUnavailableMods *Proxy = NewObject<UCallbackProxy_UninstallUnavailableMods>(); | ||
Proxy->SetFlags(RF_StrongRefOnFrame); | ||
Proxy->WorldContextObject = WorldContext; | ||
return Proxy; | ||
} | ||
|
||
void UCallbackProxy_UninstallUnavailableMods::Activate() | ||
{ | ||
UWorld* World = GEngine->GetWorldFromContextObject( WorldContextObject, EGetWorldErrorMode::LogAndReturnNull ); | ||
FModioSubsystemPtr Modio = FModioSubsystem::Get( World ); | ||
if( Modio.IsValid() ) | ||
{ | ||
Modio->UninstallUnavailableMods( FModioGenericDelegate::CreateUObject( this, &UCallbackProxy_UninstallUnavailableMods::OnUninstallUnavailableModsDelegate ) ); | ||
} | ||
else | ||
{ | ||
// @todonow: Make something more pretty than this | ||
FModioResponse Response; | ||
OnFailure.Broadcast( Response ); | ||
} | ||
} | ||
|
||
void UCallbackProxy_UninstallUnavailableMods::OnUninstallUnavailableModsDelegate(FModioResponse Response) | ||
{ | ||
if (Response.Code >= 200 && Response.Code < 300) | ||
{ | ||
OnSuccess.Broadcast(Response); | ||
} | ||
else | ||
{ | ||
OnFailure.Broadcast(Response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Source/modio/Public/AsyncRequest/ModioAsyncRequest_UninstallUnavailableMods.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2019 modio. All Rights Reserved. | ||
// Released under MIT. | ||
|
||
#pragma once | ||
#include "AsyncRequest/ModioAsyncRequest.h" | ||
#include "Schemas/ModioResponse.h" | ||
#include "Schemas/ModioMod.h" | ||
|
||
/** | ||
* Callback returned when all unavailable mods were uninstalled | ||
* @param ModioResponse - Response from Modio backend | ||
*/ | ||
|
||
class FModioAsyncRequest_UninstallUnavailableMods : public FModioAsyncRequest | ||
{ | ||
public: | ||
int32 PendingCalls; | ||
TArray<int32> AvailableMods; | ||
|
||
FModioAsyncRequest_UninstallUnavailableMods( FModioSubsystem *Modio, FModioGenericDelegate Delegate, int32 PendingCalls ); | ||
|
||
static void Response(void *Object, ModioResponse ModioResponse, ModioMod *ModioMods, u32 ModioModsSize); | ||
|
||
private: | ||
FModioGenericDelegate ResponseDelegate; | ||
}; |
39 changes: 39 additions & 0 deletions
39
Source/modio/Public/BlueprintCallbackProxies/CallbackProxy_UninstallUnavailableMods.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2019 modio. All Rights Reserved. | ||
// Released under MIT. | ||
|
||
#pragma once | ||
|
||
#include "ModioUE4Utility.h" | ||
#include "Customizables/ModioFilterCreator.h" | ||
#include "Schemas/ModioResponse.h" | ||
#include "Schemas/ModioMod.h" | ||
#include "Net/OnlineBlueprintCallProxyBase.h" | ||
#include "CallbackProxy_UninstallUnavailableMods.generated.h" | ||
|
||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( | ||
FUninstallUnavailableModsResult, | ||
FModioResponse, | ||
Response); | ||
|
||
UCLASS() | ||
class MODIO_API UCallbackProxy_UninstallUnavailableMods : public UOnlineBlueprintCallProxyBase | ||
{ | ||
GENERATED_UCLASS_BODY() | ||
|
||
// The world context object in which this call is taking place | ||
UPROPERTY() | ||
UObject* WorldContextObject; | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FUninstallUnavailableModsResult OnSuccess; | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FUninstallUnavailableModsResult OnFailure; | ||
|
||
UFUNCTION(BlueprintCallable, Category = "mod.io", meta = (BlueprintInternalUseOnly = "true", DefaultToSelf="WorldContext")) | ||
static UCallbackProxy_UninstallUnavailableMods *UninstallUnavailableMods(UObject *WorldContext); | ||
|
||
virtual void Activate() override; | ||
|
||
virtual void OnUninstallUnavailableModsDelegate(FModioResponse Response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters