Skip to content

Commit 765547a

Browse files
committed
Ensure RD directories exist on app startup, short circuit bad settings file loads.
1 parent 964dbcc commit 765547a

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

RetailCoder.VBE/App.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Infralution.Localization.Wpf;
1+
using System.IO;
2+
using Infralution.Localization.Wpf;
23
using Microsoft.Vbe.Interop;
34
using NLog;
45
using Rubberduck.Common;
@@ -169,13 +170,29 @@ private void _configService_SettingsChanged(object sender, ConfigurationChangedE
169170
}
170171
}
171172

173+
private void EnsureDirectoriesExist()
174+
{
175+
try
176+
{
177+
if (!Directory.Exists(ApplicationConstants.LOG_FOLDER_PATH))
178+
{
179+
Directory.CreateDirectory(ApplicationConstants.LOG_FOLDER_PATH);
180+
}
181+
}
182+
catch
183+
{
184+
//Does this need to display some sort of dialog?
185+
}
186+
}
187+
172188
private void UpdateLoggingLevel()
173189
{
174190
LogLevelHelper.SetMinimumLogLevel(LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
175191
}
176192

177193
public void Startup()
178194
{
195+
EnsureDirectoriesExist();
179196
LoadConfig();
180197
_appMenus.Initialize();
181198
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts

RetailCoder.VBE/Common/ApplicationConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Rubberduck.Common
55
{
66
public static class ApplicationConstants
77
{
8-
public static readonly string LOG_FOLDER_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "Logs");
8+
public static readonly string RUBBERDUCK_FOLDER_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck");
9+
public static readonly string LOG_FOLDER_PATH = Path.Combine(RUBBERDUCK_FOLDER_PATH, "Logs");
910
}
1011
}

RetailCoder.VBE/Common/WindowsOperatingSystem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using System.Diagnostics;
2+
using System.IO;
23

34
namespace Rubberduck.Common
45
{
56
public sealed class WindowsOperatingSystem : IOperatingSystem
67
{
78
public void ShowFolder(string folderPath)
89
{
10+
if (!Directory.Exists(folderPath))
11+
{
12+
Directory.CreateDirectory(folderPath);
13+
}
914
Process.Start(folderPath);
1015
}
1116
}

Rubberduck.SettingsProvider/XmlPersistanceService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ public string FilePath
3333

3434
public T Load(T toDeserialize)
3535
{
36-
var doc = GetConfigurationDoc(FilePath);
3736
var type = typeof(T);
37+
38+
if (!File.Exists(FilePath))
39+
{
40+
return (T)Convert.ChangeType(null, type);
41+
}
42+
var doc = GetConfigurationDoc(FilePath);
43+
3844
var node = doc.Descendants().FirstOrDefault(e => e.Name.LocalName.Equals(type.Name));
3945
if (node == null)
4046
{

0 commit comments

Comments
 (0)