public string ResolvePath() { if (ShouldlyEnvironmentContext.IsWindows()) { return(WindowsPath); } if (ShouldlyEnvironmentContext.IsMac()) { return(MacPath); } if (ShouldlyEnvironmentContext.IsLinux()) { return(LinuxPath); } return(string.Empty); }
private static string Discover(string path) { if (path == null) { return(null); } var exeName = Path.GetFileName(path); var fullPathFromPathEnv = GetFullPath(exeName); if (!string.IsNullOrEmpty(fullPathFromPathEnv)) { return(fullPathFromPathEnv); } if (ShouldlyEnvironmentContext.IsMac()) { var result = new[] { "/Applications/" } .Where(p => { return(p != null); }) .Select(pf => { var r = Path.Combine(pf, path); return(r); }) .FirstOrDefault(File.Exists); return(result); } return(new[] { Environment.GetEnvironmentVariable("ProgramFiles(x86)"), Environment.GetEnvironmentVariable("ProgramFiles"), Environment.GetEnvironmentVariable("ProgramW6432") } .Where(p => p != null) .Select(pf => Path.Combine(pf, path)) .FirstOrDefault(File.Exists)); }
private static string GetFullPath(string fileName) { if (File.Exists(fileName)) { return(Path.GetFullPath(fileName)); } var processPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process); var userPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User); var machinePath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine); var values = $"{processPath};{userPath};{machinePath}"; var separator = ShouldlyEnvironmentContext.IsWindows() ? ';' : ':'; return(values.Split(separator) .Where(p => !string.IsNullOrEmpty(p)) .Select(path => path.Trim('"')) .Select(path => TryCombine(fileName, path)) .FirstOrDefault(File.Exists)); }
private static string GenerateMessage(string message, string receivedFile, string approvedFile) { var msg = @"To approve the changes run this command:"; if (ShouldlyEnvironmentContext.IsWindows()) { msg += $@" copy /Y ""{receivedFile}"" ""{approvedFile}"""; } else { msg += $@" cp ""{receivedFile}"" ""{approvedFile}"""; } msg += $@" ---------------------------- {message}"; return(msg); }
public bool ShouldNotLaunch() { return(!ShouldlyEnvironmentContext.IsWindows()); }
private static string BeyondCompareArgs(string received, string approved, bool approvedExists) { return(approvedExists ? $"\"{received}\" \"{approved}\" " + (ShouldlyEnvironmentContext.IsWindows() ? "/" :"-") + $"mergeoutput=\"{approved}\"" : $"\"{received}\" " + (ShouldlyEnvironmentContext.IsWindows() ? "/" :"-") + $"mergeoutput=\"{approved}\""); }