6

我很好奇按钮的工作原理。你能解释一下当我点击“在 Windows 中克隆”按钮时,它是如何知道在我的机器上打开本地应用程序(GitHub)的。

4

2 回答 2

4

看看这个GitExtension补丁:它在 HKCR 中注册了该操作

  <Component Id="Protocol.github_windows" Guid="*">
    <RegistryKey Key="github-windows" Root="HKCR">
      <RegistryValue Value="URL: Github for Windows Protocol" Type="string" />
      <RegistryValue Name="URL Protocol" Value="" Type="string" />
    </RegistryKey>
    <RegistryKey Key="github-windows\DefaultIcon" Root="HKCR">
      <RegistryValue Value="[INSTALLDIR]GitExtensions.exe" Type="string" />
    </RegistryKey>
    <RegistryKey Root="HKCR" Key="github-windows\shell"/>
    <RegistryKey Root="HKCR" Key="github-windows\shell\open"/>
    <RegistryKey Root="HKCR" Key="github-windows\shell\open\command">
      <RegistryValue Value="&quot;[INSTALLDIR]GitExtensions.exe&quot; %1" Type="string" />
    </RegistryKey>
  </Component>

它补充说:

if (args[1].StartsWith("git://"))
{
    args = new string[]{args[0], "clone", args[1]};
}
if (args[1].StartsWith("github-windows://openRepo/"))
{
     args = new string[]{args[0], "clone", args[1].Replace("github-windows://openRepo/", "")};
}

GitHub for Windows将采用类似的方法。

于 2012-11-20T10:37:39.663 回答
0

它在 TortoiseGit 应用程序中非常相似。

这是TortoiseGit的github-windows 协议处理程序

newCmd.Format(_T("/command:clone /url:\"%s\" /hasurlhandler"), (LPCTSTR)url);

它将注册表项添加到注册处理程序。

<RegistryValue Root="HKLM" Key="Software\Classes\github-windows\shell\open\command" Value="&quot;[INSTALLDIR]bin\TortoiseGitProc.exe&quot; /urlhandler:&quot;%1&quot;" Type="string" />
于 2015-12-03T22:06:15.373 回答