From 6d3a604677e4c2d4bbee518d17770e5f7732a701 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 26 Jul 2013 21:53:05 -0700 Subject: [PATCH] create data folder if doesn't exist. --- .../EnvironmentInfo/AppFolderInfo.cs | 20 ++++++++++--------- .../Framework/SQLiteMigrationHelper.cs | 16 ++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs index 5f441befc..49db460b0 100644 --- a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs +++ b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs @@ -20,21 +20,23 @@ namespace NzbDrone.Common.EnvironmentInfo private readonly Environment.SpecialFolder DATA_SPECIAL_FOLDER = Environment.SpecialFolder.CommonApplicationData; - public AppFolderInfo (IDiskProvider diskProvider) - { - _diskProvider = diskProvider; + public AppFolderInfo(IDiskProvider diskProvider) + { + _diskProvider = diskProvider; - if (OsInfo.IsLinux) - { - DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData; - } + if (OsInfo.IsLinux) + { + DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData; + } - _logger = LogManager.GetCurrentClassLogger(); + _logger = LogManager.GetCurrentClassLogger(); - AppDataFolder = Path.Combine(Environment.GetFolderPath(DATA_SPECIAL_FOLDER, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone"); + AppDataFolder = Path.Combine(Environment.GetFolderPath(DATA_SPECIAL_FOLDER, Environment.SpecialFolderOption.Create), "NzbDrone"); StartUpFolder = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName; TempFolder = Path.GetTempPath(); + diskProvider.EnsureFolder(AppDataFolder); + if (!OsInfo.IsLinux) { SetPermissions(); diff --git a/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs index 4f7002664..80b4e25e8 100644 --- a/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs +++ b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data.SQLite; using System.Linq; using System.Text.RegularExpressions; +using NLog; namespace NzbDrone.Core.Datastore.Migration.Framework { @@ -24,10 +25,19 @@ namespace NzbDrone.Core.Datastore.Migration.Framework private static readonly Regex SchemaRegex = new Regex(@"['\""\[](?\w+)['\""\]]\s(?[\w-\s]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline); - public SQLiteMigrationHelper(IConnectionStringFactory connectionStringFactory) + public SQLiteMigrationHelper(IConnectionStringFactory connectionStringFactory,Logger logger) { - _connection = new SQLiteConnection(connectionStringFactory.MainDbConnectionString); - _connection.Open(); + try + { + _connection = new SQLiteConnection(connectionStringFactory.MainDbConnectionString); + _connection.Open(); + } + catch (Exception e) + { + logger.ErrorException("Couldn't open databse " + connectionStringFactory.MainDbConnectionString, e); + throw; + } + } private string GetOriginalSql(string tableName)