Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 3bd29d1

Browse files
committed
upgrade BaiduPCS API to 1.1.2
1 parent 37d1450 commit 3bd29d1

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

BaiduPCS_NET/BaiduPCS.cs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1290,13 +1290,14 @@ public static long pcs_get_download_filesize(BaiduPCS pcs, string path)
12901290
/// <param name="path">目标文件,地址需写全,如/temp/file.txt</param>
12911291
/// <param name="buffer">待上传的字节序</param>
12921292
/// <param name="overwrite">指定是否覆盖原文件,传入PcsTrue则覆盖,传入PcsFalse,则自动重命名。</param>
1293+
/// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
12931294
/// <returns>返回上传的文件的元数据 </returns>
1294-
public static PcsFileInfo pcs_upload_buffer(BaiduPCS pcs, string path, byte[] buffer, bool overwrite = false)
1295+
public static PcsFileInfo pcs_upload_buffer(BaiduPCS pcs, string path, byte[] buffer, bool overwrite = false, long maxspeed = 0)
12951296
{
12961297
IntPtr pathPtr = NativeUtils.utf8_str_ptr(path);
12971298
IntPtr bufptr = Marshal.AllocHGlobal(buffer.Length);
12981299
Marshal.Copy(buffer, 0, bufptr, buffer.Length);
1299-
IntPtr fiptr = NativeMethods.pcs_upload_buffer(pcs.Handle, pathPtr, overwrite ? NativeConst.True : NativeConst.False, bufptr, (uint)buffer.Length);
1300+
IntPtr fiptr = NativeMethods.pcs_upload_buffer(pcs.Handle, pathPtr, overwrite ? NativeConst.True : NativeConst.False, bufptr, (uint)buffer.Length, maxspeed);
13001301
NativeUtils.free_str_ptr(pathPtr);
13011302
Marshal.FreeHGlobal(bufptr);
13021303
if (fiptr == IntPtr.Zero)
@@ -1312,12 +1313,13 @@ public static PcsFileInfo pcs_upload_buffer(BaiduPCS pcs, string path, byte[] bu
13121313
/// </summary>
13131314
/// <param name="pcs"></param>
13141315
/// <param name="buffer">待上传的字节序</param>
1316+
/// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
13151317
/// <returns>返回上传的分片文件的元数据 </returns>
1316-
public static PcsFileInfo pcs_upload_slice(BaiduPCS pcs, byte[] buffer)
1318+
public static PcsFileInfo pcs_upload_slice(BaiduPCS pcs, byte[] buffer, long maxspeed = 0)
13171319
{
13181320
IntPtr bufptr = Marshal.AllocHGlobal(buffer.Length);
13191321
Marshal.Copy(buffer, 0, bufptr, buffer.Length);
1320-
IntPtr fiptr = NativeMethods.pcs_upload_slice(pcs.Handle, bufptr, (uint)buffer.Length);
1322+
IntPtr fiptr = NativeMethods.pcs_upload_slice(pcs.Handle, bufptr, (uint)buffer.Length, maxspeed);
13211323
Marshal.FreeHGlobal(bufptr);
13221324
if (fiptr == IntPtr.Zero)
13231325
return new PcsFileInfo();
@@ -1334,8 +1336,9 @@ public static PcsFileInfo pcs_upload_slice(BaiduPCS pcs, byte[] buffer)
13341336
/// <param name="read_func">读取该分片文件的方法</param>
13351337
/// <param name="userdata"></param>
13361338
/// <param name="content_size">总共需要上传的大小</param>
1339+
/// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
13371340
/// <returns>返回上传的分片文件的元数据 </returns>
1338-
public static PcsFileInfo pcs_upload_slicefile(BaiduPCS pcs, OnReadBlockFunction read_func, object userdata, uint content_size)
1341+
public static PcsFileInfo pcs_upload_slicefile(BaiduPCS pcs, OnReadBlockFunction read_func, object userdata, uint content_size, long maxspeed = 0)
13391342
{
13401343
UserState state = new UserState()
13411344
{
@@ -1344,7 +1347,7 @@ public static PcsFileInfo pcs_upload_slicefile(BaiduPCS pcs, OnReadBlockFunction
13441347
};
13451348
string key = saveState(state);
13461349
IntPtr keyPtr = NativeUtils.str_ptr(key);
1347-
IntPtr fiptr = NativeMethods.pcs_upload_slicefile(pcs.Handle, pcs._onReadBlock, keyPtr, content_size);
1350+
IntPtr fiptr = NativeMethods.pcs_upload_slicefile(pcs.Handle, pcs._onReadBlock, keyPtr, content_size, maxspeed);
13481351
NativeUtils.free_str_ptr(keyPtr);
13491352
removeState(key);
13501353
if (fiptr == IntPtr.Zero)
@@ -1387,12 +1390,13 @@ public static PcsFileInfo pcs_create_superfile(BaiduPCS pcs, string topath, stri
13871390
/// <param name="topath">网盘文件,地址需写全,如/temp/file.txt</param>
13881391
/// <param name="local_filename">待上传的本地文件</param>
13891392
/// <param name="overwrite">如果网盘文件已经存在,是否覆盖原文件。true - 覆盖;false - 自动重命名</param>
1393+
/// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
13901394
/// <returns>返回文件的元数据</returns>
1391-
public static PcsFileInfo pcs_upload(BaiduPCS pcs, string topath, string local_filename, bool overwrite = false)
1395+
public static PcsFileInfo pcs_upload(BaiduPCS pcs, string topath, string local_filename, bool overwrite = false, long maxspeed = 0)
13921396
{
13931397
IntPtr remotePtr = NativeUtils.utf8_str_ptr(topath);
13941398
IntPtr localPtr = NativeUtils.str_ptr(local_filename);
1395-
IntPtr fiptr = NativeMethods.pcs_upload(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False, localPtr);
1399+
IntPtr fiptr = NativeMethods.pcs_upload(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False, localPtr, maxspeed);
13961400
NativeUtils.free_str_ptr(remotePtr);
13971401
NativeUtils.free_str_ptr(localPtr);
13981402
if (fiptr == IntPtr.Zero)
@@ -1412,8 +1416,9 @@ public static PcsFileInfo pcs_upload(BaiduPCS pcs, string topath, string local_f
14121416
/// <param name="content_size">总共需要上传的大小</param>
14131417
/// <param name="userdata"></param>
14141418
/// <param name="overwrite">如果网盘文件已经存在,是否覆盖原文件。true - 覆盖;false - 自动重命名</param>
1419+
/// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
14151420
/// <returns>返回文件的元数据</returns>
1416-
public static PcsFileInfo pcs_upload_s(BaiduPCS pcs, string to_path, OnReadBlockFunction read_func, uint content_size, object userdata, bool overwrite = false)
1421+
public static PcsFileInfo pcs_upload_s(BaiduPCS pcs, string to_path, OnReadBlockFunction read_func, uint content_size, object userdata, bool overwrite = false, long maxspeed = 0)
14171422
{
14181423
UserState state = new UserState()
14191424
{
@@ -1424,7 +1429,7 @@ public static PcsFileInfo pcs_upload_s(BaiduPCS pcs, string to_path, OnReadBlock
14241429
string key = saveState(state);
14251430
IntPtr keyPtr = NativeUtils.str_ptr(key);
14261431
IntPtr fiptr = NativeMethods.pcs_upload_s(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False,
1427-
pcs._onReadBlock, keyPtr, content_size);
1432+
pcs._onReadBlock, keyPtr, content_size, maxspeed);
14281433
NativeUtils.free_str_ptr(remotePtr);
14291434
NativeUtils.free_str_ptr(keyPtr);
14301435
removeState(key);

BaiduPCS_NET/Native/NativeMethods.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ public static class NativeMethods
7474
public extern static long pcs_get_download_filesize(IntPtr handle, IntPtr path);
7575

7676
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
77-
public extern static IntPtr pcs_upload_buffer(IntPtr handle, IntPtr path, byte overwrite, IntPtr buffer, uint buffer_size);
77+
public extern static IntPtr pcs_upload_buffer(IntPtr handle, IntPtr path, byte overwrite, IntPtr buffer, uint buffer_size, long max_speed);
7878

7979
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
80-
public extern static IntPtr pcs_upload_slice(IntPtr handle, IntPtr buffer, uint buffer_size);
80+
public extern static IntPtr pcs_upload_slice(IntPtr handle, IntPtr buffer, uint buffer_size, long max_speed);
8181

8282
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
83-
public extern static IntPtr pcs_upload_slicefile(IntPtr handle, NativePcsReadBlockFunction read_func, IntPtr userdata, uint content_size);
83+
public extern static IntPtr pcs_upload_slicefile(IntPtr handle, NativePcsReadBlockFunction read_func, IntPtr userdata, uint content_size, long max_speed);
8484

8585
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
8686
public extern static IntPtr pcs_create_superfile(IntPtr handle, IntPtr path, byte overwrite, IntPtr block_list);
8787

8888
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
89-
public extern static IntPtr pcs_upload(IntPtr handle, IntPtr path, byte overwrite, IntPtr local_filename);
89+
public extern static IntPtr pcs_upload(IntPtr handle, IntPtr path, byte overwrite, IntPtr local_filename, long max_speed);
9090

9191
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
92-
public extern static IntPtr pcs_upload_s(IntPtr handle, IntPtr to_path, byte overwrite, NativePcsReadBlockFunction read_func, IntPtr userdata, uint content_size);
92+
public extern static IntPtr pcs_upload_s(IntPtr handle, IntPtr to_path, byte overwrite, NativePcsReadBlockFunction read_func, IntPtr userdata, uint content_size, long max_speed);
9393

9494
[DllImport("BaiduPCS.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
9595
public extern static long pcs_local_filesize(IntPtr handle, IntPtr path);

BaiduPCS_NET/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1.0")]
36-
[assembly: AssemblyFileVersion("1.0.1.0")]
35+
[assembly: AssemblyVersion("1.0.2.0")]
36+
[assembly: AssemblyFileVersion("1.0.2.0")]

Sample/Sample_0_FileExplorer/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1.0")]
36-
[assembly: AssemblyFileVersion("1.0.1.0")]
35+
[assembly: AssemblyVersion("1.0.2.0")]
36+
[assembly: AssemblyFileVersion("1.0.2.0")]

0 commit comments

Comments
 (0)