No Description
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.

IsExeAvailable.cs 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Codice.Utils;
  5. namespace Unity.PlasticSCM.Editor.Tool
  6. {
  7. internal static class IsExeAvailable
  8. {
  9. internal static bool ForMode(bool isGluonMode)
  10. {
  11. string toolPath = isGluonMode ?
  12. PlasticInstallPath.GetGluonExePath() :
  13. PlasticInstallPath.GetPlasticExePath();
  14. return !string.IsNullOrEmpty(toolPath);
  15. }
  16. }
  17. internal static class PlasticInstallPath
  18. {
  19. internal static string GetClientBinDir()
  20. {
  21. if (PlatformIdentifier.IsWindows())
  22. {
  23. string plasticExePath = GetPlasticExePath();
  24. if (plasticExePath == null)
  25. return null;
  26. return Path.GetDirectoryName(plasticExePath);
  27. }
  28. if (PlatformIdentifier.IsMac())
  29. {
  30. string path = GetToolCommand(Plastic.NEW_GUI_MACOS);
  31. if (path != null)
  32. return GetExistingDir(ToolConstants.NEW_MACOS_BINDIR);
  33. return GetExistingDir(ToolConstants.LEGACY_MACOS_BINDIR);
  34. }
  35. return null;
  36. }
  37. internal static string GetPlasticExePath()
  38. {
  39. if (PlatformIdentifier.IsWindows())
  40. return FindTool.ObtainToolCommand(
  41. Plastic.GUI_WINDOWS,
  42. new List<String>() { GetWindowsInstallationFolder() });
  43. if (PlatformIdentifier.IsMac())
  44. {
  45. string path = GetToolCommand(Plastic.NEW_GUI_MACOS);
  46. if(path != null)
  47. return path;
  48. return GetToolCommand(Plastic.LEGACY_GUI_MACOS);
  49. }
  50. return null;
  51. }
  52. internal static string GetGluonExePath()
  53. {
  54. if (PlatformIdentifier.IsWindows())
  55. return FindTool.ObtainToolCommand(
  56. Gluon.GUI_WINDOWS,
  57. new List<String>() { GetWindowsInstallationFolder() });
  58. if (PlatformIdentifier.IsMac())
  59. {
  60. string path = GetToolCommand(Gluon.NEW_GUI_MACOS);
  61. if (path != null)
  62. return path;
  63. return GetToolCommand(Gluon.LEGACY_GUI_MACOS);
  64. }
  65. return null;
  66. }
  67. static string GetToolCommand(string tool)
  68. {
  69. return File.Exists(tool) ? tool : null;
  70. }
  71. static string GetExistingDir(string directory)
  72. {
  73. return Directory.Exists(directory) ? directory : null;
  74. }
  75. static string GetWindowsInstallationFolder()
  76. {
  77. string programFilesFolder = Environment.GetFolderPath(
  78. Environment.SpecialFolder.ProgramFiles);
  79. return Path.Combine(Path.Combine(programFilesFolder,
  80. PLASTICSCM_FOLDER), PLASTICSCM_SUBFOLDER);
  81. }
  82. const string PLASTICSCM_FOLDER = "PlasticSCM5";
  83. const string PLASTICSCM_SUBFOLDER = "client";
  84. class Plastic
  85. {
  86. internal const string GUI_WINDOWS = "plastic.exe";
  87. internal const string LEGACY_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/PlasticSCM";
  88. internal const string NEW_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx";
  89. }
  90. class Gluon
  91. {
  92. internal const string GUI_WINDOWS = "gluon.exe";
  93. internal const string LEGACY_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/Gluon";
  94. internal const string NEW_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/macgluonx";
  95. }
  96. }
  97. }