A game about forced loneliness, made by TACStudios
at master 180 lines 6.0 kB view raw
1using System; 2using System.Collections.Generic; 3using System.IO; 4 5using Codice.Client.Common; 6using Codice.LogWrapper; 7using Codice.Utils; 8 9namespace Unity.PlasticSCM.Editor.Tool 10{ 11 internal static class IsExeAvailable 12 { 13 internal static bool ForMode(bool isGluonMode) 14 { 15 string toolPath = isGluonMode ? 16 PlasticInstallPath.GetGluonExePath() : 17 PlasticInstallPath.GetPlasticExePath(); 18 19 return !string.IsNullOrEmpty(toolPath); 20 } 21 22 internal static bool ForLocalServer() 23 { 24 return !string.IsNullOrEmpty(PlasticInstallPath.GetLocalPlasticServerExePath()); 25 } 26 } 27 28 internal static class PlasticInstallPath 29 { 30 internal static string GetClientBinDir() 31 { 32 if (PlatformIdentifier.IsWindows()) 33 { 34 string plasticExePath = GetPlasticExePath(); 35 36 if (plasticExePath == null) 37 return null; 38 39 return Path.GetDirectoryName(plasticExePath); 40 } 41 42 if (PlatformIdentifier.IsMac()) 43 { 44 string path = GetToolCommand(Plastic.NEW_GUI_MACOS); 45 if (path != null) 46 return GetExistingDir(ToolConstants.NEW_MACOS_BINDIR); 47 48 return GetExistingDir(ToolConstants.LEGACY_MACOS_BINDIR); 49 } 50 51 return null; 52 } 53 54 internal static string GetPlasticExePath() 55 { 56 if (PlatformIdentifier.IsWindows()) 57 return FindTool.ObtainToolCommand( 58 Plastic.GUI_WINDOWS, 59 new List<String>() { GetWindowsClientInstallationFolder() }); 60 61 if (PlatformIdentifier.IsMac()) 62 { 63 string path = GetToolCommand(Plastic.NEW_GUI_MACOS); 64 if(path != null) 65 return path; 66 67 return GetToolCommand(Plastic.LEGACY_GUI_MACOS); 68 } 69 70 return null; 71 } 72 73 internal static string GetGluonExePath() 74 { 75 if (PlatformIdentifier.IsWindows()) 76 return FindTool.ObtainToolCommand( 77 Gluon.GUI_WINDOWS, 78 new List<String>() { GetWindowsClientInstallationFolder() }); 79 80 if (PlatformIdentifier.IsMac()) 81 { 82 string path = GetToolCommand(Gluon.NEW_GUI_MACOS); 83 if (path != null) 84 return path; 85 86 return GetToolCommand(Gluon.LEGACY_GUI_MACOS); 87 } 88 89 return null; 90 } 91 92 internal static string GetLocalPlasticServerExePath() 93 { 94 if (PlatformIdentifier.IsWindows()) 95 { 96 return FindTool.ObtainToolCommand( 97 Plastic.LOCAL_SERVER_WINDOWS, 98 new List<String>() { GetWindowsServerInstallationFolder() }); 99 } 100 101 if (PlatformIdentifier.IsMac()) 102 { 103 return GetToolCommand(Plastic.LOCAL_SERVER_MACOS); 104 } 105 106 return null; 107 } 108 109 internal static void LogInstallationInfo() 110 { 111 string plasticClientBinDir = GetClientBinDir(); 112 113 if (string.IsNullOrEmpty(plasticClientBinDir)) 114 { 115 mLog.DebugFormat("No installation found, behaving as {0} Edition", 116 EditionToken.IsCloudEdition() ? "Cloud" : "Enterprise"); 117 } 118 else 119 { 120 bool isCloudPlasticInstall = File.Exists(Path.Combine(plasticClientBinDir, EditionToken.CLOUD_EDITION_FILE_NAME)); 121 122 mLog.DebugFormat("{0} Edition detected - installation directory: {1}", 123 isCloudPlasticInstall ? "Cloud" : "Enterprise", 124 plasticClientBinDir); 125 mLog.DebugFormat("Local token: {0} Edition", 126 EditionToken.IsCloudEdition() ? "Cloud" : "Enterprise"); 127 } 128 } 129 130 static string GetToolCommand(string tool) 131 { 132 return File.Exists(tool) ? tool : null; 133 } 134 135 static string GetExistingDir(string directory) 136 { 137 return Directory.Exists(directory) ? directory : null; 138 } 139 140 static string GetWindowsClientInstallationFolder() 141 { 142 string programFilesFolder = Environment.GetFolderPath( 143 Environment.SpecialFolder.ProgramFiles); 144 145 return Path.Combine(Path.Combine(programFilesFolder, 146 PLASTICSCM_FOLDER), PLASTICSCM_CLIENT_SUBFOLDER); 147 } 148 149 static string GetWindowsServerInstallationFolder() 150 { 151 string programFilesFolder = Environment.GetFolderPath( 152 Environment.SpecialFolder.ProgramFiles); 153 154 return Path.Combine(Path.Combine(programFilesFolder, 155 PLASTICSCM_FOLDER), PLASTICSCM_SERVER_SUBFOLDER); 156 } 157 158 const string PLASTICSCM_FOLDER = "PlasticSCM5"; 159 const string PLASTICSCM_CLIENT_SUBFOLDER = "client"; 160 const string PLASTICSCM_SERVER_SUBFOLDER = "server"; 161 162 static readonly ILog mLog = PlasticApp.GetLogger("PlasticInstallPath"); 163 164 class Plastic 165 { 166 internal const string GUI_WINDOWS = "plastic.exe"; 167 internal const string LOCAL_SERVER_WINDOWS = "plasticd.exe"; 168 internal const string LEGACY_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/PlasticSCM"; 169 internal const string NEW_GUI_MACOS = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx"; 170 internal const string LOCAL_SERVER_MACOS = "/Applications/PlasticSCMServer.app/Contents/MacOS/plasticd"; 171 } 172 173 class Gluon 174 { 175 internal const string GUI_WINDOWS = "gluon.exe"; 176 internal const string LEGACY_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/Gluon"; 177 internal const string NEW_GUI_MACOS = "/Applications/Gluon.app/Contents/MacOS/macgluonx"; 178 } 179 } 180}