diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.cpp index 4b2d3d37b9..44d6f2e738 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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,24 +59,32 @@ namespace ScriptCanvasEditor m_view->progressBar->setVisible(false); ModelNotificationsBus::Handler::BusConnect(); - - // move to model, maybe - m_keepEditorAlive = AZStd::make_unique(); } - void Controller::Log(const char* /*format*/, ...) + void Controller::AddLogEntries() { -// 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); -// } + const AZStd::vector* logs = nullptr; + LogBus::BroadcastResult(logs, &LogTraits::GetEntries); + if (!logs || 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(); + + for (auto& entry : *logs) + { + auto line = "\n" + entry; + textCursor.insertText(line.c_str()); + } + + scrollBar->setValue(scrollBar->maximum()); + m_view->textEdit->moveCursor(QTextCursor::StartOfLine); + LogBus::Broadcast(&LogTraits::Clear); } void Controller::OnCloseButtonPress() @@ -105,557 +92,10 @@ namespace ScriptCanvasEditor 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(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(m_currentAssetRowIndex), static_cast(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 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 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(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::g_saveRawTranslationOuputToFile = false; - ScriptCanvas::Grammar::g_printAbstractCodeModel = false; - ScriptCanvas::Grammar::g_saveRawTranslationOuputToFile = false; - AZ::Interface::Get()->SetIsUpgrading(true); - AZ::Interface::Get()->ClearGraphsThatNeedUpgrade(); - m_inProgressAsset = m_assetsToUpgrade.begin(); - AZ::SystemTickBus::Handler::BusConnect(); - m_view->progressBar->setVisible(true); - m_view->progressBar->setRange(0, aznumeric_cast(m_assetsToUpgrade.size())); - m_view->progressBar->setValue(m_upgradeAssetIndex); - m_keepEditorAlive = AZStd::make_unique(); - } - - AZStd::string Controller::BackupGraph(const AZ::Data::Asset& 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& asset) - { - 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* scriptCanvasAsset = asset.GetAs(); - AZ_Assert(scriptCanvasAsset, "Unable to get the asset of ScriptCanvasAsset, but received type: %s" - , azrtti_typeid().template ToString().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(); - 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& 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::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 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()) - { - 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 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::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::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::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 asset, OperationResult result, AZStd::string_view message) - { - AZStd::lock_guard 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"); - - 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()); - } - } - - if (m_upgradeResult == OperationResult::Failure) - { - AZ::Interface::Get()->GraphNeedsManualUpgrade(asset.GetId()); - } - - m_tmpFileName.clear(); - } - - void Controller::GraphUpgradeCompleteUIUpdate - (const AZ::Data::Asset asset, OperationResult result, AZStd::string_view message) - { - QString text = asset.GetHint().c_str(); - QList 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); - } - } - } - } - - void Controller::FinalizeUpgrade() - { - 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::Get()->GetGraphsThatNeedManualUpgrade().size(); - if (assetsThatNeedManualInspection > 0) - { - m_view->spinner->SetText("Some graphs will require manual corrections, you will be prompted to review them upon closing this dialog"); - } - else - { - m_view->spinner->SetText("Upgrade complete."); - } - - AZ::SystemTickBus::Handler::BusDisconnect(); - AZ::Interface::Get()->SetIsUpgrading(false); - //m_settingsCache.reset(); - } - void Controller::OnScanButtonPress() { auto isUpToDate = [this](AZ::Data::Asset asset) { - Log("InspectAsset: %s", asset.GetHint().c_str()); AZ::Entity* scriptCanvasEntity = nullptr; if (asset.GetType() == azrtti_typeid()) @@ -663,7 +103,11 @@ namespace ScriptCanvasEditor ScriptCanvasAsset* scriptCanvasAsset = asset.GetAs(); 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(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(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(m_currentAssetRowIndex), static_cast(ColumnAsset), rowName); OnScannedGraphResult(info); } @@ -819,141 +258,92 @@ namespace ScriptCanvasEditor OnScannedGraph(info, Filtered::No); } - void Controller::BackupComplete() + void Controller::OnUpgradeAllButtonPress() + { + auto simpleUpdate = [this](AZ::Data::Asset asset) + { + if (asset.GetType() == azrtti_typeid()) + { + ScriptCanvasAsset* scriptCanvasAsset = asset.GetAs(); + AZ_Assert(scriptCanvasAsset, "Unable to get the asset of ScriptCanvasAsset, but received type: %s" + , azrtti_typeid().template ToString().c_str()); + if (!scriptCanvasAsset) + { + return; + } + + AZ::Entity* scriptCanvasEntity = scriptCanvasAsset->GetScriptCanvasEntity(); + AZ_Assert(scriptCanvasEntity, "View::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(); + 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()); + } + } + }; + + ModifyConfiguration config; + config.modification = simpleUpdate; + config.backupGraphBeforeModification = m_view->makeBackupCheckbox->isChecked(); + ModelRequestsBus::Broadcast(&ModelRequestsTraits::Modify, config); + } + + void Controller::OnUpgradeAllBegin() { 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); } - void Controller::UpgradeSingle - ( QPushButton* rowGoToButton - , AzQtComponents::StyledBusyLabel* spinner - , AZ::Data::AssetInfo assetInfo) + void Controller::OnUpgradeAllComplete() { - AZ::Data::Asset asset = AZ::Data::AssetManager::Instance().GetAsset - (assetInfo.m_assetId, assetInfo.m_assetType, AZ::Data::AssetLoadBehavior::PreLoad); - - if (asset) - { - asset.BlockUntilLoadComplete(); - - if (asset.IsReady()) - { - AZ::Interface::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) - { - return assetToUpgrade.GetId() == asset.GetId(); - }); - - m_state = ProcessState::Upgrade; - AZ::SystemTickBus::Handler::BusConnect(); - } - } - } - - void Controller::ScanComplete(const AZ::Data::Asset& asset) - { - Log("ScanComplete: %s", asset.GetHint().c_str()); - m_inProgress = false; - m_view->progressBar->setValue(aznumeric_cast(m_currentAssetRowIndex)); - m_view->scanButton->setEnabled(true); - - m_inspectingAsset = m_assetsToInspect.erase(m_inspectingAsset); - - if (m_inspectingAsset == m_assetsToInspect.end()) - { - AZ::SystemTickBus::QueueFunction([this]() { FinalizeScan(); }); - - if (!m_assetsToUpgrade.empty()) - { - m_view->upgradeAllButton->setEnabled(true); - } - } - } - - void Controller::FinalizeScan() - { - Log("FinalizeScan()"); - - m_view->spinner->SetIsBusy(false); - m_view->onlyShowOutdated->setEnabled(true); - - // Enable all the Upgrade buttons - for (int row = 0; row < m_view->tableWidget->rowCount(); ++row) - { - QPushButton* button = qobject_cast(m_view->tableWidget->cellWidget(row, ColumnAction)); - if (button) - { - button->setEnabled(true); - } - } - - 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; - } - - void Controller::FlushLogs() - { - 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_logs.pop_front(); - - textCursor.insertText(line.c_str()); - } - - scrollBar->setValue(scrollBar->maximum()); - m_view->textEdit->moveCursor(QTextCursor::StartOfLine); } - void Controller::closeEvent(QCloseEvent* event) + void Controller::OnUpgradeAllDependencySortBegin() { - m_keepEditorAlive.reset(); - AzQtComponents::StyledDialog::closeEvent(event); + } + + void Controller::OnUpgradeAllDependencySortEnd(const AZStd::vector& sortedAssets) + { + m_view->progressBar->setRange(0, aznumeric_cast(sortedAssets.size())); } } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.h index 85459b4d46..f7a0315730 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Controller.h @@ -10,12 +10,9 @@ #if !defined(Q_MOC_RUN) #include -#include #include #include #include -#include -#include #include #include #include @@ -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 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&); - - // SystemTickBus::Handler - void OnSystemTick() override; - - enum class OperationResult - { - Success, - Failure, - }; - - void GraphUpgradeComplete(const AZ::Data::Asset, 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>; - UpgradeAssets m_assetsToUpgrade; - UpgradeAssets::iterator m_inProgressAsset; - - AZ::Data::Asset m_currentAsset; - - AZStd::unique_ptr m_view; - // upgrade fields - AZStd::recursive_mutex m_mutex; - bool m_upgradeComplete = false; - AZ::Data::Asset m_upgradeAsset; - int m_upgradeAssetIndex = 0; - OperationResult m_upgradeResult; - AZStd::string m_upgradeMessage; - AZStd::string m_tmpFileName; - - AZStd::unique_ptr m_keepEditorAlive; - - AZStd::deque 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&); - void UpgradeGraph(const AZ::Data::Asset&); - - void GraphUpgradeCompleteUIUpdate(const AZ::Data::Asset asset, OperationResult result, AZStd::string_view message); - void OnGraphUpgradeComplete(AZ::Data::Asset&, bool skipped = false) override; - - void OnSourceFileReleased(AZ::Data::Asset asset); - - void closeEvent(QCloseEvent* event) override; - - bool m_overwriteAll = false; - void PerformMove(AZ::Data::Asset 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& sortedAssets) override; }; } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/LogTraits.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/LogTraits.h new file mode 100644 index 0000000000..c75133f09e --- /dev/null +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/LogTraits.h @@ -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 + +#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* GetEntries() const = 0; + virtual void SetVersionExporerExclusivity(bool enabled) = 0; + virtual void SetVerbose(bool verbosity) = 0; + }; + using LogBus = AZ::EBus; + } +} diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.cpp index 8d5aa62674..ad9d39cb98 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.cpp @@ -7,8 +7,11 @@ */ #include -#include +#include #include +#include +#include +#include #include 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* 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(); + auto results = m_scanner->TakeResult(); + m_modifier = AZStd::make_unique(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(); m_scanner = AZStd::make_unique(config, [this](){ OnScanComplete(); }); } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.h index 407074fa94..72ab210e37 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Model.h @@ -15,10 +15,25 @@ #include #include +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* GetLogs(); + void Modify(const ModifyConfiguration& modification) override; + void Scan(const ScanConfiguration& config) override; private: @@ -45,9 +61,13 @@ namespace ScriptCanvasEditor AZStd::unique_ptr m_modifier; AZStd::unique_ptr m_scanner; AZStd::unique_ptr m_settingsCache; + AZStd::unique_ptr m_keepEditorAlive; void CacheSettings(); + void Idle(); + bool IsReadyToModify() const; bool IsWorking() const; + void OnModificationComplete(); void OnScanComplete(); void RestoreSettings(); }; diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h index 11a956c555..d48c15949a 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ModelTraits.h @@ -14,6 +14,12 @@ namespace ScriptCanvasEditor { namespace VersionExplorer { + struct ModifyConfiguration + { + AZStd::function)> modification; + bool backupGraphBeforeModification = false; + }; + struct ScanConfiguration { AZStd::function)> filter; @@ -24,11 +30,16 @@ namespace ScriptCanvasEditor : public AZ::EBusTraits { public: - virtual const AZStd::vector* GetLogs() = 0; + virtual void Modify(const ModifyConfiguration& modification) = 0; virtual void Scan(const ScanConfiguration& filter) = 0; }; using ModelRequestsBus = AZ::EBus; + struct ModificationResult + { + + }; + struct ScanResult { AZStd::vector 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& sortedAssets) = 0; }; using ModelNotificationsBus = AZ::EBus; } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp index a0067e1a5f..d782ebd572 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.cpp @@ -17,6 +17,19 @@ namespace ScriptCanvasEditor { namespace VersionExplorer { + Modifier::Modifier + ( const ModifyConfiguration& modification + , AZStd::vector&& assets + , AZStd::function onComplete) + { + ModelNotificationsBus::Broadcast(&ModelNotificationsTraits::OnUpgradeAllBegin); + AZ::SystemTickBus::Handler::BusConnect(); + } + + void Modifier::OnSystemTick() + { + + } } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.h index e5a40ff096..d391f51bf7 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Modifier.h @@ -9,15 +9,31 @@ #pragma once #include +#include +#include namespace ScriptCanvasEditor { namespace VersionExplorer { class Modifier + : private AZ::SystemTickBus::Handler { public: AZ_CLASS_ALLOCATOR(Modifier, AZ::SystemAllocator, 0); + + Modifier + ( const ModifyConfiguration& modification + , AZStd::vector&& assets + , AZStd::function onComplete); + + private: + size_t m_assetIndex = 0; + AZStd::function m_onComplete; + ModifyConfiguration m_config; + ModifyConfiguration m_result; + + void OnSystemTick() override; }; } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Scanner.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Scanner.cpp index 09574883b6..26765a9f97 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Scanner.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/Scanner.cpp @@ -8,11 +8,7 @@ #include #include - -namespace ScannerCpp -{ - -} +#include 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() , 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; } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.cpp b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.cpp index be4b619bfd..6f856b9d4c 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.cpp @@ -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& Log::GetEntries() const + void Log::Entry(const char* format, ...) { - return m_logs; + 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* Log::GetEntries() const + { + return &m_logs; } void Log::SetVersionExporerExclusivity(bool enabled) diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h index 1ba8e8c9b1..7399b085da 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h +++ b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/VersionExplorerLog.h @@ -10,6 +10,7 @@ #include #include +#include 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& GetEntries() const; - void SetVersionExporerExclusivity(bool enabled); - void SetVerbose(bool verbosity); + void Entry(const char* format, ...) override; + const AZStd::vector* GetEntries() const override; + void SetVersionExporerExclusivity(bool enabled) override; + void SetVerbose(bool verbosity) override; private: bool m_isExclusiveReportingEnabled = false; diff --git a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ViewTraits.h b/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ViewTraits.h deleted file mode 100644 index cf49072230..0000000000 --- a/Gems/ScriptCanvas/Code/Editor/View/Windows/Tools/UpgradeTool/ViewTraits.h +++ /dev/null @@ -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 - -namespace ScriptCanvasEditor -{ - namespace VersionExplorer - { - - } -} diff --git a/Gems/ScriptCanvas/Code/scriptcanvasgem_editor_files.cmake b/Gems/ScriptCanvas/Code/scriptcanvasgem_editor_files.cmake index 1ce2b0c502..b12c608fe5 100644 --- a/Gems/ScriptCanvas/Code/scriptcanvasgem_editor_files.cmake +++ b/Gems/ScriptCanvas/Code/scriptcanvasgem_editor_files.cmake @@ -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