public static Optional <AbsoluteFilePath> TryFindExecutableInPath(string name, IObserver <string> warnings) { try { if (Platform.OperatingSystem == OS.Windows) { var whereStartInfo = new ProcessStartInfo("where") { Arguments = '"' + name + '"', RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, }; var where = Process.Start(whereStartInfo); var path = @where.StandardOutput.ReadLine(); @where.WaitForExit(); return(@where.ExitCode != 0 ? Optional.None() : AbsoluteFilePath.TryParse(path.Trim())); } else if (Platform.OperatingSystem == OS.Mac) { Optional <AbsoluteFilePath> path = Optional.None(); var result = ProcessHelper.StartProcess( new ProcessStartInfo("which", '"' + name + '"') { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }, CancellationToken.None, which => { var pathRaw = which.StandardOutput.ReadLine(); if (pathRaw != null) { path = AbsoluteFilePath.TryParse(pathRaw.Trim()); } }); return(result != 0 ? Optional.None() : path.Select <AbsoluteFilePath, AbsoluteFilePath>(ReadLinkIfLink)); } } catch (Exception e) { warnings.OnNext("WARNING: " + e.Message); return(Optional.None()); } throw new PlatformNotSupportedException(); }
public static Optional <SourceReference> ToSourceReference(this Source src) { if (src.IsUnknown) { return(Optional.None()); } var path = AbsoluteFilePath.TryParse(src.FullPath); if (path.HasValue) { return(new SourceReference(path.Value.NativePath, src.ToLocation())); } return(Optional.None()); }
static AbsoluteFilePath ReadLinkIfLink(AbsoluteFilePath input) { Optional <AbsoluteFilePath> linkPointsToPath = Optional.None(); var result = ProcessHelper.StartProcess( new ProcessStartInfo("readlink", '"' + input.NativePath + '"') { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }, CancellationToken.None, readlink => { var pathRaw = readlink.StandardOutput.ReadLine(); linkPointsToPath = AbsoluteFilePath.TryParse(pathRaw.Trim()); }); return(result != 0 ? input : linkPointsToPath.Or(input)); }
public static void Create() { var lightTheme = new OriginalLightTheme(); var darkTheme = new OriginalDarkTheme(); var path = new BehaviorSubject <string>(string.Empty); var refresh = new BehaviorSubject <Unit>(Unit.Default); var image = path .CombineLatest(refresh, ((p, _) => p)) .Select(p => AbsoluteFilePath.TryParse(p) .Where(f => File.Exists(f.NativePath)) .Select( absPath => absPath.NativePath.EndsWith(".svg") ? (IImage) new SvgImage(() => File.OpenRead(absPath.NativePath)) : new MultiResolutionImage( new[] { new ImageStream(new Ratio <Pixels, Points>(1), () => File.OpenRead(absPath.NativePath)) })) .Or(() => (IImage) new SvgImage(() => new MemoryStream(FallbackImage)))); var content = Layout.Dock().Top( Layout.Dock() .Left(Label.Create("Path: ", font: Theme.DefaultFont, color: Theme.DefaultText).CenterVertically()) .Right(Buttons.DefaultButton("Refresh", Command.Enabled(() => refresh.OnNext(Unit.Default)))) .Fill(ThemedTextBox.Create(path.AsProperty()))) .Fill(Layout.SubdivideHorizontally(ImageVersionsRowForTheme(image, darkTheme), ImageVersionsRowForTheme(image, lightTheme))) .WithBackground(Theme.PanelBackground); Application.Desktop.CreateSingletonWindow( Observable.Return(true), dialog => new Window { Title = Observable.Return("Icon preview"), Size = Property.Create <Optional <Size <Points> > >(new Size <Points>(600, 600)).ToOptional(), Content = content, Background = Theme.PanelBackground, Foreground = Theme.DefaultText, Border = Separator.MediumStroke }); }
public DialogPathResult(string rawPath) { _rawPath = rawPath; Path = AbsoluteDirectoryPath.TryParse(rawPath).Select(p => (IAbsolutePath)p) .Or(AbsoluteFilePath.TryParse(rawPath).Select(p => (IAbsolutePath)p)); }