You've already forked Sonarr
							
							
				mirror of
				https://github.com/Sonarr/Sonarr.git
				synced 2025-10-31 00:07:55 +02:00 
			
		
		
		
	moved data from Roaming to ProgramData.
Cleaned up DiskProvider
This commit is contained in:
		| @@ -14,21 +14,21 @@ namespace NzbDrone.Api.Client | ||||
| { | ||||
|     public class ClientSettings : IHandle<ApplicationStartedEvent> | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|  | ||||
|         private static readonly Regex VersionRegex = new Regex(@"(?<=Version:\s')(.*)(?=')", RegexOptions.IgnoreCase | RegexOptions.Compiled); | ||||
|         private static readonly Regex BuildDateRegex = new Regex(@"(?<=BuildDate:\s)('.*')", RegexOptions.IgnoreCase | RegexOptions.Compiled); | ||||
|  | ||||
|         public ClientSettings(IAppDirectoryInfo appDirectoryInfo) | ||||
|         public ClientSettings(IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|         } | ||||
|  | ||||
|         public void Handle(ApplicationStartedEvent message) | ||||
|         { | ||||
|             //TODO: Update the APIKey (when we have it) | ||||
|  | ||||
|             var appFile = Path.Combine(_appDirectoryInfo.StartUpPath, "UI", "app.js"); | ||||
|             var appFile = Path.Combine(_appFolderInfo.StartUpFolder, "UI", "app.js"); | ||||
|             var contents = File.ReadAllText(appFile); | ||||
|             var version = BuildInfo.Version; | ||||
|             var date = BuildInfo.BuildDateTime; | ||||
|   | ||||
| @@ -16,11 +16,11 @@ namespace NzbDrone.Api.Frontend | ||||
|  | ||||
|         private readonly string _indexPath; | ||||
|  | ||||
|         public IndexModule(IDiskProvider diskProvider, ICacheManger cacheManger, IAppDirectoryInfo appDirectory) | ||||
|         public IndexModule(IDiskProvider diskProvider, ICacheManger cacheManger, IAppFolderInfo appFolder) | ||||
|         { | ||||
|             _diskProvider = diskProvider; | ||||
|  | ||||
|             _indexPath = Path.Combine(appDirectory.StartUpPath, "UI", "index.html"); | ||||
|             _indexPath = Path.Combine(appFolder.StartUpFolder, "UI", "index.html"); | ||||
|  | ||||
|             _indexCache = cacheManger.GetCache<string>(typeof(IndexModule)); | ||||
|             //Serve anything that doesn't have an extension | ||||
|   | ||||
| @@ -6,11 +6,11 @@ namespace NzbDrone.Api.Frontend | ||||
| { | ||||
|     public class MediaCoverMapper : IMapHttpRequestsToDisk | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|  | ||||
|         public MediaCoverMapper(IAppDirectoryInfo appDirectoryInfo) | ||||
|         public MediaCoverMapper(IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|         } | ||||
|  | ||||
|         public string Map(string resourceUrl) | ||||
| @@ -18,7 +18,7 @@ namespace NzbDrone.Api.Frontend | ||||
|             var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar); | ||||
|             path = path.Trim(Path.DirectorySeparatorChar).ToLower(); | ||||
|  | ||||
|             return Path.Combine(_appDirectoryInfo.GetAppDataPath(), path); | ||||
|             return Path.Combine(_appFolderInfo.GetAppDataPath(), path); | ||||
|         } | ||||
|  | ||||
|         public bool CanHandle(string resourceUrl) | ||||
|   | ||||
| @@ -7,7 +7,7 @@ namespace NzbDrone.Api.Frontend | ||||
| { | ||||
|     public class StaticResourceMapper : IMapHttpRequestsToDisk | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|         private static readonly string[] Extensions = new[] {  | ||||
|                                                               ".css", | ||||
|                                                               ".js", | ||||
| @@ -24,9 +24,9 @@ namespace NzbDrone.Api.Frontend | ||||
|                                                               ".eot" | ||||
|                                                             }; | ||||
|  | ||||
|         public StaticResourceMapper(IAppDirectoryInfo appDirectoryInfo) | ||||
|         public StaticResourceMapper(IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|         } | ||||
|  | ||||
|         public string Map(string resourceUrl) | ||||
| @@ -35,7 +35,7 @@ namespace NzbDrone.Api.Frontend | ||||
|             path = path.Trim(Path.DirectorySeparatorChar).ToLower(); | ||||
|  | ||||
|  | ||||
|             return Path.Combine(_appDirectoryInfo.StartUpPath, "ui", path); | ||||
|             return Path.Combine(_appFolderInfo.StartUpFolder, "ui", path); | ||||
|         } | ||||
|  | ||||
|         public bool CanHandle(string resourceUrl) | ||||
|   | ||||
| @@ -8,14 +8,14 @@ namespace NzbDrone.Api.System | ||||
| { | ||||
|     public class SystemModule : NzbDroneApiModule | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|         private readonly IRuntimeInfo _runtimeInfo; | ||||
|         private readonly IRouteCacheProvider _routeCacheProvider; | ||||
|  | ||||
|         public SystemModule(IAppDirectoryInfo appDirectoryInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider) | ||||
|         public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider) | ||||
|             : base("system") | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|             _runtimeInfo = runtimeInfo; | ||||
|             _routeCacheProvider = routeCacheProvider; | ||||
|             Get["/status"] = x => GetStatus(); | ||||
| @@ -32,8 +32,8 @@ namespace NzbDrone.Api.System | ||||
|                     IsProduction = RuntimeInfo.IsProduction, | ||||
|                     IsAdmin = _runtimeInfo.IsAdmin, | ||||
|                     IsUserInteractive = _runtimeInfo.IsUserInteractive, | ||||
|                     StartupPath = _appDirectoryInfo.StartUpPath, | ||||
|                     AppData = _appDirectoryInfo.GetAppDataPath(), | ||||
|                     StartupPath = _appFolderInfo.StartUpFolder, | ||||
|                     AppData = _appFolderInfo.GetAppDataPath(), | ||||
|                     OsVersion = OsInfo.Version.ToString(), | ||||
|                     IsMono = OsInfo.IsMono, | ||||
|                     IsLinux = OsInfo.IsLinux, | ||||
|   | ||||
| @@ -17,7 +17,7 @@ namespace NzbDrone.Common.Test | ||||
|         { | ||||
|             WithTempAsAppPath(); | ||||
|  | ||||
|             var configFile = Mocker.Resolve<IAppDirectoryInfo>().GetConfigPath(); | ||||
|             var configFile = Mocker.Resolve<IAppFolderInfo>().GetConfigPath(); | ||||
|  | ||||
|             if (File.Exists(configFile)) | ||||
|                 File.Delete(configFile); | ||||
|   | ||||
| @@ -55,7 +55,7 @@ namespace NzbDrone.Common.Test | ||||
|         public void moveFile_should_overwrite_existing_file() | ||||
|         { | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|  | ||||
|             var targetPath = Path.Combine(_binFolderCopy.FullName, "file.move"); | ||||
|  | ||||
| @@ -69,7 +69,7 @@ namespace NzbDrone.Common.Test | ||||
|         public void moveFile_should_not_move_overwrite_itself() | ||||
|         { | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|  | ||||
|             var targetPath = _binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName; | ||||
|  | ||||
| @@ -84,7 +84,7 @@ namespace NzbDrone.Common.Test | ||||
|         { | ||||
|  | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|  | ||||
|  | ||||
|             VerifyCopy(); | ||||
| @@ -97,13 +97,13 @@ namespace NzbDrone.Common.Test | ||||
|  | ||||
|  | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|  | ||||
|             //Delete Random File | ||||
|             _binFolderCopy.Refresh(); | ||||
|             _binFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete(); | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|  | ||||
|  | ||||
|             VerifyCopy(); | ||||
| @@ -114,12 +114,12 @@ namespace NzbDrone.Common.Test | ||||
|         { | ||||
|  | ||||
|  | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyDirectory(_binFolder.FullName, _binFolderMove.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName); | ||||
|             Subject.CopyFolder(_binFolder.FullName, _binFolderMove.FullName); | ||||
|             VerifyCopy(); | ||||
|  | ||||
|  | ||||
|             Subject.MoveDirectory(_binFolderCopy.FullName, _binFolderMove.FullName); | ||||
|             Subject.MoveFolder(_binFolderCopy.FullName, _binFolderMove.FullName); | ||||
|  | ||||
|  | ||||
|             VerifyMove(); | ||||
| @@ -166,11 +166,11 @@ namespace NzbDrone.Common.Test | ||||
|         [Test] | ||||
|         public void folder_should_return_correct_value_for_last_write() | ||||
|         { | ||||
|             var appPath = new AppDirectoryInfo().WorkingDirectory; | ||||
|             var appPath = new AppFolderInfo(Subject).AppDataFolder; | ||||
|  | ||||
|             TestLogger.Info("Path is: {0}", appPath); | ||||
|  | ||||
|             Subject.WriteAllText(Path.Combine(appPath,"newfile.txt"), ""); | ||||
|             Subject.WriteAllText(Path.Combine(appPath, "newfile.txt"), ""); | ||||
|  | ||||
|             Subject.GetLastFolderWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10)); | ||||
|             Subject.GetLastFolderWrite(appPath).Should().BeBefore(DateTime.UtcNow); | ||||
| @@ -184,18 +184,6 @@ namespace NzbDrone.Common.Test | ||||
|             Console.WriteLine(new DirectoryInfo(@"C:\DRIVERS").LastWriteTimeUtc); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
|         public void IsChildOfPath_should_return_true_when_it_is_a_child() | ||||
|         { | ||||
|             Subject.IsChildOfPath(@"C:\Test\TV", @"C:\Test").Should().BeTrue(); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
|         public void IsChildOfPath_should_return_false_when_it_is_not_a_child() | ||||
|         { | ||||
|             Subject.IsChildOfPath(@"C:\NOT_Test\TV", @"C:\Test").Should().BeFalse(); | ||||
|         } | ||||
|  | ||||
|         private void VerifyCopy() | ||||
|         { | ||||
|             _binFolder.Refresh(); | ||||
|   | ||||
| @@ -7,22 +7,22 @@ using NzbDrone.Test.Common; | ||||
| namespace NzbDrone.Common.Test | ||||
| { | ||||
|     [TestFixture] | ||||
|     public class IAppDirectoryInfoTest : TestBase<AppDirectoryInfo> | ||||
|     public class IAppDirectoryInfoTest : TestBase<AppFolderInfo> | ||||
|     { | ||||
|  | ||||
|         [Test] | ||||
|         public void StartupPath_should_not_be_empty() | ||||
|         { | ||||
|             Subject.StartUpPath.Should().NotBeBlank(); | ||||
|             Path.IsPathRooted(Subject.StartUpPath).Should().BeTrue("Path is not rooted"); | ||||
|             Subject.StartUpFolder.Should().NotBeBlank(); | ||||
|             Path.IsPathRooted(Subject.StartUpFolder).Should().BeTrue("Path is not rooted"); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
|         public void ApplicationPath_should_not_be_empty() | ||||
|         { | ||||
|             Subject.WorkingDirectory.Should().NotBeBlank(); | ||||
|             Path.IsPathRooted(Subject.WorkingDirectory).Should().BeTrue("Path is not rooted"); | ||||
|             Subject.AppDataFolder.Should().NotBeBlank(); | ||||
|             Path.IsPathRooted(Subject.AppDataFolder).Should().BeTrue("Path is not rooted"); | ||||
|         } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -12,13 +12,13 @@ namespace NzbDrone.Common.Test | ||||
|     public class PathExtensionFixture : TestBase | ||||
|     { | ||||
|  | ||||
|         private IAppDirectoryInfo GetIAppDirectoryInfo() | ||||
|         private IAppFolderInfo GetIAppDirectoryInfo() | ||||
|         { | ||||
|             var fakeEnvironment = new Mock<IAppDirectoryInfo>(); | ||||
|             var fakeEnvironment = new Mock<IAppFolderInfo>(); | ||||
|  | ||||
|             fakeEnvironment.SetupGet(c => c.WorkingDirectory).Returns(@"C:\NzbDrone\"); | ||||
|             fakeEnvironment.SetupGet(c => c.AppDataFolder).Returns(@"C:\NzbDrone\"); | ||||
|  | ||||
|             fakeEnvironment.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); | ||||
|             fakeEnvironment.SetupGet(c => c.TempFolder).Returns(@"C:\Temp\"); | ||||
|  | ||||
|             return fakeEnvironment.Object; | ||||
|         } | ||||
|   | ||||
| @@ -1,35 +0,0 @@ | ||||
| using System; | ||||
| using System.IO; | ||||
| using System.Reflection; | ||||
|  | ||||
| namespace NzbDrone.Common.EnvironmentInfo | ||||
| { | ||||
|     public interface IAppDirectoryInfo | ||||
|     { | ||||
|         string WorkingDirectory { get; } | ||||
|         string SystemTemp { get; } | ||||
|         string StartUpPath { get; } | ||||
|     } | ||||
|  | ||||
|     public class AppDirectoryInfo : IAppDirectoryInfo | ||||
|     { | ||||
|  | ||||
|         public AppDirectoryInfo() | ||||
|         { | ||||
|             WorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), "NzbDrone"); | ||||
|             StartUpPath = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName; | ||||
|             SystemTemp = Path.GetTempPath(); | ||||
|  | ||||
|             if (!Directory.Exists(WorkingDirectory)) | ||||
|             { | ||||
|                 Directory.CreateDirectory(WorkingDirectory); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public string WorkingDirectory { get; private set; } | ||||
|  | ||||
|         public string StartUpPath { get; private set; } | ||||
|  | ||||
|         public String SystemTemp { get; private set; } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										52
									
								
								NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| using System; | ||||
| using System.IO; | ||||
| using System.Reflection; | ||||
|  | ||||
| namespace NzbDrone.Common.EnvironmentInfo | ||||
| { | ||||
|     public interface IAppFolderInfo | ||||
|     { | ||||
|         string AppDataFolder { get; } | ||||
|         string TempFolder { get; } | ||||
|         string StartUpFolder { get; } | ||||
|     } | ||||
|  | ||||
|     public class AppFolderInfo : IAppFolderInfo | ||||
|     { | ||||
|         private readonly IDiskProvider _diskProvider; | ||||
|  | ||||
|         public AppFolderInfo(IDiskProvider diskProvider) | ||||
|         { | ||||
|             _diskProvider = diskProvider; | ||||
|             AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone"); | ||||
|             StartUpFolder = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName; | ||||
|             TempFolder = Path.GetTempPath(); | ||||
|  | ||||
|             if (!_diskProvider.FolderExists(AppDataFolder)) | ||||
|             { | ||||
|                 MigrateFromAppDate(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         private void MigrateFromAppDate() | ||||
|         { | ||||
|             var oldAppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone"); | ||||
|  | ||||
|             if (_diskProvider.FolderExists(oldAppDataFolder)) | ||||
|             { | ||||
|                 _diskProvider.MoveFolder(oldAppDataFolder, AppDataFolder); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 _diskProvider.CreateFolder(AppDataFolder); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public string AppDataFolder { get; private set; } | ||||
|  | ||||
|         public string StartUpFolder { get; private set; } | ||||
|  | ||||
|         public String TempFolder { get; private set; } | ||||
|     } | ||||
| } | ||||
| @@ -1,5 +1,4 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Runtime.InteropServices; | ||||
| @@ -18,25 +17,21 @@ namespace NzbDrone.Common | ||||
|         bool FileExists(string path); | ||||
|         string[] GetDirectories(string path); | ||||
|         string[] GetFiles(string path, SearchOption searchOption); | ||||
|         long GetDirectorySize(string path); | ||||
|         long GetFolderSize(string path); | ||||
|         long GetFileSize(string path); | ||||
|         String CreateFolder(string path); | ||||
|         void CopyDirectory(string source, string target); | ||||
|         void MoveDirectory(string source, string destination); | ||||
|         void CopyFolder(string source, string target); | ||||
|         void MoveFolder(string source, string destination); | ||||
|         void DeleteFile(string path); | ||||
|         void MoveFile(string source, string destination); | ||||
|         void DeleteFolder(string path, bool recursive); | ||||
|         DateTime DirectoryDateCreated(string path); | ||||
|         IEnumerable<FileInfo> GetFileInfos(string path, string pattern, SearchOption searchOption); | ||||
|         void InheritFolderPermissions(string filename); | ||||
|         long GetAvilableSpace(string path); | ||||
|         string ReadAllText(string filePath); | ||||
|         void WriteAllText(string filename, string contents); | ||||
|         void FileSetLastWriteTimeUtc(string path, DateTime dateTime); | ||||
|         void DirectorySetLastWriteTimeUtc(string path, DateTime dateTime); | ||||
|         bool IsFolderLocked(string path); | ||||
|         void FolderSetLastWriteTimeUtc(string path, DateTime dateTime); | ||||
|         bool IsFileLocked(FileInfo file); | ||||
|         bool IsChildOfPath(string child, string parent); | ||||
|         string GetPathRoot(string path); | ||||
|     } | ||||
|  | ||||
| @@ -125,7 +120,7 @@ namespace NzbDrone.Common | ||||
|             return Directory.GetFiles(path, "*.*", searchOption); | ||||
|         } | ||||
|  | ||||
|         public virtual long GetDirectorySize(string path) | ||||
|         public virtual long GetFolderSize(string path) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|  | ||||
| @@ -150,22 +145,22 @@ namespace NzbDrone.Common | ||||
|             return Directory.CreateDirectory(path).FullName; | ||||
|         } | ||||
|  | ||||
|         public virtual void CopyDirectory(string source, string target) | ||||
|         public virtual void CopyFolder(string source, string target) | ||||
|         { | ||||
|             Ensure.That(() => source).IsValidPath(); | ||||
|             Ensure.That(() => target).IsValidPath(); | ||||
|  | ||||
|             TransferDirectory(source, target, TransferAction.Copy); | ||||
|             TransferFolder(source, target, TransferAction.Copy); | ||||
|         } | ||||
|  | ||||
|         public virtual void MoveDirectory(string source, string destination) | ||||
|         public virtual void MoveFolder(string source, string destination) | ||||
|         { | ||||
|             Ensure.That(() => source).IsValidPath(); | ||||
|             Ensure.That(() => destination).IsValidPath(); | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 TransferDirectory(source, destination, TransferAction.Move); | ||||
|                 TransferFolder(source, destination, TransferAction.Move); | ||||
|                 Directory.Delete(source, true); | ||||
|             } | ||||
|             catch (Exception e) | ||||
| @@ -176,7 +171,7 @@ namespace NzbDrone.Common | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void TransferDirectory(string source, string target, TransferAction transferAction) | ||||
|         private void TransferFolder(string source, string target, TransferAction transferAction) | ||||
|         { | ||||
|             Ensure.That(() => source).IsValidPath(); | ||||
|             Ensure.That(() => target).IsValidPath(); | ||||
| @@ -193,7 +188,7 @@ namespace NzbDrone.Common | ||||
|  | ||||
|             foreach (var subDir in sourceFolder.GetDirectories()) | ||||
|             { | ||||
|                 TransferDirectory(subDir.FullName, Path.Combine(target, subDir.Name), transferAction); | ||||
|                 TransferFolder(subDir.FullName, Path.Combine(target, subDir.Name), transferAction); | ||||
|             } | ||||
|  | ||||
|             foreach (var sourceFile in sourceFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly)) | ||||
| @@ -251,20 +246,6 @@ namespace NzbDrone.Common | ||||
|             Directory.Delete(path, recursive); | ||||
|         } | ||||
|  | ||||
|         public virtual DateTime DirectoryDateCreated(string path) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|  | ||||
|             return Directory.GetCreationTime(path); | ||||
|         } | ||||
|  | ||||
|         public virtual IEnumerable<FileInfo> GetFileInfos(string path, string pattern, SearchOption searchOption) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|  | ||||
|             return new DirectoryInfo(path).EnumerateFiles(pattern, searchOption); | ||||
|         } | ||||
|  | ||||
|         public virtual void InheritFolderPermissions(string filename) | ||||
|         { | ||||
|             Ensure.That(() => filename).IsValidPath(); | ||||
| @@ -350,28 +331,13 @@ namespace NzbDrone.Common | ||||
|             File.SetLastWriteTimeUtc(path, dateTime); | ||||
|         } | ||||
|  | ||||
|         public virtual void DirectorySetLastWriteTimeUtc(string path, DateTime dateTime) | ||||
|         public virtual void FolderSetLastWriteTimeUtc(string path, DateTime dateTime) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|  | ||||
|             Directory.SetLastWriteTimeUtc(path, dateTime); | ||||
|         } | ||||
|  | ||||
|         public virtual bool IsFolderLocked(string path) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|  | ||||
|             var files = GetFileInfos(path, "*.*", SearchOption.AllDirectories); | ||||
|  | ||||
|             foreach (var fileInfo in files) | ||||
|             { | ||||
|                 if (IsFileLocked(fileInfo)) | ||||
|                     return true; | ||||
|             } | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         public virtual bool IsFileLocked(FileInfo file) | ||||
|         { | ||||
|             FileStream stream = null; | ||||
| @@ -394,17 +360,6 @@ namespace NzbDrone.Common | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         public virtual bool IsChildOfPath(string child, string parent) | ||||
|         { | ||||
|             Ensure.That(() => child).IsValidPath(); | ||||
|             Ensure.That(() => parent).IsValidPath(); | ||||
|  | ||||
|             if (Path.GetFullPath(child).StartsWith(Path.GetFullPath(parent))) | ||||
|                 return true; | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         public virtual string GetPathRoot(string path) | ||||
|         { | ||||
|             Ensure.That(() => path).IsValidPath(); | ||||
|   | ||||
| @@ -15,7 +15,7 @@ namespace NzbDrone.Common.Instrumentation | ||||
|  | ||||
|         public ApplicationLogLayoutRenderer() | ||||
|         { | ||||
|             _appData = Path.Combine(new AppDirectoryInfo().GetLogFolder(), "nzbdrone.txt"); | ||||
|             _appData = Path.Combine(new AppFolderInfo(new DiskProvider()).GetLogFolder(), "nzbdrone.txt"); | ||||
|  | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -16,7 +16,7 @@ namespace NzbDrone.Common.Instrumentation | ||||
|  | ||||
|         public UpdateLogLayoutRenderer() | ||||
|         { | ||||
|             _appData = Path.Combine(new AppDirectoryInfo().GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt"); | ||||
|             _appData = Path.Combine(new AppFolderInfo(new DiskProvider()).GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt"); | ||||
|  | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -149,7 +149,7 @@ | ||||
|     <Compile Include="Model\AuthenticationType.cs" /> | ||||
|     <Compile Include="PathExtensions.cs" /> | ||||
|     <Compile Include="IDiskProvider.cs" /> | ||||
|     <Compile Include="EnvironmentInfo\AppDirectoryInfo.cs" /> | ||||
|     <Compile Include="EnvironmentInfo\AppFolderInfo.cs" /> | ||||
|     <Compile Include="Model\ProcessInfo.cs" /> | ||||
|     <Compile Include="IProcessProvider.cs" /> | ||||
|     <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
|   | ||||
| @@ -38,12 +38,12 @@ namespace NzbDrone.Common | ||||
|             return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0; | ||||
|         } | ||||
|  | ||||
|         private static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo) | ||||
|         private static string GetProperCapitalization(DirectoryInfo dirInfo) | ||||
|         { | ||||
|             var parentDirInfo = dirInfo.Parent; | ||||
|             if (null == parentDirInfo) | ||||
|                 return dirInfo.Name; | ||||
|             return Path.Combine(GetProperDirectoryCapitalization(parentDirInfo), | ||||
|             return Path.Combine(GetProperCapitalization(parentDirInfo), | ||||
|                                 parentDirInfo.GetDirectories(dirInfo.Name)[0].Name); | ||||
|         } | ||||
|  | ||||
| @@ -51,74 +51,74 @@ namespace NzbDrone.Common | ||||
|         { | ||||
|             var fileInfo = new FileInfo(filename); | ||||
|             DirectoryInfo dirInfo = fileInfo.Directory; | ||||
|             return Path.Combine(GetProperDirectoryCapitalization(dirInfo), | ||||
|             return Path.Combine(GetProperCapitalization(dirInfo), | ||||
|                                 dirInfo.GetFiles(fileInfo.Name)[0].Name); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public static string GetAppDataPath(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetAppDataPath(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return IAppDirectoryInfo.WorkingDirectory; | ||||
|             return appFolderInfo.AppDataFolder; | ||||
|         } | ||||
|  | ||||
|         public static string GetLogFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetLogFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), "logs"); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), "logs"); | ||||
|         } | ||||
|  | ||||
|         public static string GetConfigPath(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetConfigPath(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), APP_CONFIG_FILE); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), APP_CONFIG_FILE); | ||||
|         } | ||||
|  | ||||
|         public static string GetMediaCoverPath(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetMediaCoverPath(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), "MediaCover"); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), "MediaCover"); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdateLogFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdateLogFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), UPDATE_LOG_FOLDER_NAME); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), UPDATE_LOG_FOLDER_NAME); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdateSandboxFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdateSandboxFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(IAppDirectoryInfo.SystemTemp, UPDATE_SANDBOX_FOLDER_NAME); | ||||
|             return Path.Combine(appFolderInfo.TempFolder, UPDATE_SANDBOX_FOLDER_NAME); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdateBackUpFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdateBackUpFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_BACKUP_FOLDER_NAME); | ||||
|             return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_BACKUP_FOLDER_NAME); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdatePackageFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdatePackageFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_PACKAGE_FOLDER_NAME); | ||||
|             return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdateClientFolder(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdateClientFolder(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetUpdatePackageFolder(IAppDirectoryInfo), UPDATE_CLIENT_FOLDER_NAME); | ||||
|             return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_CLIENT_FOLDER_NAME); | ||||
|         } | ||||
|  | ||||
|         public static string GetUpdateClientExePath(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetUpdateClientExePath(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_CLIENT_EXE); | ||||
|             return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_CLIENT_EXE); | ||||
|         } | ||||
|  | ||||
|         public static string GetConfigBackupFile(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetConfigBackupFile(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), BACKUP_ZIP_FILE); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), BACKUP_ZIP_FILE); | ||||
|         } | ||||
|  | ||||
|         public static string GetNzbDroneDatabase(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetNzbDroneDatabase(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), NZBDRONE_DB); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), NZBDRONE_DB); | ||||
|         } | ||||
|  | ||||
|         public static string GetLogDatabase(this IAppDirectoryInfo IAppDirectoryInfo) | ||||
|         public static string GetLogDatabase(this IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             return Path.Combine(GetAppDataPath(IAppDirectoryInfo), NZBDRONE_LOG_DB); | ||||
|             return Path.Combine(GetAppDataPath(appFolderInfo), NZBDRONE_LOG_DB); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -117,9 +117,9 @@ namespace NzbDrone.Core.Test.Framework | ||||
|         [TearDown] | ||||
|         public void TearDown() | ||||
|         { | ||||
|             if (TestDirectoryInfo != null) | ||||
|             if (TestFolderInfo != null) | ||||
|             { | ||||
|                 var files = Directory.GetFiles(TestDirectoryInfo.WorkingDirectory); | ||||
|                 var files = Directory.GetFiles(TestFolderInfo.AppDataFolder); | ||||
|  | ||||
|                 foreach (var file in files) | ||||
|                 { | ||||
|   | ||||
| @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests | ||||
|         [SetUp] | ||||
|         public void Setup() | ||||
|         { | ||||
|             Mocker.SetConstant<IAppDirectoryInfo>(new AppDirectoryInfo()); | ||||
|             Mocker.SetConstant<IAppFolderInfo>(new AppFolderInfo(new DiskProvider())); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
|   | ||||
| @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests | ||||
|  | ||||
|             var path = @"C:\Test\TV\30 Rock"; | ||||
|  | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path); | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path); | ||||
|  | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(path, true), Times.Once()); | ||||
|         } | ||||
| @@ -53,9 +53,9 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests | ||||
|  | ||||
|             var path = @"C:\Test\TV\30 Rock"; | ||||
|  | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path); | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path); | ||||
|  | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.MoveDirectory(path, @"C:\Test\Recycle Bin\30 Rock"), Times.Once()); | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.MoveFolder(path, @"C:\Test\Recycle Bin\30 Rock"), Times.Once()); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
| @@ -65,9 +65,9 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests | ||||
|  | ||||
|             var path = @"C:\Test\TV\30 Rock"; | ||||
|  | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path); | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path); | ||||
|  | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.DirectorySetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny<DateTime>()), Times.Once()); | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.FolderSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny<DateTime>()), Times.Once()); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
| @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests | ||||
|             Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock", SearchOption.AllDirectories)) | ||||
|                                             .Returns(new[]{ "File1", "File2", "File3" }); | ||||
|  | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path); | ||||
|             Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path); | ||||
|  | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny<String>(), It.IsAny<DateTime>()), Times.Exactly(3)); | ||||
|         } | ||||
|   | ||||
| @@ -30,12 +30,12 @@ namespace NzbDrone.Core.Test.UpdateTests | ||||
|         [SetUp] | ||||
|         public void Setup() | ||||
|         { | ||||
|             Mocker.GetMock<IAppDirectoryInfo>().SetupGet(c => c.SystemTemp).Returns(TempFolder); | ||||
|             Mocker.GetMock<IAppFolderInfo>().SetupGet(c => c.TempFolder).Returns(TempFolder); | ||||
|             Mocker.GetMock<ICheckUpdateService>().Setup(c => c.AvailableUpdate()).Returns(_updatePackage); | ||||
|  | ||||
|             Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 }); | ||||
|  | ||||
|             _sandboxFolder = Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateSandboxFolder(); | ||||
|             _sandboxFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder(); | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -87,13 +87,13 @@ namespace NzbDrone.Core.Test.UpdateTests | ||||
|         [Test] | ||||
|         public void Should_copy_update_client_to_root_of_sandbox() | ||||
|         { | ||||
|             var updateClientFolder = Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateClientFolder(); | ||||
|             var updateClientFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateClientFolder(); | ||||
|  | ||||
|             Subject.Execute(new ApplicationUpdateCommand()); | ||||
|  | ||||
|  | ||||
|  | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder)); | ||||
|             Mocker.GetMock<IDiskProvider>().Verify(c => c.MoveFolder(updateClientFolder, _sandboxFolder)); | ||||
|         } | ||||
|  | ||||
|         [Test] | ||||
| @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.UpdateTests | ||||
|         { | ||||
|             UseRealHttp(); | ||||
|  | ||||
|             var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateSandboxFolder()); | ||||
|             var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder()); | ||||
|  | ||||
|             updateSubFolder.Exists.Should().BeFalse(); | ||||
|  | ||||
|   | ||||
| @@ -25,16 +25,16 @@ namespace NzbDrone.Core.Configuration | ||||
|  | ||||
|     public class ConfigFileProvider : IConfigFileProvider | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|         private readonly ICached<string> _cache; | ||||
|  | ||||
|         private readonly string _configFile; | ||||
|  | ||||
|         public ConfigFileProvider(IAppDirectoryInfo appDirectoryInfo, ICacheManger cacheManger) | ||||
|         public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger) | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|             _cache = cacheManger.GetCache<string>(this.GetType()); | ||||
|             _configFile = _appDirectoryInfo.GetConfigPath(); | ||||
|             _configFile = _appFolderInfo.GetConfigPath(); | ||||
|         } | ||||
|  | ||||
|         public Dictionary<string, object> GetConfigDictionary() | ||||
|   | ||||
| @@ -13,10 +13,10 @@ namespace NzbDrone.Core.Datastore | ||||
|  | ||||
|     public class ConnectionStringFactory : IConnectionStringFactory | ||||
|     { | ||||
|         public ConnectionStringFactory(IAppDirectoryInfo appDirectoryInfo) | ||||
|         public ConnectionStringFactory(IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             MainDbConnectionString = GetConnectionString(appDirectoryInfo.GetNzbDroneDatabase()); | ||||
|             LogDbConnectionString = GetConnectionString(appDirectoryInfo.GetLogDatabase()); | ||||
|             MainDbConnectionString = GetConnectionString(appFolderInfo.GetNzbDroneDatabase()); | ||||
|             LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase()); | ||||
|         } | ||||
|  | ||||
|         public string MainDbConnectionString { get; private set; } | ||||
|   | ||||
| @@ -22,7 +22,7 @@ namespace NzbDrone.Core.MediaCover | ||||
|  | ||||
|         private readonly string _coverRootFolder; | ||||
|  | ||||
|         public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IAppDirectoryInfo appDirectoryInfo, | ||||
|         public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IAppFolderInfo appFolderInfo, | ||||
|             ICoverExistsSpecification coverExistsSpecification, Logger logger) | ||||
|         { | ||||
|             _httpProvider = httpProvider; | ||||
| @@ -30,7 +30,7 @@ namespace NzbDrone.Core.MediaCover | ||||
|             _coverExistsSpecification = coverExistsSpecification; | ||||
|             _logger = logger; | ||||
|  | ||||
|             _coverRootFolder = appDirectoryInfo.GetMediaCoverPath(); | ||||
|             _coverRootFolder = appFolderInfo.GetMediaCoverPath(); | ||||
|         } | ||||
|  | ||||
|         public void HandleAsync(SeriesUpdatedEvent message) | ||||
|   | ||||
| @@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles | ||||
|                     { | ||||
|                         ProcessSubFolder(new DirectoryInfo(subfolder)); | ||||
|  | ||||
|                         if (_diskProvider.GetDirectorySize(subfolder) < 50.Megabytes()) | ||||
|                         if (_diskProvider.GetFolderSize(subfolder) < 50.Megabytes()) | ||||
|                         { | ||||
|                             _diskProvider.DeleteFolder(subfolder, true); | ||||
|                         } | ||||
|   | ||||
| @@ -26,7 +26,7 @@ namespace NzbDrone.Core.MediaFiles | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public virtual void DeleteDirectory(string path) | ||||
|         public virtual void DeleteFolder(string path) | ||||
|         { | ||||
|             logger.Trace("Attempting to send '{0}' to recycling bin", path); | ||||
|             var recyclingBin = _configService.RecycleBin; | ||||
| @@ -43,10 +43,10 @@ namespace NzbDrone.Core.MediaFiles | ||||
|                 var destination = Path.Combine(recyclingBin, new DirectoryInfo(path).Name); | ||||
|  | ||||
|                 logger.Trace("Moving '{0}' to '{1}'", path, destination); | ||||
|                 _diskProvider.MoveDirectory(path, destination); | ||||
|                 _diskProvider.MoveFolder(path, destination); | ||||
|  | ||||
|                 logger.Trace("Setting last accessed: {0}", path); | ||||
|                 _diskProvider.DirectorySetLastWriteTimeUtc(destination, DateTime.UtcNow); | ||||
|                 _diskProvider.FolderSetLastWriteTimeUtc(destination, DateTime.UtcNow); | ||||
|                 foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories)) | ||||
|                 { | ||||
|                     _diskProvider.FileSetLastWriteTimeUtc(file, DateTime.UtcNow); | ||||
| @@ -141,7 +141,7 @@ namespace NzbDrone.Core.MediaFiles | ||||
|         { | ||||
|             if (message.DeleteFiles) | ||||
|             { | ||||
|                 DeleteDirectory(message.Series.Path); | ||||
|                 DeleteFolder(message.Series.Path); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -8,11 +8,11 @@ namespace NzbDrone.Core.Providers | ||||
| { | ||||
|     public class BackupProvider | ||||
|     { | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|  | ||||
|         public BackupProvider(IAppDirectoryInfo appDirectoryInfo) | ||||
|         public BackupProvider(IAppFolderInfo appFolderInfo) | ||||
|         { | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|         } | ||||
|  | ||||
|         public BackupProvider() | ||||
| @@ -21,8 +21,8 @@ namespace NzbDrone.Core.Providers | ||||
|  | ||||
|         public virtual string CreateBackupZip() | ||||
|         { | ||||
|             var configFile = _appDirectoryInfo.GetConfigPath(); | ||||
|             var zipFile = _appDirectoryInfo.GetConfigBackupFile(); | ||||
|             var configFile = _appFolderInfo.GetConfigPath(); | ||||
|             var zipFile = _appFolderInfo.GetConfigBackupFile(); | ||||
|  | ||||
|             using (var zip = new ZipFile()) | ||||
|             { | ||||
|   | ||||
| @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Update | ||||
|     { | ||||
|         private readonly ICheckUpdateService _checkUpdateService; | ||||
|         private readonly Logger _logger; | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|  | ||||
|         private readonly IDiskProvider _diskProvider; | ||||
|         private readonly IHttpProvider _httpProvider; | ||||
| @@ -20,12 +20,12 @@ namespace NzbDrone.Core.Update | ||||
|         private readonly IProcessProvider _processProvider; | ||||
|  | ||||
|  | ||||
|         public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppDirectoryInfo appDirectoryInfo, | ||||
|         public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppFolderInfo appFolderInfo, | ||||
|                                     IDiskProvider diskProvider, IHttpProvider httpProvider, | ||||
|                                     ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger) | ||||
|         { | ||||
|             _checkUpdateService = checkUpdateService; | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|             _diskProvider = diskProvider; | ||||
|             _httpProvider = httpProvider; | ||||
|             _archiveProvider = archiveProvider; | ||||
| @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Update | ||||
|  | ||||
|         private void InstallUpdate(UpdatePackage updatePackage) | ||||
|         { | ||||
|             var updateSandboxFolder = _appDirectoryInfo.GetUpdateSandboxFolder(); | ||||
|             var updateSandboxFolder = _appFolderInfo.GetUpdateSandboxFolder(); | ||||
|  | ||||
|             var packageDestination = Path.Combine(updateSandboxFolder, updatePackage.FileName); | ||||
|  | ||||
| @@ -64,14 +64,14 @@ namespace NzbDrone.Core.Update | ||||
|             _logger.Info("Update package extracted successfully"); | ||||
|  | ||||
|             _logger.Info("Preparing client"); | ||||
|             _diskProvider.MoveDirectory(_appDirectoryInfo.GetUpdateClientFolder(), | ||||
|             _diskProvider.MoveFolder(_appFolderInfo.GetUpdateClientFolder(), | ||||
|                                         updateSandboxFolder); | ||||
|  | ||||
|  | ||||
|             _logger.Info("Starting update client"); | ||||
|             var startInfo = new ProcessStartInfo | ||||
|                 { | ||||
|                     FileName = _appDirectoryInfo.GetUpdateClientExePath(), | ||||
|                     FileName = _appFolderInfo.GetUpdateClientExePath(), | ||||
|                     Arguments = _processProvider.GetCurrentProcess().Id.ToString() | ||||
|                 }; | ||||
|  | ||||
|   | ||||
| @@ -58,7 +58,7 @@ namespace NzbDrone.Integration.Test | ||||
|         public void SmokeTestSetup() | ||||
|         { | ||||
|             Container = MainAppContainerBuilder.BuildContainer(); | ||||
|             Container.Register(typeof(IAppDirectoryInfo), new IntegrationTestDirectoryInfo()); | ||||
|             Container.Register(typeof(IAppFolderInfo), new IntegrationTestFolderInfo()); | ||||
|  | ||||
|             DbFactory.RegisterDatabase(Container); | ||||
|  | ||||
|   | ||||
| @@ -4,23 +4,23 @@ using NzbDrone.Common.EnvironmentInfo; | ||||
|  | ||||
| namespace NzbDrone.Integration.Test | ||||
| { | ||||
|     public class IntegrationTestDirectoryInfo : IAppDirectoryInfo | ||||
|     public class IntegrationTestFolderInfo : IAppFolderInfo | ||||
|     { | ||||
|         public IntegrationTestDirectoryInfo() | ||||
|         public IntegrationTestFolderInfo() | ||||
|         { | ||||
|             SystemTemp = Path.GetTempPath(); | ||||
|             WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "integ_test", DateTime.Now.Ticks.ToString()); | ||||
|             TempFolder = Path.GetTempPath(); | ||||
|             AppDataFolder = Path.Combine(Directory.GetCurrentDirectory(), "integ_test", DateTime.Now.Ticks.ToString()); | ||||
|  | ||||
|             if (!Directory.Exists(WorkingDirectory)) | ||||
|             if (!Directory.Exists(AppDataFolder)) | ||||
|             { | ||||
|                 Directory.CreateDirectory(WorkingDirectory); | ||||
|                 Directory.CreateDirectory(AppDataFolder); | ||||
|             } | ||||
|  | ||||
|             StartUpPath = Directory.GetCurrentDirectory(); | ||||
|             StartUpFolder = Directory.GetCurrentDirectory(); | ||||
|         } | ||||
|  | ||||
|         public string WorkingDirectory { get; private set; } | ||||
|         public string SystemTemp { get; private set; } | ||||
|         public string StartUpPath { get; private set; } | ||||
|         public string AppDataFolder { get; private set; } | ||||
|         public string TempFolder { get; private set; } | ||||
|         public string StartUpFolder { get; private set; } | ||||
|     } | ||||
| } | ||||
| @@ -108,7 +108,7 @@ namespace NzbDrone.Test.Common | ||||
|         } | ||||
|  | ||||
|  | ||||
|         protected IAppDirectoryInfo TestDirectoryInfo { get; private set; } | ||||
|         protected IAppFolderInfo TestFolderInfo { get; private set; } | ||||
|  | ||||
|         protected void WindowsOnly() | ||||
|         { | ||||
| @@ -129,11 +129,11 @@ namespace NzbDrone.Test.Common | ||||
|  | ||||
|         protected void WithTempAsAppPath() | ||||
|         { | ||||
|             Mocker.GetMock<IAppDirectoryInfo>() | ||||
|                 .SetupGet(c => c.WorkingDirectory) | ||||
|             Mocker.GetMock<IAppFolderInfo>() | ||||
|                 .SetupGet(c => c.AppDataFolder) | ||||
|                 .Returns(VirtualPath); | ||||
|  | ||||
|             TestDirectoryInfo = Mocker.GetMock<IAppDirectoryInfo>().Object; | ||||
|             TestFolderInfo = Mocker.GetMock<IAppFolderInfo>().Object; | ||||
|         } | ||||
|  | ||||
|         protected string GetTestFilePath(string fileName) | ||||
|   | ||||
| @@ -15,8 +15,8 @@ namespace NzbDrone.Update.Test | ||||
|         [SetUp] | ||||
|         public void Setup() | ||||
|         { | ||||
|             Mocker.GetMock<IAppDirectoryInfo>() | ||||
|                 .Setup(c => c.SystemTemp).Returns(@"C:\Temp\"); | ||||
|             Mocker.GetMock<IAppFolderInfo>() | ||||
|                 .Setup(c => c.TempFolder).Returns(@"C:\Temp\"); | ||||
|         } | ||||
|  | ||||
|         [TestCase(null)] | ||||
|   | ||||
| @@ -13,27 +13,27 @@ namespace NzbDrone.Update.UpdateEngine | ||||
|     public class BackupAndRestore : IBackupAndRestore | ||||
|     { | ||||
|         private readonly IDiskProvider _diskProvider; | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|         private readonly Logger _logger; | ||||
|  | ||||
|         public BackupAndRestore(IDiskProvider diskProvider, IAppDirectoryInfo appDirectoryInfo, Logger logger) | ||||
|         public BackupAndRestore(IDiskProvider diskProvider, IAppFolderInfo appFolderInfo, Logger logger) | ||||
|         { | ||||
|             _diskProvider = diskProvider; | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|             _logger = logger; | ||||
|         } | ||||
|  | ||||
|         public void BackUp(string source) | ||||
|         { | ||||
|             _logger.Info("Creating backup of existing installation"); | ||||
|             _diskProvider.CopyDirectory(source, _appDirectoryInfo.GetUpdateBackUpFolder()); | ||||
|             _diskProvider.CopyFolder(source, _appFolderInfo.GetUpdateBackUpFolder()); | ||||
|         } | ||||
|  | ||||
|         public void Restore(string target) | ||||
|         { | ||||
|             //TODO:this should ignore single file failures. | ||||
|             _logger.Info("Attempting to rollback upgrade"); | ||||
|             _diskProvider.CopyDirectory(_appDirectoryInfo.GetUpdateBackUpFolder(), target); | ||||
|             _diskProvider.CopyFolder(_appFolderInfo.GetUpdateBackUpFolder(), target); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -16,18 +16,18 @@ namespace NzbDrone.Update.UpdateEngine | ||||
|         private readonly IDiskProvider _diskProvider; | ||||
|         private readonly IDetectApplicationType _detectApplicationType; | ||||
|         private readonly ITerminateNzbDrone _terminateNzbDrone; | ||||
|         private readonly IAppDirectoryInfo _appDirectoryInfo; | ||||
|         private readonly IAppFolderInfo _appFolderInfo; | ||||
|         private readonly IBackupAndRestore _backupAndRestore; | ||||
|         private readonly IStartNzbDrone _startNzbDrone; | ||||
|         private readonly Logger _logger; | ||||
|  | ||||
|         public InstallUpdateService(IDiskProvider diskProvider, IDetectApplicationType detectApplicationType, ITerminateNzbDrone terminateNzbDrone, | ||||
|             IAppDirectoryInfo appDirectoryInfo, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger) | ||||
|             IAppFolderInfo appFolderInfo, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger) | ||||
|         { | ||||
|             _diskProvider = diskProvider; | ||||
|             _detectApplicationType = detectApplicationType; | ||||
|             _terminateNzbDrone = terminateNzbDrone; | ||||
|             _appDirectoryInfo = appDirectoryInfo; | ||||
|             _appFolderInfo = appFolderInfo; | ||||
|             _backupAndRestore = backupAndRestore; | ||||
|             _startNzbDrone = startNzbDrone; | ||||
|             _logger = logger; | ||||
| @@ -44,8 +44,8 @@ namespace NzbDrone.Update.UpdateEngine | ||||
|                 throw new DirectoryNotFoundException("Target folder doesn't exist " + targetFolder); | ||||
|  | ||||
|             _logger.Info("Verifying Update Folder"); | ||||
|             if (!_diskProvider.FolderExists(_appDirectoryInfo.GetUpdatePackageFolder())) | ||||
|                 throw new DirectoryNotFoundException("Update folder doesn't exist " + _appDirectoryInfo.GetUpdatePackageFolder()); | ||||
|             if (!_diskProvider.FolderExists(_appFolderInfo.GetUpdatePackageFolder())) | ||||
|                 throw new DirectoryNotFoundException("Update folder doesn't exist " + _appFolderInfo.GetUpdatePackageFolder()); | ||||
|         } | ||||
|  | ||||
|         public void Start(string installationFolder) | ||||
| @@ -64,7 +64,7 @@ namespace NzbDrone.Update.UpdateEngine | ||||
|  | ||||
|                 try | ||||
|                 { | ||||
|                     _diskProvider.CopyDirectory(_appDirectoryInfo.GetUpdatePackageFolder(), installationFolder); | ||||
|                     _diskProvider.CopyFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user