Files
o3de/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Util/Util.cpp
T
lumberyard-employee-dm 5fc4551ac0 [LYN-8041] Enable relocation of the Project Game Release Layout (#5380)
* Enable relocation of the Project Game Release Layout

Relocating the Project Game Release Layout to another directory on the file system failed due to the querying of the engine root failing due to the ComponentApplication::m_engineRoot not using the project path stored in the SettingsRegisry if the engine root cannot be detected

Removed the ApplicationRequestBus GetEngineRoot function.
The ComponentApplicationRequestBus has a function of the same name that returns the same path.

Removed the deprecated GetAppRoot function.
The path it returns has no defined value. It was not the engine root or the project root.
Removed unused CFileUtil and CFileUtil_impl functions that were invoking the ApplicationREquestBus GetEngineRoot function.
On the way to update the functions it was discovered that they aren't called

Added a CalculateBranchToken overload that can populate a fixed_string to avoid heap allocations

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Protect against an empty list of artifacts to remove when generating the
engine.pak

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-11-09 12:03:52 -06:00

145 lines
5.1 KiB
C++

/*
* 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
*
*/
#include <AtomToolsFramework/Util/Util.h>
#include <AzCore/IO/SystemFile.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzCore/Utils/Utils.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzQtComponents/Components/Widgets/FileDialog.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QApplication>
#include <QMessageBox>
#include <QProcess>
AZ_POP_DISABLE_WARNING
namespace AtomToolsFramework
{
QFileInfo GetSaveFileInfo(const QString& initialPath)
{
const QFileInfo initialFileInfo(initialPath);
const QString initialExt(initialFileInfo.completeSuffix());
const QFileInfo selectedFileInfo(AzQtComponents::FileDialog::GetSaveFileName(
QApplication::activeWindow(),
"Save File",
initialFileInfo.absolutePath() +
AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING +
initialFileInfo.baseName(),
QString("Files (*.%1)").arg(initialExt)));
if (selectedFileInfo.absoluteFilePath().isEmpty())
{
// Cancelled operation
return QFileInfo();
}
if (!selectedFileInfo.absoluteFilePath().endsWith(initialExt))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("File name must have .%1 extension.").arg(initialExt));
return QFileInfo();
}
return selectedFileInfo;
}
QFileInfo GetOpenFileInfo(const AZStd::vector<AZ::Data::AssetType>& assetTypes)
{
using namespace AZ::Data;
using namespace AzToolsFramework::AssetBrowser;
// [GFX TODO] Should this just be an open file dialog filtered to supported source data extensions?
auto selection = AssetSelectionModel::AssetTypesSelection(assetTypes);
// [GFX TODO] This is functional but UI is not as designed
AssetBrowserComponentRequestBus::Broadcast(&AssetBrowserComponentRequests::PickAssets, selection, QApplication::activeWindow());
if (!selection.IsValid())
{
return QFileInfo();
}
auto entry = selection.GetResult();
const SourceAssetBrowserEntry* sourceEntry = azrtti_cast<const SourceAssetBrowserEntry*>(entry);
if (!sourceEntry)
{
const ProductAssetBrowserEntry* productEntry = azrtti_cast<const ProductAssetBrowserEntry*>(entry);
if (productEntry)
{
sourceEntry = azrtti_cast<const SourceAssetBrowserEntry*>(productEntry->GetParent());
}
}
if (!sourceEntry)
{
return QFileInfo();
}
return QFileInfo(sourceEntry->GetFullPath().c_str());
}
QFileInfo GetUniqueFileInfo(const QString& initialPath)
{
int counter = 0;
QFileInfo fileInfo = initialPath;
const QString extension = "." + fileInfo.completeSuffix();
const QString basePathAndName = fileInfo.absoluteFilePath().left(fileInfo.absoluteFilePath().size() - extension.size());
while (fileInfo.exists())
{
fileInfo = QString("%1_%2%3").arg(basePathAndName).arg(++counter).arg(extension);
}
return fileInfo;
}
QFileInfo GetDuplicationFileInfo(const QString& initialPath)
{
const QFileInfo initialFileInfo(initialPath);
const QString initialExt(initialFileInfo.completeSuffix());
const QFileInfo duplicateFileInfo(AzQtComponents::FileDialog::GetSaveFileName(
QApplication::activeWindow(),
"Duplicate File",
GetUniqueFileInfo(initialPath).absoluteFilePath(),
QString("Files (*.%1)").arg(initialExt)));
if (duplicateFileInfo == initialFileInfo)
{
// Cancelled operation or selected same path
return QFileInfo();
}
if (duplicateFileInfo.absoluteFilePath().isEmpty())
{
// Cancelled operation or selected same path
return QFileInfo();
}
if (!duplicateFileInfo.absoluteFilePath().endsWith(initialExt))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("File name must have .%1 extension.").arg(initialExt));
return QFileInfo();
}
return duplicateFileInfo;
}
bool LaunchTool(const QString& baseName, const QString& extension, const QStringList& arguments)
{
AZ::IO::FixedMaxPath engineRoot = AZ::Utils::GetEnginePath();
AZ_Assert(!engineRoot.empty(), "Cannot query Engine Path");
AZ::IO::FixedMaxPath launchPath = AZ::IO::FixedMaxPath(AZ::Utils::GetExecutableDirectory())
/ (baseName + extension).toUtf8().constData();
return QProcess::startDetached(launchPath.c_str(), arguments, engineRoot.c_str());
}
}