GodotSharpExport.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if (Directory.Exists(outputDataDir))
  36. Directory.Delete(outputDataDir, recursive: true); // Clean first
  37. Directory.CreateDirectory(outputDataDir);
  38. foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
  39. {
  40. Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
  41. }
  42. foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
  43. {
  44. File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
  45. }
  46. }
  47. }
  48. public static bool PlatformHasTemplateDir(HashSet<string> featureSet)
  49. {
  50. // OSX export templates are contained in a zip, so we place
  51. // our custom template inside it and let Godot do the rest.
  52. return !featureSet.Contains("OSX");
  53. }
  54. [MethodImpl(MethodImplOptions.InternalCall)]
  55. extern static string GetTemplatesDir();
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. extern static string GetDataDirName();
  58. }
  59. }