示例#1
0
        public void TestAddHandler()
        {
            OpenRepo.Handler.TestRegistry registry = new TestRegistry();
            var registration = new HandlerRegistration() { Description = "Unit Test Github for Windows (OpenRepo 1.01 Shim)", ProtocolName = "github-windows", HandlerPath = "fake-handler.exe" };
            registry.SetHandlerForProtocol(registration);

            Assert.IsTrue(registry.OpenURL("github-windows://fake"));
        }
示例#2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("OpenRepo github-windows:// shim");
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("Launching this with an argument of github-windows://<path> should open SourceTree to clone the repo");
                Console.WriteLine("To set this up, run openrepo.exe /register-github (as current user, or Administrator)");

                Environment.Exit(1);
            }

            if (args[0].Contains("register-github"))
            {
               var registration = new HandlerRegistration() { Description = "Github for Windows (OpenRepo 1.01 Shim)", ProtocolName = "github-windows", HandlerPath = Assembly.GetEntryAssembly().Location };
               var provider = new WindowsRegistry();

                provider.SetHandlerForProtocol(registration);
                Console.WriteLine("Registered github-windows:// protocol handler");
                Environment.Exit(0);
            }

            if (!args[0].StartsWith("github-windows://"))
            {
                Environment.Exit(1);
            }

            else
            {
                string[] split = args[0].ToLowerInvariant().Split(new[] { "github-windows://openrepo/" }, StringSplitOptions.RemoveEmptyEntries); //there has to be a nicer way to do this
                bool useShellExecute = true; //if I'm starting another handler, I can use shellexecute. If I'm starting an exe out of PATH I can't.
                string handler = "sourcetree://cloneRepo/"; //default config, try using SourceTree
                string commandLine = split[0];
                //for example, github-windows://openRepo/https://github.com/voltagex/junkcode

                var info = new ProcessStartInfo()
                {
                    UseShellExecute = useShellExecute,
                    FileName = handler,
                    Arguments = commandLine,
                    RedirectStandardOutput = false
                };

                Process.Start(info);
            }
        }
示例#3
0
        public bool SetHandlerForProtocol(HandlerRegistration handler)
        {
            Trace.WriteLine(string.Format("Attempting to register as {0}:// handler",handler.ProtocolName));
            RegistryKey softwareClasses =
                Registry.CurrentUser.OpenSubKey("Software\\Classes", true).CreateSubKey(handler.ProtocolName);
            softwareClasses.SetValue("", "URL:" + handler.Description);
            softwareClasses.SetValue("URL Protocol", "");

            RegistryKey shell = softwareClasses.CreateSubKey("shell");
            RegistryKey open = shell.CreateSubKey("open");
            RegistryKey command = open.CreateSubKey("command");
            command.SetValue("", System.Reflection.Assembly.GetEntryAssembly().Location + " %1");

            RegistryKey defaultIcon = softwareClasses.CreateSubKey("DefaultIcon");
            defaultIcon.SetValue("", Path.GetFileName(string.IsNullOrEmpty(handler.DefaultIconPath) ? handler.HandlerPath : handler.DefaultIconPath));
            return
                Registry.CurrentUser.OpenSubKey("Software\\Classes", true)
                    .GetSubKeyNames()
                    .Contains(handler.ProtocolName);
        }
示例#4
0
 public bool SetHandlerForProtocol(HandlerRegistration handler)
 {
     Trace.WriteLine(string.Format("Attempting to register as {0}:// handler", handler.ProtocolName));
     handlers.Add(handler);
     return true;
 }