Beispiel #1
0
 static Canvas()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         WindowsEnvironment.Init();
     }
 }
Beispiel #2
0
        public CommandContext()
        {
            Streams = new StandardStreams();
            Trace   = new Trace();
            Git     = new LibGit2(Trace);

            if (PlatformUtils.IsWindows())
            {
                FileSystem      = new WindowsFileSystem();
                Environment     = new WindowsEnvironment(FileSystem);
                Terminal        = new WindowsTerminal(Trace);
                CredentialStore = WindowsCredentialManager.Open();
            }
            else if (PlatformUtils.IsPosix())
            {
                if (PlatformUtils.IsMacOS())
                {
                    FileSystem      = new MacOSFileSystem();
                    CredentialStore = MacOSKeychain.Open();
                }
                else if (PlatformUtils.IsLinux())
                {
                    throw new NotImplementedException();
                }

                Environment = new PosixEnvironment(FileSystem);
                Terminal    = new PosixTerminal(Trace);
            }

            string repoPath = Git.GetRepositoryPath(FileSystem.GetCurrentDirectory());

            Settings          = new Settings(Environment, Git, repoPath);
            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);
        }
        public void WindowsEnvironment_TryLocateExecutable_NotExists_ReturnFalse()
        {
            string pathVar  = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows";
            string execName = "foo.exe";
            var    fs       = new TestFileSystem();
            var    envars   = new Dictionary <string, string> {
                ["PATH"] = pathVar
            };
            var env = new WindowsEnvironment(fs, envars);

            bool actualResult = env.TryLocateExecutable(execName, out string actualPath);

            Assert.False(actualResult);
            Assert.Null(actualPath);
        }
        public void WindowsEnvironment_TryLocateExecutable_Windows_Exists_ReturnTrueAndPath()
        {
            string pathVar      = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows";
            string execName     = "foo.exe";
            string expectedPath = @"C:\Windows\system32\foo.exe";
            var    fs           = new TestFileSystem
            {
                Files = new Dictionary <string, byte[]>
                {
                    [@"C:\Windows\system32\foo.exe"] = new byte[0],
                }
            };
            var envars = new Dictionary <string, string> {
                ["PATH"] = pathVar
            };
            var env = new WindowsEnvironment(fs, envars);

            bool actualResult = env.TryLocateExecutable(execName, out string actualPath);

            Assert.True(actualResult);
            Assert.Equal(expectedPath, actualPath);
        }
Beispiel #5
0
        public CommandContext()
        {
            Streams = new StandardStreams();
            Trace   = new Trace();

            if (PlatformUtils.IsWindows())
            {
                FileSystem     = new WindowsFileSystem();
                SessionManager = new WindowsSessionManager();
                SystemPrompts  = new WindowsSystemPrompts();
                Environment    = new WindowsEnvironment(FileSystem);
                Terminal       = new WindowsTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem);
                Git = new GitProcess(
                    Trace,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings        = new Settings(Environment, Git);
                CredentialStore = new WindowsCredentialManager(Settings.CredentialNamespace);
            }
            else if (PlatformUtils.IsMacOS())
            {
                FileSystem     = new MacOSFileSystem();
                SessionManager = new MacOSSessionManager();
                SystemPrompts  = new MacOSSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new PosixTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem);
                Git = new GitProcess(
                    Trace,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings        = new Settings(Environment, Git);
                CredentialStore = new MacOSKeychain(Settings.CredentialNamespace);
            }
            else if (PlatformUtils.IsLinux())
            {
                FileSystem = new LinuxFileSystem();
                // TODO: support more than just 'Posix' or X11
                SessionManager = new PosixSessionManager();
                SystemPrompts  = new LinuxSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new PosixTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem);
                Git = new GitProcess(
                    Trace,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings = new Settings(Environment, Git);
                IGpg gpg = new Gpg(
                    Environment.LocateExecutable("gpg"),
                    SessionManager
                    );
                CredentialStore = new LinuxCredentialStore(FileSystem, Settings, SessionManager, gpg, Environment);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);

            // Set the parent window handle/ID
            SystemPrompts.ParentWindowId = Settings.ParentWindowId;
        }
 public static Optional <AbsoluteDirectoryPath> SublimeTextPath()
 {
     return(Platform.OperatingSystem == OS.Mac
                         ? MacEnvironment.GetPathToApplicationsThatContains("com.sublimetext.3").FirstOrNone()
                         : WindowsEnvironment.LookForPathInUninstall("Sublime Text Build").FirstOrNone());
 }
 public static Optional <AbsoluteDirectoryPath> AtomPath()
 {
     return(Platform.OperatingSystem == OS.Mac
                         ? MacEnvironment.GetPathToApplicationsThatContains("com.github.atom").FirstOrNone()
                         : WindowsEnvironment.LookForPathInApplications("atom.exe").FirstOrNone().Select(path => path.ContainingDirectory));
 }
 public static Optional <AbsoluteDirectoryPath> VsCodePath()
 {
     return(Platform.OperatingSystem == OS.Mac
                         ? MacEnvironment.GetPathToApplicationsThatContains("com.microsoft.VSCode").FirstOrNone()
                         : WindowsEnvironment.LookForPathInUninstall("Microsoft Visual Studio Code").FirstOrNone());
 }
        public CommandContext(string appPath)
        {
            EnsureArgument.NotNullOrWhiteSpace(appPath, nameof(appPath));

            ApplicationPath = appPath;
            Streams         = new StandardStreams();
            Trace           = new Trace();

            if (PlatformUtils.IsWindows())
            {
                FileSystem     = new WindowsFileSystem();
                SessionManager = new WindowsSessionManager();
                SystemPrompts  = new WindowsSystemPrompts();
                Environment    = new WindowsEnvironment(FileSystem);
                Terminal       = new WindowsTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem, Trace);
                Git = new GitProcess(
                    Trace,
                    Environment,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings = new WindowsSettings(Environment, Git, Trace);
            }
            else if (PlatformUtils.IsMacOS())
            {
                FileSystem     = new MacOSFileSystem();
                SessionManager = new MacOSSessionManager();
                SystemPrompts  = new MacOSSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new MacOSTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem, Trace);
                Git = new GitProcess(
                    Trace,
                    Environment,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings = new Settings(Environment, Git);
            }
            else if (PlatformUtils.IsLinux())
            {
                FileSystem = new LinuxFileSystem();
                // TODO: support more than just 'Posix' or X11
                SessionManager = new PosixSessionManager();
                SystemPrompts  = new LinuxSystemPrompts();
                Environment    = new PosixEnvironment(FileSystem);
                Terminal       = new LinuxTerminal(Trace);
                string gitPath = GetGitPath(Environment, FileSystem, Trace);
                Git = new GitProcess(
                    Trace,
                    Environment,
                    gitPath,
                    FileSystem.GetCurrentDirectory()
                    );
                Settings = new Settings(Environment, Git);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            HttpClientFactory = new HttpClientFactory(FileSystem, Trace, Settings, Streams);
            CredentialStore   = new CredentialStore(this);

            // Set the parent window handle/ID
            SystemPrompts.ParentWindowId = Settings.ParentWindowId;
        }