diff --git a/ShareX.Chrome.sln b/ShareX.Chrome.sln new file mode 100644 index 000000000..c41131227 --- /dev/null +++ b/ShareX.Chrome.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareX.Chrome", "ShareX.Chrome\ShareX.Chrome.csproj", "{254E398D-F7F5-4B2A-9024-5C121EA6C564}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {254E398D-F7F5-4B2A-9024-5C121EA6C564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {254E398D-F7F5-4B2A-9024-5C121EA6C564}.Debug|Any CPU.Build.0 = Debug|Any CPU + {254E398D-F7F5-4B2A-9024-5C121EA6C564}.Release|Any CPU.ActiveCfg = Release|Any CPU + {254E398D-F7F5-4B2A-9024-5C121EA6C564}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ShareX.Chrome/Chrome/Icons/ShareX-128.png b/ShareX.Chrome/Chrome/Icons/ShareX-128.png new file mode 100644 index 000000000..f0251b492 Binary files /dev/null and b/ShareX.Chrome/Chrome/Icons/ShareX-128.png differ diff --git a/ShareX.Chrome/Chrome/Icons/ShareX-16.png b/ShareX.Chrome/Chrome/Icons/ShareX-16.png new file mode 100644 index 000000000..da5ea57bb Binary files /dev/null and b/ShareX.Chrome/Chrome/Icons/ShareX-16.png differ diff --git a/ShareX.Chrome/Chrome/Icons/ShareX-48.png b/ShareX.Chrome/Chrome/Icons/ShareX-48.png new file mode 100644 index 000000000..9f4f43f5b Binary files /dev/null and b/ShareX.Chrome/Chrome/Icons/ShareX-48.png differ diff --git a/ShareX.Chrome/Chrome/eventPage.js b/ShareX.Chrome/Chrome/eventPage.js new file mode 100644 index 000000000..65468aace --- /dev/null +++ b/ShareX.Chrome/Chrome/eventPage.js @@ -0,0 +1,14 @@ +chrome.contextMenus.create({ + "id": "ShareX", + "title": "Upload with ShareX", + "contexts": ["selection", "image", "video", "audio"] +}); + +chrome.contextMenus.onClicked.addListener(onClicked); + +function onClicked(info, tab) { + chrome.runtime.sendNativeMessage("com.getsharex.sharex", { + URL: info.srcUrl, + Text: info.selectionText + }); +} \ No newline at end of file diff --git a/ShareX.Chrome/Chrome/manifest.json b/ShareX.Chrome/Chrome/manifest.json new file mode 100644 index 000000000..663bccc06 --- /dev/null +++ b/ShareX.Chrome/Chrome/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + "name": "ShareX", + "version": "1.0.1", + "description": "Adds 'Upload with ShareX' button to image, video, audio and text selection context menu.", + "author": "ShareX Team", + "homepage_url": "https://getsharex.com", + "icons": { + "16": "Icons/ShareX-16.png", + "48": "Icons/ShareX-48.png", + "128": "Icons/ShareX-128.png" + }, + "background": { + "persistent": false, + "scripts": [ "eventPage.js" ] + }, + "permissions": [ "contextMenus", "nativeMessaging" ] +} \ No newline at end of file diff --git a/ShareX.Chrome/ChromeInput.cs b/ShareX.Chrome/ChromeInput.cs new file mode 100644 index 000000000..55041ebb5 --- /dev/null +++ b/ShareX.Chrome/ChromeInput.cs @@ -0,0 +1,33 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2016 ShareX Team + + 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 2 + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX.Chrome +{ + public class ChromeInput + { + public string URL { get; set; } + public string Text { get; set; } + } +} \ No newline at end of file diff --git a/ShareX.Chrome/Program.cs b/ShareX.Chrome/Program.cs new file mode 100644 index 000000000..ac9f713f0 --- /dev/null +++ b/ShareX.Chrome/Program.cs @@ -0,0 +1,117 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2016 ShareX Team + + 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 2 + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using Newtonsoft.Json; +using System; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Text; +using System.Windows.Forms; + +namespace ShareX.Chrome +{ + internal class Program + { + private static void Main(string[] args) + { + try + { + Run(); + } + catch (Exception e) + { + MessageBox.Show(e.ToString(), "ShareX Chrome - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private static void Run() + { + string input = GetInput(); + + if (!string.IsNullOrEmpty(input)) + { + ChromeInput chromeInput = JsonConvert.DeserializeObject(input); + + if (chromeInput != null) + { + string argument = null; + + if (!string.IsNullOrEmpty(chromeInput.URL)) + { + argument = EscapeText(chromeInput.URL); + } + else if (!string.IsNullOrEmpty(chromeInput.Text)) + { + string filepath = GetTempPath("txt"); + File.WriteAllText(filepath, chromeInput.Text, Encoding.UTF8); + argument = EscapeText(filepath); + } + + if (!string.IsNullOrEmpty(argument)) + { + string path = GetAbsolutePath("ShareX.exe"); + Process.Start(path, argument); + } + } + } + } + + private static string GetInput() + { + Stream inputStream = Console.OpenStandardInput(); + + byte[] bytesLength = new byte[4]; + inputStream.Read(bytesLength, 0, bytesLength.Length); + int inputLength = BitConverter.ToInt32(bytesLength, 0); + + byte[] bytesInput = new byte[inputLength]; + inputStream.Read(bytesInput, 0, bytesInput.Length); + return Encoding.UTF8.GetString(bytesInput); + } + + private static string EscapeText(string text) + { + return string.Format("\"{0}\"", text.Replace("\\", "\\\\").Replace("\"", "\\\"")); + } + + public static string GetAbsolutePath(string path) + { + if (!Path.IsPathRooted(path)) // Is relative path? + { + string startupDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + path = Path.Combine(startupDirectory, path); + } + + return Path.GetFullPath(path); + } + + public static string GetTempPath(string extension) + { + string path = Path.GetTempFileName(); + return Path.ChangeExtension(path, extension); + } + } +} \ No newline at end of file diff --git a/ShareX.Chrome/Properties/AssemblyInfo.cs b/ShareX.Chrome/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5625ea254 --- /dev/null +++ b/ShareX.Chrome/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +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("ShareX Chrome")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("ShareX Team")] +[assembly: AssemblyProduct("ShareX")] +[assembly: AssemblyCopyright("Copyright (c) 2007-2016 ShareX Team")] +[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("254e398d-f7f5-4b2a-9024-5c121ea6c564")] + +// 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")] \ No newline at end of file diff --git a/ShareX.Chrome/ShareX.Chrome.csproj b/ShareX.Chrome/ShareX.Chrome.csproj new file mode 100644 index 000000000..0de9bf8e1 --- /dev/null +++ b/ShareX.Chrome/ShareX.Chrome.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {254E398D-F7F5-4B2A-9024-5C121EA6C564} + WinExe + Properties + ShareX.Chrome + ShareX.Chrome + v4.0 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + Off + + + AnyCPU + none + true + bin\Release\ + TRACE + prompt + 4 + Off + + + + + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShareX.Chrome/packages.config b/ShareX.Chrome/packages.config new file mode 100644 index 000000000..7c276ed86 --- /dev/null +++ b/ShareX.Chrome/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ShareX_Steam.sln b/ShareX.Steam.sln similarity index 100% rename from ShareX_Steam.sln rename to ShareX.Steam.sln