コード例 #1
0
        public frmMetaInformation(PcsFileInfo fileInfo)
        {
            InitializeComponent();
            if (fileInfo.isdir)
            {
                txFileName.Text = fileInfo.server_filename;
                txFileType.Text = "Directory";
                txLocation.Text = fileInfo.path;
                txSize.Text = fileInfo.size.ToString() + "Bytes (" + Utils.HumanReadableSize(fileInfo.size) + ")";
                txCreateTime.Text = Utils.FromUnixTimeStamp(fileInfo.server_ctime).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
                txModifyTime.Text = Utils.FromUnixTimeStamp(fileInfo.server_mtime).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
                txMd5.Text = fileInfo.md5;

            }
            else
            {
                txFileName.Text = fileInfo.server_filename;
                txFileType.Text = Path.GetExtension(fileInfo.server_filename);
                txLocation.Text = fileInfo.path;
                txSize.Text = fileInfo.size.ToString() + "Bytes (" + Utils.HumanReadableSize(fileInfo.size) + ")";
                txCreateTime.Text = Utils.FromUnixTimeStamp(fileInfo.server_ctime).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
                txModifyTime.Text = Utils.FromUnixTimeStamp(fileInfo.server_mtime).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
                txMd5.Text = fileInfo.md5;
            }
        }
コード例 #2
0
        private long taskId = 0; //本地下载任务的 ID

        #endregion Fields

        #region Constructors

        public MultiThreadDownloader(BaiduPCS pcs, PcsFileInfo from, string to,
            string workfolder, int threadCount, int minSliceSize = MIN_SLICE_SIZE)
            : base(pcs, from, to)
        {
            this.WorkFolder = workfolder;
            this.ThreadCount = threadCount;
            this.MinSliceSize = minSliceSize;
        }
コード例 #3
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 快速上传
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="topath">网盘文件</param>
 /// <param name="filesize">本地文件的字节大小</param>
 /// <param name="file_md5">文件的md5值</param>
 /// <param name="slice_md5">验证文件的分片的md5值</param>
 /// <param name="overwrite">如果 topath 已经存在,是否覆盖。true - 覆盖;false - 自动重命名</param>
 /// <returns>返回上传的文件的元数据</returns>
 public static PcsFileInfo pcs_rapid_upload_r(BaiduPCS pcs, string topath, long filesize, string file_md5, string slice_md5, bool overwrite = false)
 {
     IntPtr remotePtr = NativeUtils.utf8_str_ptr(topath);
     IntPtr fileMd5Ptr = Marshal.AllocHGlobal(36);
     IntPtr sliceMd5Ptr = Marshal.AllocHGlobal(36);
     NativeUtils.str_set(fileMd5Ptr, file_md5);
     NativeUtils.str_set(sliceMd5Ptr, slice_md5);
     IntPtr fiptr = NativeMethods.pcs_rapid_upload_r(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False,
         filesize, fileMd5Ptr, sliceMd5Ptr);
     file_md5 = NativeUtils.utf8_str(fileMd5Ptr);
     slice_md5 = NativeUtils.utf8_str(sliceMd5Ptr);
     NativeUtils.free_str_ptr(remotePtr);
     Marshal.FreeHGlobal(fileMd5Ptr);
     Marshal.FreeHGlobal(sliceMd5Ptr);
     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;
 }
コード例 #4
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 快速上传
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="topath">网盘文件</param>
 /// <param name="local_filename">本地文件</param>
 /// <param name="file_md5">文件的md5值</param>
 /// <param name="slice_md5">验证文件的分片的md5值</param>
 /// <param name="overwrite">如果 topath 已经存在,是否覆盖。true - 覆盖;false - 自动重命名</param>
 /// <returns>返回上传的文件的元数据</returns>
 public static PcsFileInfo pcs_rapid_upload(BaiduPCS pcs, string topath, string local_filename, ref string file_md5, ref string slice_md5, bool overwrite = false)
 {
     IntPtr remotePtr = NativeUtils.utf8_str_ptr(topath);
     IntPtr localPtr = NativeUtils.str_ptr(local_filename);
     IntPtr fileMd5Ptr = Marshal.AllocHGlobal(36);
     IntPtr sliceMd5Ptr = Marshal.AllocHGlobal(36);
     if (!string.IsNullOrEmpty(file_md5) && file_md5.Length == 32)
         NativeUtils.str_set(fileMd5Ptr, file_md5);
     else
         Marshal.Copy(NativeConst.ZERO_MATRIX_8X8, 0, fileMd5Ptr, 36); /* need fix? */
     if (!string.IsNullOrEmpty(slice_md5) && slice_md5.Length == 32)
         NativeUtils.str_set(sliceMd5Ptr, slice_md5);
     else
         Marshal.Copy(NativeConst.ZERO_MATRIX_8X8, 0, sliceMd5Ptr, 36); /* need fix? */
     IntPtr fiptr = NativeMethods.pcs_rapid_upload(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False, localPtr, fileMd5Ptr, sliceMd5Ptr);
     file_md5 = NativeUtils.utf8_str(fileMd5Ptr);
     slice_md5 = NativeUtils.utf8_str(sliceMd5Ptr);
     NativeUtils.free_str_ptr(remotePtr);
     NativeUtils.free_str_ptr(localPtr);
     Marshal.FreeHGlobal(fileMd5Ptr);
     Marshal.FreeHGlobal(sliceMd5Ptr);
     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;
 }
コード例 #5
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 获取文件或目录的元信息,该方法通过pcs_search实现。
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="path">待获取的文件或目录,地址需写全,如/temp, /temp/file.txt</param>
 /// <returns>返回文件元数据</returns>
 public static PcsFileInfo pcs_meta(BaiduPCS pcs, string path)
 {
     IntPtr pathPtr = NativeUtils.utf8_str_ptr(path);
     IntPtr fiptr = NativeMethods.pcs_meta(pcs.Handle, pathPtr);
     NativeUtils.free_str_ptr(pathPtr);
     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;
 }
コード例 #6
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 合并分片文件
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="topath">合并后产生的文件路径,必须写全。</param>
 /// <param name="block_list">待合并的分片列表,每一个都是上传分片文件时返回的 md5 值</param>
 /// <param name="overwrite">如果 topath 已经存在,是否覆盖</param>
 /// <returns>返回合并后的文件的元数据</returns>
 public static PcsFileInfo pcs_create_superfile(BaiduPCS pcs, string topath, string[] block_list, bool overwrite = false)
 {
     IntPtr pathPtr = NativeUtils.utf8_str_ptr(topath);
     IntPtr slPtr = NativeUtils.slist_ptr(block_list);
     IntPtr fiptr = NativeMethods.pcs_create_superfile(pcs.Handle, pathPtr, overwrite ? NativeConst.True : NativeConst.False, slPtr);
     NativeUtils.free_str_ptr(pathPtr);
     NativeUtils.free_slist_ptr(slPtr);
     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;
 }
コード例 #7
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <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;
 }
コード例 #8
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 上传分片数据
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="buffer">待上传的字节序</param>
 /// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
 /// <returns>返回上传的分片文件的元数据 </returns>
 public static PcsFileInfo pcs_upload_slice(BaiduPCS pcs, byte[] buffer, long maxspeed = 0)
 {
     IntPtr bufptr = Marshal.AllocHGlobal(buffer.Length);
     Marshal.Copy(buffer, 0, bufptr, buffer.Length);
     IntPtr fiptr = NativeMethods.pcs_upload_slice(pcs.Handle, bufptr, (uint)buffer.Length, maxspeed);
     Marshal.FreeHGlobal(bufptr);
     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;
 }
コード例 #9
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 把内存中的字节序上传到网盘
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="path">目标文件,地址需写全,如/temp/file.txt</param>
 /// <param name="buffer">待上传的字节序</param>
 /// <param name="overwrite">指定是否覆盖原文件,传入PcsTrue则覆盖,传入PcsFalse,则自动重命名。</param>
 /// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
 /// <returns>返回上传的文件的元数据 </returns>
 public static PcsFileInfo pcs_upload_buffer(BaiduPCS pcs, string path, byte[] buffer, bool overwrite = false, long maxspeed = 0)
 {
     IntPtr pathPtr = NativeUtils.utf8_str_ptr(path);
     IntPtr bufptr = Marshal.AllocHGlobal(buffer.Length);
     Marshal.Copy(buffer, 0, bufptr, buffer.Length);
     IntPtr fiptr = NativeMethods.pcs_upload_buffer(pcs.Handle, pathPtr, overwrite ? NativeConst.True : NativeConst.False, bufptr, (uint)buffer.Length, maxspeed);
     NativeUtils.free_str_ptr(pathPtr);
     Marshal.FreeHGlobal(bufptr);
     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;
 }
コード例 #10
0
ファイル: BaiduPCS.cs プロジェクト: youmuyou/BaiduPCS_NET
 /// <summary>
 /// 上传文件到网盘。
 /// 可通过 PCS_OPTION_PROGRESS_FUNCTION 选项设定进度条回调,
 /// 使用 PCS_OPTION_PROGRESS 启用该回调后,可简单实现上传进度。
 /// </summary>
 /// <param name="pcs"></param>
 /// <param name="topath">网盘文件,地址需写全,如/temp/file.txt</param>
 /// <param name="local_filename">待上传的本地文件</param>
 /// <param name="overwrite">如果网盘文件已经存在,是否覆盖原文件。true - 覆盖;false - 自动重命名</param>
 /// <param name="maxspeed">最大上传速度,0 为不限制上传速度。</param>
 /// <returns>返回文件的元数据</returns>
 public static PcsFileInfo pcs_upload(BaiduPCS pcs, string topath, string local_filename, bool overwrite = false, long maxspeed = 0)
 {
     IntPtr remotePtr = NativeUtils.utf8_str_ptr(topath);
     IntPtr localPtr = NativeUtils.str_ptr(local_filename);
     IntPtr fiptr = NativeMethods.pcs_upload(pcs.Handle, remotePtr, overwrite ? NativeConst.True : NativeConst.False, localPtr, maxspeed);
     NativeUtils.free_str_ptr(remotePtr);
     NativeUtils.free_str_ptr(localPtr);
     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;
 }
コード例 #11
0
ファイル: Downloader.cs プロジェクト: nwcs/BaiduPCS_NET
 public Downloader(BaiduPCS pcs, PcsFileInfo from, string to)
 {
     this.pcs = pcs;
     this.from = from;
     this.to = to;
 }
コード例 #12
0
ファイル: BaiduPCS.cs プロジェクト: nwcs/BaiduPCS_NET
 /// <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;
 }