OpenBve.Options.SaveOptions C# (CSharp) Méthode

SaveOptions() static private méthode

static private SaveOptions ( ) : void
Résultat void
        internal static void SaveOptions()
        {
            string assemblyFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string optionsFolder = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(assemblyFolder, "UserData"),"Settings");
            string configFile = OpenBveApi.Path.CombineFile(optionsFolder, "options_rv.cfg");
            try
            {
                //Delete original options file
                if (System.IO.File.Exists(configFile))
                {
                    System.IO.File.Delete(configFile);
                }
                if (!System.IO.Directory.Exists(optionsFolder))
                {
                    Directory.CreateDirectory(optionsFolder);
                }
                using(StreamWriter sw = new StreamWriter(configFile))
                {
                    sw.WriteLine("; Options");
                    sw.WriteLine("; =======");
                    sw.WriteLine("; This file was automatically generated. Please modify only if you know what you're doing.");
                    sw.WriteLine("; Route Viewer specific options file");
                    sw.WriteLine();
                    sw.WriteLine("[display]");
                    sw.WriteLine("vsync = " + Interface.CurrentOptions.VerticalSynchronization);
                    sw.WriteLine("windowWidth = " + Renderer.ScreenWidth);
                    sw.WriteLine("windowHeight = " + Renderer.ScreenHeight);
                    sw.WriteLine();
                    sw.WriteLine("[quality]");
                    sw.WriteLine("interpolation = " + Interface.CurrentOptions.Interpolation);
                    sw.WriteLine("anisotropicfilteringlevel = " + Interface.CurrentOptions.AnisotropicFilteringLevel);
                    sw.WriteLine("antialiasinglevel = " + Interface.CurrentOptions.AntialiasingLevel);
                    sw.WriteLine("transparencymode = " + Interface.CurrentOptions.TransparencyMode);
					sw.WriteLine("[loading]");
					sw.WriteLine("showlogo = " + Interface.CurrentOptions.LoadingLogo.ToString());
					sw.WriteLine("showprogressbar = " + Interface.CurrentOptions.LoadingProgressBar.ToString());
					sw.WriteLine("showbackground = " + Interface.CurrentOptions.LoadingBackground.ToString());
				}
            }
            catch
            {
                MessageBox.Show("An error occured whilst saving the options to disk." + System.Environment.NewLine +
                                "Please check you have write permission.");
            }
        }
    }

Usage Example

Exemple #1
0
        private void CloseButton_Click(object sender, EventArgs e)
        {
            InterpolationMode previousInterpolationMode = Interface.CurrentOptions.Interpolation;
            int previousAntialasingLevel = Interface.CurrentOptions.AntiAliasingLevel;
            int previousAnsiotropicLevel = Interface.CurrentOptions.AnisotropicFilteringLevel;

            //Interpolation mode
            switch (InterpolationMode.SelectedIndex)
            {
            case 0:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.NearestNeighbor;
                break;

            case 1:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.Bilinear;
                break;

            case 2:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.NearestNeighborMipmapped;
                break;

            case 3:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.BilinearMipmapped;
                break;

            case 4:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.TrilinearMipmapped;
                break;

            case 5:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.InterpolationMode.AnisotropicFiltering;
                break;
            }

            //Ansiotropic filtering level
            Interface.CurrentOptions.AnisotropicFilteringLevel = (int)AnsiotropicLevel.Value;
            //Antialiasing level
            Interface.CurrentOptions.AntiAliasingLevel = (int)AntialiasingLevel.Value;
            if (Interface.CurrentOptions.AntiAliasingLevel != previousAntialasingLevel)
            {
                Program.currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel);
            }

            //Transparency quality
            switch (TransparencyQuality.SelectedIndex)
            {
            case 0:
                Interface.CurrentOptions.TransparencyMode = TransparencyMode.Performance;
                break;

            default:
                Interface.CurrentOptions.TransparencyMode = TransparencyMode.Quality;
                break;
            }

            //Set width and height
            if (Program.Renderer.Screen.Width != width.Value || Program.Renderer.Screen.Height != height.Value)
            {
                if (width.Value >= 300)
                {
                    Program.Renderer.Screen.Width   = (int)width.Value;
                    Program.currentGameWindow.Width = (int)width.Value;
                }

                if (height.Value >= 300)
                {
                    Program.Renderer.Screen.Height   = (int)height.Value;
                    Program.currentGameWindow.Height = (int)height.Value;
                }

                Program.Renderer.UpdateViewport();
            }

            Interface.CurrentOptions.CurrentXParser   = (XParsers)comboBoxNewXParser.SelectedIndex;
            Interface.CurrentOptions.CurrentObjParser = (ObjParsers)comboBoxNewObjParser.SelectedIndex;
            for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
            {
                if (Program.CurrentHost.Plugins[i].Object != null)
                {
                    Program.CurrentHost.Plugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentXParser);
                    Program.CurrentHost.Plugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentObjParser);
                }
            }

            Interface.CurrentOptions.ObjectOptimizationMode = (ObjectOptimizationMode)comboBoxOptimizeObjects.SelectedIndex;

            Options.SaveOptions();
            Program.RefreshObjects();
            this.Close();
        }
All Usage Examples Of OpenBve.Options::SaveOptions