a5d4eb5d44
The AssetBundler is a new ToolsApplication that allows users to work through the entire Asset Bundling process without ever touching a command line. * Integrating github/AssetBundler through commit 1d65018 * Asset Bundler bug fixes: platform initialization and GUI styling (#5) * fixed enabled platform initialization * fixed the cached engine root. This fixed some of my Seeds tab data issues. The default Engine Seed List appeared, and was able to display the contents on screen. * updated my notes of active bugs * changed some casing in various include lines to hopefully fix my linux build * another include fix for linux * AssetBundler GUI is now compiling on Mac * removed some things off of my todo list because the mac build fix actually fixed the visuals! everything's the right color again * removed the word Lumberyard from the bundler * Asset bundler bug fixes - Bundles, Gems, and Tests (#9) * Fixed the Bundle loading and generation problem. Turned out to be a FileWatcher issue. * turns out gem loading wasn't broken, there were just no existing SeedListFiles for any of the gems loaded by the AutomatedTesting project. I added a default SeedListFile for the PrimitiveAssets Gem. * fixed some failing AssetBundler Gem tests * Misunderstood the need to have default seed lists for asset-only gems. removing the previously created seed list file * Asset bundler bug fixes: Seeds Tab display issues and _dependencies.xml loading (#10) * Fixed the Project Source column in the Seeds tab * The AssetBundler will no longer attempt to copy a template version of the ProjectName_dependencies.xml file into your active project. However, it will throw an error if you do not have one. A follow-up ticket has been cut to address this issue. * updated the AssetBundler icon. This one matches the current style guides * PR feedback: pass a const ref instead of a value * PR feedback: safer conversion from a string_view to a QString Co-authored-by: alexpete <alexpete@amazon.com>
252 lines
8.3 KiB
C++
252 lines
8.3 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <source/models/AssetListFileTableModel.h>
|
|
#include <source/models/AssetListTableModel.h>
|
|
|
|
#include <source/utils/utils.h>
|
|
|
|
#include <AzCore/Outcome/Outcome.h>
|
|
#include <AzFramework/IO/LocalFileIO.h>
|
|
#include <AzFramework/Platform/PlatformDefaults.h>
|
|
#include <AzFramework/StringFunc/StringFunc.h>
|
|
#include <AzToolsFramework/Asset/AssetBundler.h>
|
|
|
|
#include <QFileInfo>
|
|
#include <QFont>
|
|
|
|
namespace AssetBundler
|
|
{
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// AssetListFileInfo
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AssetListFileInfo::AssetListFileInfo(const AZStd::string& absolutePath, const QString& fileName, const AZStd::string& platform)
|
|
: m_absolutePath(absolutePath)
|
|
, m_fileName(fileName)
|
|
, m_platform(QString(platform.c_str()))
|
|
{
|
|
AzFramework::StringFunc::Path::Normalize(m_absolutePath);
|
|
|
|
// Modification time will either give us the time the file was last overwritten
|
|
// (or the time it was created if it has never been overwritten)
|
|
QFileInfo fileInfo(m_absolutePath.c_str());
|
|
m_fileCreationTime = fileInfo.fileTime(QFileDevice::FileModificationTime);
|
|
|
|
// Load the contents of the asset list file into memory
|
|
m_assetListModel.reset(new AssetListTableModel(nullptr, absolutePath, platform));
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// AssetListFileTableModel
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AssetListFileTableModel::AssetListFileTableModel()
|
|
: AssetBundlerAbstractFileTableModel()
|
|
{
|
|
}
|
|
|
|
QSharedPointer<AssetListTableModel> AssetListFileTableModel::GetAssetListFileContents(const QModelIndex& index)
|
|
{
|
|
auto assetListFileInfoOutcome = GetAssetFileInfo(index);
|
|
if (!assetListFileInfoOutcome.IsSuccess())
|
|
{
|
|
return QSharedPointer<AssetListTableModel>();
|
|
}
|
|
|
|
return assetListFileInfoOutcome.GetValue()->m_assetListModel;
|
|
}
|
|
|
|
bool AssetListFileTableModel::DeleteFile(const QModelIndex& index)
|
|
{
|
|
auto assetFileInfoOutcome = GetAssetFileInfo(index);
|
|
if (!assetFileInfoOutcome.IsSuccess())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(assetFileInfoOutcome.GetValue()->m_absolutePath);
|
|
if (m_assetListFileInfoMap.find(key) == m_assetListFileInfoMap.end())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
AssetListFileInfoPtr assetFileInfo = m_assetListFileInfoMap[key];
|
|
|
|
// Remove file from disk
|
|
const char* absolutePath = assetFileInfo->m_absolutePath.c_str();
|
|
if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath))
|
|
{
|
|
if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(absolutePath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(absolutePath);
|
|
if (!deleteResult)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Remove file from model
|
|
m_assetListFileInfoMap.erase(key);
|
|
RemoveFileKey(index);
|
|
|
|
return true;
|
|
}
|
|
|
|
void AssetListFileTableModel::LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& /*projectName*/, bool /*isDefaultFile*/)
|
|
{
|
|
AZStd::string fullFileName;
|
|
AzFramework::StringFunc::Path::GetFullFileName(absoluteFilePath.c_str(), fullFileName);
|
|
|
|
// Get the file name without the platform for display purposes
|
|
AZStd::string baseFileName;
|
|
AZStd::string platformIdentifier;
|
|
AzToolsFramework::SplitFilename(fullFileName, baseFileName, platformIdentifier);
|
|
|
|
// Read the AssetListFile into memory and store it
|
|
AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath);
|
|
m_assetListFileInfoMap[key].reset(new AssetListFileInfo(absoluteFilePath, QString(baseFileName.c_str()), platformIdentifier));
|
|
AddFileKey(key);
|
|
}
|
|
|
|
bool AssetListFileTableModel::WriteToDisk(const AZStd::string& /*key*/)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
AZStd::string AssetListFileTableModel::GetFileAbsolutePath(const QModelIndex& index) const
|
|
{
|
|
auto assetFileInfoOutcome = GetAssetFileInfo(index);
|
|
if (!assetFileInfoOutcome.IsSuccess())
|
|
{
|
|
// Error has already been thrown
|
|
return AZStd::string();
|
|
}
|
|
return assetFileInfoOutcome.GetValue()->m_absolutePath;
|
|
}
|
|
|
|
int AssetListFileTableModel::GetFileNameColumnIndex() const
|
|
{
|
|
return Column::ColumnFileName;
|
|
}
|
|
|
|
int AssetListFileTableModel::GetTimeStampColumnIndex() const
|
|
{
|
|
return Column::ColumnFileCreationTime;
|
|
}
|
|
|
|
int AssetListFileTableModel::columnCount(const QModelIndex& parent) const
|
|
{
|
|
return parent.isValid() ? 0 : Column::Max;
|
|
}
|
|
|
|
QVariant AssetListFileTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
|
{
|
|
switch (section)
|
|
{
|
|
case Column::ColumnFileName:
|
|
return QString(tr("Asset List File"));
|
|
case Column::ColumnPlatform:
|
|
return QString(tr("Platform"));
|
|
case Column::ColumnFileCreationTime:
|
|
return QString(tr("Creation Time"));
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
QVariant AssetListFileTableModel::data(const QModelIndex& index, int role) const
|
|
{
|
|
auto assetListFileInfoOutcome = GetAssetFileInfo(index);
|
|
if (!assetListFileInfoOutcome.IsSuccess())
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
int col = index.column();
|
|
|
|
switch (role)
|
|
{
|
|
case Qt::DisplayRole:
|
|
[[fallthrough]];
|
|
case SortRole:
|
|
{
|
|
if (col == Column::ColumnFileName)
|
|
{
|
|
return assetListFileInfoOutcome.GetValue()->m_fileName;
|
|
}
|
|
else if (col == Column::ColumnPlatform)
|
|
{
|
|
return assetListFileInfoOutcome.GetValue()->m_platform;
|
|
}
|
|
else if (col == Column::ColumnFileCreationTime)
|
|
{
|
|
if (role == SortRole)
|
|
{
|
|
return assetListFileInfoOutcome.GetValue()->m_fileCreationTime;
|
|
}
|
|
else
|
|
{
|
|
return assetListFileInfoOutcome.GetValue()->m_fileCreationTime.toString(DateTimeFormat);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Returning an empty QString will ensure the checkboxes do not have any text displayed next to them
|
|
return QString();
|
|
}
|
|
}
|
|
case Qt::FontRole:
|
|
{
|
|
if (col == Column::ColumnFileName)
|
|
{
|
|
QFont boldFont;
|
|
boldFont.setBold(true);
|
|
return boldFont;
|
|
}
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
AZ::Outcome<AssetListFileInfoPtr, void> AssetListFileTableModel::GetAssetFileInfo(const QModelIndex& index) const
|
|
{
|
|
AZStd::string key = GetFileKey(index);
|
|
if (key.empty())
|
|
{
|
|
// Error has already been thrown
|
|
return AZ::Failure();
|
|
}
|
|
|
|
if (m_assetListFileInfoMap.find(key) != m_assetListFileInfoMap.end())
|
|
{
|
|
return AZ::Success(m_assetListFileInfoMap.at(key));
|
|
}
|
|
else
|
|
{
|
|
AZ_Error(AssetBundler::AppWindowName, false, "Cannot find Asset List File Info");
|
|
return AZ::Failure();
|
|
}
|
|
}
|
|
|
|
} // namespace AssetBundler
|