Ejemplo n.º 1
0
        private void btPackage_Click(object sender, EventArgs e)
        {
            string src  = tbPath.Text;
            string file = tbName.Text + "-" + tbVersion.Text.Replace('.', '-') + ".udp";
            string dst  = DirTool.Combine(DirTool.GetFilePath(tbPath.Text), file);

            if (FilePackageTool.Pack(src, dst) > 0 && File.Exists(dst))
            {
                string md5Code = FileTool.GetMD5(dst);
                //设置更新模型,14个属性
                AppUpdateInfo aui = new AppUpdateInfo()
                {
                    Name         = tbName.Text,
                    Author       = tbAuthor.Text,
                    Desc         = tbDesc.Text,
                    Version      = tbVersion.Text,
                    ReleasePath  = tbReleasePath.Text,
                    Necessary    = cbNecessary.Checked,
                    DateTime     = DateTime.Now,
                    DownloadMode = rbHttpMode.Checked ? 0 : 1,
                    HttpUrl      = tbHttpUrl.Text,
                    FtpIp        = tbFtpIp.Text,
                    FtpAccount   = tbFtpAccount.Text,
                    FtpPassword  = tbFtpPassword.Text,
                    FtpFile      = tbFtpFile.Text,
                    Md5          = md5Code,
                };
                string auiJson = JsonTool.ToStr(aui);
                TxtTool.Create(dst + ".txt", auiJson);
            }
        }
Ejemplo n.º 2
0
        private void BTPack_Click(object sender, EventArgs e)
        {
            string src  = TBPath.Text;
            string file = Path.GetFileName(src) + ".package";
            string dst  = DirTool.Combine(DirTool.GetFilePath(TBPath.Text), file);

            FilePackageTool.Pack(src, dst);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="info">新版本信息</param>
        /// <param name="tempPath">文件下载位置</param>
        /// <param name="dictionary">文件相对位置字典</param>
        /// <param name="downProgress">下载进度回调</param>
        /// <param name="downSender">下载进度事件数据</param>
        /// <param name="releaseProgress">释放进度回调</param>
        /// <param name="releaseSender">释放进度事件数据</param>
        /// <returns>
        /// -10000;//没有新版本
        /// -20000;//文件下载失败
        /// -30000;//文件释放失败
        /// </returns>
        public int Update(AppUpdateInfo info, string tempPath, Dictionary <string, string> dictionary,
                          ProgressDelegate.ProgressHandler downProgress    = null, object downSender    = null,
                          ProgressDelegate.ProgressHandler releaseProgress = null, object releaseSender = null)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            //请求最新版本信息
            if (info != null)
            {
                string file = DirTool.Combine(tempPath, GuidTool.Short() + "-" + info.Version);
                //准备更新(下载)
                string downfile = Download(file, info, downProgress, downSender);
                if (!string.IsNullOrWhiteSpace(downfile) && File.Exists(downfile))
                {
                    //格式化释放文件目录(相对路径转换为绝对路径)
                    string releasepath = AppDirTool.Get(info.ReleasePath, dictionary);
                    //释放文件,释放完成后删除临时文件
                    int unpackCode = FilePackageTool.Unpack(downfile, releasepath, releaseProgress, releaseSender);
                    File.Delete(file);
                    if (unpackCode > 0)
                    {
                        stopwatch.Stop();
                        return((int)stopwatch.Elapsed.TotalSeconds);
                    }
                    else
                    {
                        return(-30000 + unpackCode);//文件释放失败
                    }
                }
                else
                {
                    return(-20000);//文件下载失败
                }
            }
            else
            {
                return(-10000);//没有新版本
            }
        }
Ejemplo n.º 4
0
 private void BTUnpack_Click(object sender, EventArgs e)
 {
     FilePackageTool.Unpack(TBFrom.Text, TBTo.Text, UIProgress);
 }
Ejemplo n.º 5
0
 private void TestUpdateForm_Load(object sender, EventArgs e)
 {
     FilePackageTool.Pack(@"D:\CoCo\Work\IMOS小助手\IMOS.Assistant\程序发布\1.0.0.0", @"D:\CoCo\Work\IMOS小助手\IMOS.Assistant\程序发布\所有版本打包\Assistant[1.0.0.0].udp");
 }