mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Merge remote-tracking branch 'remotes/origin/master' into release/1.2.9
This commit is contained in:
commit
0323705513
276 changed files with 5382 additions and 3666 deletions
|
@ -52,11 +52,17 @@ namespace GreenshotPlugin.Core {
|
|||
private static readonly CoreConfiguration Config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
static NetworkHelper() {
|
||||
// Disable certificate checking
|
||||
ServicePointManager.ServerCertificateValidationCallback +=
|
||||
delegate {
|
||||
return true;
|
||||
};
|
||||
try
|
||||
{
|
||||
// Disable certificate checking
|
||||
ServicePointManager.ServerCertificateValidationCallback += delegate {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Warn("An error has occured while allowing self-signed certificates:", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -137,12 +143,18 @@ namespace GreenshotPlugin.Core {
|
|||
using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8, true)) {
|
||||
content = streamReader.ReadLine();
|
||||
}
|
||||
Regex imageUrlRegex = new Regex(@"(http|https)://.*(\.png|\.gif|\.jpg|\.tiff|\.jpeg|\.bmp)");
|
||||
Match match = imageUrlRegex.Match(content);
|
||||
if (match.Success) {
|
||||
using (MemoryStream memoryStream2 = GetAsMemoryStream(match.Value)) {
|
||||
using (Image image = Image.FromStream(memoryStream2)) {
|
||||
return ImageHelper.Clone(image, PixelFormat.Format32bppArgb);
|
||||
if (!string.IsNullOrEmpty(content))
|
||||
{
|
||||
Regex imageUrlRegex = new Regex(@"(http|https)://.*(\.png|\.gif|\.jpg|\.tiff|\.jpeg|\.bmp)");
|
||||
Match match = imageUrlRegex.Match(content);
|
||||
if (match.Success)
|
||||
{
|
||||
using (MemoryStream memoryStream2 = GetAsMemoryStream(match.Value))
|
||||
{
|
||||
using (Image image = Image.FromStream(memoryStream2))
|
||||
{
|
||||
return ImageHelper.Clone(image, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,12 +205,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>WebRequest</returns>
|
||||
public static HttpWebRequest CreateWebRequest(Uri uri) {
|
||||
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
|
||||
if (Config.UseProxy) {
|
||||
webRequest.Proxy = CreateProxy(uri);
|
||||
} else {
|
||||
// BUG-1655: Fix that Greenshot always uses the default proxy even if the "use default proxy" checkbox is unset
|
||||
webRequest.Proxy = null;
|
||||
}
|
||||
webRequest.Proxy = Config.UseProxy ? CreateProxy(uri) : null;
|
||||
// Make sure the default credentials are available
|
||||
webRequest.Credentials = CredentialCache.DefaultCredentials;
|
||||
|
||||
|
@ -396,9 +403,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// Post the parameters "x-www-form-urlencoded"
|
||||
/// </summary>
|
||||
/// <param name="webRequest"></param>
|
||||
/// <param name="parameters"></param>
|
||||
public static void UploadFormUrlEncoded(HttpWebRequest webRequest, IDictionary<string, object> parameters) {
|
||||
webRequest.ContentType = "application/x-www-form-urlencoded";
|
||||
string urlEncoded = NetworkHelper.GenerateQueryParameters(parameters);
|
||||
string urlEncoded = GenerateQueryParameters(parameters);
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(urlEncoded);
|
||||
using (var requestStream = webRequest.GetRequestStream()) {
|
||||
|
@ -460,6 +468,7 @@ namespace GreenshotPlugin.Core {
|
|||
///
|
||||
/// </summary>
|
||||
/// <param name="webRequest"></param>
|
||||
/// <param name="alsoReturnContentOnError"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetResponseAsString(HttpWebRequest webRequest, bool alsoReturnContentOnError) {
|
||||
string responseData = null;
|
||||
|
@ -552,10 +561,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// A container to supply files to a Multi-part form data upload
|
||||
/// </summary>
|
||||
public class ByteContainer : IBinaryContainer {
|
||||
private byte[] file;
|
||||
private string fileName;
|
||||
private string contentType;
|
||||
private int fileSize;
|
||||
private readonly byte[] _file;
|
||||
private readonly string _fileName;
|
||||
private readonly string _contentType;
|
||||
private readonly int _fileSize;
|
||||
public ByteContainer(byte[] file) : this(file, null) {
|
||||
}
|
||||
public ByteContainer(byte[] file, string filename) : this(file, filename, null) {
|
||||
|
@ -563,14 +572,10 @@ namespace GreenshotPlugin.Core {
|
|||
public ByteContainer(byte[] file, string filename, string contenttype) : this(file, filename, contenttype, 0) {
|
||||
}
|
||||
public ByteContainer(byte[] file, string filename, string contenttype, int filesize) {
|
||||
this.file = file;
|
||||
fileName = filename;
|
||||
contentType = contenttype;
|
||||
if (filesize == 0) {
|
||||
fileSize = file.Length;
|
||||
} else {
|
||||
fileSize = filesize;
|
||||
}
|
||||
_file = file;
|
||||
_fileName = filename;
|
||||
_contentType = contenttype;
|
||||
_fileSize = filesize == 0 ? file.Length : filesize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -578,7 +583,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <returns>string</returns>
|
||||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
return Convert.ToBase64String(file, 0, fileSize, formattingOptions);
|
||||
return Convert.ToBase64String(_file, 0, _fileSize, formattingOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -586,7 +591,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <returns>byte[]</returns>
|
||||
public byte[] ToByteArray() {
|
||||
return file;
|
||||
return _file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -600,13 +605,13 @@ namespace GreenshotPlugin.Core {
|
|||
string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n",
|
||||
boundary,
|
||||
name,
|
||||
fileName ?? name,
|
||||
contentType ?? "application/octet-stream");
|
||||
_fileName ?? name,
|
||||
_contentType ?? "application/octet-stream");
|
||||
|
||||
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
|
||||
|
||||
// Write the file data directly to the Stream, rather than serializing it to a string.
|
||||
formDataStream.Write(file, 0, fileSize);
|
||||
formDataStream.Write(_file, 0, _fileSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -615,7 +620,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="dataStream">Stream to write to</param>
|
||||
public void WriteToStream(Stream dataStream) {
|
||||
// Write the file data directly to the Stream, rather than serializing it to a string.
|
||||
dataStream.Write(file, 0, fileSize);
|
||||
dataStream.Write(_file, 0, _fileSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -623,8 +628,8 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="webRequest"></param>
|
||||
public void Upload(HttpWebRequest webRequest) {
|
||||
webRequest.ContentType = contentType;
|
||||
webRequest.ContentLength = fileSize;
|
||||
webRequest.ContentType = _contentType;
|
||||
webRequest.ContentLength = _fileSize;
|
||||
using (var requestStream = webRequest.GetRequestStream()) {
|
||||
WriteToStream(requestStream);
|
||||
}
|
||||
|
@ -635,14 +640,14 @@ namespace GreenshotPlugin.Core {
|
|||
/// A container to supply images to a Multi-part form data upload
|
||||
/// </summary>
|
||||
public class BitmapContainer : IBinaryContainer {
|
||||
private Bitmap bitmap;
|
||||
private SurfaceOutputSettings outputSettings;
|
||||
private string fileName;
|
||||
private readonly Bitmap _bitmap;
|
||||
private readonly SurfaceOutputSettings _outputSettings;
|
||||
private readonly string _fileName;
|
||||
|
||||
public BitmapContainer(Bitmap bitmap, SurfaceOutputSettings outputSettings, string filename) {
|
||||
this.bitmap = bitmap;
|
||||
this.outputSettings = outputSettings;
|
||||
fileName = filename;
|
||||
_bitmap = bitmap;
|
||||
_outputSettings = outputSettings;
|
||||
_fileName = filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -652,7 +657,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>string</returns>
|
||||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(bitmap, null, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(_bitmap, null, stream, _outputSettings);
|
||||
return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +669,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>byte[]</returns>
|
||||
public byte[] ToByteArray() {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(bitmap, null, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(_bitmap, null, stream, _outputSettings);
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -680,11 +685,11 @@ namespace GreenshotPlugin.Core {
|
|||
string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n",
|
||||
boundary,
|
||||
name,
|
||||
fileName ?? name,
|
||||
"image/" + outputSettings.Format.ToString());
|
||||
_fileName ?? name,
|
||||
"image/" + _outputSettings.Format);
|
||||
|
||||
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
|
||||
ImageOutput.SaveToStream(bitmap, null, formDataStream, outputSettings);
|
||||
ImageOutput.SaveToStream(_bitmap, null, formDataStream, _outputSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -693,7 +698,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="dataStream"></param>
|
||||
public void WriteToStream(Stream dataStream) {
|
||||
// Write the file data directly to the Stream, rather than serializing it to a string.
|
||||
ImageOutput.SaveToStream(bitmap, null, dataStream, outputSettings);
|
||||
ImageOutput.SaveToStream(_bitmap, null, dataStream, _outputSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -701,7 +706,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="webRequest"></param>
|
||||
public void Upload(HttpWebRequest webRequest) {
|
||||
webRequest.ContentType = "image/" + outputSettings.Format.ToString();
|
||||
webRequest.ContentType = "image/" + _outputSettings.Format;
|
||||
using (var requestStream = webRequest.GetRequestStream()) {
|
||||
WriteToStream(requestStream);
|
||||
}
|
||||
|
@ -712,14 +717,14 @@ namespace GreenshotPlugin.Core {
|
|||
/// A container to supply surfaces to a Multi-part form data upload
|
||||
/// </summary>
|
||||
public class SurfaceContainer : IBinaryContainer {
|
||||
private ISurface surface;
|
||||
private SurfaceOutputSettings outputSettings;
|
||||
private string fileName;
|
||||
private readonly ISurface _surface;
|
||||
private readonly SurfaceOutputSettings _outputSettings;
|
||||
private readonly string _fileName;
|
||||
|
||||
public SurfaceContainer(ISurface surface, SurfaceOutputSettings outputSettings, string filename) {
|
||||
this.surface = surface;
|
||||
this.outputSettings = outputSettings;
|
||||
fileName = filename;
|
||||
_surface = surface;
|
||||
_outputSettings = outputSettings;
|
||||
_fileName = filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -729,7 +734,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>string</returns>
|
||||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(surface, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(_surface, stream, _outputSettings);
|
||||
return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
}
|
||||
}
|
||||
|
@ -741,7 +746,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>byte[]</returns>
|
||||
public byte[] ToByteArray() {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(surface, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(_surface, stream, _outputSettings);
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -757,11 +762,11 @@ namespace GreenshotPlugin.Core {
|
|||
string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n",
|
||||
boundary,
|
||||
name,
|
||||
fileName ?? name,
|
||||
"image/" + outputSettings.Format);
|
||||
_fileName ?? name,
|
||||
"image/" + _outputSettings.Format);
|
||||
|
||||
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
|
||||
ImageOutput.SaveToStream(surface, formDataStream, outputSettings);
|
||||
ImageOutput.SaveToStream(_surface, formDataStream, _outputSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -770,7 +775,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="dataStream"></param>
|
||||
public void WriteToStream(Stream dataStream) {
|
||||
// Write the file data directly to the Stream, rather than serializing it to a string.
|
||||
ImageOutput.SaveToStream(surface, dataStream, outputSettings);
|
||||
ImageOutput.SaveToStream(_surface, dataStream, _outputSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -778,7 +783,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="webRequest"></param>
|
||||
public void Upload(HttpWebRequest webRequest) {
|
||||
webRequest.ContentType = "image/" + outputSettings.Format.ToString();
|
||||
webRequest.ContentType = "image/" + _outputSettings.Format.ToString();
|
||||
using (var requestStream = webRequest.GetRequestStream()) {
|
||||
WriteToStream(requestStream);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue