From 7bd6807956077f4c0caddcb4f663cf12cf5cf5d9 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 3 Oct 2023 20:13:59 -0400
Subject: [PATCH] Apply hacky bandaids all over the AO to make the viewer build

---
 indra/newview/alaoengine.cpp       | 87 +++++++++++++++++-------------
 indra/newview/alaoengine.h         |  5 +-
 indra/newview/alfloaterao.cpp      |  2 +-
 indra/newview/llinventorymodel.cpp |  2 +-
 4 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/indra/newview/alaoengine.cpp b/indra/newview/alaoengine.cpp
index c60ebe2f67b..e2db6061fc8 100644
--- a/indra/newview/alaoengine.cpp
+++ b/indra/newview/alaoengine.cpp
@@ -776,23 +776,22 @@ void ALAOEngine::updateSortOrder(ALAOSet::AOState* state)
 	}
 }
 
-LLUUID ALAOEngine::addSet(const std::string& name, const bool reload)
+void ALAOEngine::addSet(const std::string& name, const bool reload, inventory_func_type callback)
 {
 	if (mAOFolder.isNull())
 	{
 		LL_WARNS("AOEngine") << ROOT_AO_FOLDER << " folder not there yet. Requesting recreation." << LL_ENDL;
 		tick();
-		return LLUUID::null;
+		return;
 	}
 
 	LL_DEBUGS("AOEngine") << "adding set folder " << name << LL_ENDL;
-	LLUUID newUUID = gInventory.createNewCategory(mAOFolder, LLFolderType::FT_NONE, name);
+	gInventory.createNewCategory(mAOFolder, LLFolderType::FT_NONE, name, callback);
 
 	if (reload)
 	{
 		mTimerCollection.setReloadTimer(true);
 	}
-	return newUUID;
 }
 
 bool ALAOEngine::createAnimationLink(const ALAOSet* set, ALAOSet::AOState* state, const LLInventoryItem* item)
@@ -1855,37 +1854,8 @@ void ALAOEngine::parseNotecard(std::unique_ptr<char[]> buffer)
 	processImport(false);
 }
 
-void ALAOEngine::processImport(bool aFromTimer)
+void ALAOEngine::processImportInternal(bool aFromTimer)
 {
-	if (mImportCategory.isNull())
-	{
-		mImportCategory = addSet(mImportSet->getName(), false);
-		if (mImportCategory.isNull())
-		{
-			mImportRetryCount++;
-			if (mImportRetryCount == 5)
-			{
-				// NOTE: cleanup is the same as at the end of this function. Needs streamlining.
-				mTimerCollection.setImportTimer(false);
-				delete mImportSet;
-				mImportSet = NULL;
-				mImportCategory.setNull();
-				mUpdatedSignal();
-				LLSD args;
-				args["NAME"] = mImportSet->getName();
-				LLNotificationsUtil::add("AOImportAbortCreateSet", args);
-			}
-			else
-			{
-				LLSD args;
-				args["NAME"] = mImportSet->getName();
-				LLNotificationsUtil::add("AOImportRetryCreateSet", args);
-			}
-			return;
-		}
-		mImportSet->setInventoryUUID(mImportCategory);
-	}
-
 	bool allComplete = true;
 	for (S32 index = 0; index < ALAOSet::AOSTATES_MAX; ++index)
 	{
@@ -1895,7 +1865,7 @@ void ALAOEngine::processImport(bool aFromTimer)
 			if (state->mCycleTime)
 			{
 				const std::string oldName = state->mName + ":CT";
-				state->mName = llformat("%s%d",oldName.c_str(),state->mCycleTime);
+				state->mName = llformat("%s%d", oldName.c_str(), state->mCycleTime);
 			}
 			if (state->mCycle)
 			{
@@ -1910,8 +1880,8 @@ void ALAOEngine::processImport(bool aFromTimer)
 				LL_DEBUGS("AOEngine") << "linking animation " << state->mAnimations[animationIndex].mName << LL_ENDL;
 				if (createAnimationLink(mImportSet, state, gInventory.getItem(state->mAnimations[animationIndex].mInventoryUUID)))
 				{
-					LL_DEBUGS("AOEngine")	<< "link success, size "<< state->mAnimations.size() << ", removing animation "
-								<< (*(state->mAnimations.begin() + animationIndex)).mName << " from import state" << LL_ENDL;
+					LL_DEBUGS("AOEngine") << "link success, size " << state->mAnimations.size() << ", removing animation "
+						<< (*(state->mAnimations.begin() + animationIndex)).mName << " from import state" << LL_ENDL;
 					state->mAnimations.erase(state->mAnimations.begin() + animationIndex);
 					LL_DEBUGS("AOEngine") << "deleted, size now: " << state->mAnimations.size() << LL_ENDL;
 				}
@@ -1935,6 +1905,49 @@ void ALAOEngine::processImport(bool aFromTimer)
 	}
 }
 
+void ALAOEngine::processImportNewCat(const LLUUID& id, bool process)
+{
+	mImportCategory = id;
+		if (mImportCategory.isNull())
+		{
+			mImportRetryCount++;
+			if (mImportRetryCount == 5)
+			{
+				// NOTE: cleanup is the same as at the end of this function. Needs streamlining.
+				mTimerCollection.setImportTimer(false);
+				delete mImportSet;
+				mImportSet = NULL;
+				mImportCategory.setNull();
+				mUpdatedSignal();
+				LLSD args;
+				args["NAME"] = mImportSet->getName();
+				LLNotificationsUtil::add("AOImportAbortCreateSet", args);
+			}
+			else
+			{
+				LLSD args;
+				args["NAME"] = mImportSet->getName();
+				LLNotificationsUtil::add("AOImportRetryCreateSet", args);
+			}
+			return;
+		}
+	mImportSet->setInventoryUUID(mImportCategory);
+
+	processImportInternal(process);
+}
+
+void ALAOEngine::processImport(bool aFromTimer)
+{
+	if (mImportCategory.isNull())
+	{
+		addSet(mImportSet->getName(), false, [this, aFromTimer](const LLUUID& newid) { processImportNewCat(newid, aFromTimer); });
+	}
+	else
+	{
+		processImportInternal(aFromTimer);
+	}
+}
+
 const LLUUID& ALAOEngine::getAOFolder() const
 {
 	return mAOFolder;
diff --git a/indra/newview/alaoengine.h b/indra/newview/alaoengine.h
index 71ac93363be..6568f71b559 100644
--- a/indra/newview/alaoengine.h
+++ b/indra/newview/alaoengine.h
@@ -35,6 +35,7 @@
 
 #include "llextendedstatus.h"
 #include "llsingleton.h"
+#include "llviewerinventory.h"
 
 class ALAOTimerCollection final : public LLEventTimer
 {
@@ -103,7 +104,7 @@ class ALAOEngine final : public LLSingleton<ALAOEngine>
 
 	const LLUUID& getAOFolder() const;
 
-	LLUUID addSet(const std::string& name, bool reload = true);
+	void addSet(const std::string& name, bool reload = true, inventory_func_type callback = {});
 	bool removeSet(ALAOSet* set);
 
 	bool addAnimation(const ALAOSet* set, ALAOSet::AOState* state,
@@ -114,6 +115,8 @@ class ALAOEngine final : public LLSingleton<ALAOEngine>
 
 	bool importNotecard(const LLInventoryItem* item);
 	void processImport(const bool process);
+	void processImportInternal(const bool process);
+	void processImportNewCat(const LLUUID&, bool process);
 
 	bool swapWithPrevious(ALAOSet::AOState* state, S32 index);
 	bool swapWithNext(ALAOSet::AOState* state, S32 index);
diff --git a/indra/newview/alfloaterao.cpp b/indra/newview/alfloaterao.cpp
index 61ed286ab8c..e62848d4c89 100644
--- a/indra/newview/alfloaterao.cpp
+++ b/indra/newview/alfloaterao.cpp
@@ -443,7 +443,7 @@ BOOL ALFloaterAO::newSetCallback(const LLSD& notification, const LLSD& response)
 	
 	if (option == 0)
 	{
-		if (ALAOEngine::instance().addSet(new_name).notNull())
+		ALAOEngine::instance().addSet(new_name);
 		{
 			reloading(true);
 			return TRUE;
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index 751558f7013..9284f6ffe18 100644
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -977,7 +977,7 @@ const LLUUID LLInventoryModel::findCategoryUUIDForNameInRoot(std::string const&
 	{
 		if (root_id.notNull())
 		{
-			return createNewCategory(root_id, LLFolderType::FT_NONE, folder_name);
+			createNewCategory(root_id, LLFolderType::FT_NONE, folder_name);
 		}
 	}
 	return rv;
-- 
GitLab