예제 #1
0
        private new void Update()
        {
            //下载更新软件
            var url      = XmlHelp.GetInnerTextByPath("Config:WebUrl") + updateSoft;
            var fileName = Path.GetFileName(updateSoft);
            var b        = HtmlHelp.DownFile(url, fileName);

            if (!b)
            {
                MessageBox.Show("下载更新文件失败!");
            }
            else
            {
                var aPath = Application.StartupPath + "/";

                var updateFileName = XmlHelp.GetInnerTextByPath("Config:UpdateFileName");
                if (File.Exists(updateFileName))
                {
                    File.Delete(updateFileName);
                }

                ZipHelp.ExtractToDirectory(fileName, aPath);
                File.Delete(fileName);

                //启动更新程序
                Process.Start(updateFileName);
                //关闭主进程
                var proc = Process.GetProcessesByName(XmlHelp.GetInnerTextByPath("Config:MainProcess").Replace(".exe", ""));
                foreach (var p in proc)
                {
                    p.Kill();
                }
            }
        }
예제 #2
0
        private void UpdateSoft()
        {
            try
            {
                var url  = XmlHelp.GetInnerTextByPath("Config:UpdateUrl");
                var json = HtmlHelp.Get(url);

                var result = JsonHelp.DeserializeObject <ResultEntity>(json);

                if (result.Code == "1")
                {
                    var url2 = XmlHelp.GetInnerTextByPath("Config:WebUrl");
                    var zip  = Path.GetFileName(result.FileName);
                    var b    = HtmlHelp.DownFile(url2 + result.FileName, zip, progressBar1);

                    if (!b)
                    {
                        throw new Exception();
                    }

                    //解压下载的文件
                    var aPath = Application.StartupPath + "/";
                    ZipHelp.ExtractToDirectory(zip, aPath + "NewPixiv");

                    //删除下载的压缩文件
                    File.Delete(aPath + zip);

                    //替换文件
                    ReplaceFile(aPath, aPath + "NewPixiv");

                    //删除解压后的文件
                    Directory.Delete(aPath + "NewPixiv", true);

                    //重新启动主程序
                    var mainPreocess = XmlHelp.GetInnerTextByPath("Config:MainProcess");
                    Process.Start(mainPreocess);
                }
                else
                {
                    MessageBox.Show(result.Message);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("更新文件失败!");
            }
        }
예제 #3
0
        /// <summary>
        /// 获取指定作品的动画
        /// </summary>
        public void GetCanvasZipFile(string itemUrl, string savePath, string pid)
        {
            //可以获取zip的url
            var zipHtmlUrl = string.Format("https://www.pixiv.net/ajax/illust/{0}/ugoira_meta", pid);

            var html = DownHelp.GetHtmlString(zipHtmlUrl, Encoding.UTF8, 5);
            var fReg = new Regex(RegexHelp.Other.GetAnimation, RegexOptions.Singleline);
            var fM   = fReg.Match(html);

            if (fM == null || fM.Groups["Url"].Value == "")
            {
                AddErrorMsg(string.Format("获取 {0} 的动画失败!\r\n", itemUrl));
                return;
            }

            //zip的Url路径
            var fileUrl = fM.Groups["Url"].Value.Replace("\\/", "/");

            //zip文件名
            var fileName = savePath + "/" + Path.GetFileName(fileUrl);

            lock (Multithreading.ObjLockExistFile)
            {
                if (File.Exists(fileName))
                {
                    if (form.ChkNeglect.Checked)
                    {
                        AddErrorMsg(string.Format("文件{0}已存在,已忽略!\r\n", fileName));
                    }
                    return;
                }
            }

            //获取文件总大小
            var total = HtmlHelp.GetFileContenLength(fileUrl, itemUrl);

            if (total == 0)
            {
                AddErrorMsg(string.Format("获取 {0} 的大小失败!\r\n", fileUrl));
                return;
            }

            //分批获取文件
            var b = HtmlHelp.DownFile(fileUrl, fileName, itemUrl, 299999, total);

            if (b)
            {
                AddSuccessMsg(string.Format("下载 {0} 的文件成功!\r\n", fileUrl));
            }
            else
            {
                AddErrorMsg(string.Format("下载 {0} 的文件失败!\r\n Url:{1}\r\n", fileUrl, itemUrl));
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                return;
            }

            //获取delay
            var dr    = new Regex(RegexHelp.Other.GetDelay, RegexOptions.Singleline);
            var dm    = dr.Match(html);
            var delay = "50";

            if (dm != null && dm.Groups["Delay"].Value != "")
            {
                delay = dm.Groups["Delay"].Value;
            }

            var dic = new Dictionary <string, string>()
            {
                { "SavePath", savePath },
                { "FileUrl", fileUrl },
                { "FileName", fileName },
                { "Delay", delay }
            };

            while (!mut.UnZipFile(dic, UnZipFile))
            {
                Thread.Sleep(5000);
            }
        }