This repository has been archived by the owner. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution should be working already.
- Loading branch information
Showing
6 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26206.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdgeDeflector", "EdgeDeflector\EdgeDeflector.csproj", "{64E191BC-E8CE-4190-939E-C77A75AA0E28}" | ||
EndProject | ||
Global | ||
GlobalSection(Performance) = preSolution | ||
HasPerformanceSessions = true | ||
EndGlobalSection | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{64E191BC-E8CE-4190-939E-C77A75AA0E28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{64E191BC-E8CE-4190-939E-C77A75AA0E28}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{64E191BC-E8CE-4190-939E-C77A75AA0E28}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{64E191BC-E8CE-4190-939E-C77A75AA0E28}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> | ||
</startup> | ||
<uri> | ||
<idn enabled="All"/> | ||
<iriParsing enabled="true"/> | ||
</uri> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{64E191BC-E8CE-4190-939E-C77A75AA0E28}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>EdgeDeflector</RootNamespace> | ||
<AssemblyName>EdgeDeflector</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<RunCodeAnalysis>true</RunCodeAnalysis> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<RunCodeAnalysis>true</RunCodeAnalysis> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject>EdgeDeflector.Program</StartupObject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>Icon.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<BootstrapperPackage Include=".NETFramework,Version=v4.6"> | ||
<Visible>False</Visible> | ||
<ProductName>Microsoft .NET Framework 4.6 %28x86 and x64%29</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Icon.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Security.Principal; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace EdgeDeflector | ||
{ | ||
class Program | ||
{ | ||
static bool IsElevated() | ||
{ | ||
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); | ||
} | ||
|
||
private static void ElevatePermissions() | ||
{ | ||
ProcessStartInfo rerun = new ProcessStartInfo() | ||
{ | ||
FileName = System.Reflection.Assembly.GetExecutingAssembly().Location, | ||
UseShellExecute = true, | ||
Verb = "runas" | ||
}; | ||
Process.Start(rerun); | ||
} | ||
|
||
private static void RegisterProtocolHandler() | ||
{ | ||
RegistryKey uriclass_key = Registry.ClassesRoot.OpenSubKey("EdgeUriDeflector", true); | ||
if (uriclass_key == null) | ||
{ | ||
uriclass_key = Registry.ClassesRoot.CreateSubKey("EdgeUriDeflector", true); | ||
} | ||
|
||
uriclass_key.SetValue(string.Empty, "URL: Microsoft Edge Protocol Deflector"); | ||
|
||
RegistryKey icon_key = uriclass_key.OpenSubKey("DefaultIcon", true); | ||
if (icon_key == null) | ||
{ | ||
icon_key = uriclass_key.CreateSubKey("DefaultIcon"); | ||
} | ||
|
||
string exec_path = System.Reflection.Assembly.GetExecutingAssembly().Location; | ||
|
||
icon_key.SetValue(string.Empty, exec_path + ",0"); | ||
icon_key.Close(); | ||
|
||
RegistryKey shellcmd_key = uriclass_key.OpenSubKey(@"shell\open\command", true); | ||
if (shellcmd_key == null) | ||
{ | ||
shellcmd_key = uriclass_key.CreateSubKey(@"shell\open\command"); | ||
} | ||
|
||
shellcmd_key.SetValue(string.Empty, exec_path + " \"%1\""); | ||
shellcmd_key.Close(); | ||
|
||
uriclass_key.SetValue("URL Protocol", string.Empty); | ||
|
||
uriclass_key.Close(); | ||
|
||
RegistryKey software_key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\EdgeUriDeflector", true); | ||
if (software_key == null) | ||
{ | ||
software_key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Clients\EdgeUriDeflector", true); | ||
} | ||
|
||
RegistryKey capability_key = software_key.OpenSubKey("Capabilities", true); | ||
if (capability_key == null) | ||
{ | ||
capability_key = software_key.CreateSubKey("Capabilities", true); | ||
} | ||
|
||
capability_key.SetValue("ApplicationDescription", "Open web links normally forced to open in Microsoft Edge in your default web browser."); | ||
capability_key.SetValue("ApplicationName", "EdgeDeflector"); | ||
|
||
RegistryKey urlass_key = capability_key.OpenSubKey("UrlAssociations", true); | ||
if (urlass_key == null) | ||
{ | ||
urlass_key = capability_key.CreateSubKey("UrlAssociations", true); | ||
} | ||
|
||
urlass_key.SetValue("microsoft-edge", "EdgeUriDeflector"); | ||
urlass_key.Close(); | ||
|
||
capability_key.Close(); | ||
software_key.Close(); | ||
|
||
RegistryKey registeredapps_key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\RegisteredApplications", true); | ||
registeredapps_key.SetValue("EdgeUriDeflector", @"SOFTWARE\Clients\EdgeUriDeflector\Capabilities"); | ||
registeredapps_key.Close(); | ||
} | ||
|
||
static bool IsBrowserUri(string uristring) | ||
{ | ||
Uri uri = new Uri(uristring); | ||
return (IsHttpUri(uristring) || IsMsEdgeUri(uristring)) && uri.IsWellFormedOriginalString(); | ||
} | ||
|
||
static bool IsHttpUri(string uri) | ||
{ | ||
uri = uri.ToLower(); | ||
return uri.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || uri.StartsWith("https://", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
static bool IsMsEdgeUri(string uri) | ||
{ | ||
uri = uri.ToLower(); | ||
return uri.StartsWith("microsoft-edge:", StringComparison.OrdinalIgnoreCase) && !uri.Contains(" "); | ||
} | ||
|
||
static string RewriteMsEdgeUriSchema(string uri) | ||
{ | ||
string msedge_protocol_pattern = "^microsoft-edge:/*"; | ||
|
||
Regex rgx = new Regex(msedge_protocol_pattern); | ||
string new_uri = rgx.Replace(uri, string.Empty); | ||
|
||
if (IsHttpUri(new_uri)) | ||
{ | ||
return new_uri; | ||
} | ||
|
||
return "http://" + new_uri; | ||
} | ||
|
||
static void OpenUri(string uri) | ||
{ | ||
if (!IsBrowserUri(uri)) | ||
{ | ||
Environment.Exit(1); | ||
} | ||
|
||
ProcessStartInfo launcher = new ProcessStartInfo() | ||
{ | ||
FileName = uri, | ||
UseShellExecute = true | ||
}; | ||
Process.Start(launcher); | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
// Assume argument is URI | ||
if (args.Length == 1 && IsMsEdgeUri(args[0])) | ||
{ | ||
string uri = RewriteMsEdgeUriSchema(args[0]); | ||
OpenUri(uri); | ||
} | ||
// Install when running without argument | ||
else if (args.Equals(null) || args.Length == 0) | ||
{ | ||
if (!IsElevated()) | ||
{ | ||
ElevatePermissions(); | ||
} | ||
else | ||
{ | ||
RegisterProtocolHandler(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("EdgeDeflector")] | ||
[assembly: AssemblyDescription("Rewrites microsoft-edge URI addresses into standard http URI addresses.")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("EdgeDeflector")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("64e191bc-e8ce-4190-939e-c77a75aa0e28")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |