#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingBasics.h"
#include "UObject/UObjectHash.h"
#include "SysInfo_PackageContents.generated.h"


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

UCLASS()
class UWing_SysInfo_PackageContents : public UWingHandler
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, meta=(Description="Package path, e.g. /Game/Testing/BP_Test"))
	FString Package;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Print the name and type of every object in a package."));
	}

	virtual void Handle() override
	{
		UPackage* Pkg = LoadPackage(nullptr, *Package, LOAD_None);
		if (!Pkg)
		{
			WingOut::Stdout.Printf(TEXT("ERROR: Could not load package '%s'\n"), *Package);
			return;
		}

		TArray<UObject*> Objects;
		GetObjectsWithPackage(Pkg, Objects);

		for (UObject* Obj : Objects)
		{
			WingOut::Stdout.Printf(TEXT("%s  %s\n"), *Obj->GetClass()->GetName(), *Obj->GetPathName());
		}
	}
};
