using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; namespace Orbit_Defender { /// /// This is the class for the application launcher - the GUI responsible for recieving initialization instructions from the user. /// public partial class Launcher : Form { /// /// Handles the click event of the launch button control. /// /// The source of the event. /// The instance containing the event data. private void bLaunch_Click(object sender, EventArgs e) { #region Set application settings. // Store application settings. try { using (StreamWriter settings = new StreamWriter("Orbit Defender.ini")) { settings.WriteLine(tbResolutionSlider.Value); // Resolution slider value. settings.WriteLine(cbWindowed.Checked); // Checkbox checked value. } } catch (UnauthorizedAccessException) { // << THIS IS WHERE I GET TO. >> } #endregion #region Determine the height and the width. // Define temporary variables to hold the height/width. Int32 height = 0; Int32 width = 0; // Switch the resolution slider value variable. switch (tbResolutionSlider.Value) { // 640 by 480. case 0: height = 480; width = 640; break; // 600 by 600. case 1: height = 600; width = 800; break; // 1024 by 768. case 2: height = 768; width = 1024; break; // 1152 by 864. case 3: height = 864; width = 1152; break; // 1280 by 1024. case 4: height = 1024; width = 1280; break; // Something mighty weird happened - the slider slid too far. default: new Exception("tbResolutionSlider.Value was out of range."); break; } #endregion // Set the height and the width. Logic.Height = height; Logic.Width = width; // Shall the game be windowed? Logic.Windowed = cbWindowed.Checked; } /// /// Initializes a new instance of the class. /// public Launcher() { // Initialize the component. InitializeComponent(); } /// /// Handles the Load event of the Launcher window. /// /// The source of the event. /// The instance containing the event data. private void Launcher_Load(object sender, EventArgs e) { try { // Open the settings file. using (StreamReader settings = new StreamReader("Orbit Defender.ini")) { #region Determine the scrollbar value. // Get the scrollbar value. switch (settings.ReadLine().Trim()) { // Resolution is 640 by 480. case "0": tbResolutionSlider.Value = 0; break; // Resolution is 800 by 600. case "1": tbResolutionSlider.Value = 1; break; // Resolution is 1024 by 768. case "2": tbResolutionSlider.Value = 2; break; // Resolution is 1152 by 864. case "3": tbResolutionSlider.Value = 3; break; // Resolution is 1280 by 1024. case "4": tbResolutionSlider.Value = 4; break; // Invalid value in settings file. default: new Exception("Invalid value on first line of settings value - value must be 0 to 4."); break; } #endregion #region Determine whether or not the checkbox should be pre-checked. // Get the checkbox value. switch (settings.ReadLine().Trim().ToLower()) { // The windowed checkbox should be checked. case "true": cbWindowed.Checked = true; break; // The windowed checkbox should not be checked. case "false": cbWindowed.Checked = false; break; // Invalid value. default: new Exception("Invalid value on line 2 of settings file; value must be True or False."); break; } #endregion } } catch (FileNotFoundException) { // Create the file. File.Create("Orbit Defender.ini"); File.SetAttributes("Orbit Defender.ini", FileAttributes.Hidden); } catch (NullReferenceException) { // File is empty - it will be populated soon. Do nothing just now. } } } }