Skip to content

Commit

Permalink
added zip exporting to the release exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
orels1 committed Jul 4, 2024
1 parent 4e6882c commit 1f977cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Packages/sh.orels.shaders.inspector/Editor/MaterialLibraries/Resources/**/*.json
/Assets/_PoiyomiShaders
/Assets/_PoiyomiShaders.meta
/Thry
/Exports

/Assets/Samples
/Assets/Samples.meta
Expand Down
44 changes: 38 additions & 6 deletions Assets/Tools/Editor/ReleaseExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -67,17 +68,23 @@ private static void ExportAsUnityPackage()
var exportDir = Path.Combine(Directory.GetCurrentDirectory(), "Exports");
Directory.CreateDirectory(exportDir);

ExportAsUnityPackage(_exportFolders, ignored, Path.Combine(exportDir, $"sh.orels.shaders-combined-{manifest.version}.unitypackage"), manifest.version);
ExportAsUnityPackage(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-standalone-{manifest.version}.unitypackage"), manifest.version);
ExportAsUnityPackage(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-standalone-{manifest.version}.unitypackage"), manifest.version);
ExportAsUnityPackage(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-standalone-{manifest.version}.unitypackage"), manifest.version);
// Export .unitypackage files
ExportAsUnityPackage(_exportFolders, ignored, Path.Combine(exportDir, $"sh.orels.shaders-combined-{manifest.version}.unitypackage"));
ExportAsUnityPackage(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-standalone-{manifest.version}.unitypackage"));
ExportAsUnityPackage(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-standalone-{manifest.version}.unitypackage"));
ExportAsUnityPackage(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-standalone-{manifest.version}.unitypackage"));

// Export .zip files
ExportAsZip(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-{manifest.version}.zip"));
ExportAsZip(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-{manifest.version}.zip"));
ExportAsZip(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-{manifest.version}.zip"));

// Open the export folder
var exportedPath = new FileInfo("Exports").FullName;
Process.Start(exportedPath);
}

private static void ExportAsUnityPackage(string[] baseFolders, List<string> ingored, string exportPath, string version)
private static void ExportAsUnityPackage(string[] baseFolders, List<string> ingored, string exportPath)
{
var list = baseFolders.SelectMany(f => Directory.GetFiles(f, "*", SearchOption.AllDirectories))
.Select(f => f.Replace('/', '\\'))
Expand All @@ -88,13 +95,38 @@ private static void ExportAsUnityPackage(string[] baseFolders, List<string> ingo
AssetDatabase.ExportPackage(list, exportPath, ExportPackageOptions.Recurse);
}

private static void ExportAsUnityPackage(string baseFolder, List<string> ingored, string exportPath, string version)
private static void ExportAsUnityPackage(string baseFolder, List<string> ingored, string exportPath)
{
var list = Directory.GetFiles(baseFolder, "*", SearchOption.AllDirectories)
.Select(f => f.Replace('/', '\\'))
.Where(f => !ingored.Any(i => f.Contains(i, StringComparison.InvariantCultureIgnoreCase)))
.ToArray();
AssetDatabase.ExportPackage(list, exportPath, ExportPackageOptions.Recurse);
}

private static void ExportAsZip(string baseFolder, List<string> ingored, string exportPath)
{
var list = Directory.GetFiles(baseFolder, "*", SearchOption.AllDirectories)
.Select(f => f.Replace('/', '\\'))
.Where(f => !ingored.Any(i => f.Contains(i, StringComparison.InvariantCultureIgnoreCase)))
.ToArray();

if (File.Exists(exportPath)) File.Delete(exportPath);
var basePath = baseFolder.Replace('/', '\\') + '\\';
using (var zip = new ZipArchive(File.OpenWrite(exportPath), ZipArchiveMode.Create))
{
foreach (var file in list)
{
var entry = zip.CreateEntry(file.Replace(basePath, ""));
using (var stream = File.OpenRead(file))
{
using (var entryStream = entry.Open())
{
stream.CopyTo(entryStream);
}
}
}
}
}
}
}

0 comments on commit 1f977cb

Please sign in to comment.