Exemple #1
0
 private void CompressHelper_doSendMsg(CompressMsg msg)
 {
     if (msg.Tag == CompressStatus.Error || msg.Tag == CompressStatus.End)
     {
         StartCompress(1);
     }
 }
Exemple #2
0
        private void SendMsgHander(CompressMsg msg)
        {
            switch (msg.Tag)
            {
            case CompressStatus.Start:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView1.Items[msg.Id].SubItems[4].Text = "开始压缩";
                });
                break;

            case CompressStatus.GetLength:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView1.Items[msg.Id].SubItems[4].Text = "链接成功";
                });
                break;

            case CompressStatus.Compress:
                this.Invoke(new MethodInvoker(() =>
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        listView1.Items[msg.Id].SubItems[2].Text = msg.SizeInfo;
                        listView1.Items[msg.Id].SubItems[3].Text = msg.Progress.ToString() + "%";
                        listView1.Items[msg.Id].SubItems[4].Text = "压缩中";
                        listView1.Items[msg.Id].SubItems[5].Text = msg.Pwd;
                        listView1.Items[msg.Id].SubItems[8].Text = msg.Address;
                        Application.DoEvents();
                    });
                }));
                break;

            case CompressStatus.End:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView1.Items[msg.Id].SubItems[2].Text = "已完成";
                    listView1.Items[msg.Id].SubItems[3].Text = "100%";
                    listView1.Items[msg.Id].SubItems[4].Text = "压缩完成";
                    listView1.Items[msg.Id].SubItems[5].Text = msg.Pwd;
                    listView1.Items[msg.Id].SubItems[6].Text = msg.PwdFileUrl;
                    listView1.Items[msg.Id].SubItems[7].Text = msg.Price.ToString();
                });
                break;

            case CompressStatus.Error:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView1.Items[msg.Id].SubItems[4].Text = "失败";
                });
                break;

            default:
                break;
            }
        }
Exemple #3
0
        private void QiniuHelper_doSendMsg(CompressMsg msg)
        {
            msg.Tag = CompressStatus.End;
            //上传至8图片
            StringBuilder sbPid = new StringBuilder(60);

            iniFileHelper.GetIniString("pic", "Pid", "", sbPid, sbPid.Capacity);
            StringBuilder sbKey = new StringBuilder(60);

            iniFileHelper.GetIniString("pic", "Key", "", sbKey, sbKey.Capacity);
            //这里采用单线程执行。免得8图片抗不做
            var result = HttpHelper.Get <PicResult>("http://web.8tupian.com/api/b.php?act=up1&pic=" + msg.PwdFileUrl + "&price=" + msg.Price + "&pid=" + sbPid + "&key=" + sbKey + "");

            if (result.code == 0)
            {
                msg.PwdFileUrl = result.picurl;
            }
            else
            {
                msg.PwdFileUrl = "8图片上传失败(七牛云网络图片地址错误)";
                msg.Tag        = CompressStatus.Error;
            }
            doSendMsg(msg);
            //删除密码图片及文件夹
            Task.Run(() => {
                if (!System.IO.File.Exists(msg.File + ".txt"))
                {
                    byte[] bytes  = null;
                    bytes         = Encoding.UTF8.GetBytes("在浏览器输入地址查看解压密码。" + msg.PwdFileUrl);
                    FileStream fs = new FileStream(msg.File + ".txt", FileMode.Create, FileAccess.Write);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
                else
                {
                    byte[] bytes  = null;
                    bytes         = Encoding.UTF8.GetBytes("在浏览器输入地址查看解压密码。" + msg.PwdFileUrl);
                    FileStream fs = new FileStream(msg.File + ".txt", FileMode.Open, FileAccess.Write);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }


                var img = msg.File + ".jpg";
                File.Delete(img);
                Directory.Delete(msg.File);
            });

            //lock (obj)
            //{

            //}
        }
Exemple #4
0
 public void Operation(string saveAddress, string item, string elseAddress, string password = "", int id = 0, int bPrice = 0, int ePrice = 0, string comment = "")
 {
     try
     {
         CompressMsg compress = new CompressMsg();
         compress.Tag = CompressStatus.Start;
         compress.Id  = id;
         doSendMsg(compress);
         //创建保存文件夹
         var saveDirectory = saveAddress + "\\" + Path.GetFileNameWithoutExtension(item);
         Directory.CreateDirectory(saveDirectory);
         //复制当前文件到文件夹
         FileHelper.CopyDirectory(item, saveDirectory, true);
         //获取另外文件路径
         if (!string.IsNullOrEmpty(elseAddress))
         {
             FileHelper.CopyDirectory(elseAddress, saveDirectory, true);
         }
         if (password == "0") //生成随机6位数压缩密码
         {
             password = FileHelper.GetRnd(6, true, true, true, true, "");
         }
         //压缩文件夹
         //FileHelper.CondenseRarOrZip(saveDirectory, saveAddress + "\\" + Path.GetFileNameWithoutExtension(item), true, password);
         //采用ZIP 压缩
         FileHelper.ZipDirectory(saveDirectory, saveDirectory + ".rar", password, comment);
         // FileHelper.ZipFile()
         compress.Tag     = CompressStatus.Compress;
         compress.Pwd     = password;
         compress.Address = saveAddress + "\\" + Path.GetFileNameWithoutExtension(item) + ".rar";
         doSendMsg(compress);
         if (!string.IsNullOrEmpty(password))
         {
             ///创建密码图片
             FileHelper.CreateImgages("解压密码:" + password, saveAddress + "\\" + Path.GetFileNameWithoutExtension(item) + ".jpg");
             /////上传密码图片
             FileStream fs = File.OpenRead(saveAddress + "\\" + Path.GetFileNameWithoutExtension(item) + ".jpg");
             if (ePrice == 0)
             {
                 compress.Price = bPrice;
             }
             else
             {
                 compress.Price = new Random().Next(bPrice, ePrice);
             }
             compress.File = saveAddress + "\\" + Path.GetFileNameWithoutExtension(item);
             QiniuHelper qiniuHelper = new QiniuHelper(compress);
             qiniuHelper.doSendMsg += QiniuHelper_doSendMsg;
             qiniuHelper.Upload(fs, Path.GetFileNameWithoutExtension(item));
         }
         else
         {
             compress.Tag = CompressStatus.End;
             doSendMsg(compress);
         }
     }
     catch (Exception)
     {
         CompressMsg compress = new CompressMsg();
         compress.Tag = CompressStatus.Error;
         doSendMsg(compress);
     }
 }
Exemple #5
0
 public QiniuHelper(CompressMsg compressMsg)
 {
     this.compressMsg = compressMsg;
 }