|
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
| 6 | +using System.Security.Cryptography; |
| 7 | +using System.Text; |
6 | 8 | using GodotTools.Build; |
7 | 9 | using GodotTools.Core; |
8 | 10 | using GodotTools.Internals; |
@@ -45,6 +47,17 @@ public partial class ExportPlugin : EditorExportPlugin |
45 | 47 | } |
46 | 48 | }, |
47 | 49 | { "default_value", true } |
| 50 | + }, |
| 51 | + new Godot.Collections.Dictionary() |
| 52 | + { |
| 53 | + { |
| 54 | + "option", new Godot.Collections.Dictionary() |
| 55 | + { |
| 56 | + { "name", "dotnet/embed_build_outputs" }, |
| 57 | + { "type", (int)Variant.Type.Bool } |
| 58 | + } |
| 59 | + }, |
| 60 | + { "default_value", false } |
48 | 61 | } |
49 | 62 | }; |
50 | 63 | } |
@@ -146,6 +159,8 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long |
146 | 159 | } |
147 | 160 | } |
148 | 161 |
|
| 162 | + bool embedBuildResults = (bool)GetOption("dotnet/embed_build_outputs"); |
| 163 | + |
149 | 164 | foreach (var arch in archs) |
150 | 165 | { |
151 | 166 | string ridOS = DetermineRuntimeIdentifierOS(platform); |
@@ -190,17 +205,44 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long |
190 | 205 | "Publish succeeded but project assembly not found in the output directory"); |
191 | 206 | } |
192 | 207 |
|
193 | | - // Add to the exported project shared object list. |
| 208 | + var manifest = new StringBuilder(); |
194 | 209 |
|
| 210 | + // Add to the exported project shared object list or packed resources. |
195 | 211 | foreach (string file in Directory.GetFiles(publishOutputTempDir, "*", SearchOption.AllDirectories)) |
196 | 212 | { |
197 | | - AddSharedObject(file, tags: null, |
198 | | - Path.Join(projectDataDirName, |
199 | | - Path.GetRelativePath(publishOutputTempDir, Path.GetDirectoryName(file)))); |
| 213 | + if (embedBuildResults) |
| 214 | + { |
| 215 | + var filePath = SanitizeSlashes(Path.GetRelativePath(publishOutputTempDir, file)); |
| 216 | + var fileData = File.ReadAllBytes(file); |
| 217 | + var hash = Convert.ToBase64String(SHA512.HashData(fileData)); |
| 218 | + |
| 219 | + manifest.Append($"{filePath}\t{hash}\n"); |
| 220 | + |
| 221 | + AddFile($"res://.godot/mono/publish/{arch}/{filePath}", fileData, false); |
| 222 | + } |
| 223 | + else |
| 224 | + { |
| 225 | + AddSharedObject(file, tags: null, |
| 226 | + Path.Join(projectDataDirName, |
| 227 | + Path.GetRelativePath(publishOutputTempDir, Path.GetDirectoryName(file)))); |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + if (embedBuildResults) |
| 232 | + { |
| 233 | + var fileData = Encoding.Default.GetBytes(manifest.ToString()); |
| 234 | + AddFile($"res://.godot/mono/publish/{arch}/.dotnet-publish-manifest", fileData, false); |
200 | 235 | } |
201 | 236 | } |
202 | 237 | } |
203 | 238 |
|
| 239 | + private string SanitizeSlashes(string path) |
| 240 | + { |
| 241 | + if (Path.DirectorySeparatorChar == '\\') |
| 242 | + return path.Replace('\\', '/'); |
| 243 | + return path; |
| 244 | + } |
| 245 | + |
204 | 246 | private string DetermineRuntimeIdentifierOS(string platform) |
205 | 247 | => OS.DotNetOSPlatformMap[platform]; |
206 | 248 |
|
|
0 commit comments