Modifier step WIP

Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
monroegm-disable-blank-issue-2
chcurran 4 years ago
parent 1badb5a31f
commit cb12d31821

@ -29,6 +29,7 @@
#include <AzToolsFramework/SourceControl/SourceControlAPI.h>
#include <Editor/Settings.h>
#include <Editor/View/Windows/Tools/UpgradeTool/Controller.h>
#include <Editor/View/Windows/Tools/UpgradeTool/LogTraits.h>
#include <ScriptCanvas/Assets/ScriptCanvasAssetHandler.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvas/Components/EditorGraph.h>
@ -40,28 +41,6 @@ namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
EditorKeepAlive::EditorKeepAlive()
{
ISystem* system = nullptr;
CrySystemRequestBus::BroadcastResult(system, &CrySystemRequestBus::Events::GetCrySystem);
m_edKeepEditorActive = system->GetIConsole()->GetCVar("ed_KeepEditorActive");
if (m_edKeepEditorActive)
{
m_keepEditorActive = m_edKeepEditorActive->GetIVal();
m_edKeepEditorActive->Set(1);
}
}
EditorKeepAlive::~EditorKeepAlive()
{
if (m_edKeepEditorActive)
{
m_edKeepEditorActive->Set(m_keepEditorActive);
}
}
Controller::Controller(QWidget* parent)
: AzQtComponents::StyledDialog(parent)
, m_view(new Ui::Controller())
@ -80,582 +59,43 @@ namespace ScriptCanvasEditor
m_view->progressBar->setVisible(false);
ModelNotificationsBus::Handler::BusConnect();
// move to model, maybe
m_keepEditorAlive = AZStd::make_unique<EditorKeepAlive>();
}
void Controller::Log(const char* /*format*/, ...)
{
// if (m_view->verbose->isChecked())
// {
// char sBuffer[2048];
// va_list ArgList;
// va_start(ArgList, format);
// azvsnprintf(sBuffer, sizeof(sBuffer), format, ArgList);
// sBuffer[sizeof(sBuffer) - 1] = '\0';
// va_end(ArgList);
//
// AZ_TracePrintf(ScriptCanvas::k_VersionExplorerWindow.data(), "%s\n", sBuffer);
// }
}
void Controller::OnCloseButtonPress()
{
reject();
}
void Controller::OnSystemTick()
{
// switch (m_state)
// {
// case ProcessState::Scan:
//
// if (!m_inProgress && m_inspectingAsset != m_assetsToInspect.end())
// {
// m_inProgress = true;
// AZ::Data::AssetInfo& assetToUpgrade = *m_inspectingAsset;
// m_currentAsset = AZ::Data::AssetManager::Instance().GetAsset(assetToUpgrade.m_assetId, assetToUpgrade.m_assetType, AZ::Data::AssetLoadBehavior::PreLoad);
// Log("SystemTick::ProcessState::Scan: %s pre-blocking load hint", m_currentAsset.GetHint().c_str());
// m_currentAsset.BlockUntilLoadComplete();
// if (m_currentAsset.IsReady())
// {
// // The asset is ready, grab its info
// m_inProgress = true;
// InspectAsset(m_currentAsset, assetToUpgrade);
// }
// else
// {
// m_view->tableWidget->insertRow(static_cast<int>(m_currentAssetRowIndex));
// QTableWidgetItem* rowName = new QTableWidgetItem
// (tr(AZStd::string::format("Error: %s", assetToUpgrade.m_relativePath.c_str()).c_str()));
// m_view->tableWidget->setItem(static_cast<int>(m_currentAssetRowIndex), static_cast<int>(ColumnAsset), rowName);
// ++m_currentAssetRowIndex;
//
// Log("SystemTick::ProcessState::Scan: %s post-blocking load, problem loading asset", assetToUpgrade.m_relativePath.c_str());
// ++m_failedAssets;
// ScanComplete(m_currentAsset);
// }
// }
// break;
//
// case ProcessState::Upgrade:
// {
// AZStd::lock_guard<AZStd::recursive_mutex> lock(m_mutex);
// if (m_upgradeComplete)
// {
// ++m_upgradeAssetIndex;
// m_inProgress = false;
// m_view->progressBar->setVisible(true);
// m_view->progressBar->setValue(m_upgradeAssetIndex);
//
// if (m_scriptCanvasEntity)
// {
// m_scriptCanvasEntity->Deactivate();
// m_scriptCanvasEntity = nullptr;
// }
//
// GraphUpgradeCompleteUIUpdate(m_upgradeAsset, m_upgradeResult, m_upgradeMessage);
//
// if (!m_isUpgradingSingleGraph)
// {
// if (m_inProgressAsset != m_assetsToUpgrade.end())
// {
// m_inProgressAsset = m_assetsToUpgrade.erase(m_inProgressAsset);
// }
//
// if (m_inProgressAsset == m_assetsToUpgrade.end())
// {
// FinalizeUpgrade();
// }
// }
// else
// {
// m_inProgressAsset = m_assetsToUpgrade.erase(m_inProgressAsset);
// m_inProgress = false;
// m_state = ProcessState::Inactive;
// // m_settingsCache.reset();
// AZ::SystemTickBus::Handler::BusDisconnect();
//
// }
//
// m_isUpgradingSingleGraph = false;
//
// if (m_assetsToUpgrade.empty())
// {
// m_view->upgradeAllButton->setEnabled(false);
// }
//
// m_upgradeComplete = false;
// }
//
// if (!IsUpgrading() && m_state == ProcessState::Upgrade)
// {
// AZStd::string errorMessage = BackupGraph(*m_inProgressAsset);
// // Make the backup
// if (errorMessage.empty())
// {
// Log("SystemTick::ProcessState::Upgrade: Backup Success %s ", m_inProgressAsset->GetHint().c_str());
// QList<QTableWidgetItem*> items = m_view->tableWidget->findItems(m_inProgressAsset->GetHint().c_str(), Qt::MatchFlag::MatchExactly);
// if (!items.isEmpty())
// {
// for (auto* item : items)
// {
// int row = item->row();
// AzQtComponents::StyledBusyLabel* spinner = qobject_cast<AzQtComponents::StyledBusyLabel*>(m_view->tableWidget->cellWidget(row, ColumnStatus));
// spinner->SetIsBusy(true);
// }
// }
//
// // Upgrade the graph
// UpgradeGraph(*m_inProgressAsset);
// }
// else
// {
// Log("SystemTick::ProcessState::Upgrade: Backup Failed %s ", m_inProgressAsset->GetHint().c_str());
// GraphUpgradeComplete(*m_inProgressAsset, OperationResult::Failure, errorMessage);
// }
//
// }
// break;
// }
// default:
// break;
// }
//
// FlushLogs();
//
// AZ::Data::AssetManager::Instance().DispatchEvents();
// AZ::SystemTickBus::ExecuteQueuedEvents();
}
// Backup
void Controller::OnUpgradeAllButtonPress()
{
m_state = ProcessState::Upgrade;
//m_settingsCache = AZStd::make_unique<ScriptCanvas::Grammar::SettingsCache>();
ScriptCanvas::Grammar::g_saveRawTranslationOuputToFile = false;
ScriptCanvas::Grammar::g_printAbstractCodeModel = false;
ScriptCanvas::Grammar::g_saveRawTranslationOuputToFile = false;
AZ::Interface<IUpgradeRequests>::Get()->SetIsUpgrading(true);
AZ::Interface<IUpgradeRequests>::Get()->ClearGraphsThatNeedUpgrade();
m_inProgressAsset = m_assetsToUpgrade.begin();
AZ::SystemTickBus::Handler::BusConnect();
m_view->progressBar->setVisible(true);
m_view->progressBar->setRange(0, aznumeric_cast<int>(m_assetsToUpgrade.size()));
m_view->progressBar->setValue(m_upgradeAssetIndex);
m_keepEditorAlive = AZStd::make_unique<EditorKeepAlive>();
}
AZStd::string Controller::BackupGraph(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
if (!m_view->makeBackupCheckbox->isChecked())
{
// considered a success
return "";
}
QDateTime theTime = QDateTime::currentDateTime();
QString subFolder = theTime.toString("yyyy-MM-dd [HH.mm.ss]");
AZStd::string backupPath = AZStd::string::format("@devroot@/ScriptCanvas_BACKUP/%s", subFolder.toUtf8().data());
char backupPathCStr[AZ_MAX_PATH_LEN] = { 0 };
AZ::IO::FileIOBase::GetInstance()->ResolvePath(backupPath.c_str(), backupPathCStr, AZ_MAX_PATH_LEN);
backupPath = backupPathCStr;
if (!AZ::IO::FileIOBase::GetInstance()->Exists(backupPath.c_str()))
{
if (AZ::IO::FileIOBase::GetInstance()->CreatePath(backupPath.c_str()) != AZ::IO::ResultCode::Success)
{
AZ_Error(ScriptCanvas::k_VersionExplorerWindow.data(), false, "Failed to create backup folder %s", backupPath.c_str());
return "Failed to create backup folder";
}
}
AZStd::string devRoot = "@devroot@";
AZStd::string devAssets = "@devassets@";
char devRootCStr[AZ_MAX_PATH_LEN] = { 0 };
AZ::IO::FileIOBase::GetInstance()->ResolvePath(devRoot.c_str(), devRootCStr, AZ_MAX_PATH_LEN);
char devAssetsCStr[AZ_MAX_PATH_LEN] = { 0 };
AZ::IO::FileIOBase::GetInstance()->ResolvePath(devAssets.c_str(), devAssetsCStr, AZ_MAX_PATH_LEN);
AZStd::string relativePath = devAssetsCStr;
AzFramework::StringFunc::Replace(relativePath, devRootCStr, "");
if (relativePath.starts_with("/"))
{
relativePath = relativePath.substr(1, relativePath.size() - 1);
}
AZStd::string sourceFilePath;
AZStd::string watchFolder;
AZ::Data::AssetInfo assetInfo;
bool sourceInfoFound{};
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourceInfoFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath, asset.GetHint().c_str(), assetInfo, watchFolder);
if (sourceInfoFound)
{
AZStd::string assetPath;
AzFramework::StringFunc::Path::Join(watchFolder.c_str(), assetInfo.m_relativePath.c_str(), assetPath);
sourceFilePath = assetPath;
}
else
{
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "Controller::BackupGraph: Failed to find file: %s", asset.GetHint().c_str());
return "Failed to find source file";
}
devRoot = devRootCStr;
AzFramework::StringFunc::Path::Normalize(devRoot);
relativePath = sourceFilePath;
AzFramework::StringFunc::Replace(relativePath, devRoot.c_str(), "");
if (relativePath.starts_with("/"))
{
relativePath = relativePath.substr(1, relativePath.size() - 1);
}
AzFramework::StringFunc::Path::Normalize(relativePath);
AzFramework::StringFunc::Path::Normalize(backupPath);
AZStd::string targetFilePath = backupPath;
targetFilePath += relativePath;
if (AZ::IO::FileIOBase::GetInstance()->Copy(sourceFilePath.c_str(), targetFilePath.c_str()) != AZ::IO::ResultCode::Success)
{
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "Controller::BackupGraph: Error creating backup: %s ---> %s\n", sourceFilePath.c_str(), targetFilePath.c_str());
return "Failed to copy source file to backup location";
}
Log("Controller::BackupGraph: Backed up: %s ---> %s\n", sourceFilePath.c_str(), targetFilePath.c_str());
return "";
}
void Controller::UpgradeGraph(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
void Controller::AddLogEntries()
{
m_inProgress = true;
m_upgradeComplete = false;
Log("UpgradeGraph %s ", m_inProgressAsset->GetHint().c_str());
m_view->spinner->SetText(QObject::tr("Upgrading: %1").arg(asset.GetHint().c_str()));
m_scriptCanvasEntity = nullptr;
UpgradeNotifications::Bus::Handler::BusConnect();
if (asset.GetType() == azrtti_typeid<ScriptCanvasAsset>())
const AZStd::vector<AZStd::string>* logs = nullptr;
LogBus::BroadcastResult(logs, &LogTraits::GetEntries);
if (!logs || logs->empty())
{
ScriptCanvasAsset* scriptCanvasAsset = asset.GetAs<ScriptCanvasAsset>();
AZ_Assert(scriptCanvasAsset, "Unable to get the asset of ScriptCanvasAsset, but received type: %s"
, azrtti_typeid<ScriptCanvasAsset>().template ToString<AZStd::string>().c_str());
if (!scriptCanvasAsset)
{
return;
}
AZ::Entity* scriptCanvasEntity = scriptCanvasAsset->GetScriptCanvasEntity();
AZ_Assert(scriptCanvasEntity, "Controller::UpgradeGraph The Script Canvas asset must have a valid entity");
if (!scriptCanvasEntity)
{
return;
}
AZ::Entity* queryEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(queryEntity, &AZ::ComponentApplicationRequests::FindEntity, scriptCanvasEntity->GetId());
if (queryEntity)
{
if (queryEntity->GetState() == AZ::Entity::State::Active)
{
queryEntity->Deactivate();
}
scriptCanvasEntity = queryEntity;
}
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Constructed)
{
scriptCanvasEntity->Init();
}
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Init)
{
scriptCanvasEntity->Activate();
}
AZ_Assert(scriptCanvasEntity->GetState() == AZ::Entity::State::Active, "Graph entity is not active");
auto graphComponent = scriptCanvasEntity->FindComponent<ScriptCanvasEditor::Graph>();
AZ_Assert(graphComponent, "The Script Canvas entity must have a Graph component");
if (graphComponent)
{
m_scriptCanvasEntity = scriptCanvasEntity;
graphComponent->UpgradeGraph
(asset
, m_view->forceUpgrade->isChecked() ? Graph::UpgradeRequest::Forced : Graph::UpgradeRequest::IfOutOfDate
, m_view->verbose->isChecked());
}
}
AZ_Assert(m_scriptCanvasEntity, "The ScriptCanvas asset should have an entity");
}
void Controller::OnGraphUpgradeComplete(AZ::Data::Asset<AZ::Data::AssetData>& asset, bool /*skipped*/ /*= false*/)
{
AZStd::string relativePath, fullPath;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(relativePath, &AZ::Data::AssetCatalogRequests::GetAssetPathById, asset.GetId());
bool fullPathFound = false;
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(fullPathFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relativePath, fullPath);
if (!fullPathFound)
{
AZ_Error(ScriptCanvas::k_VersionExplorerWindow.data(), false, "Full source path not found for %s", relativePath.c_str());
}
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
AZ::IO::FileRequestPtr flushRequest = streamer->FlushCache(fullPath);
streamer->SetRequestCompleteCallback(flushRequest, [this, asset]([[maybe_unused]] AZ::IO::FileRequestHandle request)
{
this->OnSourceFileReleased(asset);
});
streamer->QueueRequest(flushRequest);
}
void Controller::OnSourceFileReleased(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
AZStd::string relativePath, fullPath;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(relativePath, &AZ::Data::AssetCatalogRequests::GetAssetPathById, asset.GetId());
bool fullPathFound = false;
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(fullPathFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relativePath, fullPath);
m_tmpFileName.clear();
AZStd::string tmpFileName;
// here we are saving the graph to a temp file instead of the original file and then copying the temp file to the original file.
// This ensures that AP will not a get a file change notification on an incomplete graph file causing it to fail processing. Temp files are ignored by AP.
if (!AZ::IO::CreateTempFileName(fullPath.c_str(), tmpFileName))
{
GraphUpgradeComplete(asset, OperationResult::Failure, "Failure to create temporary file name");
return;
}
bool tempSavedSucceeded = false;
AZ::IO::FileIOStream fileStream(tmpFileName.c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeText);
if (fileStream.IsOpen())
{
if (asset.GetType() == azrtti_typeid<ScriptCanvasAsset>())
{
ScriptCanvasEditor::ScriptCanvasAssetHandler handler;
tempSavedSucceeded = handler.SaveAssetData(asset, &fileStream);
}
fileStream.Close();
}
// attempt to remove temporary file no matter what
m_tmpFileName = tmpFileName;
if (!tempSavedSucceeded)
{
GraphUpgradeComplete(asset, OperationResult::Failure, "Save asset data to temporary file failed");
return;
}
using SCCommandBus = AzToolsFramework::SourceControlCommandBus;
SCCommandBus::Broadcast(&SCCommandBus::Events::RequestEdit, fullPath.c_str(), true,
[this, asset, fullPath, tmpFileName]([[maybe_unused]] bool success, const AzToolsFramework::SourceControlFileInfo& info)
{
constexpr const size_t k_maxAttemps = 10;
if (!info.IsReadOnly())
{
PerformMove(asset, tmpFileName, fullPath, k_maxAttemps);
}
else
{
if (m_overwriteAll)
{
AZ::IO::SystemFile::SetWritable(info.m_filePath.c_str(), true);
PerformMove(asset, tmpFileName, fullPath, k_maxAttemps);
}
else
{
int result = QMessageBox::No;
if (!m_overwriteAll)
{
QMessageBox mb(QMessageBox::Warning,
QObject::tr("Failed to Save Upgraded File"),
QObject::tr("The upgraded file could not be saved because the file is read only.\nDo you want to make it writeable and overwrite it?"),
QMessageBox::YesToAll | QMessageBox::Yes | QMessageBox::No, this);
result = mb.exec();
if (result == QMessageBox::YesToAll)
{
m_overwriteAll = true;
}
}
if (result == QMessageBox::Yes || m_overwriteAll)
{
AZ::IO::SystemFile::SetWritable(info.m_filePath.c_str(), true);
PerformMove(asset, tmpFileName, fullPath, k_maxAttemps);
}
}
}
});
}
void Controller::PerformMove(AZ::Data::Asset<AZ::Data::AssetData> asset, AZStd::string source, AZStd::string target
, size_t remainingAttempts)
{
// ViewCpp::FileEventHandler fileEventHandler;
if (remainingAttempts == 0)
{
// all attempts failed, give up
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "moving converted file to source destination failed: %s. giving up", target.c_str());
GraphUpgradeComplete(asset, OperationResult::Failure, "Failed to move updated file from backup to source destination");
}
else if (remainingAttempts == 2)
{
// before the final attempt, flush all caches
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "moving converted file to source destination failed: %s, trying again", target.c_str());
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
AZ::IO::FileRequestPtr flushRequest = streamer->FlushCaches();
streamer->SetRequestCompleteCallback(flushRequest
, [this, asset, remainingAttempts, source, target]([[maybe_unused]] AZ::IO::FileRequestHandle request)
{
// Continue saving.
AZ::SystemTickBus::QueueFunction(
[this, asset, remainingAttempts, source, target]() { PerformMove(asset, source, target, remainingAttempts - 1); });
});
streamer->QueueRequest(flushRequest);
}
else
{
// the actual move attempt
auto moveResult = AZ::IO::SmartMove(source.c_str(), target.c_str());
if (moveResult.GetResultCode() == AZ::IO::ResultCode::Success)
{
m_tmpFileName.clear();
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
AZ::IO::FileRequestPtr flushRequest = streamer->FlushCache(target.c_str());
// Bump the slice asset up in the asset processor's queue.
AzFramework::AssetSystemRequestBus::Broadcast(&AzFramework::AssetSystem::AssetSystemRequests::EscalateAssetBySearchTerm, target.c_str());
AZ::SystemTickBus::QueueFunction([this, asset]()
{
GraphUpgradeComplete(asset, OperationResult::Success, "");
});
}
else
{
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "moving converted file to source destination failed: %s, trying again", target.c_str());
auto streamer = AZ::Interface<AZ::IO::IStreamer>::Get();
AZ::IO::FileRequestPtr flushRequest = streamer->FlushCache(target.c_str());
streamer->SetRequestCompleteCallback(flushRequest, [this, asset, source, target, remainingAttempts]([[maybe_unused]] AZ::IO::FileRequestHandle request)
{
// Continue saving.
AZ::SystemTickBus::QueueFunction([this, asset, source, target, remainingAttempts]() { PerformMove(asset, source, target, remainingAttempts - 1); });
});
streamer->QueueRequest(flushRequest);
}
}
}
void Controller::GraphUpgradeComplete
(const AZ::Data::Asset<AZ::Data::AssetData> asset, OperationResult result, AZStd::string_view message)
{
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_mutex);
m_upgradeComplete = true;
m_upgradeResult = result;
m_upgradeMessage = message;
m_upgradeAsset = asset;
if (!m_tmpFileName.empty())
{
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
AZ_Assert(fileIO, "GraphUpgradeComplete: No FileIO instance");
const QTextCursor oldCursor = m_view->textEdit->textCursor();
QScrollBar* scrollBar = m_view->textEdit->verticalScrollBar();
if (fileIO->Exists(m_tmpFileName.c_str()) && !fileIO->Remove(m_tmpFileName.c_str()))
{
AZ_TracePrintf(ScriptCanvas::k_VersionExplorerWindow.data(), "Failed to remove temporary file: %s", m_tmpFileName.c_str());
}
}
m_view->textEdit->moveCursor(QTextCursor::End);
QTextCursor textCursor = m_view->textEdit->textCursor();
if (m_upgradeResult == OperationResult::Failure)
for (auto& entry : *logs)
{
AZ::Interface<IUpgradeRequests>::Get()->GraphNeedsManualUpgrade(asset.GetId());
auto line = "\n" + entry;
textCursor.insertText(line.c_str());
}
m_tmpFileName.clear();
}
void Controller::GraphUpgradeCompleteUIUpdate
(const AZ::Data::Asset<AZ::Data::AssetData> asset, OperationResult result, AZStd::string_view message)
{
QString text = asset.GetHint().c_str();
QList<QTableWidgetItem*> items = m_view->tableWidget->findItems(text, Qt::MatchFlag::MatchExactly);
if (!items.isEmpty())
{
for (auto* item : items)
{
int row = item->row();
QTableWidgetItem* label = m_view->tableWidget->item(row, ColumnAsset);
QString assetName = asset.GetHint().c_str();
if (label->text().compare(assetName) == 0)
{
m_view->tableWidget->removeCellWidget(row, ColumnAction);
m_view->tableWidget->removeCellWidget(row, ColumnStatus);
QToolButton* doneButton = new QToolButton(this);
doneButton->setToolTip("Upgrade complete");
if (result == OperationResult::Success)
{
doneButton->setIcon(QIcon(":/stylesheet/img/UI20/checkmark-menu.svg"));
}
else
{
doneButton->setIcon(QIcon(":/stylesheet/img/UI20/titlebar-close.svg"));
doneButton->setToolTip(message.data());
}
m_view->tableWidget->setCellWidget(row, ColumnStatus, doneButton);
}
}
}
scrollBar->setValue(scrollBar->maximum());
m_view->textEdit->moveCursor(QTextCursor::StartOfLine);
LogBus::Broadcast(&LogTraits::Clear);
}
void Controller::FinalizeUpgrade()
void Controller::OnCloseButtonPress()
{
Log("FinalizeUpgrade!");
m_inProgress = false;
m_assetsToUpgrade.clear();
m_view->upgradeAllButton->setEnabled(false);
m_view->onlyShowOutdated->setEnabled(true);
m_keepEditorAlive.reset();
m_view->progressBar->setVisible(false);
// Manual correction
size_t assetsThatNeedManualInspection = AZ::Interface<IUpgradeRequests>::Get()->GetGraphsThatNeedManualUpgrade().size();
if (assetsThatNeedManualInspection > 0)
{
m_view->spinner->SetText("<html><head/><body><img src=':/stylesheet/img/UI20/Info.svg' width='16' height='16'/>Some graphs will require manual corrections, you will be prompted to review them upon closing this dialog</body></html>");
}
else
{
m_view->spinner->SetText("Upgrade complete.");
}
AZ::SystemTickBus::Handler::BusDisconnect();
AZ::Interface<IUpgradeRequests>::Get()->SetIsUpgrading(false);
//m_settingsCache.reset();
reject();
}
void Controller::OnScanButtonPress()
{
auto isUpToDate = [this](AZ::Data::Asset<AZ::Data::AssetData> asset)
{
Log("InspectAsset: %s", asset.GetHint().c_str());
AZ::Entity* scriptCanvasEntity = nullptr;
if (asset.GetType() == azrtti_typeid<ScriptCanvasAsset>())
@ -663,7 +103,11 @@ namespace ScriptCanvasEditor
ScriptCanvasAsset* scriptCanvasAsset = asset.GetAs<ScriptCanvasAsset>();
if (!scriptCanvasAsset)
{
Log("InspectAsset: %s, AsestData failed to return ScriptCanvasAsset", asset.GetHint().c_str());
AZ_Warning
( ScriptCanvas::k_VersionExplorerWindow.data()
, false
, "InspectAsset: %s, AsestData failed to return ScriptCanvasAsset"
, asset.GetHint().c_str());
return true;
}
@ -697,8 +141,6 @@ namespace ScriptCanvasEditor
void Controller::OnScanComplete(const ScanResult& result)
{
Log("Full Scan Complete.");
m_view->onlyShowOutdated->setEnabled(true);
// Enable all the Upgrade buttons
@ -724,8 +166,6 @@ namespace ScriptCanvasEditor
{
m_view->upgradeAllButton->setEnabled(true);
}
m_keepEditorAlive.reset();
}
void Controller::OnScanFilteredGraph(const AZ::Data::AssetInfo& info)
@ -746,7 +186,7 @@ namespace ScriptCanvasEditor
rowGoToButton->setEnabled(false);
AzQtComponents::StyledBusyLabel* spinner = new AzQtComponents::StyledBusyLabel(this);
spinner->SetBusyIconSize(16);
//
// \\ todo restore this
// connect(rowGoToButton, &QPushButton::clicked, [this, rowGoToButton, assetInfo] {
//
// // request upgrade of a single graph
@ -797,19 +237,18 @@ namespace ScriptCanvasEditor
OnScannedGraphResult(assetInfo);
}
void Controller::OnScannedGraphResult(const AZ::Data::AssetInfo& info)
void Controller::OnScannedGraphResult([[maybe_unused]] const AZ::Data::AssetInfo& info)
{
m_view->progressBar->setValue(aznumeric_cast<int>(m_currentAssetRowIndex));
++m_currentAssetRowIndex;
Log("ScanComplete: %s", info.m_relativePath.c_str());
FlushLogs();
AddLogEntries();
}
void Controller::OnScanLoadFailure(const AZ::Data::AssetInfo& info)
{
m_view->tableWidget->insertRow(static_cast<int>(m_currentAssetRowIndex));
QTableWidgetItem* rowName = new QTableWidgetItem
(tr(AZStd::string::format("Load Error: %s", info.m_relativePath.c_str()).c_str()));
( tr(AZStd::string::format("Load Error: %s", info.m_relativePath.c_str()).c_str()));
m_view->tableWidget->setItem(static_cast<int>(m_currentAssetRowIndex), static_cast<int>(ColumnAsset), rowName);
OnScannedGraphResult(info);
}
@ -819,141 +258,92 @@ namespace ScriptCanvasEditor
OnScannedGraph(info, Filtered::No);
}
void Controller::BackupComplete()
{
m_currentAssetRowIndex = 0;
m_view->progressBar->setValue(0);
}
void Controller::UpgradeSingle
( QPushButton* rowGoToButton
, AzQtComponents::StyledBusyLabel* spinner
, AZ::Data::AssetInfo assetInfo)
void Controller::OnUpgradeAllButtonPress()
{
AZ::Data::Asset<AZ::Data::AssetData> asset = AZ::Data::AssetManager::Instance().GetAsset
(assetInfo.m_assetId, assetInfo.m_assetType, AZ::Data::AssetLoadBehavior::PreLoad);
if (asset)
auto simpleUpdate = [this](AZ::Data::Asset<AZ::Data::AssetData> asset)
{
asset.BlockUntilLoadComplete();
if (asset.IsReady())
if (asset.GetType() == azrtti_typeid<ScriptCanvasAsset>())
{
AZ::Interface<IUpgradeRequests>::Get()->SetIsUpgrading(true);
m_isUpgradingSingleGraph = true;
m_logs.clear();
m_view->textEdit->clear();
spinner->SetIsBusy(true);
rowGoToButton->setEnabled(false);
m_inProgressAsset = AZStd::find_if(m_assetsToUpgrade.begin(), m_assetsToUpgrade.end()
, [asset](const UpgradeAssets::value_type& assetToUpgrade)
ScriptCanvasAsset* scriptCanvasAsset = asset.GetAs<ScriptCanvasAsset>();
AZ_Assert(scriptCanvasAsset, "Unable to get the asset of ScriptCanvasAsset, but received type: %s"
, azrtti_typeid<ScriptCanvasAsset>().template ToString<AZStd::string>().c_str());
if (!scriptCanvasAsset)
{
return assetToUpgrade.GetId() == asset.GetId();
});
m_state = ProcessState::Upgrade;
AZ::SystemTickBus::Handler::BusConnect();
}
}
}
return;
}
void Controller::ScanComplete(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
Log("ScanComplete: %s", asset.GetHint().c_str());
m_inProgress = false;
m_view->progressBar->setValue(aznumeric_cast<int>(m_currentAssetRowIndex));
m_view->scanButton->setEnabled(true);
AZ::Entity* scriptCanvasEntity = scriptCanvasAsset->GetScriptCanvasEntity();
AZ_Assert(scriptCanvasEntity, "View::UpgradeGraph The Script Canvas asset must have a valid entity");
if (!scriptCanvasEntity)
{
return;
}
m_inspectingAsset = m_assetsToInspect.erase(m_inspectingAsset);
if (m_inspectingAsset == m_assetsToInspect.end())
{
AZ::SystemTickBus::QueueFunction([this]() { FinalizeScan(); });
AZ::Entity* queryEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(queryEntity, &AZ::ComponentApplicationRequests::FindEntity, scriptCanvasEntity->GetId());
if (queryEntity)
{
if (queryEntity->GetState() == AZ::Entity::State::Active)
{
queryEntity->Deactivate();
}
if (!m_assetsToUpgrade.empty())
{
m_view->upgradeAllButton->setEnabled(true);
}
}
}
scriptCanvasEntity = queryEntity;
}
void Controller::FinalizeScan()
{
Log("FinalizeScan()");
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Constructed)
{
scriptCanvasEntity->Init();
}
m_view->spinner->SetIsBusy(false);
m_view->onlyShowOutdated->setEnabled(true);
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Init)
{
scriptCanvasEntity->Activate();
}
// Enable all the Upgrade buttons
for (int row = 0; row < m_view->tableWidget->rowCount(); ++row)
{
QPushButton* button = qobject_cast<QPushButton*>(m_view->tableWidget->cellWidget(row, ColumnAction));
if (button)
{
button->setEnabled(true);
AZ_Assert(scriptCanvasEntity->GetState() == AZ::Entity::State::Active, "Graph entity is not active");
auto graphComponent = scriptCanvasEntity->FindComponent<ScriptCanvasEditor::Graph>();
AZ_Assert(graphComponent, "The Script Canvas entity must have a Graph component");
if (graphComponent)
{
graphComponent->UpgradeGraph
( asset
, m_view->forceUpgrade->isChecked() ? Graph::UpgradeRequest::Forced : Graph::UpgradeRequest::IfOutOfDate
, m_view->verbose->isChecked());
}
}
}
QString spinnerText = QStringLiteral("Scan Complete");
if (m_assetsToUpgrade.empty())
{
spinnerText.append(" - No graphs require upgrade!");
}
else
{
spinnerText.append(QString::asprintf(" - Discovered: %zu, Inspected: %zu, Failed: %zu, Upgradeable: %zu"
, m_discoveredAssets, m_inspectedAssets, m_failedAssets, m_assetsToUpgrade.size()));
}
m_view->spinner->SetText(spinnerText);
m_view->progressBar->setVisible(false);
if (!m_assetsToUpgrade.empty())
{
m_view->upgradeAllButton->setEnabled(true);
}
AZ::SystemTickBus::Handler::BusDisconnect();
};
m_keepEditorAlive.reset();
//m_settingsCache.reset();
m_state = ProcessState::Inactive;
ModifyConfiguration config;
config.modification = simpleUpdate;
config.backupGraphBeforeModification = m_view->makeBackupCheckbox->isChecked();
ModelRequestsBus::Broadcast(&ModelRequestsTraits::Modify, config);
}
void Controller::FlushLogs()
void Controller::OnUpgradeAllBegin()
{
if (m_logs.empty())
{
return;
}
const QTextCursor oldCursor = m_view->textEdit->textCursor();
QScrollBar* scrollBar = m_view->textEdit->verticalScrollBar();
m_view->textEdit->moveCursor(QTextCursor::End);
QTextCursor textCursor = m_view->textEdit->textCursor();
while (!m_logs.empty())
{
auto line = "\n" + m_logs.front();
m_currentAssetRowIndex = 0;
m_view->tableWidget->setRowCount(0);
m_view->progressBar->setVisible(true);
m_view->progressBar->setValue(0);
m_view->scanButton->setEnabled(false);
m_view->upgradeAllButton->setEnabled(false);
m_view->onlyShowOutdated->setEnabled(false);
}
m_logs.pop_front();
void Controller::OnUpgradeAllComplete()
{
textCursor.insertText(line.c_str());
}
}
scrollBar->setValue(scrollBar->maximum());
m_view->textEdit->moveCursor(QTextCursor::StartOfLine);
void Controller::OnUpgradeAllDependencySortBegin()
{
}
void Controller::closeEvent(QCloseEvent* event)
void Controller::OnUpgradeAllDependencySortEnd(const AZStd::vector<AZ::Data::AssetInfo>& sortedAssets)
{
m_keepEditorAlive.reset();
AzQtComponents::StyledDialog::closeEvent(event);
m_view->progressBar->setRange(0, aznumeric_cast<int>(sortedAssets.size()));
}
}
}

@ -10,12 +10,9 @@
#if !defined(Q_MOC_RUN)
#include <AzCore/Component/EntityId.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/PlatformDef.h>
#include <AzQtComponents/Components/StyledDialog.h>
#include <Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h>
#include <Editor/View/Windows/Tools/UpgradeTool/ViewTraits.h>
#include <IConsole.h>
#include <ISystem.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvas/Core/Core.h>
@ -40,24 +37,10 @@ namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
//! Scoped utility to set and restore the "ed_KeepEditorActive" CVar in order to allow
//! the upgrade tool to work even if the editor is not in the foreground
class EditorKeepAlive
{
public:
EditorKeepAlive();
~EditorKeepAlive();
private:
int m_keepEditorActive;
ICVar* m_edKeepEditorActive;
};
//! A tool that collects and upgrades all Script Canvas graphs in the asset catalog
//! Handles display change notifications, handles state change notifications, sends control requests
class Controller
: public AzQtComponents::StyledDialog
, private AZ::SystemTickBus::Handler
, private UpgradeNotifications::Bus::Handler
, private ModelNotificationsBus::Handler
{
@ -74,104 +57,28 @@ namespace ScriptCanvasEditor
static constexpr int ColumnBrowse = 2;
static constexpr int ColumnStatus = 3;
AZStd::unique_ptr<Ui::Controller> m_view;
size_t m_currentAssetRowIndex = 0;
void AddLogEntries();
void OnCloseButtonPress();
void OnScanBegin(size_t assetCount) override;
void OnScanButtonPress();
void OnUpgradeAllButtonPress();
void OnScanBegin(size_t assetCount) override;
void OnScanComplete(const ScanResult& result) override;
void OnScanFilteredGraph(const AZ::Data::AssetInfo& info) override;
void OnScanLoadFailure(const AZ::Data::AssetInfo& info) override;
void OnScanUnFilteredGraph(const AZ::Data::AssetInfo& info) override;
enum Filtered
{
No,
Yes
};
enum class Filtered { No, Yes };
void OnScannedGraph(const AZ::Data::AssetInfo& info, Filtered filtered);
void OnScannedGraphResult(const AZ::Data::AssetInfo& info);
void OnUpgradeAllButtonPress();
enum class ProcessState
{
Inactive,
Backup,
Scan,
Upgrade,
};
ProcessState m_state = ProcessState::Inactive;
void ScanComplete(const AZ::Data::Asset<AZ::Data::AssetData>&);
// SystemTickBus::Handler
void OnSystemTick() override;
enum class OperationResult
{
Success,
Failure,
};
void GraphUpgradeComplete(const AZ::Data::Asset<AZ::Data::AssetData>, OperationResult result, AZStd::string_view message);
bool IsUpgrading() const { return false; }
bool m_inProgress = false;
// scan fields
size_t m_currentAssetRowIndex = 0;
size_t m_inspectedAssets = 0;
size_t m_failedAssets = 0;
size_t m_discoveredAssets = 0;
IUpgradeRequests::AssetList m_assetsToInspect;
IUpgradeRequests::AssetList::iterator m_inspectingAsset;
using UpgradeAssets = AZStd::vector<AZ::Data::Asset<AZ::Data::AssetData>>;
UpgradeAssets m_assetsToUpgrade;
UpgradeAssets::iterator m_inProgressAsset;
AZ::Data::Asset<AZ::Data::AssetData> m_currentAsset;
AZStd::unique_ptr<Ui::Controller> m_view;
// upgrade fields
AZStd::recursive_mutex m_mutex;
bool m_upgradeComplete = false;
AZ::Data::Asset<AZ::Data::AssetData> m_upgradeAsset;
int m_upgradeAssetIndex = 0;
OperationResult m_upgradeResult;
AZStd::string m_upgradeMessage;
AZStd::string m_tmpFileName;
AZStd::unique_ptr<EditorKeepAlive> m_keepEditorAlive;
AZStd::deque<AZStd::string> m_logs;
AZ::Entity* m_scriptCanvasEntity = nullptr;
bool m_isUpgradingSingleGraph = false;
void UpgradeSingle(QPushButton* item, AzQtComponents::StyledBusyLabel* spinner, AZ::Data::AssetInfo assetInfo);
void FlushLogs();
void FinalizeUpgrade();
void FinalizeScan();
void BackupComplete();
AZStd::string BackupGraph(const AZ::Data::Asset<AZ::Data::AssetData>&);
void UpgradeGraph(const AZ::Data::Asset<AZ::Data::AssetData>&);
void GraphUpgradeCompleteUIUpdate(const AZ::Data::Asset<AZ::Data::AssetData> asset, OperationResult result, AZStd::string_view message);
void OnGraphUpgradeComplete(AZ::Data::Asset<AZ::Data::AssetData>&, bool skipped = false) override;
void OnSourceFileReleased(AZ::Data::Asset<AZ::Data::AssetData> asset);
void closeEvent(QCloseEvent* event) override;
bool m_overwriteAll = false;
void PerformMove(AZ::Data::Asset<AZ::Data::AssetData> asset, AZStd::string source, AZStd::string target, size_t remainingAttempts);
void Log(const char* format, ...);
void OnUpgradeAllBegin() override;
void OnUpgradeAllComplete() override;
void OnUpgradeAllDependencySortBegin() override;
void OnUpgradeAllDependencySortEnd(const AZStd::vector<AZ::Data::AssetInfo>& sortedAssets) override;
};
}
}

@ -0,0 +1,32 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#define VE_LOG(...) LogBus::Broadcast(&LogTraits::Entry, __VA_ARGS__);
namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
class LogTraits
: public AZ::EBusTraits
{
public:
virtual void Activate() = 0;
virtual void Clear() = 0;
virtual void Deactivate() = 0;
virtual void Entry(const char* format, ...) = 0;
virtual const AZStd::vector<AZStd::string>* GetEntries() const = 0;
virtual void SetVersionExporerExclusivity(bool enabled) = 0;
virtual void SetVerbose(bool verbosity) = 0;
};
using LogBus = AZ::EBus<LogTraits>;
}
}

@ -7,8 +7,11 @@
*/
#include <AzCore/Asset/AssetManagerBus.h>
#include <Editor/View/Windows/Tools/UpgradeTool/Model.h>
#include <CryCommon/CrySystemBus.h>
#include <Editor/Assets/ScriptCanvasAssetHelpers.h>
#include <Editor/View/Windows/Tools/UpgradeTool/Model.h>
#include <IConsole.h>
#include <ISystem.h>
#include <ScriptCanvas/Assets/ScriptCanvasAsset.h>
namespace ModifierCpp
@ -20,6 +23,31 @@ namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
EditorKeepAlive::EditorKeepAlive()
{
ISystem* system = nullptr;
CrySystemRequestBus::BroadcastResult(system, &CrySystemRequestBus::Events::GetCrySystem);
if (system)
{
m_edKeepEditorActive = system->GetIConsole()->GetCVar("ed_KeepEditorActive");
if (m_edKeepEditorActive)
{
m_keepEditorActive = m_edKeepEditorActive->GetIVal();
m_edKeepEditorActive->Set(1);
}
}
}
EditorKeepAlive::~EditorKeepAlive()
{
if (m_edKeepEditorActive)
{
m_edKeepEditorActive->Set(m_keepEditorActive);
}
}
Model::Model()
{
ModelRequestsBus::Handler::BusConnect();
@ -33,20 +61,58 @@ namespace ScriptCanvasEditor
ScriptCanvas::Grammar::g_saveRawTranslationOuputToFile = false;
}
const AZStd::vector<AZStd::string>* Model::GetLogs()
void Model::Idle()
{
return &m_log.GetEntries();
m_state = State::Idle;
m_keepEditorAlive.reset();
}
bool Model::IsReadyToModify() const
{
if (IsWorking())
{
return false;
}
if (!m_scanner)
{
return false;
}
return !m_scanner->GetResult().m_unfiltered.empty();
}
bool Model::IsWorking() const
{
return m_state != State::Idle;
}
void Model::Modify(const ModifyConfiguration& modification)
{
if (!IsReadyToModify())
{
AZ_Warning(ScriptCanvas::k_VersionExplorerWindow.data(), false, "Explorer is not ready to modify graphs.");
return;
}
m_state = State::Modifying;
m_keepEditorAlive = AZStd::make_unique<EditorKeepAlive>();
auto results = m_scanner->TakeResult();
m_modifier = AZStd::make_unique<Modifier>(modification, AZStd::move(results.m_unfiltered), [this](){ OnModificationComplete(); });
}
void Model::OnModificationComplete()
{
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnScanComplete, m_scanner->GetResult());
m_modifier.reset();
m_scanner.reset();
Idle();
}
void Model::OnScanComplete()
{
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnScanComplete, m_scanner->GetResult());
m_state = State::Idle;
Idle();
}
void Model::Scan(const ScanConfiguration& config)
@ -58,6 +124,7 @@ namespace ScriptCanvasEditor
}
m_state = State::Scanning;
m_keepEditorAlive = AZStd::make_unique<EditorKeepAlive>();
m_scanner = AZStd::make_unique<Scanner>(config, [this](){ OnScanComplete(); });
}

@ -15,10 +15,25 @@
#include <Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h>
#include <ScriptCanvas/Core/Core.h>
struct ICVar;
namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
//!Scoped utility to set and restore the "ed_KeepEditorActive" CVar in order to allow
//! the upgrade tool to work even if the editor is not in the foreground
class EditorKeepAlive
{
public:
EditorKeepAlive();
~EditorKeepAlive();
private:
int m_keepEditorActive;
ICVar* m_edKeepEditorActive;
};
//! Handles model change requests, state queries; sends state change notifications
class Model
: public ModelRequestsBus::Handler
@ -28,7 +43,8 @@ namespace ScriptCanvasEditor
Model();
const AZStd::vector<AZStd::string>* GetLogs();
void Modify(const ModifyConfiguration& modification) override;
void Scan(const ScanConfiguration& config) override;
private:
@ -45,9 +61,13 @@ namespace ScriptCanvasEditor
AZStd::unique_ptr<Modifier> m_modifier;
AZStd::unique_ptr<Scanner> m_scanner;
AZStd::unique_ptr<ScriptCanvas::Grammar::SettingsCache> m_settingsCache;
AZStd::unique_ptr<EditorKeepAlive> m_keepEditorAlive;
void CacheSettings();
void Idle();
bool IsReadyToModify() const;
bool IsWorking() const;
void OnModificationComplete();
void OnScanComplete();
void RestoreSettings();
};

@ -14,6 +14,12 @@ namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
struct ModifyConfiguration
{
AZStd::function<void(AZ::Data::Asset<AZ::Data::AssetData>)> modification;
bool backupGraphBeforeModification = false;
};
struct ScanConfiguration
{
AZStd::function<bool(AZ::Data::Asset<AZ::Data::AssetData>)> filter;
@ -24,11 +30,16 @@ namespace ScriptCanvasEditor
: public AZ::EBusTraits
{
public:
virtual const AZStd::vector<AZStd::string>* GetLogs() = 0;
virtual void Modify(const ModifyConfiguration& modification) = 0;
virtual void Scan(const ScanConfiguration& filter) = 0;
};
using ModelRequestsBus = AZ::EBus<ModelRequestsTraits>;
struct ModificationResult
{
};
struct ScanResult
{
AZStd::vector<AZ::Data::AssetInfo> m_catalogAssets;
@ -46,6 +57,11 @@ namespace ScriptCanvasEditor
virtual void OnScanFilteredGraph(const AZ::Data::AssetInfo& info) = 0;
virtual void OnScanLoadFailure(const AZ::Data::AssetInfo& info) = 0;
virtual void OnScanUnFilteredGraph(const AZ::Data::AssetInfo& info) = 0;
virtual void OnUpgradeAllBegin() = 0;
virtual void OnUpgradeAllComplete() = 0;
virtual void OnUpgradeAllDependencySortBegin() = 0;
virtual void OnUpgradeAllDependencySortEnd(const AZStd::vector<AZ::Data::AssetInfo>& sortedAssets) = 0;
};
using ModelNotificationsBus = AZ::EBus<ModelNotificationsTraits>;
}

@ -17,6 +17,19 @@ namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
Modifier::Modifier
( const ModifyConfiguration& modification
, AZStd::vector<AZ::Data::AssetInfo>&& assets
, AZStd::function<void()> onComplete)
{
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnUpgradeAllBegin);
AZ::SystemTickBus::Handler::BusConnect();
}
void Modifier::OnSystemTick()
{
}
}
}

@ -9,15 +9,31 @@
#pragma once
#include <ScriptCanvas/Core/Core.h>
#include <Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h>
#include <AzCore/Component/TickBus.h>
namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
class Modifier
: private AZ::SystemTickBus::Handler
{
public:
AZ_CLASS_ALLOCATOR(Modifier, AZ::SystemAllocator, 0);
Modifier
( const ModifyConfiguration& modification
, AZStd::vector<AZ::Data::AssetInfo>&& assets
, AZStd::function<void()> onComplete);
private:
size_t m_assetIndex = 0;
AZStd::function<void()> m_onComplete;
ModifyConfiguration m_config;
ModifyConfiguration m_result;
void OnSystemTick() override;
};
}
}

@ -8,11 +8,7 @@
#include <Editor/View/Windows/Tools/UpgradeTool/Scanner.h>
#include <ScriptCanvas/Assets/ScriptCanvasAsset.h>
namespace ScannerCpp
{
}
#include <Editor/View/Windows/Tools/UpgradeTool/LogTraits.h>
namespace ScriptCanvasEditor
{
@ -42,11 +38,13 @@ namespace ScriptCanvasEditor
{
if (m_config.filter && m_config.filter(asset))
{
VE_LOG("Scanner: Excluded: %s ", GetCurrentAsset().m_relativePath.c_str());
m_result.m_filteredAssets.push_back(GetCurrentAsset());
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnScanFilteredGraph, GetCurrentAsset());
}
else
{
VE_LOG("Scanner: Included: %s ", GetCurrentAsset().m_relativePath.c_str());
m_result.m_unfiltered.push_back(GetCurrentAsset());
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnScanUnFilteredGraph, GetCurrentAsset());
}
@ -69,7 +67,6 @@ namespace ScriptCanvasEditor
, azrtti_typeid<ScriptCanvasAsset>()
, AZ::Data::AssetLoadBehavior::PreLoad);
// Log("Scan: Loading: %s ", m_catalogAssets[m_catalogAssetIndex].GetHint().c_str());
asset.BlockUntilLoadComplete();
if (asset.IsReady())
@ -86,7 +83,9 @@ namespace ScriptCanvasEditor
{
if (m_catalogAssetIndex == m_result.m_catalogAssets.size())
{
AZ::SystemTickBus::Handler::BusConnect();
VE_LOG("Scanner: Complete.");
AZ::SystemTickBus::Handler::BusDisconnect();
if (m_onComplete)
{
m_onComplete();
@ -96,14 +95,17 @@ namespace ScriptCanvasEditor
{
if (auto asset = LoadAsset())
{
VE_LOG("Scanner: Loaded: %s ", GetCurrentAsset().m_relativePath.c_str());
FilterAsset(asset);
}
else
{
VE_LOG("Scanner: Failed to load: %s ", GetCurrentAsset().m_relativePath.c_str());
m_result.m_loadErrors.push_back(GetCurrentAsset());
ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnScanLoadFailure, GetCurrentAsset());
}
VE_LOG("Scanner: scan of %s complete", GetCurrentAsset().m_relativePath.c_str());
++m_catalogAssetIndex;
}
}

@ -20,20 +20,12 @@ namespace ScriptCanvasEditor
void Log::Activate()
{
AZ::Debug::TraceMessageBus::Handler::BusConnect();
LogBus::Handler::BusConnect();
}
void Log::AddEntry(const char* format, ...)
void Log::Clear()
{
if (m_isVerbose)
{
char sBuffer[2048];
va_list ArgList;
va_start(ArgList, format);
azvsnprintf(sBuffer, sizeof(sBuffer), format, ArgList);
sBuffer[sizeof(sBuffer) - 1] = '\0';
va_end(ArgList);
AZ_TracePrintf(ScriptCanvas::k_VersionExplorerWindow.data(), "%s\n", sBuffer);
}
m_logs.clear();
}
bool Log::CaptureFromTraceBus(const char* window, const char* message)
@ -58,9 +50,23 @@ namespace ScriptCanvasEditor
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
}
const AZStd::vector<AZStd::string>& Log::GetEntries() const
void Log::Entry(const char* format, ...)
{
if (m_isVerbose)
{
char sBuffer[2048];
va_list ArgList;
va_start(ArgList, format);
azvsnprintf(sBuffer, sizeof(sBuffer), format, ArgList);
sBuffer[sizeof(sBuffer) - 1] = '\0';
va_end(ArgList);
AZ_TracePrintf(ScriptCanvas::k_VersionExplorerWindow.data(), "%s\n", sBuffer);
}
}
const AZStd::vector<AZStd::string>* Log::GetEntries() const
{
return m_logs;
return &m_logs;
}
void Log::SetVersionExporerExclusivity(bool enabled)

@ -10,6 +10,7 @@
#include <ScriptCanvas/Core/Core.h>
#include <AzCore/Debug/TraceMessageBus.h>
#include <Editor/View/Windows/Tools/UpgradeTool/LogTraits.h>
namespace ScriptCanvasEditor
{
@ -17,16 +18,18 @@ namespace ScriptCanvasEditor
{
class Log
: private AZ::Debug::TraceMessageBus::Handler
, private LogBus::Handler
{
public:
AZ_CLASS_ALLOCATOR(Log, AZ::SystemAllocator, 0);
void Activate();
void AddEntry(const char* format, ...);
void Activate() override;
void Clear() override;
void Deactivate();
const AZStd::vector<AZStd::string>& GetEntries() const;
void SetVersionExporerExclusivity(bool enabled);
void SetVerbose(bool verbosity);
void Entry(const char* format, ...) override;
const AZStd::vector<AZStd::string>* GetEntries() const override;
void SetVersionExporerExclusivity(bool enabled) override;
void SetVerbose(bool verbosity) override;
private:
bool m_isExclusiveReportingEnabled = false;

@ -1,18 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace ScriptCanvasEditor
{
namespace VersionExplorer
{
}
}

@ -259,24 +259,24 @@ set(FILES
Editor/View/Windows/ScriptCanvasContextMenus.cpp
Editor/View/Windows/ScriptCanvasContextMenus.h
Editor/View/Windows/ScriptCanvasEditorResources.qrc
Editor/View/Windows/Tools/UpgradeTool/Controller.cpp
Editor/View/Windows/Tools/UpgradeTool/Controller.h
Editor/View/Windows/Tools/UpgradeTool/Controller.ui
Editor/View/Windows/Tools/UpgradeTool/FileSaver.cpp
Editor/View/Windows/Tools/UpgradeTool/FileSaver.h
Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp
Editor/View/Windows/Tools/UpgradeTool/Modifier.h
Editor/View/Windows/Tools/UpgradeTool/LogTraits.h
Editor/View/Windows/Tools/UpgradeTool/Model.cpp
Editor/View/Windows/Tools/UpgradeTool/Model.h
Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp
Editor/View/Windows/Tools/UpgradeTool/Modifier.h
Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h
Editor/View/Windows/Tools/UpgradeTool/Scanner.cpp
Editor/View/Windows/Tools/UpgradeTool/Scanner.h
Editor/View/Windows/Tools/UpgradeTool/UpgradeHelper.cpp
Editor/View/Windows/Tools/UpgradeTool/UpgradeHelper.h
Editor/View/Windows/Tools/UpgradeTool/UpgradeHelper.ui
Editor/View/Windows/Tools/UpgradeTool/Controller.cpp
Editor/View/Windows/Tools/UpgradeTool/Controller.h
Editor/View/Windows/Tools/UpgradeTool/View.ui
Editor/View/Windows/Tools/UpgradeTool/ViewTraits.h
Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.cpp
Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h
Editor/View/Windows/Tools/UpgradeTool/UpgradeHelper.h
Editor/Framework/ScriptCanvasGraphUtilities.inl
Editor/Framework/ScriptCanvasGraphUtilities.h
Editor/Framework/ScriptCanvasTraceUtilities.h

Loading…
Cancel
Save