diff --git a/ShareX.HelpersLib/DNS/DNSChangerForm.cs b/ShareX.HelpersLib/DNS/DNSChangerForm.cs index 268419290..a297a5089 100644 --- a/ShareX.HelpersLib/DNS/DNSChangerForm.cs +++ b/ShareX.HelpersLib/DNS/DNSChangerForm.cs @@ -39,6 +39,7 @@ public DNSChangerForm() AddDNS(Resources.DNSChangerForm_DNSChangerForm_Manual); AddDNS("Google Public DNS", "8.8.8.8", "8.8.4.4"); // https://developers.google.com/speed/public-dns/ AddDNS("OpenDNS", "208.67.222.222", "208.67.220.220"); // https://www.opendns.com + AddDNS("Cloudflare", "1.1.1.1", "1.0.0.1"); // https://1.1.1.1 AddDNS("Level 3 Communications", "4.2.2.1", "4.2.2.2"); // http://www.level3.com AddDNS("Norton ConnectSafe", "199.85.126.10", "199.85.127.10"); // https://dns.norton.com AddDNS("Comodo Secure DNS", "8.26.56.26", "8.20.247.20"); // https://www.comodo.com/secure-dns/ diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index b9ebb2842..81b56d02a 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -1142,12 +1142,6 @@ public static void CopyAll(DirectoryInfo source, DirectoryInfo target) } } - // http://goessner.net/articles/JsonPath/ - public static string ParseJSON(string text, string jsonPath) - { - return (string)JToken.Parse(text).SelectToken("$." + jsonPath); - } - public static T[] GetInstances() where T : class { IEnumerable instances = from t in Assembly.GetCallingAssembly().GetTypes() diff --git a/ShareX.HelpersLib/Properties/Resources.Designer.cs b/ShareX.HelpersLib/Properties/Resources.Designer.cs index 274188cd7..95f16cb03 100644 --- a/ShareX.HelpersLib/Properties/Resources.Designer.cs +++ b/ShareX.HelpersLib/Properties/Resources.Designer.cs @@ -252,6 +252,15 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Scan QR code. + /// + internal static string AfterCaptureTasks_ScanQRCode { + get { + return ResourceManager.GetString("AfterCaptureTasks_ScanQRCode", resourceCulture); + } + } + /// /// Looks up a localized string similar to Print image. /// diff --git a/ShareX.HelpersLib/Properties/Resources.resx b/ShareX.HelpersLib/Properties/Resources.resx index 9b5179a79..1b73defa2 100644 --- a/ShareX.HelpersLib/Properties/Resources.resx +++ b/ShareX.HelpersLib/Properties/Resources.resx @@ -1160,4 +1160,7 @@ Would you like to download it? Browse for a sound file... + + Scan QR code + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs index bf838b42a..a8ea89007 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs @@ -105,7 +105,6 @@ public Color CurrentColor private TextAnimation editorPanTipAnimation; private Bitmap bmpBackgroundImage; private Cursor defaultCursor; - private ScrollbarManager scrollbarManager; public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, Image canvas = null) { @@ -129,19 +128,14 @@ public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, I Duration = TimeSpan.FromMilliseconds(200) }; - if (IsEditorMode) + if (IsEditorMode && Options.ShowEditorPanTip) { - scrollbarManager = new ScrollbarManager(this); - - if (Options.ShowEditorPanTip) + editorPanTipAnimation = new TextAnimation() { - editorPanTipAnimation = new TextAnimation() - { - Duration = TimeSpan.FromMilliseconds(5000), - FadeOutDuration = TimeSpan.FromMilliseconds(1000), - Text = Resources.RegionCaptureForm_TipYouCanPanImageByHoldingMouseMiddleButtonAndDragging - }; - } + Duration = TimeSpan.FromMilliseconds(5000), + FadeOutDuration = TimeSpan.FromMilliseconds(1000), + Text = Resources.RegionCaptureForm_TipYouCanPanImageByHoldingMouseMiddleButtonAndDragging + }; } borderPen = new Pen(Color.Black); @@ -236,6 +230,8 @@ private void InitializeComponent() MouseDown += RegionCaptureForm_MouseDown; Resize += RegionCaptureForm_Resize; LocationChanged += RegionCaptureForm_LocationChanged; + LostFocus += RegionCaptureForm_LostFocus; + GotFocus += RegionCaptureForm_GotFocus; FormClosing += RegionCaptureForm_FormClosing; ResumeLayout(false); @@ -480,6 +476,16 @@ private void RegionCaptureForm_LocationChanged(object sender, EventArgs e) OnMoved(); } + private void RegionCaptureForm_GotFocus(object sender, EventArgs e) + { + Resume(); + } + + private void RegionCaptureForm_LostFocus(object sender, EventArgs e) + { + Pause(); + } + private void RegionCaptureForm_FormClosing(object sender, FormClosingEventArgs e) { if (IsEditorMode) @@ -661,11 +667,6 @@ private new void Update() borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15; ShapeManager.Update(); - - if (scrollbarManager != null) - { - scrollbarManager.Update(); - } } protected override void OnPaintBackground(PaintEventArgs e) @@ -859,12 +860,6 @@ private void Draw(Graphics g) { DrawTextAnimation(g, ShapeManager.MenuTextAnimation); } - - // Draw scroll bars - if (scrollbarManager != null) - { - scrollbarManager.Draw(g); - } } internal void DrawRegionArea(Graphics g, Rectangle rect, bool isAnimated) diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ImageEditorScrollBar.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ImageEditorScrollBar.cs new file mode 100644 index 000000000..f955dee2b --- /dev/null +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ImageEditorScrollBar.cs @@ -0,0 +1,155 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2018 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 . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace ShareX.ScreenCaptureLib +{ + internal class ImageEditorScrollbar : DrawableObject + { + public Orientation Orientation { get; set; } + public int Thickness { get; set; } = 10; + public int Margin { get; set; } = 15; + public int Padding { get; set; } = 2; + public float Opacity { get; set; } + public Rectangle ThumbRectangle { get; set; } + + private RegionCaptureForm form; + + public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form) + { + Orientation = orientation; + this.form = form; + } + + public void Update() + { + UpdateOpacity(); + + if (Visible) + { + Rectangle imageRectangleVisible = form.CanvasRectangle; + imageRectangleVisible.Intersect(form.ClientArea); + + int inClientAreaSize, inImageVisibleSize, inImageSize, sideOffsetBase; + float inCanvasCenterOffset; + + if (Orientation == Orientation.Horizontal) + { + inClientAreaSize = form.ClientArea.Width; + inImageVisibleSize = imageRectangleVisible.Width; + inImageSize = form.CanvasRectangle.Width; + sideOffsetBase = form.ClientArea.Bottom; + inCanvasCenterOffset = form.CanvasCenterOffset.X; + } + else + { + inClientAreaSize = form.ClientArea.Height; + inImageVisibleSize = imageRectangleVisible.Height; + inImageSize = form.CanvasRectangle.Height; + sideOffsetBase = form.ClientArea.Right; + inCanvasCenterOffset = form.CanvasCenterOffset.Y; + } + + int trackLength = inClientAreaSize - Margin * 2 - Padding * 2 - Thickness; + int trackLengthInternal = trackLength - Padding * 2; + + int thumbLength = Math.Max(Thickness, (int)Math.Round((float)inImageVisibleSize / inImageSize * trackLengthInternal)); + double thumbLimit = (trackLengthInternal - thumbLength) / 2.0f; + int thumbPosition = (int)Math.Round(Margin + trackLength / 2.0f - (thumbLength / 2.0f) - + Math.Min(thumbLimit, Math.Max(-thumbLimit, inCanvasCenterOffset / inImageSize * trackLengthInternal))); + + int trackWidth = Padding * 2 + Thickness; + int trackSideOffset = sideOffsetBase - Margin - Thickness - 1 - Padding * 2; + int thumbSideOffset = sideOffsetBase - Margin - Thickness - 1 - Padding; + + if (Orientation == Orientation.Horizontal) + { + Rectangle = new Rectangle(Margin, trackSideOffset, trackLength, trackWidth); + ThumbRectangle = new Rectangle(thumbPosition, thumbSideOffset, thumbLength, Thickness); + } + else + { + Rectangle = new Rectangle(trackSideOffset, Margin, trackWidth, trackLength); + ThumbRectangle = new Rectangle(thumbSideOffset, thumbPosition, Thickness, thumbLength); + } + } + } + + private void UpdateOpacity() + { + bool isScrollbarNeeded; + + if (Orientation == Orientation.Horizontal) + { + isScrollbarNeeded = form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right; + } + else + { + isScrollbarNeeded = form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom; + } + + if (!isScrollbarNeeded) + { + Opacity = 0f; + } + else if (form.ShapeManager.IsPanning || IsCursorHover) + { + Opacity = 1f; + } + else + { + Opacity = 0.8f; + } + + Visible = Opacity > 0; + } + + public override void OnDraw(Graphics g) + { + if (!Visible) return; + + using (Brush trackBrush = new SolidBrush(Color.FromArgb((int)(255 * Opacity), 60, 60, 60))) + using (Brush thumbBrush = new SolidBrush(Color.FromArgb((int)(255 * Opacity), 130, 130, 130))) + { + g.SmoothingMode = SmoothingMode.HighQuality; + g.DrawCapsule(trackBrush, Rectangle); + g.DrawCapsule(thumbBrush, ThumbRectangle); + g.SmoothingMode = SmoothingMode.None; + } + } + + public override void OnMouseDown(Point position) + { + base.OnMouseDown(position); + + // Pan here + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs index bad174858..5517972d7 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs @@ -23,177 +23,31 @@ #endregion License Information (GPL v3) -using ShareX.HelpersLib; -using System; -using System.Diagnostics; using System.Drawing; -using System.Drawing.Drawing2D; +using System.Windows.Forms; namespace ShareX.ScreenCaptureLib { internal class ScrollbarManager { - public bool IsVisible => IsHorizontalScrollbarVisible || IsVerticalScrollbarVisible; - public bool IsHorizontalScrollbarVisible { get; private set; } - public bool IsVerticalScrollbarVisible { get; private set; } - - public int Thickness { get; set; } = 10; - public int Margin { get; set; } = 15; - public int Padding { get; set; } = 2; - - // Timings in milliseconds - public int FadeInTime { get; set; } = 150; - public int FadeOutDelay { get; set; } = 500; - public int FadeOutTime { get; set; } = 150; + public bool IsVisible => horizontalScrollbar.Visible || verticalScrollbar.Visible; private RegionCaptureForm form; - private Rectangle horizontalTrackRectangle, horizontalThumbRectangle, verticalTrackRectangle, verticalThumbRectangle; - private bool shouldDrawHorizontalScrollbar = true; - private bool shouldDrawVerticalScrollbar = true; - private bool shouldDrawHorizontalScrollbarBefore = true; - private bool shouldDrawVerticalScrollbarBefore = true; - private Stopwatch horizontalScrollbarChangeTime; - private Stopwatch verticalScrollbarChangeTime; - private int HorizontalScrollbarOpacityLast = 255; - private int HorizontalScrollbarOpacityCurrent = 255; - private int VerticalScrollbarOpacityLast = 255; - private int VerticalScrollbarOpacityCurrent = 255; + private ImageEditorScrollbar horizontalScrollbar, verticalScrollbar; - public ScrollbarManager(RegionCaptureForm regionCaptureForm) + public ScrollbarManager(RegionCaptureForm regionCaptureForm, ShapeManager shapeManager) { form = regionCaptureForm; - horizontalScrollbarChangeTime = Stopwatch.StartNew(); - verticalScrollbarChangeTime = Stopwatch.StartNew(); - - if (form.ClientArea.Contains(form.CanvasRectangle)) - { - HorizontalScrollbarOpacityLast = 0; - HorizontalScrollbarOpacityCurrent = 0; - VerticalScrollbarOpacityLast = 0; - VerticalScrollbarOpacityCurrent = 0; - } + horizontalScrollbar = new ImageEditorScrollbar(Orientation.Horizontal, form); + shapeManager.DrawableObjects.Add(horizontalScrollbar); + verticalScrollbar = new ImageEditorScrollbar(Orientation.Vertical, form); + shapeManager.DrawableObjects.Add(verticalScrollbar); } public void Update() { - Rectangle imageRectangleVisible = form.CanvasRectangle; - imageRectangleVisible.Intersect(form.ClientArea); - - shouldDrawHorizontalScrollbar = form.ShapeManager.IsPanning && - (form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right); - - if (shouldDrawHorizontalScrollbar != shouldDrawHorizontalScrollbarBefore) - { - horizontalScrollbarChangeTime = Stopwatch.StartNew(); - HorizontalScrollbarOpacityLast = HorizontalScrollbarOpacityCurrent; - } - shouldDrawHorizontalScrollbarBefore = shouldDrawHorizontalScrollbar; - - if (shouldDrawHorizontalScrollbar) - { - HorizontalScrollbarOpacityCurrent = HorizontalScrollbarOpacityLast + OpacityGain(horizontalScrollbarChangeTime); - } - else - { - HorizontalScrollbarOpacityCurrent = HorizontalScrollbarOpacityLast - OpacityLoss(horizontalScrollbarChangeTime); - } - HorizontalScrollbarOpacityCurrent = HorizontalScrollbarOpacityCurrent.Between(0, 255); - - IsHorizontalScrollbarVisible = HorizontalScrollbarOpacityCurrent > 0; - - if (IsHorizontalScrollbarVisible) - { - int horizontalTrackLength = form.ClientArea.Width - Margin * 2 - Thickness - Padding * 2; - int horizontalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Width / form.CanvasRectangle.Width * horizontalTrackLength)); - - horizontalTrackRectangle = new Rectangle(new Point(Margin - Padding, form.ClientArea.Bottom - (Thickness + Margin) - Padding), - new Size(horizontalTrackLength + Padding * 2, Thickness + Padding * 2)); - - double limitHorizontal = (horizontalTrackLength - horizontalThumbLength) / 2.0f; - double thumbHorizontalPositionX = Math.Round(horizontalTrackRectangle.X + horizontalTrackRectangle.Width / 2.0f - (horizontalThumbLength / 2.0f) - - Math.Min(limitHorizontal, Math.Max(-limitHorizontal, form.CanvasCenterOffset.X / form.CanvasRectangle.Width * horizontalTrackLength))); - - horizontalThumbRectangle = new Rectangle(new Point((int)thumbHorizontalPositionX, form.ClientArea.Bottom - (Thickness + Margin)), - new Size(horizontalThumbLength, Thickness)); - } - - shouldDrawVerticalScrollbar = form.ShapeManager.IsPanning && - (form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom); - - if (shouldDrawVerticalScrollbar != shouldDrawVerticalScrollbarBefore) - { - verticalScrollbarChangeTime = Stopwatch.StartNew(); - VerticalScrollbarOpacityLast = VerticalScrollbarOpacityCurrent; - } - shouldDrawVerticalScrollbarBefore = shouldDrawVerticalScrollbar; - - if (shouldDrawVerticalScrollbar) - { - VerticalScrollbarOpacityCurrent = VerticalScrollbarOpacityLast + OpacityGain(verticalScrollbarChangeTime); - } - else - { - VerticalScrollbarOpacityCurrent = VerticalScrollbarOpacityLast - OpacityLoss(verticalScrollbarChangeTime); - } - VerticalScrollbarOpacityCurrent = VerticalScrollbarOpacityCurrent.Between(0, 255); - - IsVerticalScrollbarVisible = VerticalScrollbarOpacityCurrent > 0; - if (IsVerticalScrollbarVisible) - { - int verticalTrackLength = form.ClientArea.Height - Margin * 2 - Thickness - Padding * 2; - int verticalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Height / form.CanvasRectangle.Height * verticalTrackLength)); - - verticalTrackRectangle = new Rectangle(new Point(form.ClientArea.Right - (Thickness + Margin) - Padding, Margin - Padding), - new Size(Thickness + Padding * 2, verticalTrackLength + Padding * 2)); - - double limitVertical = (verticalTrackLength - verticalThumbLength) / 2.0f; - double thumbVerticalPositionY = Math.Round(verticalTrackRectangle.Y + verticalTrackRectangle.Height / 2.0f - (verticalThumbLength / 2.0f) - - Math.Min(limitVertical, Math.Max(-limitVertical, form.CanvasCenterOffset.Y / form.CanvasRectangle.Height * verticalTrackLength))); - - verticalThumbRectangle = new Rectangle(new Point(form.ClientArea.Right - (Thickness + Margin), (int)thumbVerticalPositionY), - new Size(Thickness, verticalThumbLength)); - } - } - - public void Draw(Graphics g) - { - if (IsVisible) - { - if (IsHorizontalScrollbarVisible) - { - using (Brush trackBrush = new SolidBrush(Color.FromArgb(HorizontalScrollbarOpacityCurrent, 60, 60, 60))) - using (Brush thumbBrush = new SolidBrush(Color.FromArgb(HorizontalScrollbarOpacityCurrent, 130, 130, 130))) - { - g.SmoothingMode = SmoothingMode.HighQuality; - g.DrawCapsule(trackBrush, horizontalTrackRectangle); - g.DrawCapsule(thumbBrush, horizontalThumbRectangle); - g.SmoothingMode = SmoothingMode.None; - } - } - - if (IsVerticalScrollbarVisible) - { - using (Brush trackBrush = new SolidBrush(Color.FromArgb(VerticalScrollbarOpacityCurrent, 60, 60, 60))) - using (Brush thumbBrush = new SolidBrush(Color.FromArgb(VerticalScrollbarOpacityCurrent, 130, 130, 130))) - { - g.SmoothingMode = SmoothingMode.HighQuality; - g.DrawCapsule(trackBrush, verticalTrackRectangle); - g.DrawCapsule(thumbBrush, verticalThumbRectangle); - g.SmoothingMode = SmoothingMode.None; - } - } - } - } - - private int OpacityGain(Stopwatch changeTime) - { - return (int)Math.Min(255.0f, 255.0f * changeTime.ElapsedMilliseconds / Math.Max(0, (float)FadeInTime)); - } - - private int OpacityLoss(Stopwatch changeTime) - { - int deltaTime = Math.Max(0, (int)changeTime.ElapsedMilliseconds - FadeOutDelay); - return (int)Math.Min(255.0f, 255.0f * deltaTime / Math.Max(0, (float)FadeOutTime)); + horizontalScrollbar.Update(); + verticalScrollbar.Update(); } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 72441b78d..e3dbc29c0 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -222,6 +222,7 @@ public bool NodesVisible internal RegionCaptureForm Form { get; private set; } private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed; + private ScrollbarManager scrollbarManager; public ShapeManager(RegionCaptureForm form) { @@ -264,6 +265,11 @@ public ShapeManager(RegionCaptureForm form) { CurrentTool = ShapeType.RegionRectangle; } + + if (form.IsEditorMode) + { + scrollbarManager = new ScrollbarManager(form, this); + } } private void form_Shown(object sender, EventArgs e) @@ -741,6 +747,11 @@ public void Update() UpdateCurrentHoverShape(); UpdateNodes(); + + if (scrollbarManager != null) + { + scrollbarManager.Update(); + } } private void StartRegionSelection() diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index d9f963350..327275776 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -76,6 +76,8 @@ internal void CreateToolbar() menuForm.KeyDown += MenuForm_KeyDown; menuForm.KeyUp += MenuForm_KeyUp; menuForm.LocationChanged += MenuForm_LocationChanged; + menuForm.GotFocus += MenuForm_GotFocus; + menuForm.LostFocus += MenuForm_LostFocus; menuForm.SuspendLayout(); @@ -1024,6 +1026,16 @@ private void MenuForm_LocationChanged(object sender, EventArgs e) CheckMenuPosition(); } + private void MenuForm_GotFocus(object sender, EventArgs e) + { + Form.Resume(); + } + + private void MenuForm_LostFocus(object sender, EventArgs e) + { + Form.Pause(); + } + private void TsMain_MouseLeave(object sender, EventArgs e) { MenuTextAnimation.Stop(); diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 977b7d1e6..e44d7f68c 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -126,6 +126,7 @@ StickerPackForm.cs + diff --git a/ShareX.Setup/InnoSetup/ShareX-setup.iss b/ShareX.Setup/InnoSetup/ShareX-setup.iss index 1127aa15d..dc29d1a56 100644 --- a/ShareX.Setup/InnoSetup/ShareX-setup.iss +++ b/ShareX.Setup/InnoSetup/ShareX-setup.iss @@ -90,12 +90,6 @@ Name: "{userstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppFilename}"; WorkingD [Run] Filename: "{app}\{#MyAppFilename}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall; Check: not IsNoRun -[UninstallRun] -Filename: regsvr32; WorkingDir: {app}; Parameters: "/s /u screen-capture-recorder.dll"; Check: not IsWin64 -Filename: regsvr32; WorkingDir: {app}; Parameters: "/s /u screen-capture-recorder-x64.dll"; Check: IsWin64 -Filename: regsvr32; WorkingDir: {app}; Parameters: "/s /u audio_sniffer.dll"; Check: not IsWin64 -Filename: regsvr32; WorkingDir: {app}; Parameters: "/s /u audio_sniffer-x64.dll"; Check: IsWin64 - [Registry] Root: "HKCU"; Subkey: "Software\Classes\*\shell\{#MyAppName}"; ValueType: string; ValueData: "Upload with {#MyAppName}"; Tasks: CreateContextMenuButton Root: "HKCU"; Subkey: "Software\Classes\*\shell\{#MyAppName}"; ValueType: string; ValueName: "Icon"; ValueData: """{app}\{#MyAppFilename}"",0"; Tasks: CreateContextMenuButton @@ -105,7 +99,6 @@ Root: "HKCU"; Subkey: "Software\Classes\Directory\shell\{#MyAppName}"; ValueType Root: "HKCU"; Subkey: "Software\Classes\Directory\shell\{#MyAppName}\command"; ValueType: string; ValueData: """{app}\{#MyAppFilename}"" ""%1"""; Tasks: CreateContextMenuButton Root: "HKCU"; Subkey: "Software\Classes\*\shell\{#MyAppName}"; Flags: dontcreatekey uninsdeletekey Root: "HKCU"; Subkey: "Software\Classes\Directory\shell\{#MyAppName}"; Flags: dontcreatekey uninsdeletekey -Root: "HKCU"; Subkey: "Software\Classes\Folder\shell\{#MyAppName}"; Flags: dontcreatekey uninsdeletekey Root: "HKCU"; Subkey: "Software\Classes\.sxcu"; Flags: dontcreatekey uninsdeletekey Root: "HKCU"; Subkey: "Software\Classes\ShareX.sxcu"; Flags: dontcreatekey uninsdeletekey diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs index 6497713a9..655d84571 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs @@ -538,7 +538,6 @@ private void InitializeComponent() this.cbGistUseRawURL = new System.Windows.Forms.CheckBox(); this.cbGistPublishPublic = new System.Windows.Forms.CheckBox(); this.oAuth2Gist = new ShareX.UploadersLib.OAuthControl(); - this.atcGistAccountType = new ShareX.UploadersLib.AccountTypeControl(); this.tpUpaste = new System.Windows.Forms.TabPage(); this.cbUpasteIsPublic = new System.Windows.Forms.CheckBox(); this.lblUpasteUserKey = new System.Windows.Forms.Label(); @@ -4433,7 +4432,6 @@ private void InitializeComponent() this.tpGist.Controls.Add(this.cbGistUseRawURL); this.tpGist.Controls.Add(this.cbGistPublishPublic); this.tpGist.Controls.Add(this.oAuth2Gist); - this.tpGist.Controls.Add(this.atcGistAccountType); resources.ApplyResources(this.tpGist, "tpGist"); this.tpGist.Name = "tpGist"; // @@ -4474,20 +4472,13 @@ private void InitializeComponent() // // oAuth2Gist // - resources.ApplyResources(this.oAuth2Gist, "oAuth2Gist"); this.oAuth2Gist.IsRefreshable = false; + resources.ApplyResources(this.oAuth2Gist, "oAuth2Gist"); this.oAuth2Gist.Name = "oAuth2Gist"; this.oAuth2Gist.OpenButtonClicked += new ShareX.UploadersLib.OAuthControl.OpenButtonClickedEventHandler(this.oAuth2Gist_OpenButtonClicked); this.oAuth2Gist.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oAuth2Gist_CompleteButtonClicked); this.oAuth2Gist.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oAuth2Gist_ClearButtonClicked); // - // atcGistAccountType - // - resources.ApplyResources(this.atcGistAccountType, "atcGistAccountType"); - this.atcGistAccountType.Name = "atcGistAccountType"; - this.atcGistAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous; - this.atcGistAccountType.AccountTypeChanged += new ShareX.UploadersLib.AccountTypeControl.AccountTypeChangedEventHandler(this.atcGistAccountType_AccountTypeChanged); - // // tpUpaste // this.tpUpaste.BackColor = System.Drawing.SystemColors.Window; @@ -5546,7 +5537,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtPaste_eeUserAPIKey; private System.Windows.Forms.CheckBox cbGistPublishPublic; private OAuthControl oAuth2Gist; - private AccountTypeControl atcGistAccountType; private System.Windows.Forms.CheckBox cbUpasteIsPublic; private System.Windows.Forms.Label lblUpasteUserKey; private System.Windows.Forms.TextBox txtUpasteUserKey; diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs index 92d229272..2e40db533 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs @@ -312,8 +312,6 @@ public void LoadSettings() #region Gist - atcGistAccountType.SelectedAccountType = Config.GistAnonymousLogin ? AccountType.Anonymous : AccountType.User; - if (OAuth2Info.CheckOAuth(Config.GistOAuth2Info)) { oAuth2Gist.Status = OAuthLoginStatus.LoginSuccessful; @@ -1263,12 +1261,6 @@ private void txtPaste_eeUserAPIKey_TextChanged(object sender, EventArgs e) #region Gist - private void atcGistAccountType_AccountTypeChanged(AccountType accountType) - { - Config.GistAnonymousLogin = accountType == AccountType.Anonymous; - oAuth2Gist.Enabled = !Config.GistAnonymousLogin; - } - private void oAuth2Gist_OpenButtonClicked() { GistAuthOpen(); diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx index 61e70659e..8f63cc4df 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx @@ -3545,6 +3545,24 @@ store.book[0].title 5 + + Fill + + + 3, 3 + + + 980, 563 + + + 0 + + + tcURLShorteners + + + 5 + 18, 33 @@ -3578,207 +3596,6 @@ store.book[0].title 60, 13 - - 5 - - - .app.goo.gl - - - lblFirebaseDynamicDomain - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpFirebaseDynamicLinks - - - 1 - - - True - - - 15, 64 - - - 107, 13 - - - 4 - - - Dynamic link domain: - - - lblFirebaseDomain - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpFirebaseDynamicLinks - - - 2 - - - 18, 80 - - - 45, 20 - - - 3 - - - txtFirebaseDomain - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpFirebaseDynamicLinks - - - 3 - - - True - - - NoControl - - - 15, 17 - - - 74, 13 - - - 2 - - - Web API Key: - - - lblFirebaseWebAPIKey - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpFirebaseDynamicLinks - - - 4 - - - True - - - 19, 106 - - - 70, 17 - - - 0 - - - Short link - - - cbFirebaseIsShort - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpFirebaseDynamicLinks - - - 5 - - - 4, 22 - - - 3, 3, 3, 3 - - - 972, 537 - - - 7 - - - Firebase Dynamic Links - - - tpFirebaseDynamicLinks - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcURLShorteners - - - 6 - - - Fill - - - 3, 3 - - - 980, 563 - - - 0 - - - tcURLShorteners - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpURLShorteners - - - 0 - - - 4, 22 - - - 3, 3, 3, 3 - - - 986, 569 - - - 3 - - - URL shorteners - - - tpURLShorteners - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcUploaders - - - 3 - 184, 44 @@ -4958,6 +4775,21 @@ store.book[0].title btnFTPDuplicate + + 696, 11 + + + 96, 23 + + + 3 + + + Duplicate + + + btnFTPDuplicate + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -11958,7 +11790,7 @@ Using an encrypted library disables sharing. 4, 4, 4, 4 - 792, 4113 + 792, 999 6 @@ -13050,7 +12882,7 @@ Using an encrypted library disables sharing. NoControl - 224, 364 + 224, 316 158, 13 @@ -13080,16 +12912,16 @@ Using an encrypted library disables sharing. NoControl - 16, 64 + 13, 16 - 282, 13 + 200, 13 23 - Note: User account is not supported for GitHub Enterprise. + Note: GitHub Enterprise is not supported. lblGistOAuthInfo @@ -13110,7 +12942,7 @@ Using an encrypted library disables sharing. NoControl - 13, 344 + 13, 296 82, 13 @@ -13134,7 +12966,7 @@ Using an encrypted library disables sharing. 2 - 16, 360 + 16, 312 200, 20 @@ -13161,7 +12993,7 @@ Using an encrypted library disables sharing. NoControl - 16, 320 + 16, 272 90, 17 @@ -13191,7 +13023,7 @@ Using an encrypted library disables sharing. NoControl - 16, 296 + 16, 248 109, 17 @@ -13214,11 +13046,8 @@ Using an encrypted library disables sharing. 5 - - False - - 16, 88 + 16, 40 328, 205 @@ -13238,32 +13067,11 @@ Using an encrypted library disables sharing. 6 - - 16, 16 - - - 214, 40 - - - 0 - - - atcGistAccountType - - - ShareX.UploadersLib.AccountTypeControl, ShareX.UploadersLib, Version=12.1.1.0, Culture=neutral, PublicKeyToken=null - - - tpGist - - - 7 - 4, 22 - 178, 42 + 972, 537 2 diff --git a/ShareX.UploadersLib/Forms/UploadersConfigFormHelper.cs b/ShareX.UploadersLib/Forms/UploadersConfigFormHelper.cs index 1b6467eed..17207aba4 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigFormHelper.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigFormHelper.cs @@ -2008,7 +2008,6 @@ public void GistAuthComplete(string code) { oAuth2Gist.Status = OAuthLoginStatus.LoginFailed; MessageBox.Show(Resources.UploadersConfigForm_Login_failed, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error); - atcGistAccountType.SelectedAccountType = AccountType.Anonymous; } } } diff --git a/ShareX.UploadersLib/Helpers/CustomUploaderItem.cs b/ShareX.UploadersLib/Helpers/CustomUploaderItem.cs index 254890e64..438e13445 100644 --- a/ShareX.UploadersLib/Helpers/CustomUploaderItem.cs +++ b/ShareX.UploadersLib/Helpers/CustomUploaderItem.cs @@ -23,6 +23,7 @@ #endregion License Information (GPL v3) +using Newtonsoft.Json.Linq; using ShareX.HelpersLib; using ShareX.UploadersLib.Properties; using System; @@ -390,7 +391,7 @@ private string ParseRegexSyntax(string syntax) // http://goessner.net/articles/JsonPath/ private string ParseJsonSyntax(string syntaxJsonPath) { - return Helpers.ParseJSON(response, syntaxJsonPath); + return (string)JToken.Parse(response).SelectToken("$." + syntaxJsonPath); } // http://www.w3schools.com/xsl/xpath_syntax.asp diff --git a/ShareX.UploadersLib/TextUploaders/GitHubGist.cs b/ShareX.UploadersLib/TextUploaders/GitHubGist.cs index 041f74be3..a6bf6938c 100644 --- a/ShareX.UploadersLib/TextUploaders/GitHubGist.cs +++ b/ShareX.UploadersLib/TextUploaders/GitHubGist.cs @@ -30,6 +30,7 @@ using ShareX.UploadersLib.Properties; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Net; using System.Windows.Forms; @@ -41,18 +42,14 @@ public class GitHubGistTextUploaderService : TextUploaderService public override Icon ServiceIcon => Resources.GitHub; - public override bool CheckConfig(UploadersConfig config) => true; + public override bool CheckConfig(UploadersConfig config) + { + return OAuth2Info.CheckOAuth(config.GistOAuth2Info); + } public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo) { - OAuth2Info oauth = null; - - if (!config.GistAnonymousLogin) - { - oauth = config.GistOAuth2Info; - } - - return new GitHubGist(oauth) + return new GitHubGist(config.GistOAuth2Info) { PublicUpload = config.GistPublishPublic, RawURL = config.GistRawURL, @@ -73,10 +70,6 @@ public sealed class GitHubGist : TextUploader, IOAuth2Basic public bool RawURL { get; set; } public string CustomURLAPI { get; set; } - public GitHubGist() - { - } - public GitHubGist(OAuth2Info oAuthInfos) { AuthInfo = oAuthInfos; @@ -133,8 +126,6 @@ public override UploadResult UploadText(string text, string fileName) } }; - string json = JsonConvert.SerializeObject(gistUploadObject); - string url; if (!string.IsNullOrEmpty(CustomURLAPI)) @@ -148,27 +139,41 @@ public override UploadResult UploadText(string text, string fileName) url = URLHelpers.CombineURL(url, "gists"); - if (AuthInfo != null) - { - url += "?access_token=" + AuthInfo.Token.access_token; - } + string json = JsonConvert.SerializeObject(gistUploadObject); - string response = SendRequest(HttpMethod.POST, url, json, ContentTypeJSON); + Dictionary args = new Dictionary(); + args.Add("access_token", AuthInfo.Token.access_token); + + string response = SendRequest(HttpMethod.POST, url, json, ContentTypeJSON, args); + + GistResponse gistResponse = JsonConvert.DeserializeObject(response); if (response != null) { if (RawURL) { - ur.URL = Helpers.ParseJSON(response, "files.*.raw_url"); + ur.URL = gistResponse.files.First().Value.raw_url; } else { - ur.URL = Helpers.ParseJSON(response, "html_url"); + ur.URL = gistResponse.html_url; } } } return ur; } + + private class GistResponse + { + public string html_url { get; set; } + public Dictionary files { get; set; } + } + + private class GistFileInfo + { + public string filename { get; set; } + public string raw_url { get; set; } + } } } \ No newline at end of file diff --git a/ShareX.UploadersLib/UploadersConfig.cs b/ShareX.UploadersLib/UploadersConfig.cs index ce8e5273d..a2a2ba66f 100644 --- a/ShareX.UploadersLib/UploadersConfig.cs +++ b/ShareX.UploadersLib/UploadersConfig.cs @@ -116,7 +116,6 @@ public class UploadersConfig : SettingsBase #region Gist - public bool GistAnonymousLogin = true; public OAuth2Info GistOAuth2Info = null; public bool GistPublishPublic = false; public bool GistRawURL = false; diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs index 529b155d4..20628a54d 100644 --- a/ShareX/Enums.cs +++ b/ShareX/Enums.cs @@ -110,10 +110,11 @@ public enum AfterCaptureTasks // Localized CopyFileToClipboard = 1 << 10, CopyFilePathToClipboard = 1 << 11, ShowInExplorer = 1 << 12, - DoOCR = 1 << 13, - ShowBeforeUploadWindow = 1 << 14, - UploadImageToHost = 1 << 15, - DeleteFile = 1 << 16 + ScanQRCode = 1 << 13, + DoOCR = 1 << 14, + ShowBeforeUploadWindow = 1 << 15, + UploadImageToHost = 1 << 16, + DeleteFile = 1 << 17 } [Flags] diff --git a/ShareX/Forms/AutoCaptureForm.Designer.cs b/ShareX/Forms/AutoCaptureForm.Designer.cs index 1d7ed94ee..c1644d457 100644 --- a/ShareX/Forms/AutoCaptureForm.Designer.cs +++ b/ShareX/Forms/AutoCaptureForm.Designer.cs @@ -77,6 +77,7 @@ private void InitializeComponent() // // tsslStatus // + this.tsslStatus.BackColor = System.Drawing.Color.Transparent; this.tsslStatus.Name = "tsslStatus"; resources.ApplyResources(this.tsslStatus, "tsslStatus"); // diff --git a/ShareX/Forms/AutoCaptureForm.cs b/ShareX/Forms/AutoCaptureForm.cs index 673503109..eab12c8ff 100644 --- a/ShareX/Forms/AutoCaptureForm.cs +++ b/ShareX/Forms/AutoCaptureForm.cs @@ -51,6 +51,7 @@ public static AutoCaptureForm Instance } public static bool IsRunning { get; private set; } + public TaskSettings TaskSettings { get; internal set; } private bool isLoaded; private Timer statusTimer; @@ -107,27 +108,25 @@ private void TakeScreenshot() if (!rect.IsEmpty) { - TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings(); - - Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureRectangle(rect); + Image img = TaskHelpers.GetScreenshot(TaskSettings).CaptureRectangle(rect); if (img != null) { - taskSettings.UseDefaultAfterCaptureJob = false; - taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AnnotateImage); - taskSettings.UseDefaultAdvancedSettings = false; - taskSettings.AdvancedSettings.DisableNotifications = true; + TaskSettings.UseDefaultAfterCaptureJob = false; + TaskSettings.AfterCaptureJob = TaskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AnnotateImage); + TaskSettings.UseDefaultAdvancedSettings = false; + TaskSettings.AdvancedSettings.DisableNotifications = true; - UploadManager.RunImageTask(img, taskSettings, true, true); + UploadManager.RunImageTask(img, TaskSettings, true, true); } } } - private void SelectRegion(TaskSettings taskSettings) + private void SelectRegion() { Rectangle rect; - if (RegionCaptureTasks.GetRectangleRegion(out rect, taskSettings.CaptureSettings.SurfaceOptions)) + if (RegionCaptureTasks.GetRectangleRegion(out rect, TaskSettings.CaptureSettings.SurfaceOptions)) { Program.Settings.AutoCaptureRegion = rect; UpdateRegion(); @@ -208,8 +207,7 @@ private void rbCustomRegion_CheckedChanged(object sender, EventArgs e) private void btnRegion_Click(object sender, EventArgs e) { - TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings(); - SelectRegion(taskSettings); + SelectRegion(); } private void nudDuration_ValueChanged(object sender, EventArgs e) diff --git a/ShareX/Forms/AutoCaptureForm.resx b/ShareX/Forms/AutoCaptureForm.resx index 3df4f445e..9a2ead24d 100644 --- a/ShareX/Forms/AutoCaptureForm.resx +++ b/ShareX/Forms/AutoCaptureForm.resx @@ -121,6 +121,12 @@ 17, 17 + + 75, 16 + + + 0, 17 + 0, 241 @@ -146,12 +152,6 @@ 7 - - 75, 16 - - - 0, 17 - False @@ -369,54 +369,6 @@ 1 - - rbFullscreen - - - System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - gbRegion - - - 0 - - - rbCustomRegion - - - System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - gbRegion - - - 1 - - - 8, 8 - - - 304, 96 - - - 0 - - - Region - - - gbRegion - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - True @@ -471,6 +423,30 @@ 1 + + 8, 8 + + + 304, 96 + + + 0 + + + Region + + + gbRegion + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + True diff --git a/ShareX/Forms/QRCodeForm.cs b/ShareX/Forms/QRCodeForm.cs index c932e43e9..2c4304764 100644 --- a/ShareX/Forms/QRCodeForm.cs +++ b/ShareX/Forms/QRCodeForm.cs @@ -52,18 +52,29 @@ public QRCodeForm(string text = null) { txtQRCode.Text = text; } - else - { - if (Clipboard.ContainsText()) - { - text = Clipboard.GetText(); + } - if (TaskHelpers.CheckQRCodeContent(text)) - { - txtQRCode.Text = text; - } + public static QRCodeForm EncodeClipboard() + { + if (Clipboard.ContainsText()) + { + string text = Clipboard.GetText(); + + if (TaskHelpers.CheckQRCodeContent(text)) + { + return new QRCodeForm(text); } } + + return new QRCodeForm(); + } + + public static QRCodeForm DecodeFile(string filePath) + { + QRCodeForm form = new QRCodeForm(); + form.tcMain.SelectedTab = form.tpDecode; + form.DecodeFromFile(filePath); + return form; } private void QRCodeForm_Shown(object sender, EventArgs e) @@ -110,6 +121,20 @@ private void DecodeImage(Bitmap bmp) txtDecodeResult.Text = output; } + private void DecodeFromFile(string filePath) + { + if (!string.IsNullOrEmpty(filePath)) + { + using (Image img = ImageHelpers.LoadImage(filePath)) + { + if (img != null) + { + DecodeImage((Bitmap)img); + } + } + } + } + private void QRCodeForm_Resize(object sender, EventArgs e) { EncodeText(txtQRCode.Text); @@ -212,16 +237,7 @@ private void btnDecodeFromFile_Click(object sender, EventArgs e) { string filePath = ImageHelpers.OpenImageFileDialog(); - if (!string.IsNullOrEmpty(filePath)) - { - using (Image img = ImageHelpers.LoadImage(filePath)) - { - if (img != null) - { - DecodeImage((Bitmap)img); - } - } - } + DecodeFromFile(filePath); } } } \ No newline at end of file diff --git a/ShareX/IntegrationHelpers.cs b/ShareX/IntegrationHelpers.cs index 479d23831..52bb92d96 100644 --- a/ShareX/IntegrationHelpers.cs +++ b/ShareX/IntegrationHelpers.cs @@ -39,35 +39,32 @@ namespace ShareX { public static class IntegrationHelpers { - private static readonly string ApplicationName = "ShareX"; - private static readonly string ApplicationPath = string.Format("\"{0}\"", Application.ExecutablePath); + private static readonly string ApplicationPath = $"\"{Application.ExecutablePath}\""; - private static readonly string ShellExtMenuFiles = @"Software\Classes\*\shell\" + ApplicationName; - private static readonly string ShellExtMenuFilesCmd = ShellExtMenuFiles + @"\command"; - private static readonly string ShellExtMenuDirectory = @"Software\Classes\Directory\shell\" + ApplicationName; - private static readonly string ShellExtMenuDirectoryCmd = ShellExtMenuDirectory + @"\command"; - private static readonly string ShellExtMenuFolders = @"Software\Classes\Folder\shell\" + ApplicationName; - private static readonly string ShellExtMenuFoldersCmd = ShellExtMenuFolders + @"\command"; + private static readonly string ShellExtMenuName = "ShareX"; + private static readonly string ShellExtMenuFiles = $@"Software\Classes\*\shell\{ShellExtMenuName}"; + private static readonly string ShellExtMenuFilesCmd = $@"{ShellExtMenuFiles}\command"; + private static readonly string ShellExtMenuDirectory = $@"Software\Classes\Directory\shell\{ShellExtMenuName}"; + private static readonly string ShellExtMenuDirectoryCmd = $@"{ShellExtMenuDirectory}\command"; private static readonly string ShellExtDesc = Resources.IntegrationHelpers_UploadWithShareX; - private static readonly string ShellExtIcon = ApplicationPath + ",0"; - private static readonly string ShellExtPath = ApplicationPath + " \"%1\""; + private static readonly string ShellExtIcon = $"{ApplicationPath},0"; + private static readonly string ShellExtPath = $"{ApplicationPath} \"%1\""; - private static readonly string ShellExtEditMenuJpeg = @"Software\Classes\.jpg\shell\" + ApplicationName; - private static readonly string ShellExtEditMenuJpegCmd = ShellExtEditMenuJpeg + @"\command"; - private static readonly string ShellExtEditMenuPng = @"Software\Classes\.png\shell\" + ApplicationName; - private static readonly string ShellExtEditMenuPngCmd = ShellExtEditMenuPng + @"\command"; + private static readonly string ShellExtEditName = "ShareXImageEditor"; + private static readonly string ShellExtEditImage = $@"Software\Classes\SystemFileAssociations\image\shell\{ShellExtEditName}"; + private static readonly string ShellExtEditImageCmd = $@"{ShellExtEditImage}\command"; private static readonly string ShellExtEditDesc = "Edit with ShareX"; // TODO: Translate - private static readonly string ShellExtEditIcon = ApplicationPath + ",0"; - private static readonly string ShellExtEditPath = ApplicationPath + " -ImageEditor \"%1\""; + private static readonly string ShellExtEditIcon = $"{ApplicationPath},0"; + private static readonly string ShellExtEditPath = $"{ApplicationPath} -ImageEditor \"%1\""; private static readonly string ShellCustomUploaderExtensionPath = @"Software\Classes\.sxcu"; private static readonly string ShellCustomUploaderExtensionValue = "ShareX.sxcu"; - private static readonly string ShellCustomUploaderAssociatePath = @"Software\Classes\" + ShellCustomUploaderExtensionValue; + private static readonly string ShellCustomUploaderAssociatePath = $@"Software\Classes\{ShellCustomUploaderExtensionValue}"; private static readonly string ShellCustomUploaderAssociateValue = "ShareX custom uploader"; - 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 + " -CustomUploader \"%1\""; + 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} -CustomUploader \"%1\""; private static readonly string ChromeNativeMessagingHosts = @"SOFTWARE\Google\Chrome\NativeMessagingHosts\com.getsharex.sharex"; private static readonly string FirefoxNativeMessagingHosts = @"SOFTWARE\Mozilla\NativeMessagingHosts\ShareX"; @@ -76,7 +73,8 @@ public static bool CheckShellContextMenuButton() { try { - return RegistryHelpers.CheckRegistry(ShellExtMenuFilesCmd, null, ShellExtPath) && RegistryHelpers.CheckRegistry(ShellExtMenuDirectoryCmd, null, ShellExtPath); + return RegistryHelpers.CheckRegistry(ShellExtMenuFilesCmd, null, ShellExtPath) && + RegistryHelpers.CheckRegistry(ShellExtMenuDirectoryCmd, null, ShellExtPath); } catch (Exception e) { @@ -121,14 +119,13 @@ private static void UnregisterShellContextMenuButton() { RegistryHelpers.RemoveRegistry(ShellExtMenuFiles, true); RegistryHelpers.RemoveRegistry(ShellExtMenuDirectory, true); - RegistryHelpers.RemoveRegistry(ShellExtMenuFolders, true); } public static bool CheckEditShellContextMenuButton() { try { - return RegistryHelpers.CheckRegistry(ShellExtEditMenuJpegCmd, null, ShellExtEditPath) && RegistryHelpers.CheckRegistry(ShellExtEditMenuPngCmd, null, ShellExtEditPath); + return RegistryHelpers.CheckRegistry(ShellExtEditImageCmd, null, ShellExtEditPath); } catch (Exception e) { @@ -160,19 +157,14 @@ public static void CreateEditShellContextMenuButton(bool create) private static void RegisterEditShellContextMenuButton() { - RegistryHelpers.CreateRegistry(ShellExtEditMenuJpeg, ShellExtEditDesc); - RegistryHelpers.CreateRegistry(ShellExtEditMenuJpeg, "Icon", ShellExtEditIcon); - RegistryHelpers.CreateRegistry(ShellExtEditMenuJpegCmd, ShellExtEditPath); - - RegistryHelpers.CreateRegistry(ShellExtEditMenuPng, ShellExtEditDesc); - RegistryHelpers.CreateRegistry(ShellExtEditMenuPng, "Icon", ShellExtEditIcon); - RegistryHelpers.CreateRegistry(ShellExtEditMenuPngCmd, ShellExtEditPath); + RegistryHelpers.CreateRegistry(ShellExtEditImage, ShellExtEditDesc); + RegistryHelpers.CreateRegistry(ShellExtEditImage, "Icon", ShellExtEditIcon); + RegistryHelpers.CreateRegistry(ShellExtEditImageCmd, ShellExtEditPath); } private static void UnregisterEditShellContextMenuButton() { - RegistryHelpers.RemoveRegistry(ShellExtEditMenuJpeg, true); - RegistryHelpers.RemoveRegistry(ShellExtEditMenuPng, true); + RegistryHelpers.RemoveRegistry(ShellExtEditImage, true); } public static bool CheckCustomUploaderExtension() @@ -230,7 +222,8 @@ public static bool CheckChromeExtensionSupport() { try { - return RegistryHelpers.CheckRegistry(ChromeNativeMessagingHosts, null, Program.ChromeHostManifestFilePath) && File.Exists(Program.ChromeHostManifestFilePath); + return RegistryHelpers.CheckRegistry(ChromeNativeMessagingHosts, null, Program.ChromeHostManifestFilePath) && + File.Exists(Program.ChromeHostManifestFilePath); } catch (Exception e) { @@ -299,7 +292,8 @@ public static bool CheckFirefoxAddonSupport() { try { - return RegistryHelpers.CheckRegistry(FirefoxNativeMessagingHosts, null, Program.FirefoxHostManifestFilePath) && File.Exists(Program.FirefoxHostManifestFilePath); + return RegistryHelpers.CheckRegistry(FirefoxNativeMessagingHosts, null, Program.FirefoxHostManifestFilePath) && + File.Exists(Program.FirefoxHostManifestFilePath); } catch (Exception e) { @@ -409,6 +403,7 @@ public static void Uninstall() { StartupManagerSingletonProvider.CurrentStartupManager.State = StartupTaskState.Disabled; CreateShellContextMenuButton(false); + CreateEditShellContextMenuButton(false); CreateCustomUploaderExtension(false); CreateSendToMenuButton(false); } diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 8899f3973..21eafb068 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -135,10 +135,10 @@ public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLIComm OCRImage(safeTaskSettings); break; case HotkeyType.AutoCapture: - OpenAutoCapture(); + OpenAutoCapture(safeTaskSettings); break; case HotkeyType.StartAutoCapture: - StartAutoCapture(); + StartAutoCapture(safeTaskSettings); break; // Screen record case HotkeyType.ScreenRecorder: @@ -653,8 +653,11 @@ public static void OpenScrollingCapture(TaskSettings taskSettings = null, bool f scrollingCaptureForm.Show(); } - public static void OpenAutoCapture() + public static void OpenAutoCapture(TaskSettings taskSettings = null) { + if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); + + AutoCaptureForm.Instance.TaskSettings = taskSettings; AutoCaptureForm.Instance.ForceActivate(); } @@ -674,11 +677,14 @@ public static void OpenWebpageCapture(TaskSettings taskSettings = null) webpageCaptureForm.Show(); } - public static void StartAutoCapture() + public static void StartAutoCapture(TaskSettings taskSettings = null) { + if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); + if (!AutoCaptureForm.IsRunning) { AutoCaptureForm form = AutoCaptureForm.Instance; + form.TaskSettings = taskSettings; form.Show(); form.Execute(); } @@ -1004,7 +1010,7 @@ public static void RunShareXAsAdmin(string arguments) public static void OpenQRCode() { - new QRCodeForm().Show(); + QRCodeForm.EncodeClipboard().Show(); } public static void OpenRuler(TaskSettings taskSettings = null) @@ -1330,6 +1336,8 @@ public static Image FindMenuIcon(int index) return Resources.clipboard_list; case AfterCaptureTasks.ShowInExplorer: return Resources.folder_stand; + case AfterCaptureTasks.ScanQRCode: + return Resources.barcode_2d; case AfterCaptureTasks.DoOCR: return Resources.edit_drop_cap; case AfterCaptureTasks.ShowBeforeUploadWindow: diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index df2f31895..903ccbdb3 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -718,6 +718,11 @@ private void DoFileJobs() { Helpers.OpenFolderWithFile(Info.FilePath); } + + if (Info.TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.ScanQRCode) && Info.DataType == EDataType.Image) + { + QRCodeForm.DecodeFile(Info.FilePath).ShowDialog(); + } } }