From f4f871734e5503761205fd1c109eb0e50b85c364 Mon Sep 17 00:00:00 2001 From: Paul Sladen Date: Sun, 5 Apr 2009 16:11:25 +0300 Subject: [PATCH] * overload GetSettingsFolder() to create the config directory before return it --- debian/changelog | 1 + openBVE/OpenBve/Interface.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/debian/changelog b/debian/changelog index 661732e..1c73bd9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ openbve (1.0.2.0-0buntu1) unreleased; urgency=low * New upstream version (bugfix release) * debian/rules: tweak to allow easy building of Debug or Release target * pass '/fhs' from the mono wrapper instead of hardcoding + * overload GetSettingsFolder() to create the config directory before return it -- Paul Sladen Sun, 05 Apr 2009 12:33:10 +0000 diff --git a/openBVE/OpenBve/Interface.cs b/openBVE/OpenBve/Interface.cs index 713cec5..d5c1f74 100644 --- a/openBVE/OpenBve/Interface.cs +++ b/openBVE/OpenBve/Interface.cs @@ -7,9 +7,15 @@ namespace OpenBve { // special folders internal static string GetSettingsFolder() { + return GetSettingsFolder(true); + } + internal static string GetSettingsFolder(bool ensure_exists) { if (Program.UseFilesystemHierarchyStandard) { string Folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - return GetCombinedFolderName(Folder, "OpenBve"); + Folder = GetCombinedFolderName(Folder, "OpenBve"); + if (ensure_exists && !System.IO.Directory.Exists(Folder)) + System.IO.Directory.CreateDirectory(Folder); + return Folder; } else { return GetCombinedFolderName(System.Windows.Forms.Application.StartupPath, "Settings"); } @@ -527,7 +533,10 @@ namespace OpenBve { Builder.AppendLine(CurrentOptions.TrainEncodings[i].Codepage.ToString(Culture) + " = " + CurrentOptions.TrainEncodings[i].Value); } string File = Interface.GetCombinedFileName(GetSettingsFolder(), "options.cfg"); + try { + Console.Error.WriteLine("Writing to:'" + File + "'"); System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); + } catch (Exception exp) { Console.Error.WriteLine(exp.Message); } } // ================================ -- 1.6.0.4