阿里云盘windows客户端开发
c# wpf开发阿里云盘window客户端
实现自动同步上传文件
功能支持
自动同步上传
文件批量上传
批量拖拽上传
剪贴板上传
文件目录增删改查
复制下载链接
生成链接二维码
防盗链下载器
文件在线分享
文件夹分享
运行环境
.NET Framework 4.6
namespacealiyundrive_Client_CSharp.aliyundrive
{
classDriveApi
{
publicstaticstringapi="https://api.aliyundrive.com/v2";
publicstaticstringapiToken="https://websv.aliyundrive.com";
publicstaticstringtoken_refresh=apiToken+"/token/refresh";
publicstaticstringfile_list=api+"/file/list";
publicstaticstringfile_complete=api+"/file/complete";
publicstaticstringfile_search=api+"/file/search";
publicstaticstringfile_create=api+"/file/create";
publicstaticstringfile_update=api+"/file/update";
publicstaticstringfile_get=api+"/file/get";
publicstaticstringfile_share=api+"/share_link/create";
publicstaticstringbatch=api+"/batch";
publicstaticstringdatabox_get_personal_info=api+"/databox/get_personal_info";
}
classUtil
{
privatestaticstring_qrapi;
publicstaticstringQRapi{get{
if(_qrapi!=null)return_qrapi;
try
{
_qrapi="https://gqrcode.alicdn.com/img?type=hv&text=";
if(!newHttpClient().GetAsync(_qrapi+"qr").Result.IsSuccessStatusCode)
thrownewException();
}
catch(Exception)
{
_qrapi="http://qr.js.cn/api/qr?qr=";
}
Console.WriteLine("_qrapi:{0}",_qrapi);
return_qrapi;
}
}
publicstaticstringGetQrUrl(stringurl)
{
returnQRapi+Encode(url);
}
publicstaticstringEncode(stringstr)
{
returnRegex.Replace(str,"[^a-zA-Z0-9]",delegate(Matchmatch) {return"%"+BitConverter.ToString(Encoding.UTF8.GetBytes(match.Value)).Replace("-","%"); });
}
publicstringConfigName=MethodBase.GetCurrentMethod().DeclaringType.FullName;
publicstaticstringsha1(stringdata)
{
returnBitConverter.ToString(SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(data))).Replace("-","");
}
publicstaticstringsha1(byte[]data)
{
returnBitConverter.ToString(SHA1.Create().ComputeHash(data)).Replace("-","");
}
publicstaticstringsha1(Streamstream)
{
returnBitConverter.ToString(SHA1.Create().ComputeHash(stream)).Replace("-","");
}
publicstaticstringsha1File(stringFullName)
{
using(varstream=GetFileStream(FullName))
returnBitConverter.ToString(SHA1.Create().ComputeHash(stream)).Replace("-","");
}
publicstaticstringBin2Hex(byte[]bytes)
{
stringreturnStr="";
if(bytes!=null)
{
for(inti=0;i<bytes.Length;i++)
{
returnStr+=bytes[i].ToString("X2");
}
}
returnreturnStr;
}
publicstaticbyte[]Hex2Bin(stringhexString)
{
if((hexString.Length%2)!=0)
hexString+="";
byte[]returnBytes=newbyte[hexString.Length/2];
for(inti=0;i<returnBytes.Length;i++)
returnBytes[i]=Convert.ToByte(hexString.Substring(i*2,2),16);
returnreturnBytes;
}
publicstaticStreamGetFileStream(stringpath)
{
returnFile.Open(path,FileMode.Open,FileAccess.Read,FileShare.Read);
}
publicstaticstringGetShowSize(longsize)
{
string[]units=newstring[] {"B","KB","MB","GB","TB","PB"};
longmod=1024;
inti=0;
while(size>=mod)
{
size/=mod;
i++;
}
returnsize+units[i];
}
}
publicstaticclassMyExceptionEx
{
publicstaticstringError(thisExceptionex)
{
returnGetFirstException(ex).Message;
}
publicstaticExceptionGetFirstException(Exceptionex)
{
if(ex.InnerException==null)returnex;
returnGetFirstException(ex.InnerException);
}
}
publicclassConfigwhereT:new()
{
protectedstaticobjectlock_obj{set;get; }=newobject();
protectedstaticstringAppDataPath{set;get; }
staticConfig()
{
Assemblyassembly=Assembly.GetExecutingAssembly();
AssemblyProductAttributeproduct=assembly.GetCustomAttribute();
AppDataPath=Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"PlainWizard",
product.Product
);
if(Directory.Exists(AppDataPath)==false)
{
Directory.CreateDirectory(AppDataPath);
}
}
publicConfig()
{
}
publicvoidConfig_Save()
{
try
{
lock(lock_obj)File.WriteAllText($"{AppDataPath}\\.Config.{typeof(T).FullName}.ini",JsonConvert.SerializeObject(this));
}
catch(Exceptionex)
{
Console.Error.WriteLine(ex);
}
}
publicvoidConfig_Save(stringname)
{
lock(lock_obj)File.WriteAllText($"{AppDataPath}\\.Config.custom.{name}.ini",JsonConvert.SerializeObject(this));
}
publicstaticTConfig_Get(stringname)
{
try
{
returnJsonConvert.DeserializeObject(File.ReadAllText($"{AppDataPath}\\.Config.custom.{name}.ini"));
}
catch
{
returnnewT();
}
}
protectedstaticT_Instance;
publicstaticTInstance
{
get
{
if(_Instance==null)
{
lock(lock_obj)
{
if(_Instance==null)
{
try
{
_Instance=JsonConvert.DeserializeObject(File.ReadAllText($"{AppDataPath}\\.Config.{typeof(T).FullName}.ini"));
}
catch(Exceptionex) {Console.WriteLine($"获取配置错误:{ex.Message}"); }
}
if(_Instance==null)_Instance=newT();
}
}
return_Instance;
}
set
{
_Instance=value;
}
}
}
}