Program.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Xml;
  8. namespace SynchProjects
  9. {
  10. class Program
  11. {
  12. static string BASEPATH;
  13. static void CopyCompileFilesAsLinks(string platformName, string srcCsProj, string platformDest, string pathPrefix)
  14. {
  15. platformName = AdjustBasePath(platformName);
  16. srcCsProj = AdjustBasePath(srcCsProj);
  17. platformDest = AdjustBasePath(platformDest);
  18. pathPrefix = AdjustBasePath(pathPrefix);
  19. string dstCsProj = string.Format(platformDest, platformName);
  20. try
  21. {
  22. int warningCount = 0;
  23. const string XMLNS = "http://schemas.microsoft.com/developer/msbuild/2003";
  24. HashSet<string> linksDone = new HashSet<string>();
  25. Console.ForegroundColor = ConsoleColor.Gray;
  26. Console.WriteLine("Synch vsproj compiles {0} ...", Path.GetFileNameWithoutExtension(dstCsProj));
  27. XmlDocument xsrc = new XmlDocument();
  28. XmlDocument xdst = new XmlDocument();
  29. xsrc.Load(srcCsProj);
  30. xdst.Load(dstCsProj);
  31. XmlNamespaceManager sxns = new XmlNamespaceManager(xsrc.NameTable);
  32. XmlNamespaceManager dxns = new XmlNamespaceManager(xdst.NameTable);
  33. sxns.AddNamespace("ms", XMLNS);
  34. dxns.AddNamespace("ms", XMLNS);
  35. XmlElement srccont = xsrc.SelectSingleNode("/ms:Project/ms:ItemGroup[count(ms:Compile) != 0]", sxns) as XmlElement;
  36. XmlElement dstcont = xdst.SelectSingleNode("/ms:Project/ms:ItemGroup[count(ms:Compile) != 0]", dxns) as XmlElement;
  37. // dirty hack
  38. dstcont.InnerXml = srccont.InnerXml;
  39. List<XmlElement> toRemove = new List<XmlElement>();
  40. foreach (XmlElement xe in dstcont.ChildNodes.OfType<XmlElement>())
  41. {
  42. string file = xe.GetAttribute("Include");
  43. string link = Path.GetFileName(file);
  44. if (link.Contains(".g4"))
  45. {
  46. toRemove.Add(xe);
  47. continue;
  48. }
  49. if (!linksDone.Add(link))
  50. {
  51. ++warningCount;
  52. Console.ForegroundColor = ConsoleColor.Yellow;
  53. Console.WriteLine("\t[WARNING] - Duplicate file: {0}", link);
  54. }
  55. file = pathPrefix + file;
  56. xe.SetAttribute("Include", file);
  57. XmlElement xlink = xe.OwnerDocument.CreateElement("Link", XMLNS);
  58. xlink.InnerText = link;
  59. xe.AppendChild(xlink);
  60. }
  61. foreach (XmlElement xe in toRemove)
  62. xe.ParentNode.RemoveChild(xe);
  63. xdst.Save(dstCsProj);
  64. Console.ForegroundColor = ConsoleColor.Green;
  65. Console.WriteLine("\t[DONE] ({0} warnings)", warningCount);
  66. }
  67. catch (Exception ex)
  68. {
  69. Console.ForegroundColor = ConsoleColor.Red;
  70. Console.WriteLine("\t[ERROR] - {0}", ex.Message);
  71. }
  72. Console.WriteLine("\n");
  73. }
  74. private static string AdjustBasePath(string str)
  75. {
  76. return str.Replace("{BASEPATH}", BASEPATH);
  77. }
  78. static void Main(string[] args)
  79. {
  80. Console.ForegroundColor = ConsoleColor.Magenta;
  81. Console.WriteLine("********************************************************");
  82. Console.WriteLine("* !! REMEMBER TO RSYNC UNITY AND .NET CORE PROJECTS !! *");
  83. Console.WriteLine("********************************************************");
  84. const string INTERPRETER_PROJECT = @"{BASEPATH}\MoonSharp.Interpreter\MoonSharp.Interpreter.net35-client.csproj";
  85. const string INTERPRETER_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.Interpreter\_Projects\MoonSharp.Interpreter.{0}\MoonSharp.Interpreter.{0}.csproj";
  86. const string INTERPRETER_PATH_PREFIX = @"..\..\";
  87. const string DEBUGGER_PROJECT = @"{BASEPATH}\MoonSharp.RemoteDebugger\MoonSharp.RemoteDebugger.net35-client.csproj";
  88. const string DEBUGGER_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.RemoteDebugger\_Projects\MoonSharp.RemoteDebugger.{0}\MoonSharp.RemoteDebugger.{0}.csproj";
  89. const string DEBUGGER_PATH_PREFIX = @"..\..\";
  90. const string VSCODEDEBUGGER_PROJECT = @"{BASEPATH}\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.net35-client.csproj";
  91. const string VSCODEDEBUGGER_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.VsCodeDebugger\_Projects\MoonSharp.VsCodeDebugger.{0}\MoonSharp.VsCodeDebugger.{0}.csproj";
  92. const string VSCODEDEBUGGER_PATH_PREFIX = @"..\..\";
  93. const string TESTS_PROJECT = @"{BASEPATH}\MoonSharp.Interpreter.Tests\MoonSharp.Interpreter.Tests.net35-client.csproj";
  94. const string TESTS_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.Interpreter.Tests\_Projects\MoonSharp.Interpreter.Tests.{0}\MoonSharp.Interpreter.Tests.{0}.csproj";
  95. const string TESTS_PATH_PREFIX = @"..\..\";
  96. string[] INTERPRETER_PLATFORMS = new string[] { "net40-client", "portable40" };
  97. string[] DEBUGGER_PLATFORMS = new string[] { "net40-client" };
  98. string[] VSCODEDEBUGGER_PLATFORMS = new string[] { "net40-client" };
  99. string[] TESTS_PLATFORMS = new string[] { "net40-client", "portable40", "Embeddable.portable40" };
  100. CalcBasePath();
  101. foreach (string platform in INTERPRETER_PLATFORMS)
  102. CopyCompileFilesAsLinks(platform, INTERPRETER_PROJECT, INTERPRETER_SUBPROJECTS_PATHS, INTERPRETER_PATH_PREFIX);
  103. foreach (string platform in DEBUGGER_PLATFORMS)
  104. CopyCompileFilesAsLinks(platform, DEBUGGER_PROJECT, DEBUGGER_SUBPROJECTS_PATHS, DEBUGGER_PATH_PREFIX);
  105. foreach (string platform in VSCODEDEBUGGER_PLATFORMS)
  106. CopyCompileFilesAsLinks(platform, VSCODEDEBUGGER_PROJECT, VSCODEDEBUGGER_SUBPROJECTS_PATHS, VSCODEDEBUGGER_PATH_PREFIX);
  107. foreach (string platform in TESTS_PLATFORMS)
  108. CopyCompileFilesAsLinks(platform, TESTS_PROJECT, TESTS_SUBPROJECTS_PATHS, TESTS_PATH_PREFIX);
  109. Console.ReadLine();
  110. }
  111. private static void CalcBasePath()
  112. {
  113. string path = "";
  114. string[] dir = AppDomain.CurrentDomain.BaseDirectory.Split('\\');
  115. for (int i = 0; i < dir.Length; i++)
  116. {
  117. if (dir[i].ToLower() == "devtools")
  118. break;
  119. if (path.Length > 0)
  120. path = path + "\\" + dir[i];
  121. else
  122. path = dir[i];
  123. }
  124. BASEPATH = path;
  125. }
  126. }
  127. }