Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 128 additions & 55 deletions Intersect.Editor/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,11 @@ private void createUpdate(string sourceDirectory, string targetDirectory, Update
targetSubdirectoryInfo.Delete(true);
}

// Check if asset packaging is enabled
var packageUpdateAssets = Preferences.LoadPreference("PackageUpdateAssets");
var packagingEnabled = !string.IsNullOrWhiteSpace(packageUpdateAssets) &&
Convert.ToBoolean(packageUpdateAssets, CultureInfo.InvariantCulture);

// Intersect excluded files
var editorBaseName = Process.GetCurrentProcess().ProcessName.ToLowerInvariant();
var editorFileNameExe = $"{editorBaseName}.exe";
Expand Down Expand Up @@ -2160,10 +2165,7 @@ private void createUpdate(string sourceDirectory, string targetDirectory, Update
[
"resources/client_strings.json",
];
List<string> editorExcludeDirectories =
[
"resources/packs",
];
List<string> editorExcludeDirectories = new();
string[] excludeExtensions =
[
".dll",
Expand All @@ -2180,81 +2182,152 @@ private void createUpdate(string sourceDirectory, string targetDirectory, Update
const string resourcesDirectoryName = "resources";
var pathToResourcesDirectory = Path.Combine(sourceDirectory, resourcesDirectoryName);
var pathToPacksDirectory = Path.Combine(pathToResourcesDirectory, "packs");
if (Directory.Exists(pathToPacksDirectory))
if (packagingEnabled && Directory.Exists(pathToPacksDirectory))
{
// When packaging is enabled: include packs, exclude source files
var packFileNames = Directory.GetFiles(pathToPacksDirectory, "*.meta");
editorExcludeFiles.AddRange(packFileNames);

// Exclude source texture files that were packed
clientExcludeFiles.AddRange(
packFileNames.Select(
pack =>
packFileNames.SelectMany(
pack =>
{
try
{
var tokenPack = JToken.Parse(GzipCompression.ReadDecompressedString(pack));
if (tokenPack is not JObject objectPack)
if (tokenPack is not JObject objectPack || !objectPack.TryGetValue("frames", out var tokenFrames))
{
return null;
return Enumerable.Empty<string>();
}

return objectPack.TryGetValue("frames", out var tokenFrames) ? tokenFrames : null;
return tokenFrames.Children()
.OfType<JObject>()
.Where(frameObject => frameObject.TryGetValue("filename", out _))
.Select(frameObject => frameObject["filename"]?.Value<string>())
.Where(filename => !string.IsNullOrWhiteSpace(filename))
.Select(filename => Path.Combine(resourcesDirectoryName, filename!).Replace('\\', '/'))
.OfType<string>();
}
catch
{
return Enumerable.Empty<string>();
}
)
.SelectMany(
token => token?.Children() ?? [],
(_, frameToken) =>
frameToken is JObject frameObject &&
frameObject.TryGetValue("filename", out var tokenFilename)
? tokenFilename.Value<string>()
: null
)
.Where(filename => !string.IsNullOrWhiteSpace(filename))
.OfType<string>()
}
)
);

// Exclude source sound files that were packed
var soundIndex = Path.Combine(pathToPacksDirectory, "sound.index");
if (File.Exists(soundIndex))
{
editorExcludeFiles.Add(soundIndex);
using AssetPacker soundPacker = new(soundIndex, pathToPacksDirectory);
editorExcludeFiles.AddRange(
soundPacker.CachedPackages.Select(
cachedPackage => Path.Combine(soundPacker.PackageLocation, cachedPackage)
)
);

clientExcludeFiles.AddRange(
soundPacker.FileList.Select(
sound => Path.Combine(
resourcesDirectoryName,
"sounds",
sound.ToLower(CultureInfo.CurrentCulture)
)
.Replace('\\', '/')
)
);
try
{
using AssetPacker soundPacker = new(soundIndex, pathToPacksDirectory);
clientExcludeFiles.AddRange(
soundPacker.FileList.Select(
sound => Path.Combine(resourcesDirectoryName, "sounds", sound.ToLower(CultureInfo.CurrentCulture)).Replace('\\', '/')
)
);
}
catch
{
// Ignore packer errors
}
}

// Exclude source music files that were packed
var musicIndex = Path.Combine(pathToPacksDirectory, "music.index");
if (File.Exists(musicIndex))
{
editorExcludeFiles.Add(musicIndex);
using AssetPacker musicPacker = new(musicIndex, pathToPacksDirectory);
try
{
using AssetPacker musicPacker = new(musicIndex, pathToPacksDirectory);
clientExcludeFiles.AddRange(
musicPacker.FileList.Select(
music => Path.Combine(resourcesDirectoryName, "music", music.ToLower(CultureInfo.CurrentCulture)).Replace('\\', '/')
)
);
}
catch
{
// Ignore packer errors
}
}
}
else if (!packagingEnabled)
{
// When packaging is disabled: exclude packs directory
editorExcludeDirectories.Add("resources/packs");

if (Directory.Exists(pathToPacksDirectory))
{
var packFileNames = Directory.GetFiles(pathToPacksDirectory, "*.meta");
editorExcludeFiles.AddRange(packFileNames.Select(f => Path.GetRelativePath(sourceDirectory, f).Replace('\\', '/')));

// Exclude texture source files referenced in pack metadata
editorExcludeFiles.AddRange(
musicPacker.CachedPackages.Select(
cachedPackage => Path.Combine(musicPacker.PackageLocation, cachedPackage)
)
packFileNames.SelectMany(pack =>
{
try
{
var tokenPack = JToken.Parse(GzipCompression.ReadDecompressedString(pack));
if (tokenPack is not JObject objectPack || !objectPack.TryGetValue("frames", out var tokenFrames))
{
return Enumerable.Empty<string>();
}

return tokenFrames.Children()
.OfType<JObject>()
.Where(frameObject => frameObject.TryGetValue("filename", out _))
.Select(frameObject => frameObject["filename"]?.Value<string>())
.Where(filename => !string.IsNullOrWhiteSpace(filename))
.OfType<string>();
}
catch
{
return Enumerable.Empty<string>();
}
})
);

clientExcludeFiles.AddRange(
musicPacker.FileList.Select(
music => Path.Combine(
resourcesDirectoryName,
"music",
music.ToLower(CultureInfo.CurrentCulture)
var soundIndex = Path.Combine(pathToPacksDirectory, "sound.index");
if (File.Exists(soundIndex))
{
editorExcludeFiles.Add(Path.GetRelativePath(sourceDirectory, soundIndex).Replace('\\', '/'));
try
{
using AssetPacker soundPacker = new(soundIndex, pathToPacksDirectory);
editorExcludeFiles.AddRange(
soundPacker.CachedPackages.Select(
cachedPackage => Path.Combine("resources/packs", cachedPackage).Replace('\\', '/')
)
.Replace('\\', '/')
)
);
}
);
}
catch
{
// Ignore packer errors
}
}

var musicIndex = Path.Combine(pathToPacksDirectory, "music.index");
if (File.Exists(musicIndex))
{
editorExcludeFiles.Add(Path.GetRelativePath(sourceDirectory, musicIndex).Replace('\\', '/'));
try
{
using AssetPacker musicPacker = new(musicIndex, pathToPacksDirectory);
editorExcludeFiles.AddRange(
musicPacker.CachedPackages.Select(
cachedPackage => Path.Combine("resources/packs", cachedPackage).Replace('\\', '/')
)
);
}
catch
{
// Ignore packer errors
}
}
}
}

var fileCount = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories).Length;
Expand Down
Loading