GodotSharpExport.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.CompilerServices;
  5. namespace GodotSharpTools.Editor
  6. {
  7. public static class GodotSharpExport
  8. {
  9. public static void _ExportBegin(string[] features, bool debug, string path, int flags)
  10. {
  11. var featureSet = new HashSet<string>(features);
  12. if (PlatformHasTemplateDir(featureSet))
  13. {
  14. string templateDirName = "data.mono";
  15. if (featureSet.Contains("Windows"))
  16. {
  17. templateDirName += ".windows";
  18. templateDirName += featureSet.Contains("64") ? ".64" : ".32";
  19. }
  20. else if (featureSet.Contains("X11"))
  21. {
  22. templateDirName += ".x11";
  23. templateDirName += featureSet.Contains("64") ? ".64" : ".32";
  24. }
  25. else
  26. {
  27. throw new NotSupportedException("Target platform not supported");
  28. }
  29. templateDirName += debug ? ".debug" : ".release";
  30. string templateDirPath = Path.Combine(GetTemplatesDir(), templateDirName);
  31. if (!Directory.Exists(templateDirPath))
  32. throw new FileNotFoundException("Data template directory not found");
  33. string outputDir = new FileInfo(path).Directory.FullName;
  34. string outputDataDir = Path.Combine(outputDir, GetDataDirName());
  35. Directory.Delete(outputDataDir, recursive: true); // Clean first
  36. Directory.CreateDirectory(outputDataDir);
  37. foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
  38. {
  39. Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
  40. }
  41. foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
  42. {
  43. File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
  44. }
  45. }
  46. }
  47. public static bool PlatformHasTemplateDir(HashSet<string> featureSet)
  48. {
  49. // OSX export templates are contained in a zip, so we place
  50. // our custom template inside it and let Godot do the rest.
  51. return !featureSet.Contains("OSX");
  52. }
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. extern static string GetTemplatesDir();
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. extern static string GetDataDirName();
  57. }
  58. }