diff --git a/Greenshot/releases/additional_files/readme.txt.template b/Greenshot/releases/additional_files/readme.txt.template index e99adfc57..b09e57a9c 100644 --- a/Greenshot/releases/additional_files/readme.txt.template +++ b/Greenshot/releases/additional_files/readme.txt.template @@ -11,7 +11,8 @@ All details to our tickets can be found here: https://greenshot.atlassian.net Bugs Resolved: * BUG-1809: OverflowException when changing the windows input language -* BUG-1835: Imgur uploads were cancelled due to a timeout which was set too small +* BUG-1835: Imgur: uploads were cancelled due to a timeout which was set too small +* BUG-1833: Imgur: API-Key issues when using anonymous uploads 1.2.6.7-359dcf3 RELEASE diff --git a/GreenshotImgurPlugin/Forms/ImgurHistory.Designer.cs b/GreenshotImgurPlugin/Forms/ImgurHistory.Designer.cs index 2fb75eb8d..f3d3d221f 100644 --- a/GreenshotImgurPlugin/Forms/ImgurHistory.Designer.cs +++ b/GreenshotImgurPlugin/Forms/ImgurHistory.Designer.cs @@ -117,6 +117,7 @@ namespace GreenshotImgurPlugin this.finishedButton.TabIndex = 11; this.finishedButton.Text = "Finished"; this.finishedButton.UseVisualStyleBackColor = true; + this.finishedButton.Click += new System.EventHandler(this.FinishedButtonClick); // // clipboardButton // diff --git a/GreenshotImgurPlugin/Forms/ImgurHistory.cs b/GreenshotImgurPlugin/Forms/ImgurHistory.cs index 597134103..064fcc21f 100644 --- a/GreenshotImgurPlugin/Forms/ImgurHistory.cs +++ b/GreenshotImgurPlugin/Forms/ImgurHistory.cs @@ -167,6 +167,11 @@ namespace GreenshotImgurPlugin { } } + private void FinishedButtonClick(object sender, EventArgs e) + { + this.Hide(); + } + private void OpenButtonClick(object sender, EventArgs e) { if (listview_imgur_uploads.SelectedItems != null && listview_imgur_uploads.SelectedItems.Count > 0) { for (int i = 0; i < listview_imgur_uploads.SelectedItems.Count; i++) { diff --git a/GreenshotImgurPlugin/ImgurConfiguration.cs b/GreenshotImgurPlugin/ImgurConfiguration.cs index 9fdb3950c..4dfb5acb3 100644 --- a/GreenshotImgurPlugin/ImgurConfiguration.cs +++ b/GreenshotImgurPlugin/ImgurConfiguration.cs @@ -30,9 +30,11 @@ namespace GreenshotImgurPlugin { /// [IniSection("Imgur", Description="Greenshot Imgur Plugin configuration")] public class ImgurConfiguration : IniSection { - [IniProperty("ImgurApiUrl", Description="Url to Imgur system.", DefaultValue="http://api.imgur.com/2")] + [IniProperty("ImgurApiUrl", Description="Url to Imgur system.", DefaultValue= "http://api.imgur.com/2")] public string ImgurApiUrl; - + [IniProperty("ImgurApi3Url", Description = "Url to Imgur system.", DefaultValue = "https://api.imgur.com/3")] + public string ImgurApi3Url; + [IniProperty("UploadFormat", Description="What file type to use for uploading", DefaultValue="png")] public OutputFormat UploadFormat; [IniProperty("UploadJpegQuality", Description="JPEG file save quality in %.", DefaultValue="80")] diff --git a/GreenshotImgurPlugin/ImgurInfo.cs b/GreenshotImgurPlugin/ImgurInfo.cs index 52daacf6d..6b65f48ef 100644 --- a/GreenshotImgurPlugin/ImgurInfo.cs +++ b/GreenshotImgurPlugin/ImgurInfo.cs @@ -143,10 +143,15 @@ namespace GreenshotImgurPlugin try { XmlDocument doc = new XmlDocument(); doc.LoadXml(response); - XmlNodeList nodes = doc.GetElementsByTagName("hash"); + XmlNodeList nodes = doc.GetElementsByTagName("id"); if(nodes.Count > 0) { imgurInfo.Hash = nodes.Item(0).InnerText; } + nodes = doc.GetElementsByTagName("hash"); + if (nodes.Count > 0) + { + imgurInfo.Hash = nodes.Item(0).InnerText; + } nodes = doc.GetElementsByTagName("deletehash"); if(nodes.Count > 0) { imgurInfo.DeleteHash = nodes.Item(0).InnerText; diff --git a/GreenshotImgurPlugin/ImgurUtils.cs b/GreenshotImgurPlugin/ImgurUtils.cs index 833657964..7e4829a64 100644 --- a/GreenshotImgurPlugin/ImgurUtils.cs +++ b/GreenshotImgurPlugin/ImgurUtils.cs @@ -33,7 +33,8 @@ namespace GreenshotImgurPlugin { /// public static class ImgurUtils { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImgurUtils)); - private const string IMGUR_ANONYMOUS_API_KEY = "8116a978913f3cf5dfc8e1117a055056"; + private const string IMGUR_ANONYMOUS_API_KEY = "60e8838e21d6b66"; + private const string SMALL_URL_PATTERN = "http://i.imgur.com/{0}s.png"; private static ImgurConfiguration config = IniConfig.GetIniSection(); /// @@ -57,9 +58,9 @@ namespace GreenshotImgurPlugin { continue; } try { - ImgurInfo imgurInfo = ImgurUtils.RetrieveImgurInfo(hash, config.ImgurUploadHistory[hash]); + ImgurInfo imgurInfo = RetrieveImgurInfo(hash, config.ImgurUploadHistory[hash]); if (imgurInfo != null) { - ImgurUtils.RetrieveImgurThumbnail(imgurInfo); + RetrieveImgurThumbnail(imgurInfo); config.runtimeImgurHistory.Add(hash, imgurInfo); } else { LOG.DebugFormat("Deleting not found ImgUr {0} from config.", hash); @@ -95,7 +96,7 @@ namespace GreenshotImgurPlugin { /// /// private static void SetClientId(HttpWebRequest webRequest) { - webRequest.Headers.Add("Authorization", "Client-ID " + ImgurCredentials.CONSUMER_KEY); + webRequest.Headers.Add("Authorization", "Client-ID " + IMGUR_ANONYMOUS_API_KEY); } /// @@ -121,9 +122,9 @@ namespace GreenshotImgurPlugin { string responseString = null; if (config.AnonymousAccess) { // add key, we only use the other parameters for the AnonymousAccess - otherParameters.Add("key", IMGUR_ANONYMOUS_API_KEY); - HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(config.ImgurApiUrl + "/upload.xml?" + NetworkHelper.GenerateQueryParameters(otherParameters), HTTPMethod.POST); - webRequest.ContentType = "image/" + outputSettings.Format.ToString(); + //otherParameters.Add("key", IMGUR_ANONYMOUS_API_KEY); + HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(config.ImgurApi3Url + "/upload.xml?" + NetworkHelper.GenerateQueryParameters(otherParameters), HTTPMethod.POST); + webRequest.ContentType = "image/" + outputSettings.Format; webRequest.ServicePoint.Expect100Continue = false; SetClientId(webRequest); @@ -193,7 +194,7 @@ namespace GreenshotImgurPlugin { return; } LOG.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo.SmallSquare); - HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(imgurInfo.SmallSquare, HTTPMethod.GET); + HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(string.Format(SMALL_URL_PATTERN, imgurInfo.Hash), HTTPMethod.GET); webRequest.ServicePoint.Expect100Continue = false; SetClientId(webRequest); using (WebResponse response = webRequest.GetResponse()) { @@ -304,7 +305,7 @@ namespace GreenshotImgurPlugin { // Update the credits in the config, this is shown in a form int credits = 0; - if (int.TryParse(nameValues["X-RateLimit-Remaining"], out credits)) { + if (nameValues.ContainsKey("X-RateLimit-Remaining") && int.TryParse(nameValues["X-RateLimit-Remaining"], out credits)) { config.Credits = credits; } } diff --git a/GreenshotPlugin/Core/SourceForgeHelper.cs b/GreenshotPlugin/Core/SourceForgeHelper.cs index bf4e35022..c54c27ff5 100644 --- a/GreenshotPlugin/Core/SourceForgeHelper.cs +++ b/GreenshotPlugin/Core/SourceForgeHelper.cs @@ -29,39 +29,39 @@ using log4net; namespace GreenshotPlugin.Core { public class SourceforgeFile { - private string file; + private readonly string _file; public string File { - get {return file;} + get {return _file;} } - private DateTime pubdate; + private readonly DateTime _pubdate; public DateTime Pubdate { - get {return pubdate;} + get {return _pubdate;} } - private string link; + private readonly string _link; public string Link { - get {return link;} + get {return _link;} } - private string directLink; + private readonly string _directLink; public string DirectLink { - get {return directLink;} + get {return _directLink;} } - private Version version; + private Version _version; public Version Version { - get {return version;} + get {return _version;} set { - version = value; + _version = value; } } - private string language; + private string _language; public string Language { - get {return language;} - set {language = value;} + get {return _language;} + set {_language = value;} } public bool isExe { get { - if (file != null) { - return file.ToLower().EndsWith(".exe"); + if (_file != null) { + return _file.ToLower().EndsWith(".exe"); } return false; } @@ -69,8 +69,8 @@ namespace GreenshotPlugin.Core { public bool isUnstable { get { - if (file != null) { - return file.ToLower().Contains("unstable"); + if (_file != null) { + return _file.ToLower().Contains("unstable"); } return false; } @@ -78,18 +78,18 @@ namespace GreenshotPlugin.Core { public bool isReleaseCandidate { get { - if (file != null) { - return Regex.IsMatch(file.ToLower(), "rc[0-9]+"); + if (_file != null) { + return Regex.IsMatch(_file.ToLower(), "rc[0-9]+"); } return false; } } public SourceforgeFile(string file, string pubdate, string link, string directLink) { - this.file = file; - this.pubdate = DateTime.Parse(pubdate); - this.link = link; - this.directLink = directLink; + this._file = file; + DateTime.TryParse(pubdate, out _pubdate); + this._link = link; + this._directLink = directLink; } } /// diff --git a/GreenshotPlugin/Core/WmInputLangChangeRequestFilter.cs b/GreenshotPlugin/Core/WmInputLangChangeRequestFilter.cs index 0b8a8b1e4..5e2ad2699 100644 --- a/GreenshotPlugin/Core/WmInputLangChangeRequestFilter.cs +++ b/GreenshotPlugin/Core/WmInputLangChangeRequestFilter.cs @@ -21,6 +21,7 @@ using GreenshotPlugin.UnmanagedHelpers; using System.Windows.Forms; +using log4net; namespace GreenshotPlugin.Core { @@ -31,11 +32,15 @@ namespace GreenshotPlugin.Core /// public class WmInputLangChangeRequestFilter : IMessageFilter { + private static readonly ILog LOG = LogManager.GetLogger(typeof(WmInputLangChangeRequestFilter)); + public bool PreFilterMessage(ref Message m) { - if (m.Msg == (int)WindowsMessages.WM_INPUTLANGCHANGEREQUEST || m.Msg == (int)WindowsMessages.WM_INPUTLANGCHANGE) + WindowsMessages message = (WindowsMessages)m.Msg; + if (message == WindowsMessages.WM_INPUTLANGCHANGEREQUEST || message == WindowsMessages.WM_INPUTLANGCHANGE) { - return m.LParam.ToInt64() > 0x7FFFFFFF; + LOG.WarnFormat("Filtering: {0}, {1:X} - {2:X} - {3:X}", message, m.LParam.ToInt64(), m.WParam.ToInt64(), m.HWnd.ToInt64()); + return (m.LParam.ToInt64() | 0xFFFFFFFF) != 0; } return false; }