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>
237 lines
7.5 KiB
C++
237 lines
7.5 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/BundleFileListModel.h>
|
|
|
|
#include <AzFramework/IO/LocalFileIO.h>
|
|
#include <AzToolsFramework/AssetBundle/AssetBundleComponent.h>
|
|
|
|
#include <source/utils/utils.h>
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
namespace AssetBundler
|
|
{
|
|
BundleFileInfo::BundleFileInfo(const AZStd::string& absolutePath)
|
|
: m_absolutePath(absolutePath)
|
|
, m_compressedSize(0u)
|
|
{
|
|
AzFramework::StringFunc::Path::Normalize(m_absolutePath);
|
|
|
|
AZStd::string fileNameStr;
|
|
if (AzFramework::StringFunc::Path::GetFileName(m_absolutePath.c_str(), fileNameStr))
|
|
{
|
|
m_fileName = QString(fileNameStr.c_str());
|
|
}
|
|
else
|
|
{
|
|
AZ_Error("AssetBundler", false, "Failed to get file name from %s", m_absolutePath.c_str());
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
BundleFileListModel::BundleFileListModel()
|
|
: AssetBundlerAbstractFileTableModel()
|
|
{
|
|
}
|
|
|
|
bool BundleFileListModel::DeleteFile(const QModelIndex& index)
|
|
{
|
|
AZStd::string fileKey = GetFileKey(index);
|
|
if (fileKey.empty())
|
|
{
|
|
// Error has already been thrown
|
|
return false;
|
|
}
|
|
|
|
auto bundleFileInfoIt = m_bundleFileInfoMap.find(fileKey);
|
|
if (bundleFileInfoIt == m_bundleFileInfoMap.end())
|
|
{
|
|
AZ_Error(AssetBundler::AppWindowName, false, "Unable to find Bundle Info with key ( %s )", fileKey.c_str());
|
|
return false;
|
|
}
|
|
|
|
BundleFileInfoPtr bundleFileInfo = bundleFileInfoIt->second;
|
|
|
|
// Remove file from disk
|
|
const char* absolutePath = bundleFileInfo->m_absolutePath.c_str();
|
|
if (AZ::IO::FileIOBase::GetInstance()->Exists(absolutePath))
|
|
{
|
|
if (AZ::IO::FileIOBase::GetInstance()->IsReadOnly(absolutePath))
|
|
{
|
|
AZ_Error(AssetBundler::AppWindowName, false, "File (%s) is Read-Only. Please check your version control and try again.", absolutePath);
|
|
return false;
|
|
}
|
|
|
|
auto deleteResult = AZ::IO::FileIOBase::GetInstance()->Remove(absolutePath);
|
|
if (!deleteResult)
|
|
{
|
|
AZ_Error(AssetBundler::AppWindowName, false, "Unable to delete: %s", absolutePath);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Remove file from Model
|
|
m_bundleFileInfoMap.erase(fileKey);
|
|
RemoveFileKey(index);
|
|
|
|
return true;
|
|
}
|
|
|
|
int BundleFileListModel::columnCount(const QModelIndex& parent) const
|
|
{
|
|
return parent.isValid() ? 0 : Column::Max;
|
|
}
|
|
|
|
QVariant BundleFileListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
|
{
|
|
switch (section)
|
|
{
|
|
case Column::ColumnFileName:
|
|
return QString(tr("Name"));
|
|
case Column::ColumnFileCreationTime:
|
|
return QString(tr("Creation Time"));
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
QVariant BundleFileListModel::data(const QModelIndex& index, int role) const
|
|
{
|
|
auto bundleInfoOutcome = GetBundleInfo(index);
|
|
if (!bundleInfoOutcome.IsSuccess())
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
int col = index.column();
|
|
|
|
switch (role)
|
|
{
|
|
case Qt::DisplayRole:
|
|
[[fallthrough]];
|
|
case SortRole:
|
|
{
|
|
if (col == Column::ColumnFileName)
|
|
{
|
|
return bundleInfoOutcome.GetValue()->m_fileName;
|
|
}
|
|
else if (col == Column::ColumnFileCreationTime)
|
|
{
|
|
if (role == SortRole)
|
|
{
|
|
return bundleInfoOutcome.GetValue()->m_fileCreationTime;
|
|
}
|
|
else
|
|
{
|
|
return bundleInfoOutcome.GetValue()->m_fileCreationTime.toString(DateTimeFormat);
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
AZStd::string BundleFileListModel::GetFileAbsolutePath(const QModelIndex& index) const
|
|
{
|
|
AZStd::string key = GetFileKey(index);
|
|
if (key.empty())
|
|
{
|
|
// Error has already been thrown
|
|
return key;
|
|
}
|
|
|
|
return m_bundleFileInfoMap.at(key)->m_absolutePath;
|
|
}
|
|
|
|
int BundleFileListModel::GetFileNameColumnIndex() const
|
|
{
|
|
return Column::ColumnFileName;
|
|
}
|
|
|
|
int BundleFileListModel::GetTimeStampColumnIndex() const
|
|
{
|
|
return Column::ColumnFileCreationTime;
|
|
}
|
|
|
|
void BundleFileListModel::LoadFile(const AZStd::string& absoluteFilePath, const AZStd::string& /*projectName*/, bool /*isDefaultFile*/)
|
|
{
|
|
AZStd::string key = AssetBundler::GenerateKeyFromAbsolutePath(absoluteFilePath);
|
|
|
|
BundleFileInfo* newInfo = new BundleFileInfo(absoluteFilePath);
|
|
|
|
QFile bundleFile(absoluteFilePath.c_str());
|
|
if (bundleFile.open(QIODevice::ReadOnly))
|
|
{
|
|
newInfo->m_compressedSize = bundleFile.size();
|
|
bundleFile.close();
|
|
}
|
|
else
|
|
{
|
|
AZ_Error("AssetBundler", false, "Failed to open file at %s", absoluteFilePath.c_str());
|
|
}
|
|
|
|
auto manifest = AzToolsFramework::AssetBundleComponent::GetManifestFromBundle(absoluteFilePath);
|
|
if (manifest != nullptr)
|
|
{
|
|
for (auto& bundleName : manifest->GetDependentBundleNames())
|
|
{
|
|
newInfo->m_relatedBundles.push_back(bundleName.c_str());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AZ_Error("AssetBundler", false, "Failed to get manifest from bundle at %s", absoluteFilePath.c_str());
|
|
}
|
|
|
|
m_bundleFileInfoMap[key].reset(newInfo);
|
|
// Add it to the list that gets displayed by AssetBundlerAbstractFileTableModel. Make sure that
|
|
// AddFileKey is called after m_bundleFileInfoMap is reset since the filterAcceptsRow funtion
|
|
// of the filter model will be called when a new row is inserted and it could cause a crash
|
|
// without valid data being set
|
|
AddFileKey(key);
|
|
}
|
|
|
|
AZ::Outcome<BundleFileInfoPtr, void> BundleFileListModel::GetBundleInfo(const QModelIndex& index) const
|
|
{
|
|
AZStd::string key = GetFileKey(index);
|
|
if (key.empty())
|
|
{
|
|
// Error has already been thrown
|
|
return AZ::Failure();
|
|
}
|
|
|
|
if (m_bundleFileInfoMap.find(key) != m_bundleFileInfoMap.end())
|
|
{
|
|
return AZ::Success(m_bundleFileInfoMap.at(key));
|
|
}
|
|
else
|
|
{
|
|
AZ_Error(AssetBundler::AppWindowName, false, "Cannot find Bundle File Info");
|
|
return AZ::Failure();
|
|
}
|
|
}
|
|
|
|
}
|