/// <summary> /// Removes HOSTS file redirects. /// </summary> private void UndoRedirects() { // Tell the writter to restore the HOSTS file to its // original state UpdateStatus("- Unlocking HOSTS file"); HostsFile.UnLock(); // Restore the original hosts file contents UdpateStatus("- Restoring HOSTS file... ", false); try { HostsFile.Remove("bf2web.gamespy.com"); HostsFile.Remove("gpcm.gamespy.com"); HostsFile.Remove("gpsp.gamespy.com"); HostsFile.Remove("motd.gamespy.com"); HostsFile.Remove("master.gamespy.com"); HostsFile.Remove("battlefield2.ms14.gamespy.com"); HostsFile.Remove("battlefield2.available.gamespy.com"); HostsFile.Save(); UpdateStatus("Success!"); } catch { UpdateStatus("Failed!"); MessageBox.Show( "Unable to RESTORE to HOSTS file! Unfortunatly this error can only be fixed by manually removing the HOSTS file," + " and replacing it with a new one :( . If possible, you may also try changing the permissions yourself.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); } // Flush the DNS! FlushDNS(); // Update status UpdateStatus("- All Done!"); // Reset form data RedirectsEnabled = false; RedirectButton.Text = "Begin HOSTS Redirect"; UnlockGroups(); }
/// <summary> /// Event fired when the UI is closing, Unlocks the HostsFile /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Launcher_FormClosing(object sender, FormClosingEventArgs e) { HostsFile.UnLock(); }