A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.2KB

  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. namespace Automation
  6. {
  7. class Automation
  8. {
  9. private static readonly string Name = "automation";
  10. private static readonly string XmlPrefix = "<!--Start Dependencies-->\n <ItemGroup>\n";
  11. private static readonly string XmlSuffix = " </ItemGroup>\n<!--End Dependencies-->";
  12. private static readonly string GamecraftModdingAPI_csproj = @"\GamecraftModdingAPI.csproj";
  13. static void Main(string[] args)
  14. {
  15. if (args.Length != 2 || args[0] == "-h" || args[0] == "--help")
  16. {
  17. Console.WriteLine($"Usage : {Name}.exe <path to Gamecraft DLLs> <path to GamecraftModdingAPI.csproj>");
  18. Console.WriteLine("Other arguments:");
  19. Console.WriteLine(" --help : display this message");
  20. Console.WriteLine($" --version : display {Name}'s version");
  21. return;
  22. }
  23. Console.WriteLine("Building Assembly references");
  24. string asmXml = BuildAssemblyReferencesXML(args[0]);
  25. //Console.WriteLine(asmXml);
  26. string csprojPath = args[1].EndsWith(GamecraftModdingAPI_csproj)? args[1] : args[1]+GamecraftModdingAPI_csproj;
  27. Console.WriteLine($"Parsing {csprojPath}");
  28. string csprojContents = File.ReadAllText(csprojPath);
  29. Match dependenciesStart = (new Regex(@"<\s*!--\s*Start\s+Dependencies\s*--\s*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline)).Match(csprojContents);
  30. Match dependenciesEnd = (new Regex(@"<\s*!--\s*End\s+Dependencies\s*--\s*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline)).Match(csprojContents);
  31. if (!dependenciesEnd.Success || !dependenciesStart.Success)
  32. {
  33. Console.WriteLine("Unable to find dependency XML comments, aborting!");
  34. return;
  35. }
  36. csprojContents = csprojContents.Substring(0, dependenciesStart.Index) + asmXml + csprojContents.Substring(dependenciesEnd.Index+dependenciesEnd.Length);
  37. //Console.WriteLine(csprojContents);
  38. Console.WriteLine($"Writing Assembly references into {csprojPath}");
  39. File.WriteAllText(csprojPath, csprojContents);
  40. Console.WriteLine("Successfully generated Gamecraft assembly DLL references");
  41. }
  42. static string BuildAssemblyReferencesXML(string path)
  43. {
  44. StringBuilder result = new StringBuilder();
  45. result.Append(XmlPrefix);
  46. string[] files = Directory.GetFiles(path, "*.dll");
  47. for(int i = 0; i<files.Length; i++)
  48. {
  49. if (files[i].Contains(@"\System.") || files[i].EndsWith(@"mscorlib.dll") || files[i].Contains(@"\Mono."))
  50. {
  51. // no
  52. }
  53. else
  54. {
  55. result.Append($" <Reference Include=\"{files[i].Substring(files[i].LastIndexOf(@"\") + 1).Replace(".dll", "")}\">\n <HintPath>{files[i]}</HintPath>\n </Reference>\n");
  56. }
  57. }
  58. result.Append(XmlSuffix);
  59. return result.ToString();
  60. }
  61. }
  62. }