private void formMain_FormClosing(object sender, FormClosingEventArgs e)
{
Interface.CurrentOptions.LanguageCode = CurrentLanguageCode;
Interface.CurrentOptions.FullscreenMode = radiobuttonFullscreen.Checked;
Interface.CurrentOptions.VerticalSynchronization = comboboxVSync.SelectedIndex == 1;
Interface.CurrentOptions.WindowWidth = (int)Math.Round(updownWindowWidth.Value);
Interface.CurrentOptions.WindowHeight = (int)Math.Round(updownWindowHeight.Value);
Interface.CurrentOptions.FullscreenWidth = (int)Math.Round(updownFullscreenWidth.Value);
Interface.CurrentOptions.FullscreenHeight = (int)Math.Round(updownFullscreenHeight.Value);
Interface.CurrentOptions.FullscreenBits = comboboxFullscreenBits.SelectedIndex == 0 ? 16 : 32;
Interface.CurrentOptions.Interpolation = (Interface.InterpolationMode)comboboxInterpolation.SelectedIndex;
Interface.CurrentOptions.AnisotropicFilteringLevel = (int)Math.Round(updownAnisotropic.Value);
Interface.CurrentOptions.AntiAliasingLevel = (int)Math.Round(updownAntiAliasing.Value);
Interface.CurrentOptions.TransparencyMode = (Renderer.TransparencyMode)trackbarTransparency.Value;
Interface.CurrentOptions.ViewingDistance = (int)Math.Round(updownDistance.Value);
Interface.CurrentOptions.MotionBlur = (Interface.MotionBlurMode)comboboxMotionBlur.SelectedIndex;
Interface.CurrentOptions.Toppling = checkboxToppling.Checked;
Interface.CurrentOptions.Collisions = checkboxCollisions.Checked;
Interface.CurrentOptions.Derailments = checkboxDerailments.Checked;
Interface.CurrentOptions.LoadInAdvance = checkBoxLoadInAdvance.Checked;
Interface.CurrentOptions.UnloadUnusedTextures = checkBoxUnloadTextures.Checked;
Interface.CurrentOptions.DisableDisplayLists = checkBoxDisableDisplayLists.Checked;
Interface.CurrentOptions.GameMode = (Interface.GameMode)comboboxMode.SelectedIndex;
Interface.CurrentOptions.BlackBox = checkboxBlackBox.Checked;
Interface.CurrentOptions.UseJoysticks = checkboxJoysticksUsed.Checked;
Interface.CurrentOptions.AllowAxisEB = checkBoxEBAxis.Checked;
Interface.CurrentOptions.JoystickAxisThreshold = ((double)trackbarJoystickAxisThreshold.Value - (double)trackbarJoystickAxisThreshold.Minimum) / (double)(trackbarJoystickAxisThreshold.Maximum - trackbarJoystickAxisThreshold.Minimum);
Interface.CurrentOptions.SoundNumber = (int)Math.Round(updownSoundNumber.Value);
Interface.CurrentOptions.ShowWarningMessages = checkboxWarningMessages.Checked;
Interface.CurrentOptions.ShowErrorMessages = checkboxErrorMessages.Checked;
Interface.CurrentOptions.RouteFolder = textboxRouteFolder.Text;
Interface.CurrentOptions.TrainFolder = textboxTrainFolder.Text;
Interface.CurrentOptions.MainMenuWidth = this.WindowState == FormWindowState.Maximized ? -1 : this.Size.Width;
Interface.CurrentOptions.MainMenuHeight = this.WindowState == FormWindowState.Maximized ? -1 : this.Size.Height;
if (Result.Start)
{
// recently used routes
if (Interface.CurrentOptions.RecentlyUsedLimit > 0)
{
int i; for (i = 0; i < Interface.CurrentOptions.RecentlyUsedRoutes.Length; i++)
{
if (string.Compare(Result.RouteFile, Interface.CurrentOptions.RecentlyUsedRoutes[i], StringComparison.OrdinalIgnoreCase) == 0)
{
break;
}
}
if (i == Interface.CurrentOptions.RecentlyUsedRoutes.Length)
{
if (Interface.CurrentOptions.RecentlyUsedRoutes.Length < Interface.CurrentOptions.RecentlyUsedLimit)
{
Array.Resize<string>(ref Interface.CurrentOptions.RecentlyUsedRoutes, i + 1);
}
else {
i--;
}
}
for (int j = i; j > 0; j--)
{
Interface.CurrentOptions.RecentlyUsedRoutes[j] = Interface.CurrentOptions.RecentlyUsedRoutes[j - 1];
}
Interface.CurrentOptions.RecentlyUsedRoutes[0] = Result.RouteFile;
}
// recently used trains
if (Interface.CurrentOptions.RecentlyUsedLimit > 0)
{
int i; for (i = 0; i < Interface.CurrentOptions.RecentlyUsedTrains.Length; i++)
{
if (string.Compare(Result.TrainFolder, Interface.CurrentOptions.RecentlyUsedTrains[i], StringComparison.OrdinalIgnoreCase) == 0)
{
break;
}
}
if (i == Interface.CurrentOptions.RecentlyUsedTrains.Length)
{
if (Interface.CurrentOptions.RecentlyUsedTrains.Length < Interface.CurrentOptions.RecentlyUsedLimit)
{
Array.Resize<string>(ref Interface.CurrentOptions.RecentlyUsedTrains, i + 1);
}
else {
i--;
}
}
for (int j = i; j > 0; j--)
{
Interface.CurrentOptions.RecentlyUsedTrains[j] = Interface.CurrentOptions.RecentlyUsedTrains[j - 1];
}
Interface.CurrentOptions.RecentlyUsedTrains[0] = Result.TrainFolder;
}
}
// remove non-existing recently used routes
{
int n = 0;
string[] a = new string[Interface.CurrentOptions.RecentlyUsedRoutes.Length];
for (int i = 0; i < Interface.CurrentOptions.RecentlyUsedRoutes.Length; i++)
{
if (System.IO.File.Exists(Interface.CurrentOptions.RecentlyUsedRoutes[i]))
{
a[n] = Interface.CurrentOptions.RecentlyUsedRoutes[i];
n++;
}
}
Array.Resize<string>(ref a, n);
Interface.CurrentOptions.RecentlyUsedRoutes = a;
}
// remove non-existing recently used trains
{
int n = 0;
string[] a = new string[Interface.CurrentOptions.RecentlyUsedTrains.Length];
for (int i = 0; i < Interface.CurrentOptions.RecentlyUsedTrains.Length; i++)
{
if (System.IO.Directory.Exists(Interface.CurrentOptions.RecentlyUsedTrains[i]))
{
a[n] = Interface.CurrentOptions.RecentlyUsedTrains[i];
n++;
}
}
Array.Resize<string>(ref a, n);
Interface.CurrentOptions.RecentlyUsedTrains = a;
}
// remove non-existing route encoding mappings
{
int n = 0;
TextEncoding.EncodingValue[] a = new TextEncoding.EncodingValue[Interface.CurrentOptions.RouteEncodings.Length];
for (int i = 0; i < Interface.CurrentOptions.RouteEncodings.Length; i++)
{
if (System.IO.File.Exists(Interface.CurrentOptions.RouteEncodings[i].Value))
{
a[n] = Interface.CurrentOptions.RouteEncodings[i];
n++;
}
}
Array.Resize<TextEncoding.EncodingValue>(ref a, n);
Interface.CurrentOptions.RouteEncodings = a;
}
// remove non-existing train encoding mappings
{
int n = 0;
TextEncoding.EncodingValue[] a = new TextEncoding.EncodingValue[Interface.CurrentOptions.TrainEncodings.Length];
for (int i = 0; i < Interface.CurrentOptions.TrainEncodings.Length; i++)
{
if (System.IO.Directory.Exists(Interface.CurrentOptions.TrainEncodings[i].Value))
{
a[n] = Interface.CurrentOptions.TrainEncodings[i];
n++;
}
}
Array.Resize<TextEncoding.EncodingValue>(ref a, n);
Interface.CurrentOptions.TrainEncodings = a;
}
Sounds.Deinitialize();
routeWatcher.Dispose();
routeWorkerThread.Dispose();
workerThread.Dispose();
// finish
#if !DEBUG
try
{
#endif
Interface.SaveOptions();
FileSystem.SaveCurrentFileSystemConfiguration();
#if !DEBUG
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Save options", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
#endif
#if !DEBUG
try
{
#endif
Interface.SaveControls(null);
#if !DEBUG
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Save controls", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
#endif
}