private string GetPreferredConfigPath() { string filepath; var args = new List <string> { "-c", $"XDG_UTILS_DEBUG_LEVEL=2 {XdgSettings} get default-url-scheme-handler" }; var exitCode = _osServices.Execute("sh", args, out var stdOut, out _); if (exitCode == 0) { var lines = stdOut.Split("\n"); if (lines.Any()) { var path = lines[0]; var match = Regex.Match(path, "\\s*Checking\\s*(\\S+)", RegexOptions.IgnoreCase); if (match.Success) { filepath = match.Groups[1].Value; if (Path.IsPathFullyQualified(filepath)) { Serilog.Log.Information($"preferred config Path is {filepath}"); return(filepath); } } } } filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), XdgConfigPath); if (!File.Exists(filepath)) { filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), AppRelPath); } Serilog.Log.Information($"using default config path:{filepath}"); return(filepath); }
public MacOSProtocolRegistrar(IOsServices osServices) { _osServices = osServices; string path; string err; var res = _osServices.Execute("/usr/bin/mdfind", new List <string> { $"kMDItemCFBundleIdentifier='{_scalusHandler}'" }, out path, out err); path = Regex.Replace(path, "[\r\n ]", "", RegexOptions.Singleline); if (res != 0 || string.IsNullOrEmpty(path)) { Serilog.Log.Warning($"Handler:{_scalusHandler} is not installed"); _appPath = AppPath; } if (!Directory.Exists(path)) { Serilog.Log.Warning($"Handler path:{path} does not exist or is not accessible - using default path"); _appPath = AppPath; } else { _appPath = path; } _appInfo = $"{_appPath}/Contents/Info"; _appInfoPlist = $"{_appInfo}.plist"; Serilog.Log.Information($"Using configured app from path: {_appPath}"); }
public virtual void PreExecute(IOsServices services) { if (string.IsNullOrEmpty(_fileProcessorExe)) { return; } Serilog.Log.Debug($"Starting file preprocessor: '{_fileProcessorExe}' with args: '{string.Join(' ', _fileProcessorArgs)}'"); if (!File.Exists(_fileProcessorExe)) { Serilog.Log.Error($"Selected file preprocessor does not exist:{_fileProcessorExe}"); return; } string output; string err; var res = services.Execute(_fileProcessorExe, _fileProcessorArgs, out output, out err); Serilog.Log.Information($"File preprocess result:{res}, output:{output}, err:{err}"); }
private bool RunCommand(string cmd, List <string> args, out string output) { try { string err; var res = _osServices.Execute(cmd, args, out output, out err); if (res == 0) { return(true); } if (!string.IsNullOrEmpty(err)) { output = $"{output}\n{err}"; } return(res == 0); } catch (Exception e) { output = e.Message; return(false); } }