mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
More small fixes, and some refactoring.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2140 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
e1fbc6a10e
commit
048826df3d
8 changed files with 130 additions and 100 deletions
|
@ -338,8 +338,11 @@ namespace Greenshot {
|
|||
|
||||
UpdateUI();
|
||||
|
||||
// Do loading on a different Thread to shorten the startup
|
||||
Thread pluginInitThread = new Thread (delegate() {
|
||||
// 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);
|
||||
|
||||
|
@ -357,17 +360,9 @@ namespace Greenshot {
|
|||
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();
|
||||
|
||||
SoundHelper.Initialize();
|
||||
|
||||
// Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446)
|
||||
|
|
|
@ -230,7 +230,7 @@ namespace Greenshot.Helpers {
|
|||
Dictionary<string, Assembly> tmpAssemblies = new Dictionary<string, Assembly>();
|
||||
// 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[];
|
||||
|
|
|
@ -100,12 +100,16 @@ namespace GreenshotImgurPlugin {
|
|||
private void CheckHistory() {
|
||||
try {
|
||||
ImgurUtils.LoadHistory();
|
||||
host.MainMenu.BeginInvoke((MethodInvoker)delegate {
|
||||
if (config.ImgurUploadHistory.Count > 0) {
|
||||
historyMenuItem.Enabled = true;
|
||||
} else {
|
||||
historyMenuItem.Enabled = false;
|
||||
}
|
||||
} catch {};
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Error loading history", ex);
|
||||
};
|
||||
}
|
||||
|
||||
public virtual void Shutdown() {
|
||||
|
|
|
@ -105,22 +105,20 @@ namespace GreenshotImgurPlugin {
|
|||
/// <returns>ImgurInfo with details</returns>
|
||||
public static ImgurInfo UploadToImgur(Image image, OutputSettings outputSettings, string title, string filename) {
|
||||
IDictionary<string, object> uploadParameters = new Dictionary<string, object>();
|
||||
|
||||
string responseString = null;
|
||||
if (config.AnonymousAccess) {
|
||||
IDictionary<string, object> otherParameters = new Dictionary<string, object>();
|
||||
// add title
|
||||
if (title != null) {
|
||||
uploadParameters.Add("title", title);
|
||||
otherParameters.Add("title", title);
|
||||
}
|
||||
// add filename
|
||||
if (filename != null) {
|
||||
uploadParameters.Add("name", filename);
|
||||
otherParameters.Add("name", filename);
|
||||
}
|
||||
|
||||
string responseString = null;
|
||||
if (config.AnonymousAccess) {
|
||||
// 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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\CommonProject.properties" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{9C0ECC4C-7807-4111-916A-4F57BB29788A}</ProjectGuid>
|
||||
|
@ -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)\"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -78,26 +78,25 @@ namespace GreenshotPhotobucketPlugin {
|
|||
oAuth.Token = config.Token;
|
||||
oAuth.TokenSecret = config.TokenSecret;
|
||||
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
IDictionary<string, object> signedParameters = new Dictionary<string, object>();
|
||||
// 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<string, object> unsignedParameters = new Dictionary<string, object>();
|
||||
// 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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -375,27 +375,31 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper
|
||||
/// Submit a web request using oAuth.
|
||||
/// </summary>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="requestURL"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary<string, object> parameters) {
|
||||
return MakeOAuthRequest(method, requestURL, parameters, null);
|
||||
/// <param name="method">GET or POST</param>
|
||||
/// <param name="requestURL">The full url, including the querystring for the signing/request</param>
|
||||
/// <param name="parametersToSign">Parameters for the request, which need to be signed</param>
|
||||
/// <param name="additionalParameters">Parameters for the request, which do not need to be signed</param>
|
||||
/// <param name="postData">Data to post (MemoryStream)</param>
|
||||
/// <returns>The web server response.</returns>
|
||||
public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary<string, object> parametersToSign, IDictionary<string, object> additionalParameters, IBinaryContainer postData) {
|
||||
return MakeOAuthRequest(method, requestURL, requestURL, parametersToSign, additionalParameters, postData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submit a web request using oAuth.
|
||||
/// </summary>
|
||||
/// <param name="method">GET or POST</param>
|
||||
/// <param name="requestURL">The full url, including the querystring.</param>
|
||||
/// <param name="parameters">Parameters for the request</param>
|
||||
/// <param name="signUrl">The full url, including the querystring for the signing</param>
|
||||
/// <param name="requestURL">The full url, including the querystring for the request</param>
|
||||
/// <param name="parametersToSign">Parameters for the request, which need to be signed</param>
|
||||
/// <param name="additionalParameters">Parameters for the request, which do not need to be signed</param>
|
||||
/// <param name="postData">Data to post (MemoryStream)</param>
|
||||
/// <returns>The web server response.</returns>
|
||||
public string MakeOAuthRequest(HTTPMethod method, string requestURL, IDictionary<string, object> parameters, IBinaryContainer postData) {
|
||||
if (parameters == null) {
|
||||
parameters = new Dictionary<string, object>();
|
||||
public string MakeOAuthRequest(HTTPMethod method, string signUrl, string requestURL, IDictionary<string, object> parametersToSign, IDictionary<string, object> additionalParameters, IBinaryContainer postData) {
|
||||
if (parametersToSign == null) {
|
||||
parametersToSign = new Dictionary<string, object>();
|
||||
}
|
||||
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<string, object> newParameters = new Dictionary<string, object>();
|
||||
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<string, object> newParameters = new Dictionary<string, object>();
|
||||
foreach (string parameterKey in parameters.Keys) {
|
||||
if (!parameterKey.StartsWith(OAUTH_PARAMETER_PREFIX)) {
|
||||
newParameters.Add(parameterKey, parameters[parameterKey]);
|
||||
List<string> keysToDelete = new List<string>();
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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 {
|
|||
/// <param name="method">Method (POST,PUT,GET)</param>
|
||||
/// <param name="requestURL">Url to call</param>
|
||||
/// <param name="parameters">IDictionary<string, string></param>
|
||||
public void Sign(HTTPMethod method, string requestURL, IDictionary<string, object> parameters) {
|
||||
private void Sign(HTTPMethod method, string requestURL, IDictionary<string, object> parameters) {
|
||||
if (parameters == null) {
|
||||
throw new ArgumentNullException("parameters");
|
||||
}
|
||||
|
@ -497,7 +514,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="parameters"></param>
|
||||
/// <param name="postData">IBinaryParameter</param>
|
||||
/// <returns>Response from server</returns>
|
||||
public string MakeRequest(HTTPMethod method, string requestURL, IDictionary<string, object> parameters, IBinaryContainer postData) {
|
||||
private string MakeRequest(HTTPMethod method, string requestURL, IDictionary<string, object> 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue