Code refactoring

This commit is contained in:
Jaex 2021-06-10 21:44:40 +03:00
parent e8ad4b8553
commit b48d615362
13 changed files with 50 additions and 51 deletions

View File

@ -176,8 +176,7 @@ namespace ShareX.HelpersLib
public static bool GetBorderSize(IntPtr handle, out Size size)
{
WINDOWINFO wi = new WINDOWINFO();
WINDOWINFO wi = WINDOWINFO.Create();
bool result = GetWindowInfo(handle, ref wi);
if (result)
@ -505,14 +504,14 @@ namespace ShareX.HelpersLib
public static bool CreateProcess(string path, string arguments, CreateProcessFlags flags = CreateProcessFlags.NORMAL_PRIORITY_CLASS)
{
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
//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(path, $"\"{path}\" {arguments}", ref pSec, ref tSec, false, (uint)flags, IntPtr.Zero, null, ref sInfo, out pInfo);
return CreateProcess(path, $"\"{path}\" {arguments}", ref pSec, ref tSec, false, (uint)flags, IntPtr.Zero, null, ref sInfo, out _);
}
public static Icon GetFileIcon(string filePath, bool isSmallIcon)

View File

@ -242,9 +242,11 @@ namespace ShareX.HelpersLib
public ushort atomWindowType;
public ushort wCreatorVersion;
public WINDOWINFO(bool? filler) : this() // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
public static WINDOWINFO Create()
{
cbSize = (uint)Marshal.SizeOf(typeof(WINDOWINFO));
WINDOWINFO wi = new WINDOWINFO();
wi.cbSize = (uint)Marshal.SizeOf(typeof(WINDOWINFO));
return wi;
}
}

View File

@ -82,7 +82,7 @@ namespace ShareX.IndexerLib
foreach (FileInfo fi in dir.Files)
{
sbContent.AppendLine(GetFileNameRow(fi, level));
sbContent.AppendLine(GetFileNameRow(fi));
}
sbContent.AppendLine(HtmlHelper.EndTag("ul"));
@ -144,7 +144,7 @@ namespace ShareX.IndexerLib
return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(pathTitle) + folderNameRow + HtmlHelper.EndTag("h" + heading);
}
private string GetFileNameRow(FileInfo fi, int level)
private string GetFileNameRow(FileInfo fi)
{
string fileNameRow = HtmlHelper.StartTag("li") + URLHelpers.HtmlEncode(fi.Name);

View File

@ -62,15 +62,15 @@ namespace ShareX.IndexerLib
{
if (settings.CreateParseableJson)
{
IndexFolderParseable(dir, level);
IndexFolderParseable(dir);
}
else
{
IndexFolderSimple(dir, level);
IndexFolderSimple(dir);
}
}
private void IndexFolderSimple(FolderInfo dir, int level)
private void IndexFolderSimple(FolderInfo dir)
{
jsonWriter.WritePropertyName(dir.FolderName);
jsonWriter.WriteStartArray();
@ -90,7 +90,7 @@ namespace ShareX.IndexerLib
jsonWriter.WriteEnd();
}
private void IndexFolderParseable(FolderInfo dir, int level)
private void IndexFolderParseable(FolderInfo dir)
{
jsonWriter.WritePropertyName("Name");
jsonWriter.WriteValue(dir.FolderName);

View File

@ -1169,7 +1169,7 @@ namespace ShareX.ScreenCaptureLib
totalSize.Width = Math.Max(totalSize.Width, infoTextRect.Width);
totalSize.Height += infoTextRect.Height;
itemCount++;
//itemCount++;
}
int x = mousePos.X + cursorOffsetX;

View File

@ -109,7 +109,7 @@ namespace ShareX.UploadersLib.FileUploaders
private UploadResult ConvertResult(UploadMetadataResponse metaData, UploadResult fileDataReq)
{
UploadResult result = new UploadResult(fileDataReq.Response);
UploadMetadataResponse fileData = JsonConvert.DeserializeObject<UploadMetadataResponse>(fileDataReq.Response);
//UploadMetadataResponse fileData = JsonConvert.DeserializeObject<UploadMetadataResponse>(fileDataReq.Response);
UploadMetadataResponseFile actFile = metaData.files.First().Value;
result.URL = $"{Settings.URL}/file/{metaData.id}/{actFile.id}/{URLHelpers.URLEncode(actFile.fileName)}";
return result;

View File

@ -163,7 +163,7 @@ namespace ShareX.UploadersLib.ImageUploaders
return xele.Element(field);
case "fail":
XElement err = xele.Element("err");
string code = err.GetAttributeValue("code");
//string code = err.GetAttributeValue("code");
string msg = err.GetAttributeValue("msg");
Errors.Add(msg);
break;

View File

@ -136,16 +136,16 @@ namespace ShareX.UploadersLib.ImageUploaders
switch (xele.GetAttributeFirstValue("status", "stat"))
{
case "ok":
string statusid = xele.GetElementValue("statusid");
string userid = xele.GetElementValue("userid");
string mediaid = xele.GetElementValue("mediaid");
//string statusid = xele.GetElementValue("statusid");
//string userid = xele.GetElementValue("userid");
//string mediaid = xele.GetElementValue("mediaid");
string mediaurl = xele.GetElementValue("mediaurl");
if (Options.ShowFull) mediaurl += "/full";
result.URL = mediaurl;
result.ThumbnailURL = mediaurl + ".th.jpg";
break;
case "fail":
string code = xele.Element("err").Attribute("code").Value;
//string code = xele.Element("err").Attribute("code").Value;
string msg = xele.Element("err").Attribute("msg").Value;
Errors.Add(msg);
break;

View File

@ -26,7 +26,6 @@
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ShareX.UploadersLib
@ -47,7 +46,7 @@ namespace ShareX.UploadersLib
Extensions = extensions.ToList();
}
public bool IsValidFilter(string filename, Stream stream)
public bool IsValidFilter(string filename)
{
string extension = Helpers.GetFilenameExtension(filename);

View File

@ -24,7 +24,6 @@
#endregion License Information (GPL v3)
using System;
using System.Diagnostics.Contracts;
namespace ShareX.UploadersLib
{

View File

@ -161,7 +161,7 @@ namespace ShareX
panel.TitleVisible = TitleVisible;
panel.TitleLocation = TitleLocation;
panel.MouseEnter += Panel_MouseEnter;
panel.MouseDown += (object sender, MouseEventArgs e) => Panel_MouseDown(sender, e, panel);
panel.MouseDown += (object sender, MouseEventArgs e) => Panel_MouseDown(e, panel);
panel.MouseUp += Panel_MouseUp;
return panel;
}
@ -240,10 +240,10 @@ namespace ShareX
private void Panel_MouseDown(object sender, MouseEventArgs e)
{
Panel_MouseDown(sender, e, null);
Panel_MouseDown(e, null);
}
private void Panel_MouseDown(object sender, MouseEventArgs e, TaskThumbnailPanel panel)
private void Panel_MouseDown(MouseEventArgs e, TaskThumbnailPanel panel)
{
if (panel == null)
{

View File

@ -372,31 +372,7 @@ namespace ShareX
{
if (WaitFormLoad(5000))
{
Action d = () =>
{
if (args.CommandLineArgs == null || args.CommandLineArgs.Length < 1)
{
if (MainForm.niTray != null && MainForm.niTray.Visible)
{
// Workaround for Windows startup tray icon bug
MainForm.niTray.Visible = false;
MainForm.niTray.Visible = true;
}
MainForm.ForceActivate();
}
else if (MainForm.Visible)
{
MainForm.ForceActivate();
}
CLIManager cli = new CLIManager(args.CommandLineArgs);
cli.ParseCommands();
CLI.UseCommandLineArgs(cli.Commands);
};
MainForm.InvokeSafe(d);
MainForm.InvokeSafe(() => UseCommandLineArgs(args.CommandLineArgs));
}
}
@ -414,6 +390,30 @@ namespace ShareX
return false;
}
private static void UseCommandLineArgs(string[] args)
{
if (args == null || args.Length < 1)
{
if (MainForm.niTray != null && MainForm.niTray.Visible)
{
// Workaround for Windows startup tray icon bug
MainForm.niTray.Visible = false;
MainForm.niTray.Visible = true;
}
MainForm.ForceActivate();
}
else if (MainForm.Visible)
{
MainForm.ForceActivate();
}
CLIManager cli = new CLIManager(args);
cli.ParseCommands();
CLI.UseCommandLineArgs(cli.Commands);
}
private static void UpdatePersonalPath()
{
Sandbox = CLI.IsCommandExist("sandbox");

View File

@ -929,7 +929,7 @@ namespace ShareX
{
if (Info.TaskSettings.UploadSettings.UploaderFilters != null && !string.IsNullOrEmpty(filename) && stream != null)
{
UploaderFilter filter = Info.TaskSettings.UploadSettings.UploaderFilters.FirstOrDefault(x => x.IsValidFilter(filename, stream));
UploaderFilter filter = Info.TaskSettings.UploadSettings.UploaderFilters.FirstOrDefault(x => x.IsValidFilter(filename));
if (filter != null)
{