private IResult UnregisterPath(EnvironmentVariableTarget target) { var result = new EnvironmentResult(); string pathValue = Environment.GetEnvironmentVariable(PathVariableName, target); var paths = pathValue.Split(Path.PathSeparator); string clioPath = string.Empty; foreach (var path in paths) { if (Directory.Exists(path)) { var dir = new DirectoryInfo(path); var files = dir.GetFiles("clio.cmd"); if (files.Length > 0) { clioPath = path; break; } } } if (string.IsNullOrEmpty(clioPath)) { result.AppendMessage($"Application already unregistered!"); return(result); } result.AppendMessage($"Unregister path {clioPath} in {PathVariableName} variable."); string newValue = pathValue.Replace(clioPath, string.Empty).Replace(String.Concat(Path.PathSeparator, Path.PathSeparator), Path.PathSeparator.ToString()); Environment.SetEnvironmentVariable(PathVariableName, newValue, target); result.AppendMessage($"{PathVariableName} variable unregistered."); return(result); }
private IResult RegisterPath(string path, EnvironmentVariableTarget target) { var result = new EnvironmentResult(); string pathValue = Environment.GetEnvironmentVariable(PathVariableName, target); if (string.IsNullOrEmpty(pathValue)) { pathValue = string.Empty; } if (pathValue.Contains(path)) { result.AppendMessage($"{PathVariableName} variable already registered!"); return(result); } result.AppendMessage($"register path {path} in {PathVariableName} variable."); var value = string.Concat(pathValue, Path.PathSeparator + path.Trim(Path.PathSeparator)); Environment.SetEnvironmentVariable(PathVariableName, value, target); result.AppendMessage($"{PathVariableName} variable registered."); return(result); }