diff --git a/ShareX.HelpersLib/ExternalProgram.cs b/ShareX.HelpersLib/ExternalProgram.cs index 99c665c9e..502ca03b6 100644 --- a/ShareX.HelpersLib/ExternalProgram.cs +++ b/ShareX.HelpersLib/ExternalProgram.cs @@ -52,9 +52,16 @@ public ExternalProgram(string name, string path) : this() Path = path; } + public string GetFullPath() + { + return Helpers.ExpandFolderVariables(Path); + } + public string Run(string inputPath) { - if (!string.IsNullOrEmpty(Path) && File.Exists(Path) && !string.IsNullOrWhiteSpace(inputPath)) + string path = GetFullPath(); + + if (!string.IsNullOrEmpty(path) && File.Exists(path) && !string.IsNullOrWhiteSpace(inputPath)) { inputPath = inputPath.Trim('"'); @@ -91,7 +98,7 @@ public string Run(string inputPath) { ProcessStartInfo psi = new ProcessStartInfo() { - FileName = Path, + FileName = path, Arguments = arguments, UseShellExecute = false, CreateNoWindow = HiddenWindow diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index 74413eae1..d221bfb5c 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -325,13 +325,18 @@ public static string GetRandomLineFromFile(string path) public static string GetValidFileName(string fileName, string separator = "") { char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); + if (string.IsNullOrEmpty(separator)) { return new string(fileName.Where(c => !invalidFileNameChars.Contains(c)).ToArray()); } else { - invalidFileNameChars.ForEach(x => fileName = fileName.Replace(x.ToString(), separator)); + foreach (char invalidFileNameChar in invalidFileNameChars) + { + fileName = fileName.Replace(invalidFileNameChar.ToString(), separator); + } + return fileName.Trim().Replace(separator + separator, separator); } } @@ -730,6 +735,11 @@ public static bool BrowseFile(string title, TextBox tb, string initialDirectory { string path = tb.Text; + if (detectSpecialFolders) + { + path = ExpandFolderVariables(path); + } + if (!string.IsNullOrEmpty(path)) { path = Path.GetDirectoryName(path); @@ -750,7 +760,15 @@ public static bool BrowseFile(string title, TextBox tb, string initialDirectory if (ofd.ShowDialog() == DialogResult.OK) { - tb.Text = detectSpecialFolders ? GetVariableFolderPath(ofd.FileName) : ofd.FileName; + string fileName = ofd.FileName; + + if (detectSpecialFolders) + { + fileName = GetVariableFolderPath(fileName); + } + + tb.Text = fileName; + return true; } } @@ -796,7 +814,10 @@ public static string GetVariableFolderPath(string path) { try { - GetEnums().ForEach(x => path = path.Replace(Environment.GetFolderPath(x), $"%{x}%", StringComparison.InvariantCultureIgnoreCase)); + foreach (Environment.SpecialFolder specialFolder in GetEnums()) + { + path = path.Replace(Environment.GetFolderPath(specialFolder), $"%{specialFolder}%", StringComparison.OrdinalIgnoreCase); + } } catch (Exception e) { @@ -813,7 +834,11 @@ public static string ExpandFolderVariables(string path) { try { - GetEnums().ForEach(x => path = path.Replace($"%{x}%", Environment.GetFolderPath(x), StringComparison.InvariantCultureIgnoreCase)); + foreach (Environment.SpecialFolder specialFolder in GetEnums()) + { + path = path.Replace($"%{specialFolder}%", Environment.GetFolderPath(specialFolder), StringComparison.OrdinalIgnoreCase); + } + path = Environment.ExpandEnvironmentVariables(path); } catch (Exception e) @@ -825,6 +850,18 @@ public static string ExpandFolderVariables(string path) return path; } + public static string OutputSpecialFolders() + { + StringBuilder sb = new StringBuilder(); + + foreach (Environment.SpecialFolder specialFolder in GetEnums()) + { + sb.AppendLine(string.Format("{0,-25}{1}", specialFolder, Environment.GetFolderPath(specialFolder))); + } + + return sb.ToString(); + } + public static bool WaitWhile(Func check, int interval, int timeout = -1) { Stopwatch timer = Stopwatch.StartNew(); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs index 4b4558cf1..df48213b0 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/FreehandDrawingShape.cs @@ -112,12 +112,14 @@ public override void OnDraw(Graphics g) protected void DrawFreehand(Graphics g) { + int borderSize = Math.Max(BorderSize, 1); + if (Shadow) { - DrawFreehand(g, ShadowColor, Math.Max(BorderSize, 1), positions.Select(x => x.Add(ShadowOffset)).ToArray()); + DrawFreehand(g, ShadowColor, borderSize, positions.Select(x => x.Add(ShadowOffset)).ToArray()); } - DrawFreehand(g, BorderColor, Math.Max(BorderSize, 1), positions.ToArray()); + DrawFreehand(g, BorderColor, borderSize, positions.ToArray()); } protected void DrawFreehand(Graphics g, Color borderColor, int borderSize, Point[] points) diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs index 56c078b74..399f0201b 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/LineDrawingShape.cs @@ -137,6 +137,8 @@ public override void OnDraw(Graphics g) protected void DrawLine(Graphics g) { + int borderSize = Math.Max(BorderSize, 1); + if (Shadow) { Point[] shadowPoints = new Point[Points.Length]; @@ -146,10 +148,10 @@ protected void DrawLine(Graphics g) shadowPoints[i] = Points[i].Add(ShadowOffset); } - DrawLine(g, ShadowColor, Math.Max(BorderSize, 1), shadowPoints); + DrawLine(g, ShadowColor, borderSize, shadowPoints); } - DrawLine(g, BorderColor, Math.Max(BorderSize, 1), Points); + DrawLine(g, BorderColor, borderSize, Points); } protected void DrawLine(Graphics g, Color borderColor, int borderSize, Point[] points) diff --git a/ShareX/Forms/ActionsForm.Designer.cs b/ShareX/Forms/ActionsForm.Designer.cs index 25f0012c7..d6cf029ca 100644 --- a/ShareX/Forms/ActionsForm.Designer.cs +++ b/ShareX/Forms/ActionsForm.Designer.cs @@ -153,7 +153,6 @@ private void InitializeComponent() this.Controls.Add(this.lblArgs); this.Controls.Add(this.lblPath); this.Controls.Add(this.lblName); - this.MaximizeBox = false; this.Name = "ActionsForm"; this.ResumeLayout(false); this.PerformLayout(); diff --git a/ShareX/Forms/ActionsForm.cs b/ShareX/Forms/ActionsForm.cs index ab55bbd70..785229dd2 100644 --- a/ShareX/Forms/ActionsForm.cs +++ b/ShareX/Forms/ActionsForm.cs @@ -56,7 +56,7 @@ public ActionsForm(ExternalProgram fileAction) private void btnPathBrowse_Click(object sender, EventArgs e) { - Helpers.BrowseFile(txtPath); + Helpers.BrowseFile(txtPath, "", true); } private void txtOutputExtension_TextChanged(object sender, EventArgs e) diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 0f4885eab..86faac2c3 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -895,7 +895,7 @@ private void UpdateActionsMenu(string filePath) try { - using (Icon icon = NativeMethods.GetFileIcon(action.Path, true)) + using (Icon icon = NativeMethods.GetFileIcon(action.GetFullPath(), true)) { if (icon != null && icon.Width > 0 && icon.Height > 0) {