Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Matthew Burnett 2018-04-03 21:05:58 -04:00
commit 5536e6cc41
26 changed files with 423 additions and 601 deletions

View file

@ -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/

View file

@ -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<T>() where T : class
{
IEnumerable<T> instances = from t in Assembly.GetCallingAssembly().GetTypes()

View file

@ -252,6 +252,15 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Scan QR code.
/// </summary>
internal static string AfterCaptureTasks_ScanQRCode {
get {
return ResourceManager.GetString("AfterCaptureTasks_ScanQRCode", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Print image.
/// </summary>

View file

@ -1160,4 +1160,7 @@ Would you like to download it?</value>
<data name="WavFileNameEditor_EditValue_Browse_for_a_sound_file___" xml:space="preserve">
<value>Browse for a sound file...</value>
</data>
<data name="AfterCaptureTasks_ScanQRCode" xml:space="preserve">
<value>Scan QR code</value>
</data>
</root>

View file

@ -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)

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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
}
}
}

View file

@ -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();
}
}
}

View file

@ -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()

View file

@ -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();

View file

@ -126,6 +126,7 @@
<DependentUpon>StickerPackForm.cs</DependentUpon>
</Compile>
<Compile Include="RegionHelpers\ButtonObject.cs" />
<Compile Include="RegionHelpers\ImageEditorScrollbar.cs" />
<Compile Include="RegionHelpers\ScrollbarManager.cs" />
<Compile Include="Shapes\AnnotationOptions.cs" />
<Compile Include="Enums.cs" />

View file

@ -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

View file

@ -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;

View file

@ -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();

View file

@ -3545,6 +3545,24 @@ store.book[0].title</value>
<data name="&gt;&gt;tpPolr.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="tcURLShorteners.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="tcURLShorteners.Location" type="System.Drawing.Point, System.Drawing">
<value>3, 3</value>
</data>
<data name="tcURLShorteners.Size" type="System.Drawing.Size, System.Drawing">
<value>980, 563</value>
</data>
<data name="tcURLShorteners.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="&gt;&gt;tpPolr.Parent" xml:space="preserve">
<value>tcURLShorteners</value>
</data>
<data name="&gt;&gt;tpPolr.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="txtFirebaseWebAPIKey.Location" type="System.Drawing.Point, System.Drawing">
<value>18, 33</value>
</data>
@ -3578,207 +3596,6 @@ store.book[0].title</value>
<data name="lblFirebaseDynamicDomain.Size" type="System.Drawing.Size, System.Drawing">
<value>60, 13</value>
</data>
<data name="lblFirebaseDynamicDomain.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="lblFirebaseDynamicDomain.Text" xml:space="preserve">
<value>.app.goo.gl</value>
</data>
<data name="&gt;&gt;lblFirebaseDynamicDomain.Name" xml:space="preserve">
<value>lblFirebaseDynamicDomain</value>
</data>
<data name="&gt;&gt;lblFirebaseDynamicDomain.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblFirebaseDynamicDomain.Parent" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;lblFirebaseDynamicDomain.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="lblFirebaseDomain.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="lblFirebaseDomain.Location" type="System.Drawing.Point, System.Drawing">
<value>15, 64</value>
</data>
<data name="lblFirebaseDomain.Size" type="System.Drawing.Size, System.Drawing">
<value>107, 13</value>
</data>
<data name="lblFirebaseDomain.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="lblFirebaseDomain.Text" xml:space="preserve">
<value>Dynamic link domain:</value>
</data>
<data name="&gt;&gt;lblFirebaseDomain.Name" xml:space="preserve">
<value>lblFirebaseDomain</value>
</data>
<data name="&gt;&gt;lblFirebaseDomain.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblFirebaseDomain.Parent" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;lblFirebaseDomain.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="txtFirebaseDomain.Location" type="System.Drawing.Point, System.Drawing">
<value>18, 80</value>
</data>
<data name="txtFirebaseDomain.Size" type="System.Drawing.Size, System.Drawing">
<value>45, 20</value>
</data>
<data name="txtFirebaseDomain.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="&gt;&gt;txtFirebaseDomain.Name" xml:space="preserve">
<value>txtFirebaseDomain</value>
</data>
<data name="&gt;&gt;txtFirebaseDomain.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtFirebaseDomain.Parent" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;txtFirebaseDomain.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="lblFirebaseWebAPIKey.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="lblFirebaseWebAPIKey.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="lblFirebaseWebAPIKey.Location" type="System.Drawing.Point, System.Drawing">
<value>15, 17</value>
</data>
<data name="lblFirebaseWebAPIKey.Size" type="System.Drawing.Size, System.Drawing">
<value>74, 13</value>
</data>
<data name="lblFirebaseWebAPIKey.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<data name="lblFirebaseWebAPIKey.Text" xml:space="preserve">
<value>Web API Key:</value>
</data>
<data name="&gt;&gt;lblFirebaseWebAPIKey.Name" xml:space="preserve">
<value>lblFirebaseWebAPIKey</value>
</data>
<data name="&gt;&gt;lblFirebaseWebAPIKey.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblFirebaseWebAPIKey.Parent" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;lblFirebaseWebAPIKey.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="cbFirebaseIsShort.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="cbFirebaseIsShort.Location" type="System.Drawing.Point, System.Drawing">
<value>19, 106</value>
</data>
<data name="cbFirebaseIsShort.Size" type="System.Drawing.Size, System.Drawing">
<value>70, 17</value>
</data>
<data name="cbFirebaseIsShort.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="cbFirebaseIsShort.Text" xml:space="preserve">
<value>Short link</value>
</data>
<data name="&gt;&gt;cbFirebaseIsShort.Name" xml:space="preserve">
<value>cbFirebaseIsShort</value>
</data>
<data name="&gt;&gt;cbFirebaseIsShort.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cbFirebaseIsShort.Parent" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;cbFirebaseIsShort.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="tpFirebaseDynamicLinks.Location" type="System.Drawing.Point, System.Drawing">
<value>4, 22</value>
</data>
<data name="tpFirebaseDynamicLinks.Padding" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>3, 3, 3, 3</value>
</data>
<data name="tpFirebaseDynamicLinks.Size" type="System.Drawing.Size, System.Drawing">
<value>972, 537</value>
</data>
<data name="tpFirebaseDynamicLinks.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="tpFirebaseDynamicLinks.Text" xml:space="preserve">
<value>Firebase Dynamic Links</value>
</data>
<data name="&gt;&gt;tpFirebaseDynamicLinks.Name" xml:space="preserve">
<value>tpFirebaseDynamicLinks</value>
</data>
<data name="&gt;&gt;tpFirebaseDynamicLinks.Type" xml:space="preserve">
<value>System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tpFirebaseDynamicLinks.Parent" xml:space="preserve">
<value>tcURLShorteners</value>
</data>
<data name="&gt;&gt;tpFirebaseDynamicLinks.ZOrder" xml:space="preserve">
<value>6</value>
</data>
<data name="tcURLShorteners.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="tcURLShorteners.Location" type="System.Drawing.Point, System.Drawing">
<value>3, 3</value>
</data>
<data name="tcURLShorteners.Size" type="System.Drawing.Size, System.Drawing">
<value>980, 563</value>
</data>
<data name="tcURLShorteners.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="&gt;&gt;tcURLShorteners.Name" xml:space="preserve">
<value>tcURLShorteners</value>
</data>
<data name="&gt;&gt;tcURLShorteners.Type" xml:space="preserve">
<value>System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tcURLShorteners.Parent" xml:space="preserve">
<value>tpURLShorteners</value>
</data>
<data name="&gt;&gt;tcURLShorteners.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="tpURLShorteners.Location" type="System.Drawing.Point, System.Drawing">
<value>4, 22</value>
</data>
<data name="tpURLShorteners.Padding" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>3, 3, 3, 3</value>
</data>
<data name="tpURLShorteners.Size" type="System.Drawing.Size, System.Drawing">
<value>986, 569</value>
</data>
<data name="tpURLShorteners.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="tpURLShorteners.Text" xml:space="preserve">
<value>URL shorteners</value>
</data>
<data name="&gt;&gt;tpURLShorteners.Name" xml:space="preserve">
<value>tpURLShorteners</value>
</data>
<data name="&gt;&gt;tpURLShorteners.Type" xml:space="preserve">
<value>System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tpURLShorteners.Parent" xml:space="preserve">
<value>tcUploaders</value>
</data>
<data name="&gt;&gt;tpURLShorteners.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="txtSFTPKeyPassphrase.Location" type="System.Drawing.Point, System.Drawing">
<value>184, 44</value>
</data>
@ -4958,6 +4775,21 @@ store.book[0].title</value>
<data name="&gt;&gt;btnFTPDuplicate.Name" xml:space="preserve">
<value>btnFTPDuplicate</value>
</data>
<data name="btnFTPDuplicate.Location" type="System.Drawing.Point, System.Drawing">
<value>696, 11</value>
</data>
<data name="btnFTPDuplicate.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 23</value>
</data>
<data name="btnFTPDuplicate.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="btnFTPDuplicate.Text" xml:space="preserve">
<value>Duplicate</value>
</data>
<data name="&gt;&gt;btnFTPDuplicate.Name" xml:space="preserve">
<value>btnFTPDuplicate</value>
</data>
<data name="&gt;&gt;btnFTPDuplicate.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
@ -11958,7 +11790,7 @@ Using an encrypted library disables sharing.</value>
<value>4, 4, 4, 4</value>
</data>
<data name="ucLocalhostAccounts.Size" type="System.Drawing.Size, System.Drawing">
<value>792, 4113</value>
<value>792, 999</value>
</data>
<data name="ucLocalhostAccounts.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
@ -13050,7 +12882,7 @@ Using an encrypted library disables sharing.</value>
<value>NoControl</value>
</data>
<data name="lblGistCustomURLExample.Location" type="System.Drawing.Point, System.Drawing">
<value>224, 364</value>
<value>224, 316</value>
</data>
<data name="lblGistCustomURLExample.Size" type="System.Drawing.Size, System.Drawing">
<value>158, 13</value>
@ -13080,16 +12912,16 @@ Using an encrypted library disables sharing.</value>
<value>NoControl</value>
</data>
<data name="lblGistOAuthInfo.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 64</value>
<value>13, 16</value>
</data>
<data name="lblGistOAuthInfo.Size" type="System.Drawing.Size, System.Drawing">
<value>282, 13</value>
<value>200, 13</value>
</data>
<data name="lblGistOAuthInfo.TabIndex" type="System.Int32, mscorlib">
<value>23</value>
</data>
<data name="lblGistOAuthInfo.Text" xml:space="preserve">
<value>Note: User account is not supported for GitHub Enterprise.</value>
<value>Note: GitHub Enterprise is not supported.</value>
</data>
<data name="&gt;&gt;lblGistOAuthInfo.Name" xml:space="preserve">
<value>lblGistOAuthInfo</value>
@ -13110,7 +12942,7 @@ Using an encrypted library disables sharing.</value>
<value>NoControl</value>
</data>
<data name="lblGistCustomURL.Location" type="System.Drawing.Point, System.Drawing">
<value>13, 344</value>
<value>13, 296</value>
</data>
<data name="lblGistCustomURL.Size" type="System.Drawing.Size, System.Drawing">
<value>82, 13</value>
@ -13134,7 +12966,7 @@ Using an encrypted library disables sharing.</value>
<value>2</value>
</data>
<data name="txtGistCustomURL.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 360</value>
<value>16, 312</value>
</data>
<data name="txtGistCustomURL.Size" type="System.Drawing.Size, System.Drawing">
<value>200, 20</value>
@ -13161,7 +12993,7 @@ Using an encrypted library disables sharing.</value>
<value>NoControl</value>
</data>
<data name="cbGistUseRawURL.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 320</value>
<value>16, 272</value>
</data>
<data name="cbGistUseRawURL.Size" type="System.Drawing.Size, System.Drawing">
<value>90, 17</value>
@ -13191,7 +13023,7 @@ Using an encrypted library disables sharing.</value>
<value>NoControl</value>
</data>
<data name="cbGistPublishPublic.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 296</value>
<value>16, 248</value>
</data>
<data name="cbGistPublishPublic.Size" type="System.Drawing.Size, System.Drawing">
<value>109, 17</value>
@ -13214,11 +13046,8 @@ Using an encrypted library disables sharing.</value>
<data name="&gt;&gt;cbGistPublishPublic.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="oAuth2Gist.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="oAuth2Gist.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 88</value>
<value>16, 40</value>
</data>
<data name="oAuth2Gist.Size" type="System.Drawing.Size, System.Drawing">
<value>328, 205</value>
@ -13238,32 +13067,11 @@ Using an encrypted library disables sharing.</value>
<data name="&gt;&gt;oAuth2Gist.ZOrder" xml:space="preserve">
<value>6</value>
</data>
<data name="atcGistAccountType.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 16</value>
</data>
<data name="atcGistAccountType.Size" type="System.Drawing.Size, System.Drawing">
<value>214, 40</value>
</data>
<data name="atcGistAccountType.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="&gt;&gt;atcGistAccountType.Name" xml:space="preserve">
<value>atcGistAccountType</value>
</data>
<data name="&gt;&gt;atcGistAccountType.Type" xml:space="preserve">
<value>ShareX.UploadersLib.AccountTypeControl, ShareX.UploadersLib, Version=12.1.1.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;atcGistAccountType.Parent" xml:space="preserve">
<value>tpGist</value>
</data>
<data name="&gt;&gt;atcGistAccountType.ZOrder" xml:space="preserve">
<value>7</value>
</data>
<data name="tpGist.Location" type="System.Drawing.Point, System.Drawing">
<value>4, 22</value>
</data>
<data name="tpGist.Size" type="System.Drawing.Size, System.Drawing">
<value>178, 42</value>
<value>972, 537</value>
</data>
<data name="tpGist.TabIndex" type="System.Int32, mscorlib">
<value>2</value>

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -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<string, string> args = new Dictionary<string, string>();
args.Add("access_token", AuthInfo.Token.access_token);
string response = SendRequest(HttpMethod.POST, url, json, ContentTypeJSON, args);
GistResponse gistResponse = JsonConvert.DeserializeObject<GistResponse>(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<string, GistFileInfo> files { get; set; }
}
private class GistFileInfo
{
public string filename { get; set; }
public string raw_url { get; set; }
}
}
}

View file

@ -116,7 +116,6 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
#region Gist
public bool GistAnonymousLogin = true;
public OAuth2Info GistOAuth2Info = null;
public bool GistPublishPublic = false;
public bool GistRawURL = false;

View file

@ -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]

View file

@ -77,6 +77,7 @@ private void InitializeComponent()
//
// tsslStatus
//
this.tsslStatus.BackColor = System.Drawing.Color.Transparent;
this.tsslStatus.Name = "tsslStatus";
resources.ApplyResources(this.tsslStatus, "tsslStatus");
//

View file

@ -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)

View file

@ -121,6 +121,12 @@
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="tspbBar.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 16</value>
</data>
<data name="tsslStatus.Size" type="System.Drawing.Size, System.Drawing">
<value>0, 17</value>
</data>
<data name="ssBar.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 241</value>
</data>
@ -146,12 +152,6 @@
<data name="&gt;&gt;ssBar.ZOrder" xml:space="preserve">
<value>7</value>
</data>
<data name="tspbBar.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 16</value>
</data>
<data name="tsslStatus.Size" type="System.Drawing.Size, System.Drawing">
<value>0, 17</value>
</data>
<data name="btnExecute.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
@ -369,54 +369,6 @@
<data name="&gt;&gt;lblDurationSeconds.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;rbFullscreen.Name" xml:space="preserve">
<value>rbFullscreen</value>
</data>
<data name="&gt;&gt;rbFullscreen.Type" xml:space="preserve">
<value>System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;rbFullscreen.Parent" xml:space="preserve">
<value>gbRegion</value>
</data>
<data name="&gt;&gt;rbFullscreen.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;rbCustomRegion.Name" xml:space="preserve">
<value>rbCustomRegion</value>
</data>
<data name="&gt;&gt;rbCustomRegion.Type" xml:space="preserve">
<value>System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;rbCustomRegion.Parent" xml:space="preserve">
<value>gbRegion</value>
</data>
<data name="&gt;&gt;rbCustomRegion.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="gbRegion.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 8</value>
</data>
<data name="gbRegion.Size" type="System.Drawing.Size, System.Drawing">
<value>304, 96</value>
</data>
<data name="gbRegion.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="gbRegion.Text" xml:space="preserve">
<value>Region</value>
</data>
<data name="&gt;&gt;gbRegion.Name" xml:space="preserve">
<value>gbRegion</value>
</data>
<data name="&gt;&gt;gbRegion.Type" xml:space="preserve">
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;gbRegion.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;gbRegion.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="rbFullscreen.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
@ -471,6 +423,30 @@
<data name="&gt;&gt;rbCustomRegion.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="gbRegion.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 8</value>
</data>
<data name="gbRegion.Size" type="System.Drawing.Size, System.Drawing">
<value>304, 96</value>
</data>
<data name="gbRegion.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="gbRegion.Text" xml:space="preserve">
<value>Region</value>
</data>
<data name="&gt;&gt;gbRegion.Name" xml:space="preserve">
<value>gbRegion</value>
</data>
<data name="&gt;&gt;gbRegion.Type" xml:space="preserve">
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;gbRegion.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;gbRegion.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View file

@ -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);
}
}
}

View file

@ -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);
}

View file

@ -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<T>(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:

View file

@ -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();
}
}
}