Beispiel #1
0
        /// <summary>
        /// Form Constructor
        /// </summary>
        public Main()
        {
            InitializeComponent();
            Icon = global::TextureMaxLoadEditor.Properties.Resources.icon;

            #region Check for existing instanstance

            using (InitMain initialize = new InitMain())
            {
                if (!initialize.IsSingleInstance(Text))
                {
                    MessageBox.Show("Another instance of this application is already running.",
                        "Multiple application instances", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    requireExit = true;
                }
            }

            #endregion

            #region Check if FSX is running

            using (InitMain initialize = new InitMain())
            {
                if (initialize.IsProcessOpen("fsx"))
                {
                    fsxIsRunning = true;
                }
            }

            #endregion

            #region Integrity Checks

            #region Check File Existence and Hash

            using (Hash hash = new Hash())
            {
                if (File.Exists(Application.StartupPath + @"\Resources\core.resource"))
                {
                    if (hash.Match(Application.StartupPath + @"\Resources\core.resource", "DDAE1DD174117AC9ABADCBA70323590F77F67513"))
                    {
                        // 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 Texture Max Load 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 Texture Max Load 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 Texture Max Load 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 Texture Max Load 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 Texture Max Load Editor.",
                            "Integrity Check", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            #endregion

            #region Check INI Variables

            using (IniFile iniFile = new IniFile())
            {
                using (Existence existence = new 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 Resolutions

            using (Resolutions resolutions = new Resolutions())
            {
                // Set the resolution list items
                resolutions.FillField(homeResolution, 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 Switch Main Resolution To Current

            using (Resolutions resolutions = new Resolutions())
            {
                // Select the current resolution in fsx.cfg
                resolutions.SelectCurrentResolution(homeResolution, null);

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

            #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("Texture Max Load Editor", false, Application.ExecutablePath);
                    }
                    else
                    {
                        // Check the existence of the document
                        exeXml.CheckExistence("Texture Max Load 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 resolution
                    string autoResolution = iniFile.ReadValue("OPTIONS.AUTO", "resolution");

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

                        // Set the Texture Max Load Value in fsx.cfg
                        iniFile.WriteValue("GRAPHICS", "TEXTURE_MAX_LOAD", 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 TML value has not been set
                        MessageBox.Show("Unable to set a null resolution. The Texture Max Load value has not been changed in fsx.cfg.",
                            "Null resolution", 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
        }
Beispiel #2
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 (Resolutions resolutions = new Resolutions())
            {
                // Set the resolution list items
                resolutions.FillField(homeResolution, null);
            }

            using (Resolutions resolutions = new Resolutions())
            {
                // Select the current resolution in fsx.cfg
                resolutions.SelectCurrentResolution(homeResolution, null);
            }
        }
Beispiel #3
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 Texture Max Load 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 Texture Max Load 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 (Resolutions resolutions = new Resolutions())
                {
                    // Fill the drop down box
                    resolutions.FillField(optionsAuto1, null);

                    if (iniFile.ReadValue("OPTIONS.AUTO", "resolution") == "")
                    {
                        // Select the current resolution in fsx.cfg
                        resolutions.SelectCurrentResolution(optionsAuto1, currentTmlValue);
                    }
                    else
                    {
                        // Select the chosen resolution
                        optionsAuto1.SelectedIndex = optionsAuto1.FindString(iniFile.ReadValue("OPTIONS.AUTO", "resolution"), 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 Resolutions

                using (Resolutions resolutions = new Resolutions())
                {
                    // Fill the List Box with resolutions
                    resolutions.FillField(null, optionsResolutionR);
                }

                // Disable the function buttons
                optionsResolutionEdit.Enabled = false;
                optionsResolutionAdd.Enabled = false;
                optionsResolutionRemove.Enabled = false;

                #endregion
            }
        }