2
0

GUIApplicationManager.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <source/utils/applicationManager.h>
  11. #include <AzCore/Outcome/Outcome.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzFramework/Asset/AssetCatalog.h>
  14. #include <AzFramework/Platform/PlatformDefaults.h>
  15. #include <QCoreApplication>
  16. #include <QDir>
  17. #include <QMap>
  18. #include <QSettings>
  19. #include <QSharedPointer>
  20. #include <QString>
  21. #include <QFileSystemWatcher>
  22. #endif
  23. namespace AssetBundler
  24. {
  25. enum AssetBundlingFileType : int
  26. {
  27. SeedListFileType = 0,
  28. AssetListFileType,
  29. BundleSettingsFileType,
  30. BundleFileType,
  31. RulesFileType,
  32. NumBundlingFileTypes
  33. };
  34. class MainWindow;
  35. class GUIApplicationManager
  36. : public ApplicationManager
  37. {
  38. Q_OBJECT
  39. public:
  40. AZ_CLASS_ALLOCATOR(GUIApplicationManager, AZ::SystemAllocator)
  41. struct Config
  42. {
  43. // These default values are used if the values can't be read from AssetBundlerConfig.ini,
  44. // and the call to defaultConfig fails.
  45. // Error Log
  46. int logTypeColumnWidth = -1;
  47. int logSourceColumnWidth = -1;
  48. // General File Tables
  49. int fileTableWidth = -1;
  50. int fileNameColumnWidth = -1;
  51. // Seeds Tab
  52. int checkBoxColumnWidth = -1;
  53. int seedListFileNameColumnWidth = -1;
  54. int projectNameColumnWidth = -1;
  55. int seedListContentsNameColumnWidth = -1;
  56. // Asset Lists Tab
  57. int assetListFileNameColumnWidth = -1;
  58. int assetListPlatformColumnWidth = -1;
  59. int productAssetNameColumnWidth = -1;
  60. int productAssetRelativePathColumnWidth = -1;
  61. };
  62. /*!
  63. * Loads the button config data from a settings object.
  64. */
  65. static Config loadConfig(QSettings& settings);
  66. /*!
  67. * Returns default button config data.
  68. */
  69. static Config defaultConfig();
  70. explicit GUIApplicationManager(int* argc, char*** argv, QObject* parent = 0);
  71. virtual ~GUIApplicationManager();
  72. bool Init() override;
  73. bool Run() override;
  74. AZStd::string GetCurrentProjectFolder() { return m_currentProjectFolder; }
  75. AZStd::string GetAssetBundlingFolder() { return m_assetBundlingFolder; }
  76. AZStd::string GetSeedListsFolder() { return m_seedListsFolder; }
  77. AZStd::string GetAssetListsFolder() { return m_assetListsFolder; }
  78. AZStd::string GetRulesFolder() { return m_rulesFolder; }
  79. AZStd::string GetBundleSettingsFolder() { return m_bundleSettingsFolder; }
  80. AZStd::string GetBundlesFolder() { return m_bundlesFolder; }
  81. AZStd::string GetCurrentProjectCacheFolder() { return m_currentProjectCacheFolder; }
  82. AzFramework::PlatformFlags GetEnabledPlatforms() { return m_enabledPlatforms; }
  83. void AddWatchedPath(const QString& path);
  84. void AddWatchedPaths(const QSet<QString>& paths);
  85. void RemoveWatchedPath(const QString& path);
  86. void RemoveWatchedPaths(const QSet<QString>& paths);
  87. ////////////////////////////////////////////////////////////////////////////////////////////
  88. // Override the ApplicationManager TraceMessageBus methods so that messages go through MainWindow and not the CLI
  89. bool OnPreError(const char* window, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* message) override;
  90. bool OnPreWarning(const char* /*window*/, const char* /*fileName*/, int /*line*/, const char* /*func*/, const char* /*message*/) override;
  91. bool OnPrintf(const char* /*window*/, const char* /*message*/) override;
  92. ////////////////////////////////////////////////////////////////////////////////////////////
  93. const Config& GetConfig() { return m_config; }
  94. Q_SIGNALS:
  95. void ShowWindow();
  96. void UpdateTab(const AZStd::string& directory);
  97. void UpdateFiles(AssetBundlingFileType fileType, const AZStd::vector<AZStd::string>& absoluteFilePaths);
  98. protected Q_SLOTS:
  99. void DirectoryChanged(const QString& directory);
  100. void FileChanged(const QString& path);
  101. void ApplyConfig();
  102. private:
  103. /**
  104. * Generates directory information for all paths used in this tool
  105. * @return void on success, error message on failure
  106. */
  107. AZ::Outcome<void, AZStd::string> InitializePaths();
  108. QSharedPointer<QCoreApplication> m_qApp;
  109. Config m_config;
  110. QSharedPointer<MainWindow> m_mainWindow;
  111. AZStd::string m_currentProjectFolder;
  112. AZStd::string m_assetBundlingFolder;
  113. AZStd::string m_seedListsFolder;
  114. AZStd::string m_assetListsFolder;
  115. AZStd::string m_rulesFolder;
  116. AZStd::string m_bundleSettingsFolder;
  117. AZStd::string m_bundlesFolder;
  118. AZStd::string m_currentProjectCacheFolder;
  119. AzFramework::PlatformFlags m_enabledPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  120. AZStd::unique_ptr<AzToolsFramework::PlatformAddressedAssetCatalogManager> m_platformCatalogManager;
  121. bool m_isInitializing = false;
  122. QFileSystemWatcher m_fileWatcher;
  123. };
  124. } // namespace AssetBundler