BF2Statistics.Redirector.RemoveRedirects C# (CSharp) Method

RemoveRedirects() public static method

Remove the redirects currently active
public static RemoveRedirects ( ) : void
return void
        public static void RemoveRedirects()
        {
            // Can't do anything with a dns server
            if (RedirectMethod == RedirectMode.DnsServer || !RedirectsEnabled) return;

            // UnLock system Hosts file
            if (RedirectMethod == RedirectMode.HostsFile)
            {
                // Must unlock first
                if (SysHostsFile.IsLocked)
                    HostsFileSys.UnLock();

                RemoveRedirects(HostsFileSys);
            }
            else
            {
                RemoveRedirects(HostsFileIcs);
            }
        }

Same methods

Redirector::RemoveRedirects ( HostsFile HostFile ) : void

Usage Example

        /// <summary>
        /// When the Step is changed, this method handles the processing of
        /// the next step
        /// </summary>
        protected async void AfterSelectProcessing()
        {
            // Disable buttons until processing is complete
            NextBtn.Enabled = false;
            PrevBtn.Enabled = false;
            bool IsErrorFree;

            // Do processing
            // Get our previous step
            switch (pageControl1.SelectedTab.Name)
            {
            case "tabPageSelect":
                // We dont do anything here
                NextBtn.Enabled = true;
                break;

            case "tabPageRedirectType":
                // We dont do much here
                PrevBtn.Enabled = NextBtn.Enabled = true;
                break;

            case "tabPageVerifyHosts":
            case "tabPageVerifyIcs":
                // Create new progress
                SyncProgress <TaskStep> Myprogress = new SyncProgress <TaskStep>(RedirectStatusUpdate);

                // Apply redirects
                IsErrorFree = await Redirector.ApplyRedirectsAsync(Myprogress);

                if (IsErrorFree)
                {
                    NextBtn.Enabled = true;
                }
                else
                {
                    // Remove redirect if there are errors
                    await Task.Delay(ERRORPAGE_DELAY);

                    ShowHostsErrorPage();
                }
                break;

            case "tabPageDiagnostic":
                // Run in a new thread of course
                bool DiagnosticResult = await Task.Run <bool>(() => VerifyDnsCache());

                // Switch page
                if (DiagnosticResult)
                {
                    NextBtn.Enabled = true;
                }
                else
                {
                    // Remove redirect if there are errors
                    Redirector.RemoveRedirects();
                    await Task.Delay(ERRORPAGE_DELAY);

                    // Show Error Page
                    ShowDnsErrorPage();
                }
                break;

            case "tabPageSuccess":
                PrevBtn.Visible   = false;
                CancelBtn.Visible = false;
                NextBtn.Text      = "Finish";
                NextBtn.Enabled   = true;
                NextBtn.Location  = CancelBtn.Location;
                return;

            case "tabPageError":
                break;
            }

            // Unlock the previos button
            if (pageControl1.SelectedTab != tabPageSelect)
            {
                PrevBtn.Enabled = true;
            }
        }