From 89834c88409e6d81b6d0382ec0f761640a0470e2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 11 Feb 2017 20:27:38 +0300 Subject: [PATCH] If host executable opened directly, it will show msg box to explain what it is used for --- ShareX.NativeMessagingHost/Program.cs | 28 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ShareX.NativeMessagingHost/Program.cs b/ShareX.NativeMessagingHost/Program.cs index 812b654aa..af96bbbc1 100644 --- a/ShareX.NativeMessagingHost/Program.cs +++ b/ShareX.NativeMessagingHost/Program.cs @@ -36,13 +36,21 @@ internal class Program { private static void Main(string[] args) { - try + if (args.Length > 0) { - Run(); + try + { + Run(); + } + catch (Exception e) + { + MessageBox.Show(e.ToString(), "ShareX NativeMessagingHost - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - catch (Exception e) + else { - MessageBox.Show(e.ToString(), "ShareX NativeMessagingHost - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("This executable is used to receive input from browser addon and send it to ShareX executable.", + "ShareX NativeMessagingHost", MessageBoxButtons.OK, MessageBoxIcon.Information); } } @@ -52,20 +60,20 @@ private static void Run() if (!string.IsNullOrEmpty(input)) { - NativeMessagingInput chromeInput = JsonConvert.DeserializeObject(input); + NativeMessagingInput nativeMessagingInput = JsonConvert.DeserializeObject(input); - if (chromeInput != null) + if (nativeMessagingInput != null) { string argument = null; - if (!string.IsNullOrEmpty(chromeInput.URL)) + if (!string.IsNullOrEmpty(nativeMessagingInput.URL)) { - argument = Helpers.EscapeCLIText(chromeInput.URL); + argument = Helpers.EscapeCLIText(nativeMessagingInput.URL); } - else if (!string.IsNullOrEmpty(chromeInput.Text)) + else if (!string.IsNullOrEmpty(nativeMessagingInput.Text)) { string filepath = Helpers.GetTempPath("txt"); - File.WriteAllText(filepath, chromeInput.Text, Encoding.UTF8); + File.WriteAllText(filepath, nativeMessagingInput.Text, Encoding.UTF8); argument = $"\"{filepath}\""; }