From d8fd9ab03f8c4189cc801109f474ff1517a1dd6f Mon Sep 17 00:00:00 2001
From: Allen Wolf <63997543+aaw3@users.noreply.github.com>
Date: Wed, 10 Jan 2024 00:49:36 -0600
Subject: [PATCH] Add project
---
src/App.config | 6 ++
src/LinkUnshortener.csproj | 55 ++++++++++++++++++
src/LinkUnshortener.sln | 25 ++++++++
src/Program.cs | 103 +++++++++++++++++++++++++++++++++
src/Properties/AssemblyInfo.cs | 36 ++++++++++++
5 files changed, 225 insertions(+)
create mode 100755 src/App.config
create mode 100755 src/LinkUnshortener.csproj
create mode 100755 src/LinkUnshortener.sln
create mode 100755 src/Program.cs
create mode 100755 src/Properties/AssemblyInfo.cs
diff --git a/src/App.config b/src/App.config
new file mode 100755
index 0000000..5754728
--- /dev/null
+++ b/src/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/LinkUnshortener.csproj b/src/LinkUnshortener.csproj
new file mode 100755
index 0000000..285b001
--- /dev/null
+++ b/src/LinkUnshortener.csproj
@@ -0,0 +1,55 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {5519839D-BFDF-4265-9C44-D2EA39C0B644}
+ Exe
+ LinkUnshortener
+ LinkUnshortener
+ v4.7.2
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/LinkUnshortener.sln b/src/LinkUnshortener.sln
new file mode 100755
index 0000000..29ad3d4
--- /dev/null
+++ b/src/LinkUnshortener.sln
@@ -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
diff --git a/src/Program.cs b/src/Program.cs
new file mode 100755
index 0000000..1f1233f
--- /dev/null
+++ b/src/Program.cs
@@ -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;
+ }
+
+ }
+ }
+}
diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs
new file mode 100755
index 0000000..0a9d5f0
--- /dev/null
+++ b/src/Properties/AssemblyInfo.cs
@@ -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")]