diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 6590b9e6a..4b0840ac3 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -338,36 +338,31 @@ namespace Greenshot { UpdateUI(); - // Do loading on a different Thread to shorten the startup - Thread pluginInitThread = new Thread (delegate() { - // Load all the plugins - PluginHelper.Instance.LoadPlugins(this); - - // Check destinations, remove all that don't exist - foreach(string destination in conf.OutputDestinations.ToArray()) { - if (DestinationHelper.GetDestination(destination) == null) { - conf.OutputDestinations.Remove(destination); - } - } - - // we should have at least one! - if (conf.OutputDestinations.Count == 0) { - conf.OutputDestinations.Add(Destinations.EditorDestination.DESIGNATION); - } - if (conf.DisableQuickSettings) { - contextmenu_quicksettings.Visible = false; - } else { - BeginInvoke((MethodInvoker)delegate { - // Do after all plugins & finding the destination, otherwise they are missing! - InitializeQuickSettingsMenu(); - }); - } - }); - pluginInitThread.Name = "Initialize plug-ins"; - pluginInitThread.IsBackground = true; - pluginInitThread.SetApartmentState(ApartmentState.STA); - pluginInitThread.Start(); + // This forces the registration of all destinations inside Greenshot itself. + DestinationHelper.GetAllDestinations(); + // This forces the registration of all processors inside Greenshot itself. + ProcessorHelper.GetAllProcessors(); + + // Load all the plugins + PluginHelper.Instance.LoadPlugins(this); + // Check destinations, remove all that don't exist + foreach(string destination in conf.OutputDestinations.ToArray()) { + if (DestinationHelper.GetDestination(destination) == null) { + conf.OutputDestinations.Remove(destination); + } + } + + // we should have at least one! + if (conf.OutputDestinations.Count == 0) { + conf.OutputDestinations.Add(Destinations.EditorDestination.DESIGNATION); + } + if (conf.DisableQuickSettings) { + contextmenu_quicksettings.Visible = false; + } else { + // Do after all plugins & finding the destination, otherwise they are missing! + InitializeQuickSettingsMenu(); + } SoundHelper.Initialize(); // Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446) diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs index f781f20ec..78eba9e76 100644 --- a/Greenshot/Helpers/PluginHelper.cs +++ b/Greenshot/Helpers/PluginHelper.cs @@ -230,7 +230,7 @@ namespace Greenshot.Helpers { Dictionary tmpAssemblies = new Dictionary(); // Loop over the list of available files and get the Plugin Attributes foreach (string pluginFile in pluginFiles) { - LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile); + //LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile); try { Assembly assembly = Assembly.LoadFrom(pluginFile); PluginAttribute[] pluginAttributes = assembly.GetCustomAttributes(typeof(PluginAttribute), false) as PluginAttribute[]; diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs index 5e8ffe5f1..bed56c407 100644 --- a/GreenshotImgurPlugin/ImgurPlugin.cs +++ b/GreenshotImgurPlugin/ImgurPlugin.cs @@ -100,12 +100,16 @@ namespace GreenshotImgurPlugin { private void CheckHistory() { try { ImgurUtils.LoadHistory(); - if (config.ImgurUploadHistory.Count > 0) { - historyMenuItem.Enabled = true; - } else { - historyMenuItem.Enabled = false; - } - } catch {}; + host.MainMenu.BeginInvoke((MethodInvoker)delegate { + if (config.ImgurUploadHistory.Count > 0) { + historyMenuItem.Enabled = true; + } else { + historyMenuItem.Enabled = false; + } + }); + } catch (Exception ex) { + LOG.Error("Error loading history", ex); + }; } public virtual void Shutdown() { diff --git a/GreenshotImgurPlugin/ImgurUtils.cs b/GreenshotImgurPlugin/ImgurUtils.cs index 31cb84f92..23e82dab0 100644 --- a/GreenshotImgurPlugin/ImgurUtils.cs +++ b/GreenshotImgurPlugin/ImgurUtils.cs @@ -105,22 +105,20 @@ namespace GreenshotImgurPlugin { /// ImgurInfo with details public static ImgurInfo UploadToImgur(Image image, OutputSettings outputSettings, string title, string filename) { IDictionary uploadParameters = new Dictionary(); - + IDictionary otherParameters = new Dictionary(); + // add title + if (title != null) { + otherParameters.Add("title", title); + } + // add filename + if (filename != null) { + otherParameters.Add("name", filename); + } string responseString = null; if (config.AnonymousAccess) { - // add title - if (title != null) { - uploadParameters.Add("title", title); - } - // add filename - if (filename != null) { - uploadParameters.Add("name", filename); - } - // add key uploadParameters.Add("key", IMGUR_ANONYMOUS_API_KEY); - HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(config.ImgurApiUrl + "/upload.xml?" + NetworkHelper.GenerateQueryParameters(uploadParameters)); - + HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(config.ImgurApiUrl + "/upload.xml?" + NetworkHelper.GenerateQueryParameters(uploadParameters) + NetworkHelper.GenerateQueryParameters(otherParameters)); webRequest.Method = "POST"; webRequest.ContentType = "image/" + outputSettings.Format.ToString(); webRequest.ServicePoint.Expect100Continue = false; @@ -158,19 +156,8 @@ namespace GreenshotImgurPlugin { IniConfig.Save(); } try { - string apiUrl = "http://api.imgur.com/2/account/images.xml"; - // sign without parameters - oAuth.Sign(HTTPMethod.POST, apiUrl, uploadParameters); - // add title - if (title != null) { - uploadParameters.Add("title", title); - } - // add filename - if (filename != null) { - uploadParameters.Add("name", filename); - } - uploadParameters.Add("image", new ImageContainer(image, outputSettings, filename)); - responseString = oAuth.MakeRequest(HTTPMethod.POST, apiUrl, uploadParameters, null); + otherParameters.Add("image", new ImageContainer(image, outputSettings, filename)); + responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, "http://api.imgur.com/2/account/images.xml", uploadParameters, otherParameters, null); } catch (Exception ex) { LOG.Error("Upload to imgur gave an exeption: ", ex); throw ex; @@ -227,7 +214,7 @@ namespace GreenshotImgurPlugin { } throw wE; } - LOG.Info(responseString); + LOG.Debug(responseString); ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString); imgurInfo.DeleteHash = deleteHash; return imgurInfo; diff --git a/GreenshotPhotobucketPlugin/GreenshotPhotobucketPlugin.csproj b/GreenshotPhotobucketPlugin/GreenshotPhotobucketPlugin.csproj index 7c7f916e7..c15664559 100644 --- a/GreenshotPhotobucketPlugin/GreenshotPhotobucketPlugin.csproj +++ b/GreenshotPhotobucketPlugin/GreenshotPhotobucketPlugin.csproj @@ -1,6 +1,6 @@  - - + + {9C0ECC4C-7807-4111-916A-4F57BB29788A} Library @@ -79,4 +79,32 @@ copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)bin\$ mkdir "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" + + False + Off + 4194304 + x86 + 4096 + + + False + Off + 4194304 + AnyCPU + 4096 + + + DEBUG;TRACE + False + True + None + false + + + TRACE + True + False + None + false + \ No newline at end of file diff --git a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs index 2622c3eb7..91dbdd71f 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs @@ -78,26 +78,25 @@ namespace GreenshotPhotobucketPlugin { oAuth.Token = config.Token; oAuth.TokenSecret = config.TokenSecret; - Dictionary parameters = new Dictionary(); + IDictionary signedParameters = new Dictionary(); // add album - parameters.Add("id", "Apex75/greenshot"); + signedParameters.Add("id", "Apex75/greenshot"); // add type - parameters.Add("type", "base64"); + signedParameters.Add("type", "base64"); // add title if (title != null) { - parameters.Add("title", title); + signedParameters.Add("title", title); } // add filename if (filename != null) { - parameters.Add("filename", filename); + signedParameters.Add("filename", filename); } + IDictionary unsignedParameters = new Dictionary(); + // Add image + unsignedParameters.Add("uploadfile", new ImageContainer(image, outputSettings, filename)); try { string apiUrl = "http://api.photobucket.com/album/!/upload"; - oAuth.Sign(HTTPMethod.POST, apiUrl, parameters); - apiUrl = apiUrl.Replace("api.photobucket.com", config.SubDomain); - // Add image - parameters.Add("uploadfile", new ImageContainer(image, outputSettings, filename)); - responseString = oAuth.MakeRequest(HTTPMethod.POST, apiUrl, parameters, null); + responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, unsignedParameters, null); } catch (Exception ex) { LOG.Error("Error uploading to Photobucket.", ex); throw ex; diff --git a/GreenshotPlugin/Core/Language.cs b/GreenshotPlugin/Core/Language.cs index 00ae52d55..3779f51e9 100644 --- a/GreenshotPlugin/Core/Language.cs +++ b/GreenshotPlugin/Core/Language.cs @@ -365,7 +365,7 @@ namespace GreenshotPlugin.Core { LOG.InfoFormat("Searching language directory '{0}' for language files with pattern '{1}'", languagePath, LANGUAGE_FILENAME_PATTERN); try { foreach (string languageFilepath in Directory.GetFiles(languagePath, LANGUAGE_FILENAME_PATTERN, SearchOption.AllDirectories)) { - LOG.DebugFormat("Found language file: {0}", languageFilepath); + //LOG.DebugFormat("Found language file: {0}", languageFilepath); LanguageFile languageFile = LoadFileInfo(languageFilepath); if (languageFile == null) { continue; @@ -385,7 +385,7 @@ namespace GreenshotPlugin.Core { // Check if we can display the file if (!string.IsNullOrEmpty(languageFile.LanguageGroup) && unsupportedLanguageGroups.Contains(languageFile.LanguageGroup)) { - LOG.InfoFormat("Skipping unsuported (not able to display) language {0}", languageFile.Description); + LOG.InfoFormat("Skipping unsuported (not able to display) language {0} from file {1}", languageFile.Description, languageFilepath); continue; } diff --git a/GreenshotPlugin/Core/OAuthHelper.cs b/GreenshotPlugin/Core/OAuthHelper.cs index cc37cf558..1f0896394 100644 --- a/GreenshotPlugin/Core/OAuthHelper.cs +++ b/GreenshotPlugin/Core/OAuthHelper.cs @@ -375,27 +375,31 @@ namespace GreenshotPlugin.Core { } /// - /// Wrapper + /// Submit a web request using oAuth. /// - /// - /// - /// - /// - public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary parameters) { - return MakeOAuthRequest(method, requestURL, parameters, null); + /// GET or POST + /// The full url, including the querystring for the signing/request + /// Parameters for the request, which need to be signed + /// Parameters for the request, which do not need to be signed + /// Data to post (MemoryStream) + /// The web server response. + public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary parametersToSign, IDictionary additionalParameters, IBinaryContainer postData) { + return MakeOAuthRequest(method, requestURL, requestURL, parametersToSign, additionalParameters, postData); } /// /// Submit a web request using oAuth. /// /// GET or POST - /// The full url, including the querystring. - /// Parameters for the request + /// The full url, including the querystring for the signing + /// The full url, including the querystring for the request + /// Parameters for the request, which need to be signed + /// Parameters for the request, which do not need to be signed /// Data to post (MemoryStream) /// The web server response. - public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary parameters, IBinaryContainer postData) { - if (parameters == null) { - parameters = new Dictionary(); + public string MakeOAuthRequest(HTTPMethod method, string signUrl, string requestURL, IDictionary parametersToSign, IDictionary additionalParameters, IBinaryContainer postData) { + if (parametersToSign == null) { + parametersToSign = new Dictionary(); } int retries = 2; Exception lastException = null; @@ -407,8 +411,19 @@ namespace GreenshotPlugin.Core { } } try { - Sign(method, requestURL, parameters); - return MakeRequest(method, requestURL, parameters, postData); + Sign(method, signUrl, parametersToSign); + + // Join all parameters + IDictionary newParameters = new Dictionary(); + foreach(var parameter in parametersToSign) { + newParameters.Add(parameter); + } + if (additionalParameters != null) { + foreach(var parameter in additionalParameters) { + newParameters.Add(parameter); + } + } + return MakeRequest(method, requestURL, newParameters, postData); } catch (WebException wEx) { lastException = wEx; if (wEx.Response != null) { @@ -416,15 +431,16 @@ namespace GreenshotPlugin.Core { if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) { Token = null; TokenSecret = null; - // Remove oauth keys, so they aren't added double - IDictionary newParameters = new Dictionary(); - foreach (string parameterKey in parameters.Keys) { - if (!parameterKey.StartsWith(OAUTH_PARAMETER_PREFIX)) { - newParameters.Add(parameterKey, parameters[parameterKey]); + List keysToDelete = new List(); + foreach (string parameterKey in parametersToSign.Keys) { + if (parameterKey.StartsWith(OAUTH_PARAMETER_PREFIX)) { + keysToDelete.Add(parameterKey); } } - parameters = newParameters; + foreach(string keyToDelete in keysToDelete) { + parametersToSign.Remove(keyToDelete); + } continue; } } @@ -437,6 +453,7 @@ namespace GreenshotPlugin.Core { throw new Exception("Not authorized"); } + /// /// OAuth sign the parameters, meaning all oauth parameters are added to the supplied dictionary. /// And additionally a signature is added. @@ -444,7 +461,7 @@ namespace GreenshotPlugin.Core { /// Method (POST,PUT,GET) /// Url to call /// IDictionary - public void Sign(HTTPMethod method, string requestURL, IDictionary parameters) { + private void Sign(HTTPMethod method, string requestURL, IDictionary parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } @@ -497,7 +514,7 @@ namespace GreenshotPlugin.Core { /// /// IBinaryParameter /// Response from server - public string MakeRequest(HTTPMethod method, string requestURL, IDictionary parameters, IBinaryContainer postData) { + private string MakeRequest(HTTPMethod method, string requestURL, IDictionary parameters, IBinaryContainer postData) { if (parameters == null) { throw new ArgumentNullException("parameters"); } @@ -522,7 +539,7 @@ namespace GreenshotPlugin.Core { requestParameters = parameters; } - if (HTTPMethod.GET == method) { + if (HTTPMethod.GET == method || postData != null) { if (requestParameters.Count > 0) { // Add the parameters to the request requestURL += "?" + NetworkHelper.GenerateQueryParameters(requestParameters); @@ -540,7 +557,7 @@ namespace GreenshotPlugin.Core { webRequest.Headers.Add("Authorization: OAuth " + authHeader.ToString()); } - if (HTTPMethod.POST == method && postData == null && requestParameters != null && requestParameters.Count > 0) { + if ((HTTPMethod.POST == method || HTTPMethod.PUT == method) && postData == null && requestParameters != null && requestParameters.Count > 0) { if (UseMultipartFormData) { NetworkHelper.WriteMultipartFormData(webRequest, requestParameters); } else {