windows: add custom protocol handling
This commit is contained in:
parent
bfb82bb207
commit
3d4a2bea11
|
@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
|
|||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SparkleShareInviteOpener", "SparkleShare\Windows\SparkleShareInviteOpener\SparkleShareInviteOpener.csproj", "{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
SparkleShare\Common\SparkleShare.projitems*{728483aa-e34b-4441-bf2c-c8bc2901e4e0}*SharedItemsImports = 4
|
||||
|
@ -100,6 +102,19 @@ Global
|
|||
{5714D3CA-88A6-4330-A29D-4CA90D1D193C}.ReleaseDist|Any CPU.Build.0 = Release|Any CPU
|
||||
{5714D3CA-88A6-4330-A29D-4CA90D1D193C}.ReleaseMac|Any CPU.ActiveCfg = ReleaseMac|Any CPU
|
||||
{5714D3CA-88A6-4330-A29D-4CA90D1D193C}.ReleaseWindows|Any CPU.ActiveCfg = ReleaseMac|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.DebugWindows|Any CPU.ActiveCfg = DebugWindows|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.DebugWindows|Any CPU.Build.0 = DebugWindows|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseDist|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseDist|Any CPU.Build.0 = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseMac|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseMac|Any CPU.Build.0 = Release|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseWindows|Any CPU.ActiveCfg = ReleaseWindows|Any CPU
|
||||
{1DB5492D-B897-4A5E-8DD7-175EC65F52F2}.ReleaseWindows|Any CPU.Build.0 = ReleaseWindows|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -144,15 +144,6 @@
|
|||
<Reference Include="System.Xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\AboutController.cs" />
|
||||
<Compile Include="..\Common\Avatars.cs" />
|
||||
<Compile Include="..\Common\BaseController.cs" />
|
||||
<Compile Include="..\Common\BubblesController.cs" />
|
||||
<Compile Include="..\Common\EventLogController.cs" />
|
||||
<Compile Include="..\Common\NoteController.cs" />
|
||||
<Compile Include="..\Common\SetupController.cs" />
|
||||
<Compile Include="..\Common\SparkleShare.cs" />
|
||||
<Compile Include="..\Common\StatusIconController.cs" />
|
||||
<Compile Include="UserInterface\About.cs" />
|
||||
<Compile Include="UserInterface\Bubbles.cs" />
|
||||
<Compile Include="UserInterface\EventLog.cs" />
|
||||
|
@ -161,6 +152,7 @@
|
|||
<DependentUpon>Note.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UserInterface\NotifyIcon.cs" />
|
||||
<Compile Include="UserInterface\ProtocolHandler.cs" />
|
||||
<Compile Include="UserInterface\Setup.cs" />
|
||||
<Compile Include="UserInterface\SetupWindow.cs" />
|
||||
<Compile Include="UserInterface\Shortcut.cs" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
|
||||
|
@ -29,6 +29,24 @@
|
|||
<DebugType>full</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugWindows|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\..\..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWindows|AnyCPU'">
|
||||
<OutputPath>..\..\..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
|
|
74
SparkleShare/Windows/UserInterface/ProtocolHandler.cs
Normal file
74
SparkleShare/Windows/UserInterface/ProtocolHandler.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
// SparkleShare, a collaboration and sharing tool.
|
||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System.IO;
|
||||
|
||||
namespace SparkleShare
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Maintain Protocol Handlers created by SparkleShare
|
||||
/// </summary>
|
||||
static class SparkleProtocolHandler
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Add or Update protocol handler
|
||||
/// </summary>
|
||||
/// <param name="handleName">The name of the handler to add</param>
|
||||
/// <param name="handleValue">Default value of the protocol handler</param>
|
||||
/// <param name="handleCommand">The arguments passed to the Invite Opener</param>
|
||||
internal static void AddProtocolHandler(string handleName, string handleValue, string handleCommand)
|
||||
{
|
||||
var inviteOpener = Path.Combine(Directory.GetCurrentDirectory(), "SparkleShareInviteOpener");
|
||||
|
||||
// test the handleName for third party protocols like GitHub
|
||||
// if one exist and their default value doesn't match our custom Protocol, do not update
|
||||
using (RegistryKey testKey = Registry.ClassesRoot.OpenSubKey(handleName))
|
||||
{
|
||||
if (testKey == null || handleValue.Equals(testKey.GetValue("")))
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("Classes").CreateSubKey(handleName))
|
||||
{
|
||||
key.SetValue("", handleValue);
|
||||
key.SetValue("URL Protocol", "");
|
||||
key.CreateSubKey("DefaultIcon").SetValue("", inviteOpener);
|
||||
key.CreateSubKey("shell")
|
||||
.CreateSubKey("open")
|
||||
.CreateSubKey("command")
|
||||
.SetValue("", inviteOpener + " " + handleCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove protocol handler
|
||||
/// </summary>
|
||||
/// <param name="handleName">The name of the handler to remove</param>
|
||||
/// <param name="handleValue">Default value of the protocol handler</param>
|
||||
internal static void RemoveProtocolHandler(string handleName, string handleValue)
|
||||
{
|
||||
var key = Registry.CurrentUser.OpenSubKey(handleName);
|
||||
|
||||
// if the the default value doesn't match our custom Protocol, do not remove
|
||||
if (key != null && handleValue.Equals(key.GetValue("")))
|
||||
Registry.CurrentUser.DeleteSubKeyTree(handleName);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue