internal static void LoadOptions()
{
CurrentOptions = new Options();
CultureInfo Culture = CultureInfo.InvariantCulture;
string File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "options.cfg");
if (System.IO.File.Exists(File))
{
// load options
string[] Lines = System.IO.File.ReadAllLines(File, new System.Text.UTF8Encoding());
string Section = "";
for (int i = 0; i < Lines.Length; i++)
{
Lines[i] = Lines[i].Trim();
if (Lines[i].Length != 0 && !Lines[i].StartsWith(";", StringComparison.OrdinalIgnoreCase))
{
if (Lines[i].StartsWith("[", StringComparison.Ordinal) & Lines[i].EndsWith("]", StringComparison.Ordinal))
{
Section = Lines[i].Substring(1, Lines[i].Length - 2).Trim().ToLowerInvariant();
}
else
{
int j = Lines[i].IndexOf("=", StringComparison.OrdinalIgnoreCase);
string Key, Value;
if (j >= 0)
{
Key = Lines[i].Substring(0, j).TrimEnd().ToLowerInvariant();
Value = Lines[i].Substring(j + 1).TrimStart();
}
else
{
Key = "";
Value = Lines[i];
}
switch (Section)
{
case "language":
switch (Key)
{
case "code":
Interface.CurrentOptions.LanguageCode = Value.Length != 0 ? Value : "en-US";
break;
} break;
case "interface":
switch (Key)
{
case "folder":
Interface.CurrentOptions.UserInterfaceFolder = Value.Length != 0 ? Value : "Default";
break;
case "timetablemode":
switch (Value.ToLowerInvariant())
{
case "none":
Interface.CurrentOptions.TimeTableStyle = TimeTableMode.None;
break;
case "default":
Interface.CurrentOptions.TimeTableStyle = TimeTableMode.Default;
break;
case "autogenerated":
Interface.CurrentOptions.TimeTableStyle = TimeTableMode.AutoGenerated;
break;
case "prefercustom":
Interface.CurrentOptions.TimeTableStyle = TimeTableMode.PreferCustom;
break;
}
break;
} break;
case "display":
switch (Key)
{
case "prefernativebackend":
Interface.CurrentOptions.PreferNativeBackend = string.Compare(Value, "true", StringComparison.OrdinalIgnoreCase) == 0;
break;
case "mode":
Interface.CurrentOptions.FullscreenMode = string.Compare(Value, "fullscreen", StringComparison.OrdinalIgnoreCase) == 0;
break;
case "vsync":
Interface.CurrentOptions.VerticalSynchronization = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "windowwidth":
{
int a;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
a = 960;
}
Interface.CurrentOptions.WindowWidth = a;
} break;
case "windowheight":
{
int a;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
a = 600;
}
Interface.CurrentOptions.WindowHeight = a;
} break;
case "fullscreenwidth":
{
int a;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
a = 1024;
}
Interface.CurrentOptions.FullscreenWidth = a;
} break;
case "fullscreenheight":
{
int a;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
a = 768;
}
Interface.CurrentOptions.FullscreenHeight = a;
} break;
case "fullscreenbits":
{
int a;
if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
a = 32;
}
Interface.CurrentOptions.FullscreenBits = a;
} break;
case "mainmenuwidth":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.MainMenuWidth = a;
} break;
case "mainmenuheight":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.MainMenuHeight = a;
} break;
case "disabledisplaylists":
Interface.CurrentOptions.DisableDisplayLists = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "loadinadvance":
Interface.CurrentOptions.LoadInAdvance = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "unloadtextures":
Interface.CurrentOptions.UnloadUnusedTextures = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "notextureresize":
Interface.CurrentOptions.NoTextureResize = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
} break;
case "quality":
switch (Key)
{
case "interpolation":
switch (Value.ToLowerInvariant())
{
case "nearestneighbor": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.NearestNeighbor; break;
case "bilinear": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.Bilinear; break;
case "nearestneighbormipmapped": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.NearestNeighborMipmapped; break;
case "bilinearmipmapped": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.BilinearMipmapped; break;
case "trilinearmipmapped": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.TrilinearMipmapped; break;
case "anisotropicfiltering": Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.AnisotropicFiltering; break;
default: Interface.CurrentOptions.Interpolation = Interface.InterpolationMode.BilinearMipmapped; break;
} break;
case "anisotropicfilteringlevel":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.AnisotropicFilteringLevel = a;
} break;
case "anisotropicfilteringmaximum":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.AnisotropicFilteringMaximum = a;
} break;
case "antialiasinglevel":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.AntiAliasingLevel = a;
} break;
case "transparencymode":
switch (Value.ToLowerInvariant())
{
case "sharp": Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Performance; break;
case "smooth": Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Quality; break;
default:
{
int a;
if (int.TryParse(Value, NumberStyles.Integer, Culture, out a))
{
Interface.CurrentOptions.TransparencyMode = (Renderer.TransparencyMode)a;
}
else
{
Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Quality;
}
break;
}
} break;
case "viewingdistance":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.ViewingDistance = a;
} break;
case "motionblur":
switch (Value.ToLowerInvariant())
{
case "low": Interface.CurrentOptions.MotionBlur = MotionBlurMode.Low; break;
case "medium": Interface.CurrentOptions.MotionBlur = MotionBlurMode.Medium; break;
case "high": Interface.CurrentOptions.MotionBlur = MotionBlurMode.High; break;
default: Interface.CurrentOptions.MotionBlur = MotionBlurMode.None; break;
} break;
} break;
case "objectoptimization":
switch (Key)
{
case "basicthreshold":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.ObjectOptimizationBasicThreshold = a;
} break;
case "fullthreshold":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.ObjectOptimizationFullThreshold = a;
} break;
} break;
case "simulation":
switch (Key)
{
case "toppling":
Interface.CurrentOptions.Toppling = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "collisions":
Interface.CurrentOptions.Collisions = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "derailments":
Interface.CurrentOptions.Derailments = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "blackbox":
Interface.CurrentOptions.BlackBox = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "mode":
switch (Value.ToLowerInvariant())
{
case "arcade": Interface.CurrentOptions.GameMode = Interface.GameMode.Arcade; break;
case "normal": Interface.CurrentOptions.GameMode = Interface.GameMode.Normal; break;
case "expert": Interface.CurrentOptions.GameMode = Interface.GameMode.Expert; break;
default: Interface.CurrentOptions.GameMode = Interface.GameMode.Normal; break;
} break;
case "acceleratedtimefactor":
int tf;
int.TryParse(Value, NumberStyles.Integer, Culture, out tf);
if (tf <= 0)
{
tf = 5;
}
Interface.CurrentOptions.TimeAccelerationFactor = tf;
break;
} break;
case "controls":
switch (Key)
{
case "usejoysticks":
Interface.CurrentOptions.UseJoysticks = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "joystickaxiseb":
Interface.CurrentOptions.AllowAxisEB = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "joystickaxisthreshold":
{
double a;
double.TryParse(Value, NumberStyles.Float, Culture, out a);
Interface.CurrentOptions.JoystickAxisThreshold = a;
} break;
case "keyrepeatdelay":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
if (a <= 0) a = 500;
Interface.CurrentOptions.KeyRepeatDelay = 0.001 * (double)a;
} break;
case "keyrepeatinterval":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
if (a <= 0) a = 100;
Interface.CurrentOptions.KeyRepeatInterval = 0.001 * (double)a;
} break;
} break;
case "sound":
switch (Key)
{
case "model":
switch (Value.ToLowerInvariant())
{
case "linear": Interface.CurrentOptions.SoundModel = Sounds.SoundModels.Linear; break;
default: Interface.CurrentOptions.SoundModel = Sounds.SoundModels.Inverse; break;
}
break;
case "range":
switch (Value.ToLowerInvariant())
{
case "low": Interface.CurrentOptions.SoundRange = SoundRange.Low; break;
case "medium": Interface.CurrentOptions.SoundRange = SoundRange.Medium; break;
case "high": Interface.CurrentOptions.SoundRange = SoundRange.High; break;
default: Interface.CurrentOptions.SoundRange = SoundRange.Low; break;
}
break;
case "number":
{
int a;
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.SoundNumber = a < 16 ? 16 : a;
} break;
} break;
case "verbosity":
switch (Key)
{
case "showwarningmessages":
Interface.CurrentOptions.ShowWarningMessages = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "showerrormessages":
Interface.CurrentOptions.ShowErrorMessages = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "debuglog":
Program.GenerateDebugLogging = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
} break;
case "folders":
switch (Key)
{
case "route":
Interface.CurrentOptions.RouteFolder = Value;
break;
case "train":
Interface.CurrentOptions.TrainFolder = Value;
break;
} break;
case "proxy":
switch (Key)
{
case "url":
Interface.CurrentOptions.ProxyUrl = Value;
break;
case "username":
Interface.CurrentOptions.ProxyUserName = Value;
break;
case "password":
Interface.CurrentOptions.ProxyPassword = Value;
break;
} break;
case "packages":
switch (Key)
{
case "compression":
switch (Value.ToLowerInvariant())
{
case "zip":
Interface.CurrentOptions.packageCompressionType = CompressionType.Zip;
break;
case "bzip":
Interface.CurrentOptions.packageCompressionType = CompressionType.BZ2;
break;
case "gzip":
Interface.CurrentOptions.packageCompressionType = CompressionType.TarGZ;
break;
}
break;
} break;
case "recentlyusedroutes":
{
int n = Interface.CurrentOptions.RecentlyUsedRoutes.Length;
Array.Resize<string>(ref Interface.CurrentOptions.RecentlyUsedRoutes, n + 1);
Interface.CurrentOptions.RecentlyUsedRoutes[n] = Value;
} break;
case "recentlyusedtrains":
{
int n = Interface.CurrentOptions.RecentlyUsedTrains.Length;
Array.Resize<string>(ref Interface.CurrentOptions.RecentlyUsedTrains, n + 1);
Interface.CurrentOptions.RecentlyUsedTrains[n] = Value;
} break;
case "routeencodings":
{
int a = System.Text.Encoding.UTF8.CodePage;
int.TryParse(Key, NumberStyles.Integer, Culture, out a);
int n = Interface.CurrentOptions.RouteEncodings.Length;
Array.Resize<TextEncoding.EncodingValue>(ref Interface.CurrentOptions.RouteEncodings, n + 1);
Interface.CurrentOptions.RouteEncodings[n].Codepage = a;
Interface.CurrentOptions.RouteEncodings[n].Value = Value;
} break;
case "trainencodings":
{
int a = System.Text.Encoding.UTF8.CodePage;
int.TryParse(Key, NumberStyles.Integer, Culture, out a);
int n = Interface.CurrentOptions.TrainEncodings.Length;
Array.Resize<TextEncoding.EncodingValue>(ref Interface.CurrentOptions.TrainEncodings, n + 1);
Interface.CurrentOptions.TrainEncodings[n].Codepage = a;
Interface.CurrentOptions.TrainEncodings[n].Value = Value;
} break;
}
}
}
}
}
else
{
// file not found
string Code = CultureInfo.CurrentUICulture.Name;
if (string.IsNullOrEmpty(Code)) Code = "en-US";
File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Languages"), Code + ".cfg");
if (System.IO.File.Exists(File))
{
CurrentOptions.LanguageCode = Code;
}
else
{
try
{
int i = Code.IndexOf("-", StringComparison.Ordinal);
if (i > 0)
{
Code = Code.Substring(0, i);
File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Languages"), Code + ".cfg");
if (System.IO.File.Exists(File))
{
CurrentOptions.LanguageCode = Code;
}
}
}
catch
{
CurrentOptions.LanguageCode = "en-US";
}
}
}
}
internal static void SaveOptions()