mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
ImageShack better error handling, Error form changes, Using ShowActivate instead BringToFront
This commit is contained in:
parent
d10742845e
commit
16593934bf
16 changed files with 104 additions and 76 deletions
40
HelpersLib/Forms/ErrorForm.Designer.cs
generated
40
HelpersLib/Forms/ErrorForm.Designer.cs
generated
|
@ -44,17 +44,20 @@ private void InitializeComponent()
|
|||
this.txtException.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtException.Location = new System.Drawing.Point(16, 48);
|
||||
this.txtException.BackColor = System.Drawing.Color.White;
|
||||
this.txtException.Location = new System.Drawing.Point(8, 48);
|
||||
this.txtException.Multiline = true;
|
||||
this.txtException.Name = "txtException";
|
||||
this.txtException.ReadOnly = true;
|
||||
this.txtException.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.txtException.Size = new System.Drawing.Size(461, 222);
|
||||
this.txtException.Size = new System.Drawing.Size(480, 222);
|
||||
this.txtException.TabIndex = 1;
|
||||
//
|
||||
// btnCopyAll
|
||||
//
|
||||
this.btnCopyAll.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnCopyAll.Location = new System.Drawing.Point(3, 3);
|
||||
this.btnCopyAll.Location = new System.Drawing.Point(0, 3);
|
||||
this.btnCopyAll.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3);
|
||||
this.btnCopyAll.Name = "btnCopyAll";
|
||||
this.btnCopyAll.Size = new System.Drawing.Size(72, 24);
|
||||
this.btnCopyAll.TabIndex = 0;
|
||||
|
@ -65,7 +68,7 @@ private void InitializeComponent()
|
|||
// btnSendBugReport
|
||||
//
|
||||
this.btnSendBugReport.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnSendBugReport.Location = new System.Drawing.Point(176, 3);
|
||||
this.btnSendBugReport.Location = new System.Drawing.Point(173, 3);
|
||||
this.btnSendBugReport.Name = "btnSendBugReport";
|
||||
this.btnSendBugReport.Size = new System.Drawing.Size(104, 24);
|
||||
this.btnSendBugReport.TabIndex = 2;
|
||||
|
@ -77,9 +80,9 @@ private void InitializeComponent()
|
|||
//
|
||||
this.btnClose.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.btnClose.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnClose.Location = new System.Drawing.Point(286, 3);
|
||||
this.btnClose.Location = new System.Drawing.Point(283, 3);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(93, 24);
|
||||
this.btnClose.Size = new System.Drawing.Size(106, 24);
|
||||
this.btnClose.TabIndex = 3;
|
||||
this.btnClose.Text = "Exit application";
|
||||
this.btnClose.UseVisualStyleBackColor = false;
|
||||
|
@ -88,7 +91,7 @@ private void InitializeComponent()
|
|||
// btnOpenLogFile
|
||||
//
|
||||
this.btnOpenLogFile.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnOpenLogFile.Location = new System.Drawing.Point(81, 3);
|
||||
this.btnOpenLogFile.Location = new System.Drawing.Point(78, 3);
|
||||
this.btnOpenLogFile.Name = "btnOpenLogFile";
|
||||
this.btnOpenLogFile.Size = new System.Drawing.Size(89, 24);
|
||||
this.btnOpenLogFile.TabIndex = 1;
|
||||
|
@ -105,17 +108,17 @@ private void InitializeComponent()
|
|||
this.flpMenu.Controls.Add(this.btnSendBugReport);
|
||||
this.flpMenu.Controls.Add(this.btnClose);
|
||||
this.flpMenu.Controls.Add(this.btnContinue);
|
||||
this.flpMenu.Location = new System.Drawing.Point(16, 278);
|
||||
this.flpMenu.Location = new System.Drawing.Point(8, 278);
|
||||
this.flpMenu.Name = "flpMenu";
|
||||
this.flpMenu.Size = new System.Drawing.Size(464, 32);
|
||||
this.flpMenu.Size = new System.Drawing.Size(480, 32);
|
||||
this.flpMenu.TabIndex = 2;
|
||||
//
|
||||
// btnContinue
|
||||
//
|
||||
this.btnContinue.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnContinue.Location = new System.Drawing.Point(385, 3);
|
||||
this.btnContinue.Location = new System.Drawing.Point(395, 3);
|
||||
this.btnContinue.Name = "btnContinue";
|
||||
this.btnContinue.Size = new System.Drawing.Size(72, 24);
|
||||
this.btnContinue.Size = new System.Drawing.Size(74, 24);
|
||||
this.btnContinue.TabIndex = 4;
|
||||
this.btnContinue.Text = "&OK";
|
||||
this.btnContinue.UseVisualStyleBackColor = false;
|
||||
|
@ -123,26 +126,27 @@ private void InitializeComponent()
|
|||
//
|
||||
// lblErrorMessage
|
||||
//
|
||||
this.lblErrorMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
|
||||
this.lblErrorMessage.Location = new System.Drawing.Point(16, 8);
|
||||
this.lblErrorMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.lblErrorMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
|
||||
this.lblErrorMessage.Location = new System.Drawing.Point(7, 8);
|
||||
this.lblErrorMessage.Name = "lblErrorMessage";
|
||||
this.lblErrorMessage.Size = new System.Drawing.Size(464, 32);
|
||||
this.lblErrorMessage.Size = new System.Drawing.Size(480, 34);
|
||||
this.lblErrorMessage.TabIndex = 0;
|
||||
this.lblErrorMessage.Text = "Error";
|
||||
this.lblErrorMessage.Text = "Error\r\nError 2";
|
||||
//
|
||||
// ErrorForm
|
||||
//
|
||||
this.AcceptButton = this.btnContinue;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(492, 318);
|
||||
this.ClientSize = new System.Drawing.Size(495, 313);
|
||||
this.Controls.Add(this.lblErrorMessage);
|
||||
this.Controls.Add(this.flpMenu);
|
||||
this.Controls.Add(this.txtException);
|
||||
this.Name = "ErrorForm";
|
||||
this.ShowIcon = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "ErrorForm";
|
||||
this.Text = "ShareX - Error";
|
||||
this.Shown += new System.EventHandler(this.ErrorForm_Shown);
|
||||
this.flpMenu.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
|
|
@ -32,80 +32,63 @@ namespace HelpersLib
|
|||
{
|
||||
public partial class ErrorForm : Form
|
||||
{
|
||||
public string ApplicationName { get; private set; }
|
||||
public Logger Logger { get; private set; }
|
||||
public string LogPath { get; private set; }
|
||||
public string BugReportPath { get; private set; }
|
||||
|
||||
public ErrorForm(string productName, Exception error, Logger logger, string logPath, string bugReportPath)
|
||||
: this(productName, error.Message, error.ToString(), logger, logPath, bugReportPath)
|
||||
public ErrorForm(Exception error, string logPath, string bugReportPath)
|
||||
: this(error.Message, error.ToString(), logPath, bugReportPath)
|
||||
{
|
||||
}
|
||||
|
||||
public ErrorForm(string productName, string errorMessage, string errorString, Logger logger, string logPath, string bugReportPath)
|
||||
public ErrorForm(string errorTitle, string errorMessage, string logPath, string bugReportPath)
|
||||
{
|
||||
InitializeComponent();
|
||||
Icon = ShareXResources.Icon;
|
||||
|
||||
ApplicationName = productName;
|
||||
Logger = logger;
|
||||
LogPath = logPath;
|
||||
BugReportPath = bugReportPath;
|
||||
|
||||
Text = string.Format("{0} - Error", ApplicationName);
|
||||
Logger.WriteException(errorString, "Unhandled exception");
|
||||
DebugHelper.WriteException(errorMessage, "Unhandled exception");
|
||||
|
||||
lblErrorMessage.Text = errorMessage;
|
||||
txtException.Text = errorString;
|
||||
lblErrorMessage.Text = errorTitle;
|
||||
txtException.Text = errorMessage;
|
||||
txtException.SelectionStart = txtException.TextLength;
|
||||
|
||||
btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogPath) && File.Exists(LogPath);
|
||||
btnSendBugReport.Visible = !string.IsNullOrEmpty(BugReportPath);
|
||||
}
|
||||
|
||||
private void ErrorForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
this.ShowActivate();
|
||||
}
|
||||
|
||||
private void btnCopyAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
string text = txtException.Text;
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
ClipboardHelpers.CopyText(text);
|
||||
}
|
||||
ClipboardHelpers.CopyText(txtException.Text);
|
||||
}
|
||||
|
||||
private void btnOpenLogFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(LogPath) && File.Exists(LogPath))
|
||||
{
|
||||
Process.Start(LogPath);
|
||||
}
|
||||
Helpers.OpenFile(LogPath);
|
||||
}
|
||||
|
||||
private void btnSendBugReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(BugReportPath))
|
||||
{
|
||||
Helpers.OpenURL(BugReportPath);
|
||||
}
|
||||
Helpers.OpenURL(BugReportPath);
|
||||
}
|
||||
|
||||
private void btnContinue_Click(object sender, EventArgs e)
|
||||
{
|
||||
Logger.WriteLine("{0} continue.", ProductName);
|
||||
DebugHelper.WriteLine("ShareX continue.");
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
Logger.WriteLine("{0} closing. Reason: Unhandled exception", ProductName);
|
||||
DebugHelper.WriteLine("ShareX closing. Reason: Unhandled exception");
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void ErrorForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Activate();
|
||||
BringToFront();
|
||||
}
|
||||
|
||||
public static void ThrowExceptionForTest()
|
||||
{
|
||||
throw new Exception("Error line one!\r\nError line two!");
|
||||
|
|
|
@ -112,9 +112,9 @@
|
|||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -52,7 +52,8 @@ private void InputBox_Load(object sender, EventArgs e)
|
|||
|
||||
private void InputBox_Shown(object sender, EventArgs e)
|
||||
{
|
||||
BringToFront();
|
||||
this.ShowActivate();
|
||||
|
||||
txtInputText.Focus();
|
||||
txtInputText.SelectionLength = txtInputText.Text.Length;
|
||||
}
|
||||
|
|
|
@ -404,7 +404,25 @@ public static void OpenURL(string url)
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e, "OpenURL(" + url + ") failed");
|
||||
DebugHelper.WriteException(e, string.Format("OpenURL({0}) failed", url));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenFile(string filepath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath))
|
||||
{
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(filepath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e, string.Format("OpenFile({0}) failed", filepath));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -256,8 +256,7 @@ private void UpdatePictureBox()
|
|||
private void HistoryForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Application.DoEvents();
|
||||
BringToFront();
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
RefreshHistoryItems();
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,7 @@ private HistoryItem[] him_GetHistoryItems()
|
|||
private void ImageHistoryForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Application.DoEvents();
|
||||
BringToFront();
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
RefreshHistoryItems();
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ private void InitializeComponent()
|
|||
|
||||
private void RectangleLight_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
}
|
||||
|
||||
private void RectangleLight_KeyUp(object sender, KeyEventArgs e)
|
||||
|
|
|
@ -127,7 +127,7 @@ public virtual void Prepare()
|
|||
|
||||
private void Surface_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
}
|
||||
|
||||
private void Surface_KeyUp(object sender, KeyEventArgs e)
|
||||
|
|
|
@ -48,8 +48,7 @@ public AboutForm()
|
|||
|
||||
private void AboutForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
BringToFront();
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
|
||||
cLogo.Start(50);
|
||||
}
|
||||
|
|
|
@ -134,8 +134,7 @@ private void LoadSettings()
|
|||
|
||||
private void SettingsForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
BringToFront();
|
||||
Activate();
|
||||
this.ShowActivate();
|
||||
}
|
||||
|
||||
private void SettingsForm_Resize(object sender, EventArgs e)
|
||||
|
|
|
@ -490,7 +490,7 @@ private void CheckUpdate()
|
|||
UpdateChecker updateChecker = TaskHelpers.CheckUpdate();
|
||||
|
||||
if (updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable &&
|
||||
MessageBox.Show("A newer version of ShareX is available.\r\nWould you like to download and install it?", string.Format("{0} v{1} is available", Application.ProductName, updateChecker.UpdateInfo.LatestVersion.ToString()),
|
||||
MessageBox.Show("A newer version of ShareX is available.\r\nWould you like to download and install it?", string.Format("{0} {1} is available", Application.ProductName, updateChecker.UpdateInfo.LatestVersion.ToString()),
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
||||
{
|
||||
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
|
||||
|
|
|
@ -456,7 +456,7 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
|
|||
|
||||
private static void OnError(Exception e)
|
||||
{
|
||||
using (ErrorForm errorForm = new ErrorForm(Application.ProductName, e, DebugHelper.Logger, LogsFilePath, Links.URL_ISSUES))
|
||||
using (ErrorForm errorForm = new ErrorForm(e, LogsFilePath, Links.URL_ISSUES))
|
||||
{
|
||||
errorForm.ShowDialog();
|
||||
}
|
||||
|
|
|
@ -276,8 +276,7 @@ public void ShowErrors()
|
|||
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
{
|
||||
using (ErrorForm form = new ErrorForm(Application.ProductName, "Upload errors", errors, DebugHelper.Logger,
|
||||
Program.LogsFilePath, Links.URL_ISSUES))
|
||||
using (ErrorForm form = new ErrorForm("Upload errors", errors, Program.LogsFilePath, Links.URL_ISSUES))
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ private void FTPCreateDirectory()
|
|||
using (InputBox ib = new InputBox { Text = "Create directory", Question = "Please enter the name of the directory which should be created:" })
|
||||
{
|
||||
ib.ShowDialog();
|
||||
BringToFront();
|
||||
this.ShowActivate();
|
||||
if (ib.DialogResult == DialogResult.OK)
|
||||
{
|
||||
Client.CreateDirectory(URLHelpers.CombineURL(currentDirectory, ib.InputText));
|
||||
|
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
|
@ -86,19 +87,45 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
|
||||
if (!string.IsNullOrEmpty(result.Response))
|
||||
{
|
||||
ImageShackUploadResponse resp = JsonConvert.DeserializeObject<ImageShackUploadResponse>(result.Response);
|
||||
JToken jsonResponse = JToken.Parse(result.Response);
|
||||
|
||||
if (resp != null && resp.result != null && resp.result.images.Count > 0)
|
||||
if (jsonResponse != null)
|
||||
{
|
||||
result.URL = "http://" + resp.result.images[0].direct_link;
|
||||
result.ThumbnailURL = string.Format("http://imagizer.imageshack.us/v2/{0}x{1}q90/{2}/{3}",
|
||||
Config.ThumbnailWidth, Config.ThumbnailHeight, resp.result.images[0].server, resp.result.images[0].filename);
|
||||
bool isSuccess = jsonResponse["success"].Value<bool>();
|
||||
|
||||
if (isSuccess)
|
||||
{
|
||||
ImageShackUploadResult uploadResult = jsonResponse["result"].ToObject<ImageShackUploadResult>();
|
||||
|
||||
if (uploadResult != null && uploadResult.images.Count > 0)
|
||||
{
|
||||
result.URL = "http://" + uploadResult.images[0].direct_link;
|
||||
result.ThumbnailURL = string.Format("http://imagizer.imageshack.us/v2/{0}x{1}q90/{2}/{3}",
|
||||
Config.ThumbnailWidth, Config.ThumbnailHeight, uploadResult.images[0].server, uploadResult.images[0].filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageShackErrorInfo errorInfo = jsonResponse["error"].ToObject<ImageShackErrorInfo>();
|
||||
Errors.Add(errorInfo.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public class ImageShackErrorInfo
|
||||
{
|
||||
public int error_code { get; set; }
|
||||
public string error_message { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("Error message: {0}\r\nError code: {1}", error_message, error_code);
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageShackLoginResponse
|
||||
{
|
||||
public bool success { get; set; }
|
||||
|
|
Loading…
Reference in a new issue