コード例 #1
1
ファイル: Updater.cs プロジェクト: herculesjr/razor
        private void ExtractFiles()
        {
            string tempPath = "Update.rar";
            if( File.Exists( tempPath ) )
            {
                UpdateStatus( "Extracting files..." );

                Unrar rar = new Unrar( tempPath );
                rar.DestinationPath = Directory.GetCurrentDirectory();
                rar.ExtractionProgress += new ExtractionProgressHandler( rar_ExtractionProgress );

                rar.Open();

                while( rar.ReadHeader() )
                {
                    if (rar.CurrentFile.FileName.ToLower() == "updater.exe" && File.Exists("Updater.exe"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("Updater.exe"))
                        {
                            rar.CurrentFile.FileName = "New_Updater.exe";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }
                    else if (rar.CurrentFile.FileName.ToLower() == "unrar.dll" && File.Exists("unrar.dll"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("unrar.dll"))
                        {
                            rar.CurrentFile.FileName = "New_unrar.dll";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }

                    while ( File.Exists( rar.CurrentFile.FileName ) )
                    {
                        try
                        {
                            File.Delete( rar.CurrentFile.FileName );
                        }
                        catch ( Exception e )
                        {
                            DialogResult res = MessageBox.Show( String.Format(
                                "Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of Razor are closed.\nRazor may be unusable until the update completes successfully.",
                                rar.CurrentFile.FileName, e.Message ),
                                "Access Denied",
                                MessageBoxButtons.AbortRetryIgnore,
                                MessageBoxIcon.Warning );

                            if ( res == DialogResult.Abort )
                            {
                                UpdateStatus( "Update ABORTED!" );
                                UpdateFailed();
                                return;
                            }
                            else if ( res == DialogResult.Ignore )
                            {
                                break; // just blindly try anyways
                            }
                            else
                            {
                                continue; // retry
                            }
                        }
                    }

                    rar.Extract();
                }

                rar.Close();
            }

            this.Invoke( new UpdateCompleteDelegate( UpdateComplete ) );
        }
コード例 #2
1
ファイル: UpdaterForm.cs プロジェクト: jeffboulanger/runuogdk
        protected virtual void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(this,
                    "An error occurred while downloading the update for RunUO: GDK\n" +
                    "Please try again later or post the following error on the bug board at " +
                    "http://www.runuoforge.org/gf/project/runuogdk/\n" + e.Error.Message,
                    "RunUO: GDK - Updater");
                return;
            }
            else
            {
                progressBar.Value = 100;

                string filePath = Path.Combine(Application.StartupPath, FILE_NAME);
                Unrar unrar = new Unrar(filePath);

                unrar.ExtractionProgress += new ExtractionProgressHandler(OnExtractionProgress);
                unrar.DestinationPath = Application.StartupPath;
                unrar.Open(Unrar.OpenMode.Extract);

                while (unrar.ReadHeader())
                {
                    if (unrar.CurrentFile.FileName == "Updater.exe")
                    {
                        unrar.CurrentFile.FileName = "Updater.exe.new";
                    }
                    else if (unrar.CurrentFile.FileName == "unrar.dll")
                    {
                        unrar.CurrentFile.FileName = "unrar.dll.new";
                    }

                    while (File.Exists(unrar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(unrar.CurrentFile.FileName);
                            continue;
                        }
                        catch (Exception exception)
                        {
                            DialogResult result = MessageBox.Show(string.Format("Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of RunUO: GDK are closed.\nRunUO: GDK may be unusable until the update completes successfully.", unrar.CurrentFile.FileName, exception.Message), "RunUO: GDK - Updater", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);

                            if (result == DialogResult.Abort)
                            {
                                Application.Exit();
                                return;
                            }

                            if (result != DialogResult.Ignore)
                            {
                                continue;
                            }

                            break;
                        }
                    }

                    unrar.Extract(Path.Combine(Application.StartupPath, unrar.CurrentFile.FileName));
                }

                unrar.Close();
            }

            Process.Start(Path.Combine(Application.StartupPath, GDK_ASSEMBLY_NAME));
            Application.Exit();
        }
コード例 #3
0
ファイル: UpdaterForm.cs プロジェクト: uotools/runuogdk
        protected virtual void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(this,
                                "An error occurred while downloading the update for RunUO: GDK\n" +
                                "Please try again later or post the following error on the bug board at " +
                                "http://www.runuoforge.org/gf/project/runuogdk/\n" + e.Error.Message,
                                "RunUO: GDK - Updater");
                return;
            }
            else
            {
                progressBar.Value = 100;

                string filePath = Path.Combine(Application.StartupPath, FILE_NAME);
                Unrar  unrar    = new Unrar(filePath);

                unrar.ExtractionProgress += new ExtractionProgressHandler(OnExtractionProgress);
                unrar.DestinationPath     = Application.StartupPath;
                unrar.Open(Unrar.OpenMode.Extract);

                while (unrar.ReadHeader())
                {
                    if (unrar.CurrentFile.FileName == "Updater.exe")
                    {
                        unrar.CurrentFile.FileName = "Updater.exe.new";
                    }
                    else if (unrar.CurrentFile.FileName == "unrar.dll")
                    {
                        unrar.CurrentFile.FileName = "unrar.dll.new";
                    }

                    while (File.Exists(unrar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(unrar.CurrentFile.FileName);
                            continue;
                        }
                        catch (Exception exception)
                        {
                            DialogResult result = MessageBox.Show(string.Format("Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of RunUO: GDK are closed.\nRunUO: GDK may be unusable until the update completes successfully.", unrar.CurrentFile.FileName, exception.Message), "RunUO: GDK - Updater", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);

                            if (result == DialogResult.Abort)
                            {
                                Application.Exit();
                                return;
                            }

                            if (result != DialogResult.Ignore)
                            {
                                continue;
                            }

                            break;
                        }
                    }

                    unrar.Extract(Path.Combine(Application.StartupPath, unrar.CurrentFile.FileName));
                }

                unrar.Close();
            }

            Process.Start(Path.Combine(Application.StartupPath, GDK_ASSEMBLY_NAME));
            Application.Exit();
        }
コード例 #4
0
        private void ExtractFiles()
        {
            string tempPath = "Update.rar";

            if (File.Exists(tempPath))
            {
                UpdateStatus("Extracting files...");

                Unrar rar = new Unrar(tempPath);
                rar.DestinationPath     = Directory.GetCurrentDirectory();
                rar.ExtractionProgress += new ExtractionProgressHandler(rar_ExtractionProgress);

                rar.Open();

                while (rar.ReadHeader())
                {
                    if (rar.CurrentFile.FileName.ToLower() == "updater.exe" && File.Exists("Updater.exe"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("Updater.exe"))
                        {
                            rar.CurrentFile.FileName = "New_Updater.exe";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }
                    else if (rar.CurrentFile.FileName.ToLower() == "unrar.dll" && File.Exists("unrar.dll"))
                    {
                        if (rar.CurrentFile.FileTime > File.GetLastWriteTime("unrar.dll"))
                        {
                            rar.CurrentFile.FileName = "New_unrar.dll";
                        }
                        else
                        {
                            rar.Skip();
                            continue;
                        }
                    }

                    while (File.Exists(rar.CurrentFile.FileName))
                    {
                        try
                        {
                            File.Delete(rar.CurrentFile.FileName);
                        }
                        catch (Exception e)
                        {
                            DialogResult res = MessageBox.Show(String.Format(
                                                                   "Unable to delete file \"{0}\" (Error: {1})\nMake sure all instances of Razor are closed.\nRazor may be unusable until the update completes successfully.",
                                                                   rar.CurrentFile.FileName, e.Message),
                                                               "Access Denied",
                                                               MessageBoxButtons.AbortRetryIgnore,
                                                               MessageBoxIcon.Warning);

                            if (res == DialogResult.Abort)
                            {
                                UpdateStatus("Update ABORTED!");
                                UpdateFailed();
                                return;
                            }
                            else if (res == DialogResult.Ignore)
                            {
                                break;                                 // just blindly try anyways
                            }
                            else
                            {
                                continue;                                 // retry
                            }
                        }
                    }

                    rar.Extract();
                }

                rar.Close();
            }

            this.Invoke(new UpdateCompleteDelegate(UpdateComplete));
        }