Exemple #1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     temp = download.GetStatus();
     progressBar1.Value = (int)(temp.Progress * 100);
     label1.Text        = temp.TOTALSIZE + "/" + temp.MAXSIZE;
     if (temp.Isdownloading == false)
     {
         timer1.Stop();
         if (System.IO.Directory.Exists(Path.Combine(Application.StartupPath, "temp")))
         {
             System.IO.Directory.Delete(Path.Combine(Application.StartupPath, "temp"), true);
         }
         UseZip.UnZip(Path.Combine(Application.StartupPath, "AutoUpdater.zip"), Path.Combine(Application.StartupPath, "temp"));
         killself();
     }
 }
Exemple #2
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            temp = download.GetStatus();
            progressBar1.Value = (int)(temp.Progress * 100);
            label1.Text        = (temp.TOTALSIZE / 1024).ToString("0.00") + "KB /" + (temp.MAXSIZE / 1024).ToString("0.00") + "KB";
            if (temp.Isdownloading == false)
            {
                timer2.Stop();
                if (CheckFile.GetMD5(updateinfo.ZIP_Name).ToUpper() == updateinfo.ZIP_MD5.ToUpper())
                {
                    CloseAPP();
                    RunAPP(1);
                    if (System.IO.Directory.Exists(Path.Combine(Application.StartupPath, "temp")))
                    {
                        System.IO.Directory.Delete(Path.Combine(Application.StartupPath, "temp"), true);
                    }
                    if (updateinfo.ZIP_Password == "")
                    {
                        UseZip.UnZip(updateinfo.ZIP_Name, Path.Combine(Application.StartupPath, "temp"));
                    }
                    else
                    {
                        UseZip.UnZip(updateinfo.ZIP_Name, updateinfo.ZIP_Password, Path.Combine(Application.StartupPath, "temp"));
                    }
                    foreach (string fname in System.IO.Directory.GetFiles(Path.Combine(Application.StartupPath, "temp"), "*.*", SearchOption.AllDirectories))
                    {
                        foreach (File_UpdateInfo tt in updateinfo.File_UpdateMod)
                        {
                            switch (tt.Mod)
                            {
                            case "WhenNeed":
                                if (tt.FileName == (fname.IndexOf("temp\\") == 0 ? fname.Substring(5, fname.Length - 5) : fname))
                                {
                                    if (CheckFile.GetMD5(tt.FileName) != CheckFile.GetMD5(fname))
                                    {
                                        File.Copy(fname, Path.Combine(Directory.GetParent(Path.GetDirectoryName(fname)).FullName, Path.GetFileName(fname)), true);
                                    }
                                }
                                break;

                            case "Always":
                                File.Copy(fname, Path.Combine(Directory.GetParent(Path.GetDirectoryName(fname)).FullName, Path.GetFileName(fname)), true);
                                break;

                            case "WhenNotExist":
                                File.Copy(fname, Path.Combine(Directory.GetParent(Path.GetDirectoryName(fname)).FullName, Path.GetFileName(fname)), false);
                                break;

                            case "Ignore":
                                break;

                            default:
                                File.Copy(fname, Path.Combine(Directory.GetParent(Path.GetDirectoryName(fname)).FullName, Path.GetFileName(fname)), true);
                                break;
                            }
                        }
                    }

                    if (System.IO.Directory.Exists(Path.Combine(Application.StartupPath, "temp")))
                    {
                        System.IO.Directory.Delete(Path.Combine(Application.StartupPath, "temp"), true);
                    }
                    if (File.Exists(updateinfo.ZIP_Name))
                    {
                        File.Delete(updateinfo.ZIP_Name);
                    }
                    RunAPP(2);
                    ChangeControlText("更新完成!", label3);

                    if (!WithForm)
                    {
                        MessageBox.Show("更新完成!");
                        FormClose(this);
                    }
                    Recheck.Enabled = true;
                }
                else
                {
                    label3.Text     = ("檔案驗證失敗,請再試一次");
                    Recheck.Enabled = true;
                }
            }
        }