mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Moved helper methods to HelpersLib
This commit is contained in:
parent
c935af515d
commit
65f42de600
4 changed files with 21 additions and 23 deletions
|
@ -27,7 +27,6 @@ You should have received a copy of the GNU General Public License
|
|||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -61,20 +60,20 @@ private static void Run()
|
|||
|
||||
if (!string.IsNullOrEmpty(chromeInput.URL))
|
||||
{
|
||||
argument = EscapeText(chromeInput.URL);
|
||||
argument = Helpers.EscapeCLIText(chromeInput.URL);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(chromeInput.Text))
|
||||
{
|
||||
string filepath = Helpers.GetTempPath("txt");
|
||||
File.WriteAllText(filepath, chromeInput.Text, Encoding.UTF8);
|
||||
argument = EscapeText(filepath);
|
||||
argument = Helpers.EscapeCLIText(filepath);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(argument))
|
||||
{
|
||||
string path = Helpers.GetAbsolutePath("ShareX.exe");
|
||||
|
||||
CreateProcess(path, argument);
|
||||
NativeMethods.CreateProcess(path, argument, CreateProcessFlags.CREATE_BREAKAWAY_FROM_JOB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,23 +91,5 @@ private static string GetInput()
|
|||
inputStream.Read(bytesInput, 0, bytesInput.Length);
|
||||
return Encoding.UTF8.GetString(bytesInput);
|
||||
}
|
||||
|
||||
private static string EscapeText(string text)
|
||||
{
|
||||
return string.Format("\"{0}\"", text.Replace("\\", "\\\\").Replace("\"", "\\\""));
|
||||
}
|
||||
|
||||
private static bool CreateProcess(string path, string arguments)
|
||||
{
|
||||
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
|
||||
STARTUPINFO sInfo = new STARTUPINFO();
|
||||
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
|
||||
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
|
||||
pSec.nLength = Marshal.SizeOf(pSec);
|
||||
tSec.nLength = Marshal.SizeOf(tSec);
|
||||
|
||||
return NativeMethods.CreateProcess(null, $"\"{path}\" {arguments}", ref pSec, ref tSec, false, (uint)CreateProcessFlags.CREATE_BREAKAWAY_FROM_JOB,
|
||||
IntPtr.Zero, null, ref sInfo, out pInfo);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1159,5 +1159,10 @@ public static Cursor CreateCursor(byte[] data)
|
|||
return new Cursor(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public static string EscapeCLIText(string text)
|
||||
{
|
||||
return string.Format("\"{0}\"", text.Replace("\\", "\\\\").Replace("\"", "\\\""));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -284,7 +284,7 @@ public static partial class NativeMethods
|
|||
|
||||
#region kernel32.dll
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes,
|
||||
bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
|
||||
|
||||
|
|
|
@ -493,5 +493,17 @@ public static void OpenFolderAndSelectFile(string filePath)
|
|||
ILFree(pidl);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CreateProcess(string path, string arguments, CreateProcessFlags flags = CreateProcessFlags.NORMAL_PRIORITY_CLASS)
|
||||
{
|
||||
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
|
||||
STARTUPINFO sInfo = new STARTUPINFO();
|
||||
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
|
||||
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
|
||||
pSec.nLength = Marshal.SizeOf(pSec);
|
||||
tSec.nLength = Marshal.SizeOf(tSec);
|
||||
|
||||
return CreateProcess(null, $"\"{path}\" {arguments}", ref pSec, ref tSec, false, (uint)flags, IntPtr.Zero, null, ref sInfo, out pInfo);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue