Beispiel #1
0
        /// <summary>
        /// Opens the options window
        /// </summary>
        private void homeOptionsButton_ButtonClick()
        {
            // Create a new optionsBox object
            Options optionsBox = new Options(currentValue);

            // Null the form owner (.Net 1.1 -> 2.0 workaround)
            Form formOwner = this.Owner; this.Owner = null;

            // Show the options box
            optionsBox.ShowDialog();

            // Reset the form owner
            this.Owner = formOwner;

            using (Initialization.Radii radii = new Initialization.Radii())
            {
                // Set the radius list items
                radii.FillField(homeRadius, null);
            }

            using (Initialization.Radii radii = new Initialization.Radii())
            {
                // Select the current radius in fsx.cfg
                radii.SelectCurrentRadius(homeRadius, null);
            }
        }
Beispiel #2
0
        public void InitializeOptions(bool DefaultClick)
        {
            using (IniFile iniFile = new IniFile())
            {
                if (!DefaultClick)
                {
                    /// <switch>current profile</switch>
                    iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                    iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");
                }
                else
                {
                    /// <switch>default profile</switch>
                    iniFile.IniPath = Application.StartupPath + @"\Resources\profile.resource";
                }

                #region General

                #region Run the Level of Detail Radius Editor when FSX starts

                switch (iniFile.ReadValue("OPTIONS.GENERAL", "runfsx"))
                {
                    case "1":
                        optionsGeneral0.Checked = true;
                        break;
                    case "0":
                        optionsGeneral0.Checked = false;
                        break;
                }

                #endregion

                #region Run the Level of Detail Radius Editor when you log onto this user account

                switch (iniFile.ReadValue("OPTIONS.GENERAL", "runwin"))
                {
                    case "1":
                        optionsGeneral1.Checked = true;
                        break;
                    case "0":
                        optionsGeneral1.Checked = false;
                        break;
                }

                #endregion

                #region Start this application minimized:

                switch (iniFile.ReadValue("OPTIONS.GENERAL", "minimize"))
                {
                    case "1":
                        optionsGeneral2.Checked = true;
                        optionsGeneral30.Enabled = true;
                        optionsGeneral31.Enabled = true;
                        break;
                    case "0":
                        optionsGeneral2.Checked = false;
                        optionsGeneral30.Enabled = false;
                        optionsGeneral31.Enabled = false;
                        break;
                }

                #endregion

                #region When started with FSX || Always

                switch (iniFile.ReadValue("OPTIONS.GENERAL", "sub"))
                {
                    case "1":
                        optionsGeneral31.Checked = true;
                        break;
                    case "0":
                        optionsGeneral30.Checked = true;
                        break;
                }

                #endregion

                #endregion

                #region Auto Change

                #region Enable auto-change

                switch (iniFile.ReadValue("OPTIONS.AUTO", "auto"))
                {
                    case "1":
                        optionsAuto0.Checked = true;
                        optionsAuto2.Enabled = true;
                        optionsAuto2Remove.Enabled = true;
                        optionsAuto2L.Enabled = true;
                        optionsAuto3.Enabled = true;
                        optionsAuto1.Enabled = true;
                        optionsAuto1L.Enabled = true;
                        break;
                    case "0":
                        optionsAuto0.Checked = false;
                        optionsAuto2.Enabled = false;
                        optionsAuto2Remove.Enabled = false;
                        optionsAuto2L.Enabled = false;
                        optionsAuto3.Enabled = false;
                        optionsAuto1.Enabled = false;
                        optionsAuto1L.Enabled = false;
                        break;
                }

                #endregion

                #region Set the dropdown items

                using (Initialization.Radii radii = new Initialization.Radii())
                {
                    // Fill the drop down box
                    radii.FillField(optionsAuto1, null);

                    if (iniFile.ReadValue("OPTIONS.AUTO", "radius") == "")
                    {
                        // Select the current radius in fsx.cfg
                        radii.SelectCurrentRadius(optionsAuto1, currentLodValue);
                    }
                    else
                    {
                        // Select the chosen radius
                        optionsAuto1.SelectedIndex = optionsAuto1.FindString(iniFile.ReadValue("OPTIONS.AUTO", "radius"), 0);
                    }
                }

                #endregion

                #region Application to run after change

                optionsAuto2.Text = iniFile.ReadValue("OPTIONS.AUTO", "application");

                #endregion

                #region Close this application after changes have been made

                switch (iniFile.ReadValue("OPTIONS.AUTO", "close"))
                {
                    case "1":
                        optionsAuto3.Checked = true;
                        break;
                    case "0":
                        optionsAuto3.Checked = false;
                        break;
                }

                #endregion

                #endregion

                #region Radii

                using (Initialization.Radii radii = new Initialization.Radii())
                {
                    // Fill the List Box with radii
                    radii.FillField(null, optionsRadiusR);
                }

                // Disable the function buttons
                optionsRadiusEdit.Enabled = false;
                optionsResolutionAdd.Enabled = false;
                optionsRadiusRemove.Enabled = false;

                #endregion
            }
        }
Beispiel #3
0
        /// <summary>
        /// Form Constructor
        /// </summary>
        public Main()
        {
            // Initialize the form
            InitializeComponent();

            // Assign the icon
            Icon = global::LODRadiusEditor.Properties.Resources.icon;

            #region Check for existing instanstance

            using (Initialization.InitMain initialize = new Initialization.InitMain())
            {
                // Check for an existing application instance
                if (!initialize.IsSingleInstance(Text))
                {
                    // Show a message informing the user that there's already an instance running
                    MessageBox.Show("Another instance of this application is already running.",
                        "Multiple application instances", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // Require an exit after initialization
                    requireExit = true;
                }
            }

            #endregion

            #region Check if FSX is running

            using (Initialization.InitMain initialize = new Initialization.InitMain())
            {
                if (initialize.IsProcessOpen("fsx"))
                {
                    // Flight Simulator is running
                    fsxIsRunning = true;
                }
            }

            #endregion

            #region Integrity Checks

            #region Check File Existence and Hash

            using (Integrity.Hash hash = new Integrity.Hash())
            {
                if (File.Exists(Application.StartupPath + @"\Resources\core.resource"))
                {
                    if (hash.Match(Application.StartupPath + @"\Resources\core.resource", "ED8A4A25A3F6366F484F32B06DE084D59FE2B4D6"))
                    {
                        // Get the file lines one by one
                        string[] lines = File.ReadAllLines(Application.StartupPath + @"\Resources\core.resource");

                        for (int i = 0; i < lines.Length; i++)
                        {
                            // Split the line
                            string[] splitLine = lines[i].Split(';');

                            if (File.Exists(Application.StartupPath + splitLine[0]))
                            {
                                if (!hash.Match(Application.StartupPath + splitLine[0], splitLine[1]))
                                {
                                    // Show an error
                                    MessageBox.Show("The file " + splitLine[0] + " has been modified or is corrupt. Please reinstall the Level of Detail Radius Editor.",
                                        "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                    // Require an exit
                                    requireExit = true;
                                }
                            }
                            else
                            {
                                // Show an error
                                MessageBox.Show("The file " + splitLine[0] + " could not be found. Please reinstall the Level of Detail Radius Editor.",
                                    "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                // Require an exit
                                requireExit = true;
                            }
                        }
                    }
                    else
                    {
                        // Show an error
                        MessageBox.Show("The file core.resource has been modified or is corrupt. Please reinstall the Level of Detail Radius Editor.",
                            "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        // Require an exit
                        requireExit = true;
                    }
                }
                else
                {
                    // Show an error
                    MessageBox.Show("The file core.resource could not be found. Please reinstall the Level of Detail Radius Editor.",
                        "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // Require an exit
                    requireExit = true;
                }
            }

            #endregion

            #region Check INI Files

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>current profile</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";

                if (!File.Exists(Application.StartupPath + @"\locations.ini"))
                {
                    // Copy the locations resource
                    File.Copy(Application.StartupPath + @"\Resources\locations.resource",
                        Application.StartupPath + @"\locations.ini", false);
                }

                if (!File.Exists(Application.StartupPath + iniFile.ReadValue("PROFILES", "0")))
                {
                    try
                    {
                        if (!Directory.Exists(Application.StartupPath + @"\Profiles\"))
                        {
                            Directory.CreateDirectory(Application.StartupPath + @"\Profiles\");
                        }

                        if (!File.Exists(Application.StartupPath + @"\Profiles\default.ini"))
                        {
                            // Copy the resource
                            File.Copy(Application.StartupPath + @"\Resources\profile.resource",
                                Application.StartupPath + @"\Profiles\default.ini", false);
                        }

                        // Write the new path value
                        iniFile.WriteValue("PROFILES", "0", @"\Profiles\default.ini");

                        // Success message
                        MessageBox.Show("The default profile specified in 'locations.ini' could not be found. A new one has been automatically generated.",
                            "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch
                    {
                        // Error message
                        MessageBox.Show("The default profile specified in 'locations.ini' could not be found and a new profile could not be generated. Please reinstall the Level of Detail Radius Editor.",
                            "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            #endregion

            #region Check INI Variables

            using (IniFile iniFile = new IniFile())
            {
                using (Integrity.Existence existence = new Integrity.Existence())
                {
                    /// <switch>current profile</switch>
                    iniFile.IniPath = Application.StartupPath + @"\locations.ini";

                    if (!Directory.Exists(iniFile.ReadValue("LOCATIONS", "exe")) &&
                        !Directory.Exists(iniFile.ReadValue("LOCATIONS", "cfg")) &&
                        !Directory.Exists(iniFile.ReadValue("LOCATIONS", "self")))
                    {
                        // Require a locations reset
                        iniFile.WriteValue("GENERAL", "reset", "1");
                    }
                }
            }

            #endregion

            #endregion

            #region Check For Reset Switch

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>locations.ini</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";

                if (iniFile.ReadValue("GENERAL", "reset") == "1")
                {
                    using (Locations.FSX fsxLocations = new Locations.FSX())
                    {
                        // Reset the location variables
                        iniFile.WriteValue("LOCATIONS", "exe", fsxLocations.GetExe());
                        iniFile.WriteValue("LOCATIONS", "cfg", fsxLocations.GetCfg());
                        iniFile.WriteValue("LOCATIONS", "self", Application.StartupPath);
                    }

                    try
                    {
                        if (File.Exists(iniFile.ReadValue("LOCATIONS", "cfg") + @"\exe.xml"))
                        {
                            string dateTime = DateTime.Now.ToString();
                            dateTime = dateTime.Replace("/", "");
                            dateTime = dateTime.Replace(" ", "_");
                            dateTime = dateTime.Replace(":", "");

                            if (!Directory.Exists(Application.StartupPath + @"\Backups\"))
                            {
                                Directory.CreateDirectory(Application.StartupPath + @"\Backups\");
                            }

                            // Make a copy of exe.xml
                            File.Copy(iniFile.ReadValue("LOCATIONS", "cfg") + @"\exe.xml", Application.StartupPath + @"\Backups\exe_xml_backup_" + dateTime + ".bak");
                        }
                    }
                    catch
                    {
                        // Show an error
                        MessageBox.Show("Unable to make a copy of exe.xml. The file has not been backed up.",
                            "Unable to backup exe.xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // Set the reset value back to 0
                    iniFile.WriteValue("GENERAL", "reset", "0");
                }
            }

            #endregion

            #region Set Main Radius

            using (Initialization.Radii radii = new Initialization.Radii())
            {
                // Set the radius list items
                radii.FillField(homeRadius, null);
            }

            #endregion

            #region Switch Main Radius To Current

            using (Initialization.Radii radii = new Initialization.Radii())
            {
                // Select the current radius in fsx.cfg
                radii.SelectCurrentRadius(homeRadius, null);

                // Set the current value
                string[] selectedItem = homeRadius.SelectedItem.ToString().Split(' ');
                currentValue = selectedItem[0];
                selectedItem = null;
            }

            #endregion

            #region Set Location Fields

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>locations.ini</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";

                // Set the location fields
                homeExePath.Text = iniFile.ReadValue("LOCATIONS", "exe");
                homeCfgPath.Text = iniFile.ReadValue("LOCATIONS", "cfg");
            }

            #endregion

            #region Check for exe.xml existence and entry

            using (IniFile iniFile = new IniFile())
            {
                ///<switch>locations.ini</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";

                using (ExeXml exeXml = new ExeXml(iniFile.ReadValue("LOCATIONS", "cfg") + @"\exe.xml"))
                {
                    ///<switch>current profile</switch>
                    iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");

                    if (iniFile.ReadValue("OPTIONS.GENERAL", "runfsx") == "1")
                    {
                        // Check the existence of the document
                        exeXml.CheckExistence("Level of Detail Radius Editor", false, Application.ExecutablePath);
                    }
                    else
                    {
                        // Check the existence of the document
                        exeXml.CheckExistence("Level of Detail Radius Editor", true, Application.ExecutablePath);
                    }
                }
            }

            #endregion

            #region Minimize the Form

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>current profile</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");

                if (iniFile.ReadValue("OPTIONS.GENERAL", "minimize") == "1")
                {
                    if (iniFile.ReadValue("OPTIONS.GENERAL", "sub") == "0")
                    {
                        if (fsxIsRunning)
                            this.WindowState = FormWindowState.Minimized;
                    }
                    else
                        this.WindowState = FormWindowState.Minimized;
                }
            }

            #endregion

            #region Auto Change

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>current profile</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");

                if (iniFile.ReadValue("OPTIONS.AUTO", "auto") == "1")
                {
                    // Get the auto radius
                    string autoResolution = iniFile.ReadValue("OPTIONS.AUTO", "radius");

                    if (autoResolution != "")
                    {
                        /// <switch>fsx.cfg</switch>
                        iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                        iniFile.IniPath = iniFile.ReadValue("LOCATIONS", "cfg") + @"\fsx.cfg";

                        using (Format format = new Format())
                        {
                            // Set the Level of Detail Radius value in fsx.cfg
                            iniFile.WriteValue("TERRAIN", "LOD_RADIUS", format.Radius(autoResolution));
                        }

                        /// <switch>current profile</switch>
                        iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                        iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");
                    }
                    else
                    {
                        // Show an error informing the user that the LOD Radius value has not been set
                        MessageBox.Show("Unable to set a null radius. The Level of Detail Radius value has not been changed in fsx.cfg.",
                            "Null radius", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (iniFile.ReadValue("OPTIONS.AUTO", "application") != "")
                    {
                        try
                        {
                            // Try to start the specified process
                            System.Diagnostics.Process.Start(iniFile.ReadValue("OPTIONS.AUTO", "application"));
                        }
                        catch
                        {
                            // Show an error informing the user that their application could not be started
                            MessageBox.Show("Unable to run the post auto change application you specified.",
                                "External process error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    if (iniFile.ReadValue("OPTIONS.AUTO", "close") == "1")
                    {
                        // Set the seconds for the timer
                        autoSeconds = Int32.Parse(iniFile.ReadValue("MISCELLANEOUS", "autotime"));

                        // Require an exit
                        autoCounter = 0;
                        autoChangeExit = true;
                    }
                    else
                    {
                        // Make the auto counter negative
                        autoCounter = -1;
                    }
                }
            }

            #endregion

            #region Update switch check

            using (IniFile iniFile = new IniFile())
            {
                /// <switch>current profile</switch>
                iniFile.IniPath = Application.StartupPath + @"\locations.ini";
                iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0");
            }

            #endregion
        }