mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
.sxcu extension can add custom uploader now
This commit is contained in:
parent
a07fc4f615
commit
d64735ad8d
5 changed files with 109 additions and 1 deletions
80
ShareX.HelpersLib/Helpers/JsonHelpers.cs
Normal file
80
ShareX.HelpersLib/Helpers/JsonHelpers.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
#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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace ShareX.HelpersLib
|
||||
{
|
||||
public static class JsonHelpers
|
||||
{
|
||||
public static T Deserialize<T>(TextReader textReader)
|
||||
{
|
||||
using (JsonTextReader jsonTextReader = new JsonTextReader(textReader))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
serializer.ObjectCreationHandling = ObjectCreationHandling.Replace;
|
||||
serializer.TypeNameHandling = TypeNameHandling.Auto;
|
||||
serializer.Error += (sender, e) => e.ErrorContext.Handled = true;
|
||||
return serializer.Deserialize<T>(jsonTextReader);
|
||||
}
|
||||
}
|
||||
|
||||
public static T DeserializeFromString<T>(string json)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
using (StringReader stringReader = new StringReader(json))
|
||||
{
|
||||
return Deserialize<T>(stringReader);
|
||||
}
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public static T DeserializeFromFilePath<T>(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
if (fileStream.Length > 0)
|
||||
{
|
||||
using (StreamReader streamReader = new StreamReader(fileStream))
|
||||
{
|
||||
return Deserialize<T>(streamReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ public static class RegistryHelpers
|
|||
private static readonly string ShellCustomUploaderIconPath = ShellCustomUploaderAssociatePath + @"\DefaultIcon";
|
||||
private static readonly string ShellCustomUploaderIconValue = ApplicationPath + ",0";
|
||||
private static readonly string ShellCustomUploaderCommandPath = ShellCustomUploaderAssociatePath + @"\shell\open\command";
|
||||
private static readonly string ShellCustomUploaderCommandValue = ApplicationPath + " \"%1\"";
|
||||
private static readonly string ShellCustomUploaderCommandValue = ApplicationPath + " -CustomUploader \"%1\"";
|
||||
|
||||
private static readonly string ChromeNativeMessagingHosts = @"SOFTWARE\Google\Chrome\NativeMessagingHosts\com.getsharex.sharex";
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
<Compile Include="Controls\ToolStripEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Helpers\JsonHelpers.cs" />
|
||||
<Compile Include="Input\HotkeyInfo.cs" />
|
||||
<Compile Include="Input\KeyboardHook.cs" />
|
||||
<Compile Include="NameParser\CodeMenuEntryActions.cs" />
|
||||
|
|
|
@ -750,6 +750,13 @@ public void UseCommandLineArgs(List<CLICommand> commands)
|
|||
{
|
||||
DebugHelper.WriteLine("CommandLine: " + command.Command);
|
||||
|
||||
if (command.IsCommand && command.Command.Equals("CustomUploader", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
TaskHelpers.AddCustomUploader(command.Parameter);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (command.IsCommand && (CheckCLIHotkey(command) || CheckCLIWorkflow(command)))
|
||||
{
|
||||
continue;
|
||||
|
|
|
@ -1335,5 +1335,25 @@ public static Screenshot GetScreenshot(TaskSettings taskSettings = null)
|
|||
|
||||
return screenshot;
|
||||
}
|
||||
|
||||
public static void AddCustomUploader(string filePath)
|
||||
{
|
||||
if (Program.UploadersConfig != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
CustomUploaderItem cui = JsonHelpers.DeserializeFromFilePath<CustomUploaderItem>(filePath);
|
||||
|
||||
if (cui != null)
|
||||
{
|
||||
Program.UploadersConfig.CustomUploadersList.Add(cui);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue