/// <summary> /// Fills a field with the resolutions found in the default profile /// </summary> /// <param name="comboBox">The ComboBox to fill</param> /// <param name="listBox">The ListBox to fill</param> public void FillField(ComboBox comboBox, [Optional, DefaultParameterValue(null)] ListBox listBox) { int counter = 0; string iniValue; string[] iniSplit; if (listBox == null && comboBox != null) comboBox.Items.Clear(); else if (listBox != null && comboBox == null) listBox.Items.Clear(); using (IniFile iniFile = new IniFile()) { iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); while (counter != -1) { iniValue = iniFile.ReadValue("RESOLUTIONS", counter.ToString()); if (iniValue != "") { iniSplit = iniValue.Split(','); if (listBox == null && comboBox != null) comboBox.Items.Add(iniSplit[0].ToString() + " (" + iniSplit[1] + ")"); else if (listBox != null && comboBox == null) listBox.Items.Add(iniSplit[0].ToString() + " (" + iniSplit[1] + ")"); counter++; } else { counter = -1; } } } }
void LoadSettings() { IniFile pathtosettingsini = new IniFile(HttpContext.Current.Server.MapPath("/") + "settings.ini"); IniFile ini = new IniFile(pathtosettingsini.ReadValue("SETTINGS","PATH")); core.system.settings.GENERAL.DOMAIN = ini.ReadValue("GENERAL", "DOMAIN"); core.system.settings.ARCHITECT.MASTER_PAGE_PATH = IniPathFix(ini.ReadValue("ARCHITECT", "MASTER_PAGE_PATH")); core.system.settings.ARCHITECT.CONTENT_PAGE_PATH = IniPathFix(ini.ReadValue("ARCHITECT", "CONTENT_PAGE_PATH")); core.system.settings.ARCHITECT.CSS_PATH = IniPathFix(ini.ReadValue("ARCHITECT", "CSS_PATH")); core.system.settings.ARCHITECT.JS_PATH = IniPathFix(ini.ReadValue("ARCHITECT", "JS_PATH")); core.system.settings.ARCHITECT.STATUS_PAGE_PATH = IniPathFix(ini.ReadValue("ARCHITECT", "STATUS_PAGE_PATH")); core.system.settings.DATABASE.DOMAIN = ini.ReadValue("DATABASE", "DOMAIN"); core.system.settings.DATABASE.PORT = ini.ReadValue("DATABASE", "PORT"); core.system.settings.DATABASE.USERNAME = ini.ReadValue("DATABASE", "USERNAME"); core.system.settings.DATABASE.PASSWORD = ini.ReadValue("DATABASE", "PASSWORD"); core.system.settings.DATABASE.DATABASE_NAME = ini.ReadValue("DATABASE", "DATABASE_NAME"); }
/// <summary> /// Fills a field with the radii found in the default profile /// </summary> /// <param name="comboBox">The ComboBox to fill</param> /// <param name="listBox">The ListBox to fill</param> public void FillField(ComboBox comboBox, [Optional, DefaultParameterValue(null)] ListBox listBox) { // Method vars int counter = 0; string iniValue; string[] iniSplit; // Clear the current items if (listBox == null && comboBox != null) comboBox.Items.Clear(); else if (listBox != null && comboBox == null) listBox.Items.Clear(); using (IniFile iniFile = new IniFile()) { /// <switch>current profile</switch> iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); while (counter != -1) { // Read the radius value iniValue = iniFile.ReadValue("RADII", counter.ToString()); if (iniValue != "") { // Split the radius string iniSplit = iniValue.Split(','); // Add the new item to the list if (listBox == null && comboBox != null) comboBox.Items.Add(iniSplit[0].ToString() + " (" + iniSplit[1] + ")"); else if (listBox != null && comboBox == null) listBox.Items.Add(iniSplit[0].ToString() + " (" + iniSplit[1] + ")"); // Increase the counter counter++; } else { // Break out of the loop counter = -1; } } } }
/// <summary> /// Sets the radius drop down selected item to the one that is set in fsx.cfg /// </summary> public void SelectCurrentRadius(ComboBox comboBox, [Optional]string radius) { // Method variables string formattedRadius; using (IniFile iniFile = new IniFile()) { /// <switch>fsx.cfg</switch> iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = iniFile.ReadValue("LOCATIONS", "cfg") + @"\fsx.cfg"; if (radius != null) { // Format the radius using (Format format = new Format()) formattedRadius = format.Compact(radius); // Set the current selected item comboBox.SelectedIndex = comboBox.FindString(formattedRadius, -1); // Set the index to the first if (comboBox.SelectedIndex == -1) comboBox.SelectedIndex = 0; } else { using (Format format = new Format()) { // Set the radius to the current one in fsx.cfg comboBox.SelectedIndex = comboBox.FindString(format.Compact(iniFile.ReadValue("TERRAIN", "LOD_RADIUS")), -1); // Set the index to the first if (comboBox.SelectedIndex == -1) comboBox.SelectedIndex = 0; } } } }
/// <summary> /// Sets the resolution drop down selected item to the one that is set in fsx.cfg /// </summary> public void SelectCurrentResolution(ComboBox comboBox, [Optional]string resolution) { using (IniFile iniFile = new IniFile()) { iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = iniFile.ReadValue("LOCATIONS", "cfg") + @"\fsx.cfg"; if (resolution != null) { comboBox.SelectedIndex = comboBox.FindString(resolution, -1); if (comboBox.SelectedIndex == -1) comboBox.SelectedIndex = 0; } else { comboBox.SelectedIndex = comboBox.FindString(iniFile.ReadValue("GRAPHICS", "TEXTURE_MAX_LOAD"), -1); if (comboBox.SelectedIndex == -1) comboBox.SelectedIndex = 0; } } }
/// <summary> /// Disposes of the form after saving the changes made /// </summary> private void saveButton_Click(object sender, EventArgs e) { if (optionsResolutionAdd.Text == "Save") { // Show the dialog DialogResult result = MessageBox.Show("You did not save the radius you were editing. Are you sure you want to continue?", "Radius not saved", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == System.Windows.Forms.DialogResult.No) { // Quit the save process return; } } #region Save Settings using (IniFile iniFile = new IniFile()) { // Switch: Default profile iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); #region General #region Run the LODRE when FSX starts if (optionsGeneral0.Checked) { // Write the setting value iniFile.WriteValue("OPTIONS.GENERAL", "runfsx", "1"); ///<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 + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); // Check the existence of the document exeXml.CheckExistence("Level of Detail Radius Editor", false, Application.ExecutablePath); } } else { // Write the setting value iniFile.WriteValue("OPTIONS.GENERAL", "runfsx", "0"); ///<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 + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); // Check the existence of the document exeXml.CheckExistence("Level of Detail Radius Editor", true, Application.ExecutablePath); } } #endregion #region Run the LODRE when you log onto this user account // The full path to the application shortcut string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Level of Detail Radius Editor.lnk"; if (optionsGeneral1.Checked) { iniFile.WriteValue("OPTIONS.GENERAL", "runwin", "1"); if (!System.IO.File.Exists(shortcutPath)) { // Create a new shortcut WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut appShortcut; appShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath); appShortcut.TargetPath = Application.ExecutablePath; appShortcut.Description = "Level of Detail Radius Editor"; appShortcut.Save(); } } else { iniFile.WriteValue("OPTIONS.GENERAL", "runwin", "0"); if (System.IO.File.Exists(shortcutPath)) { // Delete the shortcut System.IO.File.Delete(shortcutPath); } } // Null the path string shortcutPath = null; #endregion #region Start this application minimized: if (optionsGeneral2.Checked) iniFile.WriteValue("OPTIONS.GENERAL", "minimize", "1"); else iniFile.WriteValue("OPTIONS.GENERAL", "minimize", "0"); #endregion #region When started with FSX || Always if (optionsGeneral30.Checked) iniFile.WriteValue("OPTIONS.GENERAL", "sub", "0"); else iniFile.WriteValue("OPTIONS.GENERAL", "sub", "1"); #endregion #endregion #region Auto Change #region Auto Change enabled if (optionsAuto0.Checked) { iniFile.WriteValue("OPTIONS.AUTO", "auto", "1"); } else { iniFile.WriteValue("OPTIONS.AUTO", "auto", "0"); } #endregion #region Auto change radius try { string[] selectedAutoRes = optionsAuto1.SelectedItem.ToString().Split(' '); iniFile.WriteValue("OPTIONS.AUTO", "radius", selectedAutoRes[0]); } catch { MessageBox.Show("Unable to set the Auto Change radius selected. An item was either not selected or in the wrong format.", "Unable To Save Auto Change Settings", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion #region Application to run after change iniFile.WriteValue("OPTIONS.AUTO", "application", optionsAuto2.Text.ToString()); #endregion #region Exit after radius change if (optionsAuto3.Checked) { iniFile.WriteValue("OPTIONS.AUTO", "close", "1"); } else { iniFile.WriteValue("OPTIONS.AUTO", "close", "0"); } #endregion #endregion #region Resolutions string trimmedItem; int counter = 0; while (iniFile.ReadValue("RADII", counter.ToString()) != "") { iniFile.WriteValue("RADII", counter.ToString(), ""); counter++; } counter = 0; foreach (string item in optionsRadiusR.Items) { trimmedItem = item; trimmedItem = trimmedItem.Replace(" (", ","); trimmedItem = trimmedItem.TrimEnd(')'); iniFile.WriteValue("RADII", counter.ToString(), trimmedItem); counter++; } #endregion } #endregion // Dispose of the form this.Dispose(); }
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 } }
/// <summary> /// Shows the full path to the executable via a tool tip /// </summary> private void optionsAuto2_MouseHover(object sender, EventArgs e) { using (IniFile iniFile = new IniFile()) { // Switch: Default profile iniFile.IniPath = Application.StartupPath + @"\locations.ini"; iniFile.IniPath = Application.StartupPath + iniFile.ReadValue("PROFILES", "0"); if (iniFile.ReadValue("MISCELLANEOUS", "tooltips") == "1") { // Show the tool tip optionsAutoToolTip.Show(optionsAuto2.Text, optionsAuto2); } } }