mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 18:57:28 -07:00
Removed reference to System.Web, making the imgur plugin work on client profiles.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1891 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
6f94b056da
commit
69d50906b8
3 changed files with 15 additions and 44 deletions
|
@ -49,7 +49,6 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace GreenshotImgurPlugin {
|
|||
host.SaveToStream(image, stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
|
||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.DateTime.ToString(), filename);
|
||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
|
||||
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
|
||||
|
@ -164,43 +164,5 @@ namespace GreenshotImgurPlugin {
|
|||
uploadURL = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will be called when the menu item in the Editor is clicked
|
||||
/// </summary>
|
||||
public void EditMenuClick(object sender, EventArgs eventArgs) {
|
||||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
|
||||
|
||||
imageEditor.SaveToStream(stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, imageEditor.CaptureDetails));
|
||||
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, imageEditor.CaptureDetails.Title, filename);
|
||||
imageEditor.Surface.Modified = false;
|
||||
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
|
||||
config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
|
||||
CheckHistory();
|
||||
using (Image exportedImage = imageEditor.GetImageForExport()) {
|
||||
imgurInfo.Image = ImageHelper.CreateThumbnail(exportedImage, 90, 90);
|
||||
}
|
||||
// Make sure the configuration is save, so we don't lose the deleteHash
|
||||
IniConfig.Save();
|
||||
|
||||
if (config.UsePageLink) {
|
||||
Clipboard.SetText(imgurInfo.Page);
|
||||
} else {
|
||||
Clipboard.SetText(imgurInfo.Original);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
|
||||
} finally {
|
||||
backgroundForm.CloseDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,16 @@ namespace GreenshotImgurPlugin {
|
|||
IniConfig.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private static string EscapeText(string Text) {
|
||||
string[] UriRfc3986CharsToEscape = new[] { "!", "*", "'", "(", ")" };
|
||||
StringBuilder escaped = new StringBuilder(Uri.EscapeDataString(Text.ToString()));
|
||||
|
||||
for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++) {
|
||||
escaped.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0]));
|
||||
}
|
||||
return escaped.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do the actual upload to Imgur
|
||||
|
@ -89,7 +99,7 @@ namespace GreenshotImgurPlugin {
|
|||
StringBuilder uploadRequest = new StringBuilder();
|
||||
// Add image
|
||||
uploadRequest.Append("image=");
|
||||
uploadRequest.Append(HttpUtility.UrlEncode(System.Convert.ToBase64String(imageData, 0, dataLength)));
|
||||
uploadRequest.Append(EscapeText(System.Convert.ToBase64String(imageData, 0, dataLength)));
|
||||
// add key
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("key=");
|
||||
|
@ -98,13 +108,13 @@ namespace GreenshotImgurPlugin {
|
|||
if (title != null) {
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("title=");
|
||||
uploadRequest.Append(HttpUtility.UrlEncode(title, Encoding.UTF8));
|
||||
uploadRequest.Append(EscapeText(title));
|
||||
}
|
||||
// add filename
|
||||
if (filename != null) {
|
||||
uploadRequest.Append("&");
|
||||
uploadRequest.Append("name=");
|
||||
uploadRequest.Append(HttpUtility.UrlEncode(filename, Encoding.UTF8));
|
||||
uploadRequest.Append(EscapeText(filename));
|
||||
}
|
||||
string url = config.ImgurApiUrl + "/upload";
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
|
@ -112,7 +122,7 @@ namespace GreenshotImgurPlugin {
|
|||
webRequest.Method = "POST";
|
||||
webRequest.ContentType = "application/x-www-form-urlencoded";
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
|
||||
|
||||
using(StreamWriter streamWriter = new StreamWriter(webRequest.GetRequestStream())) {
|
||||
streamWriter.Write(uploadRequest.ToString());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue