use dll by nuget;fix bug;add Zone

This commit is contained in:
HarlanC 2018-02-08 21:25:34 +08:00
commit e6462f9d80
6 changed files with 115 additions and 49 deletions

View file

@ -43,12 +43,14 @@
this.gslblDefaultDomain = new GreenshotPlugin.Controls.GreenshotLabel();
this.gstbImageNamePrefix = new GreenshotPlugin.Controls.GreenshotTextBox();
this.gslblImageNamePrefix = new GreenshotPlugin.Controls.GreenshotLabel();
this.gslblZone = new GreenshotPlugin.Controls.GreenshotLabel();
this.gscobZone = new GreenshotPlugin.Controls.GreenshotComboBox();
this.SuspendLayout();
//
// gslblAccessKey
//
this.gslblAccessKey.AutoSize = true;
this.gslblAccessKey.Location = new System.Drawing.Point(18, 48);
this.gslblAccessKey.Location = new System.Drawing.Point(18, 79);
this.gslblAccessKey.Name = "gslblAccessKey";
this.gslblAccessKey.Size = new System.Drawing.Size(65, 12);
this.gslblAccessKey.TabIndex = 0;
@ -56,7 +58,7 @@
//
// gstbAccessKey
//
this.gstbAccessKey.Location = new System.Drawing.Point(137, 48);
this.gstbAccessKey.Location = new System.Drawing.Point(137, 79);
this.gstbAccessKey.Name = "gstbAccessKey";
this.gstbAccessKey.PropertyName = "AccessKey";
this.gstbAccessKey.SectionName = "Qiniu";
@ -65,7 +67,7 @@
//
// gstbSecretKey
//
this.gstbSecretKey.Location = new System.Drawing.Point(137, 79);
this.gstbSecretKey.Location = new System.Drawing.Point(137, 113);
this.gstbSecretKey.Name = "gstbSecretKey";
this.gstbSecretKey.PropertyName = "SecretKey";
this.gstbSecretKey.SectionName = "Qiniu";
@ -75,7 +77,7 @@
// gslblSecretKey
//
this.gslblSecretKey.AutoSize = true;
this.gslblSecretKey.Location = new System.Drawing.Point(18, 82);
this.gslblSecretKey.Location = new System.Drawing.Point(18, 116);
this.gslblSecretKey.Name = "gslblSecretKey";
this.gslblSecretKey.Size = new System.Drawing.Size(65, 12);
this.gslblSecretKey.TabIndex = 2;
@ -83,7 +85,7 @@
//
// gstbScope
//
this.gstbScope.Location = new System.Drawing.Point(137, 111);
this.gstbScope.Location = new System.Drawing.Point(137, 147);
this.gstbScope.Name = "gstbScope";
this.gstbScope.PropertyName = "Scope";
this.gstbScope.SectionName = "Qiniu";
@ -93,7 +95,7 @@
// gslblScope
//
this.gslblScope.AutoSize = true;
this.gslblScope.Location = new System.Drawing.Point(18, 114);
this.gslblScope.Location = new System.Drawing.Point(18, 150);
this.gslblScope.Name = "gslblScope";
this.gslblScope.Size = new System.Drawing.Size(35, 12);
this.gslblScope.TabIndex = 4;
@ -104,7 +106,7 @@
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.LanguageKey = "CANCEL";
this.buttonCancel.Location = new System.Drawing.Point(294, 208);
this.buttonCancel.Location = new System.Drawing.Point(294, 248);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 7;
@ -116,7 +118,7 @@
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.LanguageKey = "OK";
this.buttonOK.Location = new System.Drawing.Point(213, 208);
this.buttonOK.Location = new System.Drawing.Point(213, 248);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 6;
@ -145,7 +147,7 @@
//
// gstbDefaultDomain
//
this.gstbDefaultDomain.Location = new System.Drawing.Point(137, 144);
this.gstbDefaultDomain.Location = new System.Drawing.Point(137, 180);
this.gstbDefaultDomain.Name = "gstbDefaultDomain";
this.gstbDefaultDomain.PropertyName = "DefaultDomain";
this.gstbDefaultDomain.SectionName = "Qiniu";
@ -155,7 +157,7 @@
// gslblDefaultDomain
//
this.gslblDefaultDomain.AutoSize = true;
this.gslblDefaultDomain.Location = new System.Drawing.Point(18, 147);
this.gslblDefaultDomain.Location = new System.Drawing.Point(18, 183);
this.gslblDefaultDomain.Name = "gslblDefaultDomain";
this.gslblDefaultDomain.Size = new System.Drawing.Size(89, 12);
this.gslblDefaultDomain.TabIndex = 16;
@ -163,7 +165,7 @@
//
// gstbImageNamePrefix
//
this.gstbImageNamePrefix.Location = new System.Drawing.Point(137, 178);
this.gstbImageNamePrefix.Location = new System.Drawing.Point(137, 214);
this.gstbImageNamePrefix.Name = "gstbImageNamePrefix";
this.gstbImageNamePrefix.PropertyName = "ImageNamePrefix";
this.gstbImageNamePrefix.SectionName = "Qiniu";
@ -173,17 +175,39 @@
// gslblImageNamePrefix
//
this.gslblImageNamePrefix.AutoSize = true;
this.gslblImageNamePrefix.Location = new System.Drawing.Point(18, 181);
this.gslblImageNamePrefix.Location = new System.Drawing.Point(18, 217);
this.gslblImageNamePrefix.Name = "gslblImageNamePrefix";
this.gslblImageNamePrefix.Size = new System.Drawing.Size(107, 12);
this.gslblImageNamePrefix.TabIndex = 18;
this.gslblImageNamePrefix.Text = "Image Name Prefix";
//
// gslblZone
//
this.gslblZone.AutoSize = true;
this.gslblZone.Location = new System.Drawing.Point(18, 48);
this.gslblZone.Name = "gslblZone";
this.gslblZone.Size = new System.Drawing.Size(29, 12);
this.gslblZone.TabIndex = 22;
this.gslblZone.Text = "Zone";
//
// gscobZone
//
this.gscobZone.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.gscobZone.FormattingEnabled = true;
this.gscobZone.Location = new System.Drawing.Point(137, 48);
this.gscobZone.Name = "gscobZone";
this.gscobZone.PropertyName = "Zone";
this.gscobZone.SectionName = "Qiniu";
this.gscobZone.Size = new System.Drawing.Size(241, 20);
this.gscobZone.TabIndex = 23;
//
// SettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(396, 243);
this.ClientSize = new System.Drawing.Size(396, 283);
this.Controls.Add(this.gscobZone);
this.Controls.Add(this.gslblZone);
this.Controls.Add(this.gstbImageNamePrefix);
this.Controls.Add(this.gslblImageNamePrefix);
this.Controls.Add(this.gstbDefaultDomain);
@ -225,5 +249,7 @@
private GreenshotPlugin.Controls.GreenshotLabel gslblDefaultDomain;
private GreenshotPlugin.Controls.GreenshotTextBox gstbImageNamePrefix;
private GreenshotPlugin.Controls.GreenshotLabel gslblImageNamePrefix;
private GreenshotPlugin.Controls.GreenshotLabel gslblZone;
private GreenshotPlugin.Controls.GreenshotComboBox gscobZone;
}
}

View file

@ -28,6 +28,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility" />
@ -37,12 +38,11 @@
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\csharp-sdk\src\packages\Newtonsoft.Json.10.0.2\lib\net20\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Qiniu">
<HintPath>..\..\csharp-sdk\bin\Qiniu.dll</HintPath>
<Reference Include="Qiniu, Version=7.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Qiniu.7.3.0\lib\Net40\Qiniu.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -92,28 +92,31 @@
<ItemGroup>
<Content Include="Languages\language_qiniuplugin-en-US.xml" />
<Content Include="Languages\language_qiniuplugin-zh-CN.xml" />
<None Include="packages.config" />
<None Include="Resources\Qiniu.bmp" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
if exist "$(ProjectDir)QiniuCredentials.private.cs" (
rename "$(ProjectDir)QiniuCredentials.cs" "QiniuCredentials.orig.cs"
rename "$(ProjectDir)QiniuCredentials.private.cs" "QiniuCredentials.cs"
)
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>
if exist "$(ProjectDir)QiniuCredentials.orig.cs" (
rename "$(ProjectDir)QiniuCredentials.cs" "QiniuCredentials.private.cs"
rename "$(ProjectDir)QiniuCredentials.orig.cs" "QiniuCredentials.cs"
<PostBuildEvent>mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"
"$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"
del /q /s "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"\*
if "$(ConfigurationName)" == "Release" (
..\..\..\packages\LibZ.Tool.1.2.0.0\tools\libz.exe inject-dll --assembly $(ProjectDir)bin\$(Configuration)\$(TargetFileName) --include $(ProjectDir)bin\$(Configuration)\Qiniu.dll --include $(ProjectDir)bin\$(Configuration)\Newtonsoft.Json.dll --move
)
mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"
if "$(ConfigurationName)" == "Debug" (
copy "$(ProjectDir)bin\$(Configuration)\Qiniu.dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
copy "$(ProjectDir)bin\$(Configuration)\Newtonsoft.Json.dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
)
mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)"
copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\"
</PostBuildEvent>
copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\"</PostBuildEvent>
</PropertyGroup>
</Project>

View file

@ -37,6 +37,18 @@ namespace GreenshotQiniuPlugin
[IniProperty("UploadReduceColors", Description = "Reduce color amount of the uploaded image to 256", DefaultValue = "False")]
public bool UploadReduceColors { get; set; }
/*public static Zone ZONE_CN_East;
public static Zone ZONE_CN_North;
public static Zone ZONE_CN_South;
public static Zone ZONE_US_North;
*/
public enum UploadZone
{
CN_North, CN_East, CN_South, US_North
}
[IniProperty("Zone", Description = "Zone used for uploading", DefaultValue = "CN_North")]
public UploadZone Zone { get; set; }
[IniProperty("AccessKey", Description = "access key used for uploading", DefaultValue = "")]
public string AccessKey { get; set; }

View file

@ -28,9 +28,7 @@ using Greenshot.Plugin;
using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
using Qiniu.Common;
using Qiniu.IO;
using Qiniu.IO.Model;
using Qiniu.Http;
using Qiniu.Util;
@ -147,21 +145,23 @@ namespace GreenshotQiniuPlugin
// public static void Save(ISurface surface, string fullPath, bool allowOverwrite, SurfaceOutputSettings outputSettings, bool copyPathToClipboard)
// Run upload in the background
ImageOutput.Save(surfaceToUpload,fullPath,true,outputSettings,true);
MemoryStream streamoutput = new MemoryStream();
ImageOutput.SaveToStream(surfaceToUpload, streamoutput, outputSettings);
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("qiniu", LangKey.communication_wait),
delegate
{
HttpResult result = QiniuUtils.UploadFile(fullPath,filename);
HttpResult result = QiniuUtils.UploadFile(streamoutput, filename);
}
);
// This causes an exeption if the upload failed :)
//Log.DebugFormat("Uploaded to qiniu page: " + qiniuInfo.Page);
uploadUrl = "![]("+_config.DefaultDomain + filename+")";
uploadUrl = _config.DefaultDomain + filename;
string markdownURL = "![]("+uploadUrl+")";
Clipboard.SetText(uploadUrl);
Clipboard.SetText(markdownURL);

View file

@ -28,11 +28,9 @@ using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Qiniu.Common;
using Qiniu.IO;
using Qiniu.IO.Model;
using Qiniu.Http;
using Qiniu.Util;
using Qiniu.Storage;
@ -196,7 +194,7 @@ namespace GreenshotQiniuPlugin
}
public static HttpResult UploadFile(string fullPath,string fileName)
public static HttpResult UploadFile(Stream filestream,string fileName)
{
Mac mac = new Mac(_config.AccessKey, _config.SecretKey);
PutPolicy putPolicy = new PutPolicy();
@ -205,15 +203,37 @@ namespace GreenshotQiniuPlugin
//putPolicy.DeleteAfterDays = 1;
string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
ResumableUploader target = new ResumableUploader();
HttpResult result = target.UploadFile(fullPath, fileName, token);
Config config = new Config();
// 设置上传区域
switch (_config.Zone)
{
case QiniuConfiguration.UploadZone.CN_East:
config.Zone = Zone.ZONE_CN_East;
break;
case QiniuConfiguration.UploadZone.CN_North:
config.Zone = Zone.ZONE_CN_North;
break;
case QiniuConfiguration.UploadZone.CN_South:
config.Zone = Zone.ZONE_CN_South;
break;
case QiniuConfiguration.UploadZone.US_North:
config.Zone = Zone.ZONE_US_North;
break;
}
// 设置 http 或者 https 上传
config.UseHttps = true;
config.UseCdnDomains = true;
config.ChunkSize = ChunkUnit.U512K;
ResumableUploader target = new ResumableUploader(config);
HttpResult result = target.UploadStream(filestream, fileName, token,null);
if (result.Code != (int)HttpCode.OK)
{
File.Delete(fullPath);
Log.Error(result.Text);
throw new Exception(result.Text);
}
File.Delete(fullPath);
return result;
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="Qiniu" version="7.3.0" targetFramework="net452" />
</packages>