Add project
This commit is contained in:
6
src/App.config
Executable file
6
src/App.config
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
55
src/LinkUnshortener.csproj
Executable file
55
src/LinkUnshortener.csproj
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
<?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>{5519839D-BFDF-4265-9C44-D2EA39C0B644}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>LinkUnshortener</RootNamespace>
|
||||||
|
<AssemblyName>LinkUnshortener</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</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>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="PresentationCore" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<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>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
25
src/LinkUnshortener.sln
Executable file
25
src/LinkUnshortener.sln
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.29519.87
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinkUnshortener", "LinkUnshortener.csproj", "{5519839D-BFDF-4265-9C44-D2EA39C0B644}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5519839D-BFDF-4265-9C44-D2EA39C0B644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5519839D-BFDF-4265-9C44-D2EA39C0B644}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5519839D-BFDF-4265-9C44-D2EA39C0B644}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5519839D-BFDF-4265-9C44-D2EA39C0B644}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {C6FD5C83-B15E-4062-A6FC-35579ACE4162}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
103
src/Program.cs
Executable file
103
src/Program.cs
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using WinForm = System.Windows.Forms;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace LinkUnshortener
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
static extern IntPtr GetConsoleWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||||
|
|
||||||
|
const int SW_HIDE = 0;
|
||||||
|
const int SW_SHOW = 5;
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var handle = GetConsoleWindow();
|
||||||
|
|
||||||
|
ShowWindow(handle, SW_HIDE);
|
||||||
|
|
||||||
|
if (!Clipboard.ContainsText())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ParseClipboard(Clipboard.GetText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ParseClipboard(string uriData)
|
||||||
|
{
|
||||||
|
Uri uri;
|
||||||
|
|
||||||
|
if (Uri.IsWellFormedUriString(uriData, UriKind.Absolute))
|
||||||
|
{
|
||||||
|
uri = new Uri(uriData);
|
||||||
|
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
||||||
|
{
|
||||||
|
var returnURL = GetResponseURL(uri.AbsoluteUri);
|
||||||
|
WinForm.MessageBox.Show($"Redirected To: {returnURL}", "Link Unshortener", WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Regex.IsMatch(uriData, @"^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$", RegexOptions.IgnoreCase))
|
||||||
|
{
|
||||||
|
var dResultHTTP = WinForm.MessageBox.Show($"URI Scheme Missing!\nRetry using HTTP Scheme?\n\"{uriData}\"", "Link Unshortener", WinForm.MessageBoxButtons.YesNo, WinForm.MessageBoxIcon.Question);
|
||||||
|
|
||||||
|
if (dResultHTTP == WinForm.DialogResult.No)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string returnHTTP = GetResponseURL("http://" + uriData);
|
||||||
|
|
||||||
|
if (returnHTTP == null)
|
||||||
|
{
|
||||||
|
var dResultHTTPS = WinForm.MessageBox.Show($"HTTP Response was null!\nRetry using HTTPS Scheme?\n\"{uriData}\"", "Link Unshortener", WinForm.MessageBoxButtons.YesNo, WinForm.MessageBoxIcon.Question);
|
||||||
|
|
||||||
|
if (dResultHTTPS == WinForm.DialogResult.No)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
WinForm.MessageBox.Show($"Redirected To: {returnHTTP}", "Link Unshortener", WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Information);
|
||||||
|
|
||||||
|
string returnHTTPS = GetResponseURL("https://" + uriData);
|
||||||
|
|
||||||
|
if (returnHTTPS == null)
|
||||||
|
WinForm.MessageBox.Show($"HTTPS Response was null!\nApplication Exiting...", "Link Unshortener", WinForm.MessageBoxButtons.YesNo, WinForm.MessageBoxIcon.Information);
|
||||||
|
else
|
||||||
|
WinForm.MessageBox.Show($"Redirected To: {returnHTTPS}", "Link Unshortener", WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else
|
||||||
|
WinForm.MessageBox.Show($"We couldn't unshorten this data: \"{uriData}\"", "Link Unshortener", WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetResponseURL(string url)
|
||||||
|
{
|
||||||
|
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
webRequest.AllowAutoRedirect = false;
|
||||||
|
|
||||||
|
webRequest.Timeout = 10000;
|
||||||
|
webRequest.Method = "HEAD";
|
||||||
|
|
||||||
|
HttpWebResponse webResponse;
|
||||||
|
using (webResponse = (HttpWebResponse)webRequest.GetResponse())
|
||||||
|
{
|
||||||
|
string uriString = webResponse.Headers["Location"];
|
||||||
|
webResponse.Close();
|
||||||
|
return uriString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
src/Properties/AssemblyInfo.cs
Executable file
36
src/Properties/AssemblyInfo.cs
Executable file
@ -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("LinkUnshortener")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("LinkUnshortener")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||||
|
[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("5519839d-bfdf-4265-9c44-d2ea39c0b644")]
|
||||||
|
|
||||||
|
// 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")]
|
Reference in New Issue
Block a user