Exemplo n.º 1
0
 /// <summary>
 /// 计算 MD5 值
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="read_func">读取块类容的函数</param>
 /// <param name="userdata"></param>
 /// <param name="md5">用于接收计算结果</param>
 /// <returns>返回是否计算成功。</returns>
 public static bool pcs_md5_s(BaiduPCS pcs, OnReadBlockFunction read_func, object userdata, out string md5)
 {
     UserState state = new UserState()
     {
         onReadSlice = read_func,
         userData = userdata
     };
     string key = saveState(state);
     IntPtr keyPtr = NativeUtils.str_ptr(key);
     IntPtr md5Ptr = Marshal.AllocHGlobal(36);
     Marshal.Copy(NativeConst.ZERO_MATRIX_8X8, 0, md5Ptr, 36); /* need fix? */
     bool r = NativeMethods.pcs_md5_s(pcs.Handle, pcs._onReadBlock, keyPtr, md5Ptr) != NativeConst.False;
     NativeUtils.free_str_ptr(keyPtr);
     removeState(key);
     if (r)
         md5 = NativeUtils.utf8_str(md5Ptr);
     else
         md5 = string.Empty;
     Marshal.FreeHGlobal(md5Ptr);
     return r;
 }
Exemplo n.º 2
0
 /// <summary>
 /// 上传分片文件
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="read_func">读取该分片文件的方法</param>
 /// <param name="userdata"></param>
 /// <param name="content_size">总共需要上传的大小</param>
 /// <returns>返回上传的分片文件的元数据 </returns>
 public PcsFileInfo upload_slicefile(OnReadBlockFunction read_func, object userdata, uint content_size)
 {
     return pcs_upload_slicefile(this, read_func, userdata, content_size);
 }
Exemplo n.º 3
0
 /// <summary>
 /// 上传文件到网盘。
 /// </summary>
 /// <param name="to_path">网盘文件,地址需写全,如/temp/file.txt</param>
 /// <param name="read_func">读取该文件的方法</param>
 /// <param name="content_size">总共需要上传的大小</param>
 /// <param name="userdata"></param>
 /// <param name="overwrite">如果网盘文件已经存在,是否覆盖原文件。true - 覆盖;false - 自动重命名</param>
 /// <returns>返回文件的元数据</returns>
 public PcsFileInfo upload_s(string to_path, OnReadBlockFunction read_func, uint content_size, object userdata, bool overwrite = false)
 {
     return pcs_upload_s(this, to_path, read_func, content_size, userdata, overwrite);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 计算 MD5 值
 /// </summary>
 /// <param name="read_func">读取块类容的函数</param>
 /// <param name="userdata"></param>
 /// <param name="md5">用于接收计算结果</param>
 /// <returns>返回是否计算成功。</returns>
 public bool md5(OnReadBlockFunction read_func, object userdata, out string md5)
 {
     return pcs_md5_s(this, read_func, userdata, out md5);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 上传分片文件
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="read_func">读取该分片文件的方法</param>
 /// <param name="userdata"></param>
 /// <param name="content_size">总共需要上传的大小</param>
 /// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
 /// <returns>返回上传的分片文件的元数据 </returns>
 public static PcsFileInfo pcs_upload_slicefile(BaiduPCS pcs, OnReadBlockFunction read_func, object userdata, uint content_size, long maxspeed = 0)
 {
     UserState state = new UserState()
     {
         onReadSlice = read_func,
         userData = userdata
     };
     string key = saveState(state);
     IntPtr keyPtr = NativeUtils.str_ptr(key);
     IntPtr fiptr = NativeMethods.pcs_upload_slicefile(pcs.Handle, pcs._onReadBlock, keyPtr, content_size, maxspeed);
     NativeUtils.free_str_ptr(keyPtr);
     removeState(key);
     if (fiptr == IntPtr.Zero)
         return new PcsFileInfo();
     NativePcsFileInfo nfi = (NativePcsFileInfo)Marshal.PtrToStructure(fiptr, typeof(NativePcsFileInfo));
     PcsFileInfo fi = new PcsFileInfo(nfi);
     NativeMethods.pcs_fileinfo_destroy(fiptr);
     return fi;
 }
Exemplo n.º 6
0
 /// <summary>
 /// 上传文件到网盘。
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="to_path">网盘文件,地址需写全,如/temp/file.txt</param>
 /// <param name="read_func">读取该文件的方法</param>
 /// <param name="content_size">总共需要上传的大小</param>
 /// <param name="userdata"></param>
 /// <param name="overwrite">如果网盘文件已经存在,是否覆盖原文件。true - 覆盖;false - 自动重命名</param>
 /// <returns>返回文件的元数据</returns>
 public static PcsFileInfo pcs_upload_s(BaiduPCS pcs, string to_path, OnReadBlockFunction read_func, uint content_size, object userdata, bool overwrite = false)
 {
     UserState state = new UserState()
     {
         onReadSlice = read_func,
         userData = userdata
     };
     IntPtr remotePtr = NativeUtils.utf8_str_ptr(to_path);
     string key = saveState(state);
     IntPtr keyPtr = NativeUtils.str_ptr(key);
     IntPtr fiptr = NativeMethods.pcs_upload_s(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False,
         pcs._onReadBlock, keyPtr, content_size);
     NativeUtils.free_str_ptr(remotePtr);
     NativeUtils.free_str_ptr(keyPtr);
     removeState(key);
     if (fiptr == IntPtr.Zero)
         return new PcsFileInfo();
     NativePcsFileInfo nfi = (NativePcsFileInfo)Marshal.PtrToStructure(fiptr, typeof(NativePcsFileInfo));
     PcsFileInfo fi = new PcsFileInfo(nfi);
     NativeMethods.pcs_fileinfo_destroy(fiptr);
     return fi;
 }