IsExeAvailable.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. return GetExistingDir(ToolConstants.MACOS_BINDIR);
  30. return null;
  31. }
  32. internal static string GetPlasticExePath()
  33. {
  34. if (PlatformIdentifier.IsWindows())
  35. return FindTool.ObtainToolCommand(
  36. Plastic.GUI_WINDOWS,
  37. new List<String>() { GetWindowsInstallationFolder() });
  38. if (PlatformIdentifier.IsMac())
  39. return GetToolCommand(Plastic.GUI_MACOS);
  40. return null;
  41. }
  42. internal static string GetGluonExePath()
  43. {
  44. if (PlatformIdentifier.IsWindows())
  45. return FindTool.ObtainToolCommand(
  46. Gluon.GUI_WINDOWS,
  47. new List<String>() { GetWindowsInstallationFolder() });
  48. if (PlatformIdentifier.IsMac())
  49. return GetToolCommand(Gluon.GUI_MACOS);
  50. return null;
  51. }
  52. static string GetToolCommand(string tool)
  53. {
  54. return File.Exists(tool) ? tool : null;
  55. }
  56. static string GetExistingDir(string directory)
  57. {
  58. return Directory.Exists(directory) ? directory : null;
  59. }
  60. static string GetWindowsInstallationFolder()
  61. {
  62. string programFilesFolder = Environment.GetFolderPath(
  63. Environment.SpecialFolder.ProgramFiles);
  64. return Path.Combine(Path.Combine(programFilesFolder,
  65. PLASTICSCM_FOLDER), PLASTICSCM_SUBFOLDER);
  66. }
  67. const string PLASTICSCM_FOLDER = "PlasticSCM5";
  68. const string PLASTICSCM_SUBFOLDER = "client";
  69. class Plastic
  70. {
  71. internal const string GUI_WINDOWS = "plastic.exe";
  72. internal const string GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/PlasticSCM";
  73. }
  74. class Gluon
  75. {
  76. internal const string GUI_WINDOWS = "gluon.exe";
  77. internal const string GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/Gluon";
  78. }
  79. }
  80. }