Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

IsExeAvailable.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Codice.Client.Common;
  5. using Codice.LogWrapper;
  6. using Codice.Utils;
  7. namespace Unity.PlasticSCM.Editor.Tool
  8. {
  9. internal static class IsExeAvailable
  10. {
  11. internal static bool ForMode(bool isGluonMode)
  12. {
  13. string toolPath = isGluonMode ?
  14. PlasticInstallPath.GetGluonExePath() :
  15. PlasticInstallPath.GetPlasticExePath();
  16. return !string.IsNullOrEmpty(toolPath);
  17. }
  18. }
  19. internal static class PlasticInstallPath
  20. {
  21. internal static string GetClientBinDir()
  22. {
  23. if (PlatformIdentifier.IsWindows())
  24. {
  25. string plasticExePath = GetPlasticExePath();
  26. if (plasticExePath == null)
  27. return null;
  28. return Path.GetDirectoryName(plasticExePath);
  29. }
  30. if (PlatformIdentifier.IsMac())
  31. {
  32. string path = GetToolCommand(Plastic.NEW_GUI_MACOS);
  33. if (path != null)
  34. return GetExistingDir(ToolConstants.NEW_MACOS_BINDIR);
  35. return GetExistingDir(ToolConstants.LEGACY_MACOS_BINDIR);
  36. }
  37. return null;
  38. }
  39. internal static string GetPlasticExePath()
  40. {
  41. if (PlatformIdentifier.IsWindows())
  42. return FindTool.ObtainToolCommand(
  43. Plastic.GUI_WINDOWS,
  44. new List<String>() { GetWindowsInstallationFolder() });
  45. if (PlatformIdentifier.IsMac())
  46. {
  47. string path = GetToolCommand(Plastic.NEW_GUI_MACOS);
  48. if(path != null)
  49. return path;
  50. return GetToolCommand(Plastic.LEGACY_GUI_MACOS);
  51. }
  52. return null;
  53. }
  54. internal static string GetGluonExePath()
  55. {
  56. if (PlatformIdentifier.IsWindows())
  57. return FindTool.ObtainToolCommand(
  58. Gluon.GUI_WINDOWS,
  59. new List<String>() { GetWindowsInstallationFolder() });
  60. if (PlatformIdentifier.IsMac())
  61. {
  62. string path = GetToolCommand(Gluon.NEW_GUI_MACOS);
  63. if (path != null)
  64. return path;
  65. return GetToolCommand(Gluon.LEGACY_GUI_MACOS);
  66. }
  67. return null;
  68. }
  69. internal static void LogInstallationInfo()
  70. {
  71. string plasticClientBinDir = GetClientBinDir();
  72. if (string.IsNullOrEmpty(plasticClientBinDir))
  73. {
  74. mLog.DebugFormat("No installation found, behaving as {0} Edition",
  75. EditionToken.IsCloudEdition() ? "Cloud" : "Enterprise");
  76. }
  77. else
  78. {
  79. bool isCloudPlasticInstall = File.Exists(Path.Combine(plasticClientBinDir, EditionToken.CLOUD_EDITION_FILE_NAME));
  80. mLog.DebugFormat("{0} Edition detected - installation directory: {1}",
  81. isCloudPlasticInstall ? "Cloud" : "Enterprise",
  82. plasticClientBinDir);
  83. mLog.DebugFormat("Local token: {0} Edition",
  84. EditionToken.IsCloudEdition() ? "Cloud" : "Enterprise");
  85. }
  86. }
  87. static string GetToolCommand(string tool)
  88. {
  89. return File.Exists(tool) ? tool : null;
  90. }
  91. static string GetExistingDir(string directory)
  92. {
  93. return Directory.Exists(directory) ? directory : null;
  94. }
  95. static string GetWindowsInstallationFolder()
  96. {
  97. string programFilesFolder = Environment.GetFolderPath(
  98. Environment.SpecialFolder.ProgramFiles);
  99. return Path.Combine(Path.Combine(programFilesFolder,
  100. PLASTICSCM_FOLDER), PLASTICSCM_SUBFOLDER);
  101. }
  102. const string PLASTICSCM_FOLDER = "PlasticSCM5";
  103. const string PLASTICSCM_SUBFOLDER = "client";
  104. static readonly ILog mLog = PlasticApp.GetLogger("PlasticInstallPath");
  105. class Plastic
  106. {
  107. internal const string GUI_WINDOWS = "plastic.exe";
  108. internal const string LEGACY_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/PlasticSCM";
  109. internal const string NEW_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx";
  110. }
  111. class Gluon
  112. {
  113. internal const string GUI_WINDOWS = "gluon.exe";
  114. internal const string LEGACY_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/Gluon";
  115. internal const string NEW_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/macgluonx";
  116. }
  117. }
  118. }