Beispiel #1
0
        private void UpdateResponse(object sender, AsyncCompletedEventArgs ae)
        {
            UpdateProgressStatus("Installing updates...");

            UpdateProgressStatus("Checking files...");

            //autoupdate code

            string lul            = null;
            string lulupdate      = null;
            string arewedebugging = "no";

            //lolcode ftw
            lul       = Core.MD5Encoder.EncodeHashFromFile(Application.ExecutablePath);
            lulupdate = Core.MD5Encoder.EncodeHashFromFile("c:\\ac_updated.exe");
            if (lul != lulupdate)
            {
                if (arewedebugging.Equals("no"))
                {
                    FileInfo updateExe = new FileInfo("C:\\ac_updated.exe");
                    long     getSize   = updateExe.Length;

                    if (getSize == 0)
                    {
                        ReportForm ef = new ReportForm();
                        ef.label2.Text = "Auto-update failed!" + Environment.NewLine + "Program terminated.";
                        ef.Show();

                        updateExe.Delete();
                        Environment.Exit(0);
                    }

                    if (File.Exists(Application.StartupPath + "\\" + "ac_updated.exe"))
                    {
                        File.Delete(Application.StartupPath + "\\" + "ac_updated.exe");
                        File.Copy("c:\\ac_updated.exe", Application.StartupPath + "\\" + "ac_updated2.exe");
                        File.Delete("c:\\ac_updated.exe");
                        Process.Start("cmd.exe",
                                      "/C choice /C Y /N /D Y /T 2 & ren ac_updated2.exe ac_updated.exe");
                        Process.Start("cmd.exe",
                                      "/C choice /C Y /N /D Y /T 3 & Del " + Application.ExecutablePath);
                        Process.Start("cmd.exe", "/K echo Updating, please wait... & timeout 5 & exit");
                        Application.Exit();
                    }

                    else
                    {
                        File.Copy("c:\\ac_updated.exe", Application.StartupPath + "\\" + "ac_updated.exe");
                        File.Delete("c:\\ac_updated.exe");
                        Process.Start("cmd.exe",
                                      "/C choice /C Y /N /D Y /T 2 & Del " + Application.ExecutablePath);
                        Process.Start("cmd.exe", "/K echo Updating, please wait... & timeout 5 & exit");
                        Application.Exit();
                    }
                }

                else
                {
                    if (File.Exists("c:\\ac_updated.exe"))
                    {
                        File.Delete("c:\\ac_updated.exe");
                    }
                }
            }

            else
            {
                if (File.Exists("c:\\ac_updated.exe"))
                {
                    File.Delete("c:\\ac_updated.exe");
                }
            }

            ShowMainFormCallback callback = new ShowMainFormCallback(ShowMainForm);

            this.BeginInvoke(callback, new object[] { });
        }
Beispiel #2
0
        private void GotFTPUpdateResponse(IAsyncResult iar)
        {
            UpdateProgressStatus("Installing updates...");
            try
            {
                FtpWebRequest requestHandle = (FtpWebRequest)iar.AsyncState;

                using (WebResponse FtpResponse = requestHandle.EndGetResponse(iar))
                {
                    using (System.IO.Stream ResponseStream = FtpResponse.GetResponseStream())
                    {

                        using (System.IO.FileStream fs = new System.IO.FileStream("C:\\ac_updated.exe", FileMode.Create))
                        {
                            byte[] buffer = new byte[2048];
                            int read = 0;
                            do
                            {
                                read = ResponseStream.Read(buffer, 0, buffer.Length);
                                fs.Write(buffer, 0, read);
                            } while (read != 0);
                            ResponseStream.Close();
                            fs.Flush();
                            fs.Close();
                        }
                        ResponseStream.Close();

                    }
                }
            }
            catch (WebException)
            {
               // MessageBox.Show("Cannot download required files! Program terminating.");
                
            }

            UpdateProgressStatus("Checking files...");

            //autoupdate code
            
            //string lul = null;
            //string lulupdate = null;
            ////lolcode ftw
            //lul = Core.MD5Encoder.EncodeHashFromFile(Application.ExecutablePath);
            //lulupdate = Core.MD5Encoder.EncodeHashFromFile("c:\\ac_updated.exe");
            //if (lul != lulupdate)
            //{
            //    if (MessageBox.Show("There is a update available, would you like to perform it?" + Environment.NewLine + "We remind you that playing with a outdated version will lead to a 3 day suspension.", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            //    {
            //        File.Copy("c:\\ac_updated.exe", Application.StartupPath + "\\" + "ac_updated.exe");
            //        File.Delete("c:\\ac_updated.exe");
            //        MessageBox.Show("You can now run the updated version called ac_updated.exe and delete old version." + Environment.NewLine + "Please rename the ac_updated.exe to ac.exe or anything at your choice to avoid update bugs." + Environment.NewLine + "DO NOT DELETE THE .DLL OR ELSE YOU WILL NOT BE ABLE TO LOGIN.");
            //        Environment.Exit(0);
            //    }
            //    else //if (!System.Diagnostics.Debugger.IsAttached)
            //    {
            //        File.Delete("c:\\ac_updated.exe");
            //        Environment.Exit(0);
            //    }

            //}
            //else
            //{
                if (File.Exists("c:\\ac_updated.exe")) {
                File.Delete("c:\\ac_updated.exe");
                }
                //MessageBox.Show("No update available at the moment.");
            //}

            ShowMainFormCallback callback = new ShowMainFormCallback(ShowMainForm);
            this.BeginInvoke(callback, new object[] { });
        }