public void Imloc_Combine_SimplePaths() { var imbase = ImageLocation.FromUri(OsPath.Absolute("dir")); var combined = imbase.Combine("test.exe"); Assert.AreEqual(OsPath.Absolute("dir", "test.exe"), combined.ToString()); }
public void should_parse_null_as_empty() { var result = new OsPath(null); result.FullPath.Should().BeEmpty(); result.IsEmpty.Should().BeTrue(); }
private void MigrateLocalCategoryPath() { // TODO: Remove around January 2015, this code moves the settings to the RemotePathMappingService. if (!Settings.TvCategoryLocalPath.IsNullOrWhiteSpace()) { try { _logger.Debug("Has legacy TvCategoryLocalPath, trying to migrate to RemotePathMapping list."); var config = _proxy.GetConfig(Settings); var category = GetCategories(config).FirstOrDefault(v => v.Name == Settings.TvCategory); if (category != null) { var localPath = new OsPath(Settings.TvCategoryLocalPath); Settings.TvCategoryLocalPath = null; _remotePathMappingService.MigrateLocalCategoryPath(Definition.Id, Settings, Settings.Host, category.FullPath, localPath); _logger.Info("Discovered Local Category Path for {0}, the setting was automatically moved to the Remote Path Mapping table.", Definition.Name); } } catch (DownloadClientException ex) { _logger.ErrorException("Unable to migrate local category path", ex); throw; } } }
public void DecSvc_DecompilerProjectName() { IDecompilerService svc = new DecompilerService(); var host = new Mock <IDecompiledFileService>(); var arch = new Mock <IProcessorArchitecture>(); arch.Setup(a => a.Name).Returns("FakeArch"); arch.Setup(a => a.MemoryGranularity).Returns(8); var platform = new Mock <IPlatform>(); var fileUri = ImageLocation.FromUri(OsPath.Relative("foo", "bar", "baz.exe")); var bytes = new byte[100]; var mem = new ByteMemoryArea(Address.Ptr32(0x1000), bytes); var imageMap = new SegmentMap( mem.BaseAddress, new ImageSegment("code", mem, AccessMode.ReadWriteExecute)); var program = new Program(imageMap, arch.Object, platform.Object); var project = new Project(ImageLocation.FromUri("foo/bar/baz.project")); project.AddProgram(fileUri, program); sc.AddService <IDecompiledFileService>(host.Object); //$REVIEW: we can probably remove the code below, it never is called // anymore. platform.Setup(p => p.CreateMetadata()).Returns(new TypeLibrary()); platform.Setup(p => p.Architecture).Returns(arch.Object); var dec = new Decompiler(project, sc); svc.Decompiler = dec; Assert.IsNotNull(svc.Decompiler.Project); Assert.AreEqual("baz.exe", svc.ProjectName, "Should have project name available."); }
public override DownloadClientInfo GetStatus() { var version = Proxy.GetApiVersion(Settings); var config = Proxy.GetConfig(Settings); var destDir = new OsPath(config.SavePath); if (Settings.MusicCategory.IsNotNullOrWhiteSpace() && version >= Version.Parse("2.0")) { if (Proxy.GetLabels(Settings).TryGetValue(Settings.MusicCategory, out var label) && label.SavePath.IsNotNullOrWhiteSpace()) { var labelDir = new OsPath(label.SavePath); if (labelDir.IsRooted) { destDir = labelDir; } else { destDir = destDir + labelDir; } } } return(new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", OutputRootFolders = new List <OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) } }); }
public void Prld_MakePathsAbsolute() { var sProject = new Project_v4 { ArchitectureName = "testArch", PlatformName = "testOS", Inputs = { new DecompilerInput_v4 { Filename = "foo.exe", } } }; Given_TestArch(); Given_TestOS(); var ldr = mr.Stub <ILoader>(); ldr.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(new Program()); ldr.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(new byte[1000]); mr.ReplayAll(); var prld = new ProjectLoader(sc, ldr, listener); var project = prld.LoadProject(OsPath.Absolute("users", "bob", "projects", "foo.project"), sProject); Assert.AreEqual(OsPath.Absolute("users", "bob", "projects", "foo.exe"), project.Programs[0].Filename); }
public void should_return_os_path_when_getting_string_from_db() { var path = @"C:\Test\TV".AsOsAgnostic(); var osPath = new OsPath(path); Subject.Parse(path).Should().Be(osPath); }
public void should_return_parent_directory(string path, string expectedParent) { var osPath = new OsPath(path); osPath.Directory.Should().NotBeNull(); osPath.Directory.Should().Be(new OsPath(expectedParent)); }
public void should_add_directory_slash() { var osPath = new OsPath(@"C:\rooted\windows\path\"); osPath.Directory.Should().NotBeNull(); osPath.Directory.ToString().Should().Be(@"C:\rooted\windows\"); }
public override DownloadClientStatus GetStatus() { var config = _proxy.GetConfig(Settings); OsPath destDir = new OsPath(null); if (config.GetValueOrDefault("dir_active_download_flag") == "true") { destDir = new OsPath(config.GetValueOrDefault("dir_active_download")); } if (config.GetValueOrDefault("dir_completed_download_flag") == "true") { destDir = new OsPath(config.GetValueOrDefault("dir_completed_download")); if (config.GetValueOrDefault("dir_add_label") == "true") { destDir = destDir + Settings.TvCategory; } } var status = new DownloadClientStatus { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" }; if (!destDir.IsEmpty) { status.OutputRootFolders = new List <OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; } return(status); }
public void Prld_MakePathsAbsolute() { var sProject = new Project_v4 { ArchitectureName = "testArch", PlatformName = "testOS", Inputs = { new DecompilerInput_v4 { Filename = "foo.exe", } } }; Given_TestArch(); Given_TestOS(); var ldr = new Mock <ILoader>(); ldr.Setup(l => l.LoadExecutable( It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <Address>())).Returns(new Program()); ldr.Setup(l => l.LoadImageBytes( It.IsAny <string>(), It.IsAny <int>())).Returns(new byte[1000]); var prld = new ProjectLoader(sc, ldr.Object, listener.Object); var project = prld.LoadProject(OsPath.Absolute("users", "bob", "projects", "foo.project"), sProject); Assert.AreEqual(OsPath.Absolute("users", "bob", "projects", "foo.exe"), project.Programs[0].Filename); }
public void should_not_ignore_trailing_slash_during_compare() { var left = new OsPath(@"/rooted/linux/path/"); var right = new OsPath(@"/rooted/linux/path"); left.Should().NotBe(right); }
private void ValidateMapping(List <RemotePathMapping> existing, RemotePathMapping mapping) { if (mapping.Host.IsNullOrWhiteSpace()) { throw new ArgumentException("Invalid Host"); } var remotePath = new OsPath(mapping.RemotePath); var localPath = new OsPath(mapping.LocalPath); if (remotePath.IsEmpty) { throw new ArgumentException("Invalid RemotePath"); } if (localPath.IsEmpty || !localPath.IsRooted) { throw new ArgumentException("Invalid LocalPath"); } if (!_diskProvider.FolderExists(localPath.FullPath)) { throw new DirectoryNotFoundException("Can't add mount point directory that doesn't exist."); } if (existing.Exists(r => r.Host == mapping.Host && r.RemotePath == mapping.RemotePath)) { throw new InvalidOperationException("RemotePath already mounted."); } }
protected IEnumerable <SabnzbdCategory> GetCategories(SabnzbdConfig config) { var completeDir = new OsPath(config.Misc.complete_dir); if (!completeDir.IsRooted) { if (HasVersion(2, 0)) { var status = _proxy.GetFullStatus(Settings); completeDir = new OsPath(status.CompleteDir); } else { var queue = _proxy.GetQueue(0, 1, Settings); var defaultRootFolder = new OsPath(queue.DefaultRootFolder); completeDir = defaultRootFolder + completeDir; } } foreach (var category in config.Categories) { var relativeDir = new OsPath(category.Dir.TrimEnd('*')); category.FullPath = completeDir + relativeDir; yield return(category); } }
public void DecSvc_DecompilerProjectName() { IDecompilerService svc = new DecompilerService(); var loader = mr.StrictMock <ILoader>(); var host = mr.StrictMock <DecompilerHost>(); var arch = mr.StrictMock <IProcessorArchitecture>(); var platform = mr.StrictMock <IPlatform>(); var fileName = OsPath.Relative("foo", "bar", "baz.exe"); var bytes = new byte[100]; var mem = new MemoryArea(Address.Ptr32(0x1000), bytes); var imageMap = new SegmentMap( mem.BaseAddress, new ImageSegment("code", mem, AccessMode.ReadWriteExecute)); var prog = new Program(imageMap, arch, platform); sc.AddService <DecompilerHost>(host); platform.Stub(p => p.CreateMetadata()).Return(new TypeLibrary()); loader.Stub(l => l.LoadImageBytes(fileName, 0)).Return(bytes); loader.Stub(l => l.LoadExecutable(fileName, bytes, null)).Return(prog); loader.Replay(); var dec = new DecompilerDriver(loader, sc); mr.ReplayAll(); svc.Decompiler = dec; svc.Decompiler.Load(fileName); Assert.IsNotNull(svc.Decompiler.Project); Assert.AreEqual("baz.exe", svc.ProjectName, "Should have project name available."); mr.VerifyAll(); }
public override DownloadClientInfo GetStatus() { try { var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); // Download station returns the path without the leading `/`, but the leading // slash is required to get the full path back from download station. var path = new OsPath($"/{GetDownloadDirectory()}"); var fullPath = _sharedFolderResolver.RemapToFullPath(path, Settings, serialNumber); return(new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", OutputRootFolders = new List <OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, fullPath) } }); } catch (DownloadClientException e) { _logger.Debug(e, "Failed to get config from Download Station"); throw; } }
public void Prld_LoadScripts() { var xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <project xmlns=""http://schemata.jklnet.org/Reko/v5""> <arch>testArch</arch> <platform>testOS</platform> <script> <location>file:fake.script</location> </script> </project>"; var ldr = new Mock <ILoader>(); Given_TestArch(); Given_TestOS(); Given_Script(ldr, AbsolutePathEndingWith("dir", "fake.script")); var location = ImageLocation.FromUri(OsPath.Absolute("dir", "script.proj")); var prld = new ProjectLoader(sc, ldr.Object, location, listener.Object); var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); var project = prld.LoadProject(stream); Assert.AreEqual( OsPath.Absolute("dir", "fake.script"), project.ScriptFiles.Single().Location.FilesystemPath); }
public override DownloadClientInfo GetStatus() { var config = _proxy.GetConfig(Settings); var label = _proxy.GetLabelOptions(Settings); OsPath destDir; if (label != null && label.ApplyMoveCompleted && label.MoveCompleted) { // if label exists and a label completed path exists and is enabled use it instead of global destDir = new OsPath(label.MoveCompletedPath); } else if (config.GetValueOrDefault("move_completed", false).ToString() == "True") { destDir = new OsPath(config.GetValueOrDefault("move_completed_path") as string); } else { destDir = new OsPath(config.GetValueOrDefault("download_location") as string); } var status = new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" }; if (!destDir.IsEmpty) { status.OutputRootFolders = new List <OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; } return(status); }
public void Prld_MakePathsAbsolute_From_Uri() { var sProject = new Project_v5 { ArchitectureName = "testArch", PlatformName = "testOS", InputFiles = { new DecompilerInput_v5 { Location = "file:foo.exe", }, } }; Given_TestArch(); Given_TestOS(); var ldr = new Mock <ILoader>(); ldr.Setup(l => l.Load( It.IsAny <ImageLocation>(), It.IsAny <string>(), It.IsAny <Address>())).Returns(new Program()); ldr.Setup(l => l.LoadFileBytes( It.IsAny <string>())).Returns(new byte[1000]); var projectPath = OsPath.Absolute("users", "bob", "projects", "foo.project"); var location = ImageLocation.FromUri(projectPath); var prld = new ProjectLoader(sc, ldr.Object, location, listener.Object); var project = prld.LoadProject(sProject); Assert.AreEqual(OsPath.Absolute("users", "bob", "projects", "foo.exe"), project.Programs[0].Location.FilesystemPath); }
public void should_return_string_when_saving_os_path_to_db() { var path = @"C:\Test\TV".AsOsAgnostic(); var osPath = new OsPath(path); Subject.ToDB(osPath).Should().Be(path); }
public void DecSvc_DecompilerProjectName() { IDecompilerService svc = new DecompilerService(); var loader = new Mock <ILoader>(); var host = new Mock <IDecompiledFileService>(); var arch = new Mock <IProcessorArchitecture>(); arch.Setup(a => a.Name).Returns("FakeArch"); arch.Setup(a => a.MemoryGranularity).Returns(8); var platform = new Mock <IPlatform>(); var fileName = OsPath.Relative("foo", "bar", "baz.exe"); var bytes = new byte[100]; var mem = new ByteMemoryArea(Address.Ptr32(0x1000), bytes); var imageMap = new SegmentMap( mem.BaseAddress, new ImageSegment("code", mem, AccessMode.ReadWriteExecute)); var program = new Program(imageMap, arch.Object, platform.Object); sc.AddService <IDecompiledFileService>(host.Object); platform.Setup(p => p.CreateMetadata()).Returns(new TypeLibrary()); platform.Setup(p => p.Architecture).Returns(arch.Object); loader.Setup(l => l.LoadImageBytes(fileName, 0)).Returns(bytes); loader.Setup(l => l.LoadExecutable(fileName, bytes, null, null)).Returns(program); var dec = new Decompiler(loader.Object, sc); svc.Decompiler = dec; svc.Decompiler.Load(fileName); Assert.IsNotNull(svc.Decompiler.Project); Assert.AreEqual("baz.exe", svc.ProjectName, "Should have project name available."); }
public void should_fix_slashes_windows() { var osPath = new OsPath(@"C:/on/windows/transmission\uses/forward/slashes"); osPath.Kind.Should().Be(OsPathKind.Windows); osPath.FullPath.Should().Be(@"C:\on\windows\transmission\uses\forward\slashes"); }
public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) { // On API version >= 2.6.1 this is already set correctly if (!item.OutputPath.IsEmpty) { return(item); } var files = Proxy.GetTorrentFiles(item.DownloadId.ToLower(), Settings); if (!files.Any()) { _logger.Debug($"No files found for torrent {item.Title} in qBittorrent"); return(item); } var properties = Proxy.GetTorrentProperties(item.DownloadId.ToLower(), Settings); var savePath = new OsPath(properties.SavePath); var result = item.Clone(); // get the first subdirectory - QBittorrent returns `/` path separators even on windows... var relativePath = new OsPath(files[0].Name); while (!relativePath.Directory.IsEmpty) { relativePath = relativePath.Directory; } var outputPath = savePath + relativePath.FileName; result.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); return(result); }
public void should_fix_slashes_unix() { var osPath = new OsPath(@"/just/a/test\to\verify the/slashes\"); osPath.Kind.Should().Be(OsPathKind.Unix); osPath.FullPath.Should().Be(@"/just/a/test/to/verify the/slashes/"); }
public override DownloadClientStatus GetStatus() { var config = _proxy.GetConfig(Settings); var destDir = new OsPath(config.GetValueOrDefault("download_location") as string); if (config.GetValueOrDefault("move_completed", false).ToString() == "True") { destDir = new OsPath(config.GetValueOrDefault("move_completed_path") as string); } var status = new DownloadClientStatus { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" }; if (!destDir.IsEmpty) { status.OutputRootFolders = new List <OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; } return(status); }
public void should_compare_unix_ospathkind_case_sensitive() { var left = new OsPath(@"/rooted/Linux/path"); var right = new OsPath(@"/rooted/linux/path"); left.Should().NotBe(right); }
public void should_compare_windows_ospathkind_case_insensitive() { var left = new OsPath(@"C:\rooted\Windows\path"); var right = new OsPath(@"C:\rooted\windows\path"); left.Should().Be(right); }
private void EnsureMovieFolder(MovieFile movieFile, Movie movie, string filePath) { var movieFolder = Path.GetDirectoryName(filePath); movie.Path = movieFolder; var rootFolder = new OsPath(movieFolder).Directory.FullPath; var fileName = Path.GetFileName(filePath); if (!_diskProvider.FolderExists(rootFolder)) { throw new DirectoryNotFoundException(string.Format("Root folder '{0}' was not found.", rootFolder)); } var changed = false; var newEvent = new MovieFolderCreatedEvent(movie, movieFile); if (!_diskProvider.FolderExists(movieFolder)) { CreateFolder(movieFolder); newEvent.MovieFolder = movieFolder; changed = true; } if (changed) { _eventAggregator.PublishEvent(newEvent); } }
private void UpdateMovieLibrary(XbmcSettings settings, Movie movie) { try { var moviePath = GetMoviePath(settings, movie); if (moviePath != null) { moviePath = new OsPath(moviePath).Directory.FullPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); _logger.Debug("Updating movie {0} (Path: {1}) on XBMC host: {2}", movie, moviePath, settings.Address); } else { _logger.Debug("Movie {0} doesn't exist on XBMC host: {1}, Updating Entire Library", movie, settings.Address); } var response = _proxy.UpdateLibrary(settings, moviePath); if (!response.Equals("OK", StringComparison.InvariantCultureIgnoreCase)) { _logger.Debug("Failed to update library for: {0}", settings.Address); } } catch (Exception ex) { _logger.Debug(ex, ex.Message); } }
public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false) { if (trackedDownload.DownloadItem.Status != DownloadItemStatus.Completed) { return; } if (!ignoreWarnings) { var historyItem = _historyService.MostRecentForDownloadId(trackedDownload.DownloadItem.DownloadId); if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace()) { trackedDownload.Warn("Download wasn't grabbed by Sonarr and not in a category, Skipping."); return; } var downloadItemOutputPath = trackedDownload.DownloadItem.OutputPath; if (downloadItemOutputPath.IsEmpty) { trackedDownload.Warn("Download doesn't contain intermediate path, Skipping."); return; } if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) || (OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath)) { trackedDownload.Warn("[{0}] is not a valid local path. You may need a Remote Path Mapping.", downloadItemOutputPath); return; } var downloadedEpisodesFolder = new OsPath(_configService.DownloadedEpisodesFolder); if (downloadedEpisodesFolder.Contains(downloadItemOutputPath)) { trackedDownload.Warn("Intermediate Download path inside drone factory, Skipping."); return; } var series = _parsingService.GetSeries(trackedDownload.DownloadItem.Title); if (series == null) { if (historyItem != null) { series = _seriesService.GetSeries(historyItem.SeriesId); } if (series == null) { trackedDownload.Warn("Series title mismatch, automatic import is not possible."); return; } } } Import(trackedDownload); }
public void should_combine_mixed_slashes() { var left = new OsPath(@"C:/on/windows/transmission"); var right = new OsPath(@"uses/forward/slashes", OsPathKind.Unknown); var osPath = left + right; osPath.Kind.Should().Be(OsPathKind.Windows); osPath.FullPath.Should().Be(@"C:\on\windows\transmission\uses\forward\slashes"); }
public override HealthCheck Check() { var droneFactoryFolder = new OsPath(_configService.DownloadedEpisodesFolder); var downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new { downloadClient = v, status = v.GetStatus() }).ToList(); var downloadClientIsLocalHost = downloadClients.All(v => v.status.IsLocalhost); var downloadClientOutputInDroneFactory = !droneFactoryFolder.IsEmpty && downloadClients.Any(v => v.status.OutputRootFolders != null && v.status.OutputRootFolders.Any(droneFactoryFolder.Contains)); if (!_configService.IsDefined("EnableCompletedDownloadHandling")) { // Migration helper logic if (!downloadClientIsLocalHost) { return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Multi-Computer unsupported)", "Migrating-to-Completed-Download-Handling#Unsupported-download-client-on-different-computer"); } if (downloadClients.All(v => v.downloadClient is Sabnzbd)) { // With Sabnzbd we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd - Conflicting Category)", "Migrating-to-Completed-Download-Handling#sabnzbd-conflicting-download-client-category"); } return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd)", "Migrating-to-Completed-Download-Handling#sabnzbd-enable-completed-download-handling"); } if (downloadClients.All(v => v.downloadClient is Nzbget)) { // With Nzbget we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget - Conflicting Category)", "Migrating-to-Completed-Download-Handling#nzbget-conflicting-download-client-category"); } return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget)", "Migrating-to-Completed-Download-Handling#nzbget-enable-completed-download-handling"); } return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible", "Migrating-to-Completed-Download-Handling"); } if (!_configService.EnableCompletedDownloadHandling && droneFactoryFolder.IsEmpty) { return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling or configure Drone factory"); } return new HealthCheck(GetType()); }
public void should_auto_detect_kind(string path, OsPathKind kind) { var result = new OsPath(path); result.Kind.Should().Be(kind); if (kind == OsPathKind.Windows) { result.IsWindowsPath.Should().BeTrue(); result.IsUnixPath.Should().BeFalse(); } else if (kind == OsPathKind.Unix) { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeTrue(); } else { result.IsWindowsPath.Should().BeFalse(); result.IsUnixPath.Should().BeFalse(); } }
private void EnsureEpisodeFolder(EpisodeFile episodeFile, Series series, int seasonNumber, string filePath) { var episodeFolder = Path.GetDirectoryName(filePath); var seasonFolder = _buildFileNames.BuildSeasonPath(series, seasonNumber); var seriesFolder = series.Path; var rootFolder = new OsPath(seriesFolder).Directory.FullPath; if (!_diskProvider.FolderExists(rootFolder)) { throw new DirectoryNotFoundException(string.Format("Root folder '{0}' was not found.", rootFolder)); } var changed = false; var newEvent = new EpisodeFolderCreatedEvent(series, episodeFile); if (!_diskProvider.FolderExists(seriesFolder)) { CreateFolder(seriesFolder); newEvent.SeriesFolder = seriesFolder; changed = true; } if (seriesFolder != seasonFolder && !_diskProvider.FolderExists(seasonFolder)) { CreateFolder(seasonFolder); newEvent.SeasonFolder = seasonFolder; changed = true; } if (seasonFolder != episodeFolder && !_diskProvider.FolderExists(episodeFolder)) { CreateFolder(episodeFolder); newEvent.EpisodeFolder = episodeFolder; changed = true; } if (changed) { _eventAggregator.PublishEvent(newEvent); } }
public void should_create_relative_path(string parent, string child, string expected) { var left = new OsPath(child); var right = new OsPath(parent); var osPath = left - right; osPath.Kind.Should().Be(OsPathKind.Unknown); osPath.FullPath.Should().Be(expected); }
public void should_combine_path(string left, string right, string expectedResult) { var osPathLeft = new OsPath(left); var osPathRight = new OsPath(right); var result = osPathLeft + osPathRight; result.FullPath.Should().Be(expectedResult); }
public void should_detect_rooted_ospaths(String path) { var osPath = new OsPath(path); osPath.IsRooted.Should().BeTrue(); }
private void ValidateMapping(List<RemotePathMapping> existing, RemotePathMapping mapping) { if (mapping.Host.IsNullOrWhiteSpace()) { throw new ArgumentException("Invalid Host"); } var remotePath = new OsPath(mapping.RemotePath); var localPath = new OsPath(mapping.LocalPath); if (remotePath.IsEmpty) { throw new ArgumentException("Invalid RemotePath"); } if (localPath.IsEmpty || !localPath.IsRooted) { throw new ArgumentException("Invalid LocalPath"); } if (!_diskProvider.FolderExists(localPath.FullPath)) { throw new DirectoryNotFoundException("Can't add mount point directory that doesn't exist."); } if (existing.Exists(r => r.Host == mapping.Host && r.RemotePath == mapping.RemotePath)) { throw new InvalidOperationException("RemotePath already mounted."); } }
public OsPath RemapLocalToRemote(string host, OsPath localPath) { if (localPath.IsEmpty) { return localPath; } foreach (var mapping in All()) { if (host == mapping.Host && new OsPath(mapping.LocalPath).Contains(localPath)) { var remotePath = new OsPath(mapping.RemotePath) + (localPath - new OsPath(mapping.LocalPath)); return remotePath; } } return localPath; }
public void should_return_empty_as_parent_of_root_unc() { var osPath = new OsPath(@"\\unc"); osPath.Directory.IsEmpty.Should().BeTrue(); }
public void should_detect_unrooted_ospaths(string path) { var osPath = new OsPath(path); osPath.IsRooted.Should().BeFalse(); }
public void should_return_filename(string path, string expectedFilePath) { var osPath = new OsPath(path); osPath.FileName.Should().Be(expectedFilePath); }
public void should_evaluate_contains(string parent, string child, bool expectedResult) { var left = new OsPath(parent); var right = new OsPath(child); var result = left.Contains(right); result.Should().Be(expectedResult); }
public OsPath RemapRemoteToLocal(String host, OsPath remotePath) { if (remotePath.IsEmpty) { return remotePath; } foreach (var mapping in All()) { if (host == mapping.Host && new OsPath(mapping.RemotePath).Contains(remotePath)) { var localPath = new OsPath(mapping.LocalPath) + (remotePath - new OsPath(mapping.RemotePath)); return localPath; } } return remotePath; }
private void CreateFolder(string directoryName) { Ensure.That(directoryName, () => directoryName).IsNotNullOrWhiteSpace(); var parentFolder = new OsPath(directoryName).Directory.FullPath; if (!_diskProvider.FolderExists(parentFolder)) { CreateFolder(parentFolder); } try { _diskProvider.CreateFolder(directoryName); } catch (IOException ex) { _logger.Error(ex, "Unable to create directory: " + directoryName); } _mediaFileAttributeService.SetFolderPermissions(directoryName); }
protected override OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent) { _logger.Debug("Vuze output directory: {0}", outputPath); return outputPath; }