|
|
@@ -22,10 +22,14 @@
|
|
|
|
|
|
#include <Atomic/IO/Log.h>
|
|
|
#include <Atomic/IO/FileSystem.h>
|
|
|
+#include <Atomic/Resource/JSONFile.h> // EGS:
|
|
|
+
|
|
|
|
|
|
#include "../Subprocess/SubprocessSystem.h"
|
|
|
#include "../Project/Project.h"
|
|
|
#include "../ToolEnvironment.h"
|
|
|
+#include "../Assets/Asset.h" // EGS:
|
|
|
+
|
|
|
|
|
|
#include "BuildSystem.h"
|
|
|
#include "BuildEvents.h"
|
|
|
@@ -282,133 +286,195 @@ String BuildBase::GetSettingsDirectory()
|
|
|
|
|
|
void BuildBase::ScanResourceDirectory(const String& resourceDir)
|
|
|
{
|
|
|
- Vector<String> fileNames;
|
|
|
- FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
- fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
|
|
|
+ {
|
|
|
|
|
|
- for (unsigned i = 0; i < fileNames.Size(); i++)
|
|
|
+ //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void BuildBase::BuildDefaultResourceEntries()
|
|
|
+{
|
|
|
+ for (unsigned i = 0; i < resourceDirs_.Size(); i++)
|
|
|
{
|
|
|
- const String& filename = fileNames[i];
|
|
|
+ String resourceDir = resourceDirs_[i];
|
|
|
+ Vector<String> fileNames;
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
+ fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
|
|
|
|
|
|
- for (unsigned j = 0; j < resourceEntries_.Size(); j++)
|
|
|
+ for (unsigned i = 0; i < fileNames.Size(); i++)
|
|
|
{
|
|
|
- const BuildResourceEntry* entry = resourceEntries_[j];
|
|
|
-
|
|
|
- if (entry->packagePath_ == filename)
|
|
|
- {
|
|
|
- BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
|
|
|
+ const String& filename = fileNames[i];
|
|
|
+
|
|
|
+ if (!CheckIncludeResourceFile(resourceDir, filename))
|
|
|
continue;
|
|
|
- }
|
|
|
+
|
|
|
+ AddToResourcePackager(filename);
|
|
|
}
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- if (!CheckIncludeResourceFile(resourceDir, filename))
|
|
|
- continue;
|
|
|
+void BuildBase::BuildProjectResourceEntries()
|
|
|
+{
|
|
|
+ if (AssetBuildConfig::IsLoaded() && !assetBuildTag_.Empty())
|
|
|
+ {
|
|
|
+ // add log comment
|
|
|
+ BuildFilteredProjectResourceEntries();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // add log comment
|
|
|
+ BuildAllProjectResourceEntries();
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- BuildResourceEntry* newEntry = new BuildResourceEntry;
|
|
|
+void BuildBase::BuildAllProjectResourceEntries()
|
|
|
+{
|
|
|
+ for (unsigned i = 0; i < projectResourceDir_.Size(); i++)
|
|
|
+ {
|
|
|
+ String projectResourceDir = projectResourceDir_[i];
|
|
|
+ Vector<String> fileNamesInProject;
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
+ fileSystem->ScanDir(fileNamesInProject, projectResourceDir, "*.*", SCAN_FILES, true);
|
|
|
|
|
|
-// BEGIN LICENSE MANAGEMENT
|
|
|
- if (GetExtension(filename) == ".mdl")
|
|
|
+ for (unsigned i = 0; i < fileNamesInProject.Size(); i++)
|
|
|
{
|
|
|
- containsMDL_ = true;
|
|
|
+ AddToResourcePackager(fileNamesInProject[i]);
|
|
|
}
|
|
|
-// END LICENSE MANAGEMENT
|
|
|
-
|
|
|
- newEntry->absolutePath_ = resourceDir + filename;
|
|
|
- newEntry->resourceDir_ = resourceDir;
|
|
|
-
|
|
|
- newEntry->packagePath_ = filename;
|
|
|
-
|
|
|
- resourceEntries_.Push(newEntry);
|
|
|
-
|
|
|
- //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-void BuildBase::BuildProjectResourceEntries()
|
|
|
+void BuildBase::BuildFilteredProjectResourceEntries()
|
|
|
{
|
|
|
- Vector<String> fileNames;
|
|
|
- FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
- fileSystem->ScanDir(fileNames, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
|
|
|
-
|
|
|
+ // Loading up the assetbuildconfig.json,
|
|
|
+ // obtaining a list of files to include in the build.
|
|
|
VariantMap resourceTags;
|
|
|
AssetBuildConfig::ApplyConfig(resourceTags);
|
|
|
-
|
|
|
+ Vector<String> resourceFilesToInclude;
|
|
|
VariantMap::ConstIterator itr = resourceTags.Begin();
|
|
|
|
|
|
- Vector<String> resources;
|
|
|
while (itr != resourceTags.End())
|
|
|
{
|
|
|
if (itr->first_ == assetBuildTag_)
|
|
|
{
|
|
|
- resources = itr->second_.GetStringVector();
|
|
|
+ resourceFilesToInclude = itr->second_.GetStringVector();
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
itr++;
|
|
|
+ if (itr == resourceTags.End())
|
|
|
+ {
|
|
|
+ LOGERRORF("BuildBase::BuildFilteredProjectResourceEntries - Asset Build Tag \"%s\" not defined in .\\Settings\\assetbuildconfig.json", assetBuildTag_.CString());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- for (unsigned i = 0; i < fileNames.Size(); i++)
|
|
|
- {
|
|
|
- const String& filename = fileNames[i];
|
|
|
+ // check if the files in assetbuildconfig.json exist,
|
|
|
+ // as well as their corresponding .asset file
|
|
|
+ Vector<String> filesInResourceFolder;
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
+ fileSystem->ScanDir(filesInResourceFolder, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
|
|
|
|
|
|
- for (unsigned j = 0; j < resourceEntries_.Size(); j++)
|
|
|
+ for (auto itr = resourceFilesToInclude.Begin(); itr != resourceFilesToInclude.End(); ++itr)
|
|
|
+ {
|
|
|
+ // .asset file is of primary importance since we used it to identify the associated cached file.
|
|
|
+ // without the .asset file the resource becomes redundant.
|
|
|
+ if (!filesInResourceFolder.Contains(*itr + ".asset"))
|
|
|
{
|
|
|
- const BuildResourceEntry* entry = resourceEntries_[j];
|
|
|
-
|
|
|
- if (entry->packagePath_ == filename)
|
|
|
+ BuildWarn(ToString("BuildBase::BuildFilteredProjectResourceEntries - File \"%s\" associated .asset file not found in the Resources folder.\nRemoving \"%s\" from build pakcage", (*itr).CString()));
|
|
|
+ if (filesInResourceFolder.Contains(*itr))
|
|
|
{
|
|
|
- BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
|
|
|
+ resourceFilesToInclude.Remove(*itr);
|
|
|
+ itr--;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (auto it = resources.Begin(); it != resources.End(); ++it)
|
|
|
- {
|
|
|
- if (filename == (*it))
|
|
|
- {
|
|
|
- // TODO: Add additional filters
|
|
|
- if (GetExtension(filename) == ".psd")
|
|
|
- break;
|
|
|
-
|
|
|
- BuildResourceEntry* newEntry = new BuildResourceEntry;
|
|
|
+ resourceFilesToInclude.Push(*itr + ".asset");
|
|
|
+ }
|
|
|
|
|
|
- // BEGIN LICENSE MANAGEMENT
|
|
|
- if (GetExtension(filename) == ".mdl")
|
|
|
- {
|
|
|
- containsMDL_ = true;
|
|
|
- }
|
|
|
- // END LICENSE MANAGEMENT
|
|
|
+ // Get associated cache GUID from the asset file
|
|
|
+ Vector<String> filesWithGUIDtoInclude;
|
|
|
+ for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
|
|
|
+ {
|
|
|
+ if (GetExtension(*it) == ".asset");
|
|
|
+ {
|
|
|
+ SharedPtr<File> file(new File(context_, *it));
|
|
|
+ SharedPtr<JSONFile> json(new JSONFile(context_));
|
|
|
+ json->Load(*file);
|
|
|
+ file->Close();
|
|
|
|
|
|
- newEntry->absolutePath_ = project_->GetResourcePath() + filename;
|
|
|
- newEntry->resourceDir_ = project_->GetResourcePath();
|
|
|
+ JSONValue root = json->GetRoot();
|
|
|
|
|
|
- newEntry->packagePath_ = filename;
|
|
|
+ assert(root.Get("version").GetInt() == ASSET_VERSION);
|
|
|
|
|
|
- resourceEntries_.Push(newEntry);
|
|
|
- resourcePackager_->AddResourceEntry(newEntry);
|
|
|
+ String guid = root.Get("guid").GetString();
|
|
|
+ filesWithGUIDtoInclude.Push(guid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // obtain files in cache folder,
|
|
|
+ // check if the file contains the guid, and add it to the resourceFilesToInclude
|
|
|
+ Vector<String> filesInCacheFolder;
|
|
|
+ fileSystem->ScanDir(filesInCacheFolder, project_->GetProjectPath() + "Cache/", "*.*", SCAN_FILES, true);
|
|
|
|
|
|
- break;
|
|
|
+ for (unsigned i = 0; i < filesWithGUIDtoInclude.Size(); i++)
|
|
|
+ {
|
|
|
+ String &guid = filesWithGUIDtoInclude[i];
|
|
|
+ for (unsigned j = 0; j < filesInCacheFolder.Size(); j++)
|
|
|
+ {
|
|
|
+ String &filename = GetFileName(filesInCacheFolder[j]);
|
|
|
+ if (filename.Contains(guid))
|
|
|
+ {
|
|
|
+ resourceFilesToInclude.Push(filesInCacheFolder[j]);
|
|
|
+ // do not continue...
|
|
|
+ // there might be multiple files with the same guid
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-void BuildBase::BuildResourceEntries()
|
|
|
-{
|
|
|
- for (unsigned i = 0; i < resourceDirs_.Size(); i++)
|
|
|
+ for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
|
|
|
{
|
|
|
- ScanResourceDirectory(resourceDirs_[i]);
|
|
|
+ AddToResourcePackager(*it);
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- if (resourcePackager_.NotNull())
|
|
|
+void BuildBase::AddToResourcePackager(const String& filename)
|
|
|
+{
|
|
|
+ // Check if the file is already included in the resourceEntries_ list
|
|
|
+ for (unsigned j = 0; j < resourceEntries_.Size(); j++)
|
|
|
{
|
|
|
- for (unsigned i = 0; i < resourceEntries_.Size(); i++)
|
|
|
+ const BuildResourceEntry* entry = resourceEntries_[j];
|
|
|
+
|
|
|
+ if (entry->packagePath_ == filename)
|
|
|
{
|
|
|
- BuildResourceEntry* entry = resourceEntries_[i];
|
|
|
- resourcePackager_->AddResourceEntry(entry);
|
|
|
+ BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
|
|
|
+ continue;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add the file to the resourceEntries_ list
|
|
|
+ // TODO: Add additional filters
|
|
|
+ if (GetExtension(filename) == ".psd")
|
|
|
+ return;
|
|
|
+
|
|
|
+ BuildResourceEntry* newEntry = new BuildResourceEntry;
|
|
|
|
|
|
+ // BEGIN LICENSE MANAGEMENT
|
|
|
+ if (GetExtension(filename) == ".mdl")
|
|
|
+ {
|
|
|
+ containsMDL_ = true;
|
|
|
}
|
|
|
+ // END LICENSE MANAGEMENT
|
|
|
+
|
|
|
+ newEntry->absolutePath_ = project_->GetResourcePath() + filename;
|
|
|
+ newEntry->resourceDir_ = project_->GetResourcePath();
|
|
|
+
|
|
|
+ newEntry->packagePath_ = filename;
|
|
|
|
|
|
+ resourceEntries_.Push(newEntry);
|
|
|
+
|
|
|
+ assert(resourcePackager_.NotNull());
|
|
|
+ resourcePackager_->AddResourceEntry(newEntry);
|
|
|
}
|
|
|
|
|
|
void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
|
|
|
@@ -422,6 +488,12 @@ void BuildBase::AddResourceDir(const String& dir)
|
|
|
resourceDirs_.Push(dir);
|
|
|
}
|
|
|
|
|
|
+void BuildBase::AddProjectResourceDir(const String& dir)
|
|
|
+{
|
|
|
+ assert(!projectResourceDir_.Contains(dir));
|
|
|
+ projectResourceDir_.Push(dir);
|
|
|
+}
|
|
|
+
|
|
|
void BuildBase::ReadAssetBuildConfig()
|
|
|
{
|
|
|
String projectPath = project_->GetProjectPath();
|