Example #1
0
        /// <summary>
        /// 下载文件
        /// </summary>
        private void DownLoadFile()
        {
            if (list == null)
            {
                return;
            }
            foreach (UpdateFile uFile in list)
            {
                //更新当前名称
                UpdateFileName ufn = new UpdateFileName(UpdateCurrentFileName);
                this.Invoke(ufn, uFile.Name);
                //判断目标文件是否存在,如果存在删除
                string filePath = string.Format(@"{0}\{1}", mainPath, uFile.Name);
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                ///获取文件字节数组
                byte [] array = service.GetUpdateFile(string.Format(@"{0}\{1}", uFile.Path, uFile.Name));
                if (array == null)
                {
                    MessageBox.Show(string.Format("下载{0}文件失败!", uFile.Name));
                    continue;
                }
                //创建新文件
                FileStream   fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(array);
                bw.Close();
                fs.Close();
            }

            MessageBox.Show("更新完成");

            try
            {
                //重新打开应用程序
                UpdateFileName ufn = new UpdateFileName(UpdateCurrentFileName);
                this.Invoke(ufn, "正在重新启动应用程序...");
                System.Diagnostics.Process.Start(string.Format(@"{0}\{1}", mainPath, programType == "PC" ? "LabelPrint.exe" : "UI.exe"), "");
                //bool flag =new System.Diagnostics.Process { StartInfo = { FileName = mainPath + @"\" + programType == "PC" ? "LabelPrint.exe" : "UI.exe", Arguments = "" } }.Start();
                //MessageBox.Show(flag.ToString());
                //thread.Abort();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //thread.Abort();

            //退出更新程序
            this.Invoke(new ExitApplication(Application.Exit));
        }