private string GetVolumeLabel(FileSystemMetadata dir) { return(dir.Name); }
public TSStreamClipFile(FileSystemMetadata fileInfo) { FileInfo = fileInfo; Name = fileInfo.Name.ToUpper(); }
/// <summary> /// Sets the image path. /// </summary> /// <param name="item">The item.</param> /// <param name="imageType">Type of the image.</param> /// <param name="file">The file.</param> public static void SetImagePath(this BaseItem item, ImageType imageType, FileSystemMetadata file) { item.SetImagePath(imageType, 0, file); }
public virtual DateTime GetCreationTimeUtc(FileSystemMetadata info) { return(info.CreationTimeUtc); }
private bool ContainsFile(List <VideoInfo> result, FileSystemMetadata file) { return(result.Any(i => ContainsFile(i, file))); }
/// <summary> /// Shoulds the ignore. /// </summary> /// <param name="fileInfo">The file information.</param> /// <param name="parent">The parent.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent) { // Don't ignore top level folders if (fileInfo.IsDirectory && parent is AggregateFolder) { return(false); } var filename = fileInfo.Name; var isHidden = fileInfo.IsHidden; var path = fileInfo.FullName; // Handle mac .DS_Store // https://github.com/MediaBrowser/MediaBrowser/issues/427 if (filename.IndexOf("._", StringComparison.OrdinalIgnoreCase) == 0) { return(true); } // Ignore hidden files and folders if (isHidden) { if (parent == null) { var parentFolderName = Path.GetFileName(_fileSystem.GetDirectoryName(path)); if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) { return(false); } if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return(false); } } // Sometimes these are marked hidden if (_fileSystem.IsRootPath(path)) { return(false); } return(true); } if (fileInfo.IsDirectory) { // Ignore any folders in our list if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase)) { return(true); } if (parent != null) { // Ignore trailer folders but allow it at the collection level if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) && !(parent is AggregateFolder) && !(parent is UserRootFolder)) { return(true); } if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } } } else { if (parent != null) { // Don't resolve these into audio files if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename)) { return(true); } } // Ignore samples var sampleFilename = " " + filename.Replace(".", " ", StringComparison.OrdinalIgnoreCase) .Replace("-", " ", StringComparison.OrdinalIgnoreCase) .Replace("_", " ", StringComparison.OrdinalIgnoreCase) .Replace("!", " ", StringComparison.OrdinalIgnoreCase); if (sampleFilename.IndexOf(" sample ", StringComparison.OrdinalIgnoreCase) != -1) { return(true); } } return(false); }
private XmlReader GetXmlReader(FileSystemMetadata xmlFile) { return(GetXmlReader(_fileSystem.ReadAllText(xmlFile.FullName, Encoding.UTF8))); }
public BdInfoFileInfo(IFileSystem fileSystem, FileSystemMetadata impl) { _fileSystem = fileSystem; _impl = impl; }
public BdInfoDirectoryInfo(IFileSystem fileSystem, string path) { _fileSystem = fileSystem; _impl = _fileSystem.GetDirectoryInfo(path); }
public BdInfoFileInfo(FileSystemMetadata impl) { _impl = impl; }
public TSStreamClipFile(FileSystemMetadata fileInfo, IFileSystem fileSystem) { FileInfo = fileInfo; _fileSystem = fileSystem; Name = fileInfo.Name.ToUpper(); }
private static bool ContainsFile(AudioBookInfo result, FileSystemMetadata file) { return(result.Files.Any(i => ContainsFile(i, file)) || result.AlternateVersions.Any(i => ContainsFile(i, file)) || result.Extras.Any(i => ContainsFile(i, file))); }
private static bool ContainsFile(IEnumerable <AudioBookInfo> result, FileSystemMetadata file) { return(result.Any(i => ContainsFile(i, file))); }
public object Post(SafeDeleteAction request) { _logger.Info("POST SafeDeleteAction: {0}", request); long item_id = long.Parse(request.item_id); BaseItem item = _lm.GetItemById(item_id); List <FileSystemMetadata> del_paths = item.GetDeletePaths(false); PathWalker walker = new PathWalker(del_paths, _fs); List <KeyValuePair <string, long> > file_list = walker.GetFileNames(); Dictionary <string, int> ext_counts = walker.GetExtCounts(); // verify action token string file_info_string = ""; string file_list_hash = ""; foreach (var file_item in file_list) { file_info_string += file_item.Key + "|" + file_item.Value + "|"; } using (MD5 md5Hash = MD5.Create()) { byte[] hashBytes = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(file_info_string)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } file_list_hash = sb.ToString(); } Dictionary <string, object> result = new Dictionary <string, object>(); if (file_list_hash != request.action_token) { result.Add("result", false); result.Add("message", "The action tokens to not match."); return(result); } // do file move string recycle_path = Plugin.Instance.Configuration.RecycledPath; if (string.IsNullOrEmpty(recycle_path)) { result.Add("result", false); result.Add("message", "Recycle path not set."); return(result); } if (!_fs.DirectoryExists(recycle_path)) { result.Add("result", false); result.Add("message", "Recycle path does not exist."); return(result); } // do file moves string time_stamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"); int item_number = 0; bool action_result = true; string action_message = "Files moved."; foreach (var del_item in del_paths) { _logger.Info("Item Delete Path: " + del_item.FullName); if (del_item.IsDirectory) { FileSystemMetadata fsm = _fs.GetDirectoryInfo(del_item.FullName); string destination = System.IO.Path.Combine(recycle_path, time_stamp, item_number.ToString()); _logger.Info("Item Delete Destination Path: " + destination); try { _fs.CreateDirectory(destination); destination = System.IO.Path.Combine(destination, fsm.Name); _fs.MoveDirectory(del_item.FullName, destination); } catch (Exception e) { action_result = false; action_message = e.Message; } } else { FileSystemMetadata fsm = _fs.GetDirectoryInfo(del_item.FullName); string destination = System.IO.Path.Combine(recycle_path, time_stamp, item_number.ToString()); _logger.Info("Item Delete Destination Path: " + destination); try { _fs.CreateDirectory(destination); destination = System.IO.Path.Combine(destination, fsm.Name); _fs.MoveFile(del_item.FullName, destination); } catch (Exception e) { action_result = false; action_message = e.Message; } } if (!action_result) { break; } item_number++; } result.Add("result", action_result); result.Add("message", action_message); return(result); }
public BDROM( string path, IFileSystem fileSystem, ITextEncoding textEncoding) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } _fileSystem = fileSystem; // // Locate BDMV directories. // DirectoryBDMV = GetDirectoryBDMV(path); if (DirectoryBDMV == null) { throw new Exception("Unable to locate BD structure."); } DirectoryRoot = _fileSystem.GetDirectoryInfo(_fileSystem.GetDirectoryName(DirectoryBDMV.FullName)); DirectoryBDJO = GetDirectory("BDJO", DirectoryBDMV, 0); DirectoryCLIPINF = GetDirectory("CLIPINF", DirectoryBDMV, 0); DirectoryPLAYLIST = GetDirectory("PLAYLIST", DirectoryBDMV, 0); DirectorySNP = GetDirectory("SNP", DirectoryRoot, 0); DirectorySTREAM = GetDirectory("STREAM", DirectoryBDMV, 0); DirectorySSIF = GetDirectory("SSIF", DirectorySTREAM, 0); if (DirectoryCLIPINF == null || DirectoryPLAYLIST == null) { throw new Exception("Unable to locate BD structure."); } // // Initialize basic disc properties. // VolumeLabel = GetVolumeLabel(DirectoryRoot); Size = (ulong)GetDirectorySize(DirectoryRoot); if (null != GetDirectory("BDSVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDirectory("SLYVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDirectory("ANYVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (DirectoryBDJO != null && _fileSystem.GetFilePaths(DirectoryBDJO.FullName).Any()) { IsBDJava = true; } if (DirectorySNP != null && GetFilePaths(DirectorySNP.FullName, ".mnv").Any()) { IsPSP = true; } if (DirectorySSIF != null && _fileSystem.GetFilePaths(DirectorySSIF.FullName).Any()) { Is3D = true; } if (_fileSystem.FileExists(Path.Combine(DirectoryRoot.FullName, "FilmIndex.xml"))) { IsDBOX = true; } // // Initialize file lists. // if (DirectoryPLAYLIST != null) { FileSystemMetadata[] files = GetFiles(DirectoryPLAYLIST.FullName, ".mpls").ToArray(); foreach (FileSystemMetadata file in files) { PlaylistFiles.Add( file.Name.ToUpper(), new TSPlaylistFile(this, file, _fileSystem, textEncoding)); } } if (DirectorySTREAM != null) { FileSystemMetadata[] files = GetFiles(DirectorySTREAM.FullName, ".m2ts").ToArray(); foreach (FileSystemMetadata file in files) { StreamFiles.Add( file.Name.ToUpper(), new TSStreamFile(file, _fileSystem)); } } if (DirectoryCLIPINF != null) { FileSystemMetadata[] files = GetFiles(DirectoryCLIPINF.FullName, ".clpi").ToArray(); foreach (FileSystemMetadata file in files) { StreamClipFiles.Add( file.Name.ToUpper(), new TSStreamClipFile(file, _fileSystem, textEncoding)); } } if (DirectorySSIF != null) { FileSystemMetadata[] files = GetFiles(DirectorySSIF.FullName, ".ssif").ToArray(); foreach (FileSystemMetadata file in files) { InterleavedFiles.Add( file.Name.ToUpper(), new TSInterleavedFile(file)); } } }
private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl) { _fileSystem = fileSystem; _impl = impl; }
private static bool ContainsFile(VideoFileInfo result, FileSystemMetadata file) { return(string.Equals(result.Path, file.FullName, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Shoulds the ignore. /// </summary> /// <param name="fileInfo">The file information.</param> /// <param name="parent">The parent.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent) { // Don't ignore top level folders if (fileInfo.IsDirectory && parent is AggregateFolder) { return(false); } var filename = fileInfo.Name; var path = fileInfo.FullName; // Handle mac .DS_Store // https://github.com/MediaBrowser/MediaBrowser/issues/427 if (_ignoreDotPrefix) { if (filename.IndexOf('.') == 0) { return(true); } } // Ignore hidden files and folders //if (fileInfo.IsHidden) //{ // if (parent == null) // { // var parentFolderName = Path.GetFileName(_fileSystem.GetDirectoryName(path)); // if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) // { // return false; // } // if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) // { // return false; // } // } // // Sometimes these are marked hidden // if (_fileSystem.IsRootPath(path)) // { // return false; // } // return true; //} if (fileInfo.IsDirectory) { // Ignore any folders in our list if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase)) { return(true); } if (parent != null) { // Ignore trailer folders but allow it at the collection level if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) && !(parent is AggregateFolder) && !(parent is UserRootFolder)) { return(true); } if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } } } else { if (parent != null) { // Don't resolve these into audio files if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename)) { return(true); } } // Ignore samples Match m = Regex.Match(filename, @"\bsample\b", RegexOptions.IgnoreCase); return(m.Success); } return(false); }
public TSInterleavedFile(FileSystemMetadata fileInfo) { FileInfo = fileInfo; Name = fileInfo.Name.ToUpper(); }
public Task<QueryResult<FileSystemMetadata>> GetFiles(SyncTarget target, CancellationToken cancellationToken) { var account = GetSyncAccounts() .FirstOrDefault(i => string.Equals(i.Id, target.Id, StringComparison.OrdinalIgnoreCase)); if (account == null) { throw new ArgumentException("Invalid SyncTarget supplied."); } var result = new QueryResult<FileSystemMetadata>(); FileSystemMetadata[] files; try { files = _fileSystem.GetFiles(account.Path, true) .ToArray(); } catch (DirectoryNotFoundException) { files = new FileSystemMetadata[] { }; } result.Items = files; result.TotalRecordCount = files.Length; return Task.FromResult(result); }
/// <summary> /// Gets the filtered file system entries. /// </summary> /// <param name="directoryService">The directory service.</param> /// <param name="path">The path.</param> /// <param name="fileSystem">The file system.</param> /// <param name="appHost">The application host.</param> /// <param name="logger">The logger.</param> /// <param name="args">The args.</param> /// <param name="flattenFolderDepth">The flatten folder depth.</param> /// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param> /// <returns>Dictionary{System.StringFileSystemInfo}.</returns> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> public static FileSystemMetadata[] GetFilteredFileSystemEntries( IDirectoryService directoryService, string path, IFileSystem fileSystem, IServerApplicationHost appHost, ILogger logger, ItemResolveArgs args, int flattenFolderDepth = 0, bool resolveShortcuts = true) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } var entries = directoryService.GetFileSystemEntries(path); if (!resolveShortcuts && flattenFolderDepth == 0) { return(entries); } var dict = new Dictionary <string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase); foreach (var entry in entries) { var isDirectory = entry.IsDirectory; var fullName = entry.FullName; if (resolveShortcuts && fileSystem.IsShortcut(fullName)) { try { var newPath = appHost.ExpandVirtualPath(fileSystem.ResolveShortcut(fullName)); if (string.IsNullOrEmpty(newPath)) { // invalid shortcut - could be old or target could just be unavailable logger.LogWarning("Encountered invalid shortcut: " + fullName); continue; } // Don't check if it exists here because that could return false for network shares. var data = fileSystem.GetDirectoryInfo(newPath); // add to our physical locations args.AddAdditionalLocation(newPath); dict[newPath] = data; } catch (Exception ex) { logger.LogError(ex, "Error resolving shortcut from {path}", fullName); } } else if (flattenFolderDepth > 0 && isDirectory) { foreach (var child in GetFilteredFileSystemEntries(directoryService, fullName, fileSystem, appHost, logger, args, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts)) { dict[child.FullName] = child; } } else { dict[fullName] = entry; } } var returnResult = new FileSystemMetadata[dict.Count]; var index = 0; var values = dict.Values; foreach (var value in values) { returnResult[index] = value; index++; } return(returnResult); }
/// <inheritdoc /> public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent) { // Don't ignore top level folders if (fileInfo.IsDirectory && parent is AggregateFolder) { return(false); } var filename = fileInfo.Name; // Ignore hidden files on UNIX if (Environment.OSVersion.Platform != PlatformID.Win32NT && filename[0] == '.') { return(true); } if (fileInfo.IsDirectory) { // Ignore any folders in our list if (_ignoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase)) { return(true); } if (parent != null) { // Ignore trailer folders but allow it at the collection level if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) && !(parent is AggregateFolder) && !(parent is UserRootFolder)) { return(true); } if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) { return(true); } } } else { if (parent != null) { // Don't resolve these into audio files if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename)) { return(true); } } // Ignore samples Match m = Regex.Match(filename, @"\bsample\b", RegexOptions.IgnoreCase); return(m.Success); } return(false); }
public virtual DateTime GetLastWriteTimeUtc(FileSystemMetadata info) { return(info.LastWriteTimeUtc); }
private Game ResolveGame(FileSystemMetadata file, GameSystem gameSystem) { var path = file.FullName; var platform = ResolverHelper.AttemptGetGamePlatformTypeFromPath(_fileSystem, path); if (string.IsNullOrEmpty(platform)) { return(null); } // For MAME we will allow all games in the same dir if (string.Equals(platform, "Arcade", StringComparison.OrdinalIgnoreCase)) { var extension = Path.GetExtension(path); if (string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase)) { // ignore zips that are bios roms. if (MameUtils.IsBiosRom(path)) { return(null); } var game = new Game { Name = MameUtils.GetFullNameFromPath(path, _logger), Path = path, IsInMixedFolder = true, Album = gameSystem.Name, AlbumId = gameSystem.InternalId, Container = extension.TrimStart('.') }; return(game); } } else { var validExtensions = GetExtensions(platform); var fileExtension = Path.GetExtension(path); if (!validExtensions.Contains(fileExtension, StringComparer.OrdinalIgnoreCase)) { return(null); } var game = new Game { Path = path, Album = gameSystem.Name, AlbumId = gameSystem.InternalId, Container = fileExtension.TrimStart('.') }; //if (gameFiles.Count > 1) //{ // game.MultiPartGameFiles = gameFiles.Select(i => i.FullName).ToArray(); // game.IsMultiPart = true; //} return(game); } return(null); }
private bool ContainsFile(VideoInfo result, FileSystemMetadata file) { return(result.Files.Any(i => ContainsFile(i, file)) || result.AlternateVersions.Any(i => ContainsFile(i, file)) || result.Extras.Any(i => ContainsFile(i, file))); }
private RemoteImageInfo GetImageInfo(FileSystemMetadata xmlFile, CancellationToken cancellationToken) { var height = 225; var width = 400; var url = string.Empty; using (var streamReader = new StreamReader(xmlFile.FullName, Encoding.UTF8)) { // Use XmlReader for best performance using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings { CheckCharacters = false, IgnoreProcessingInstructions = true, IgnoreComments = true, ValidationType = ValidationType.None })) { reader.MoveToContent(); // Loop through each element while (reader.Read()) { cancellationToken.ThrowIfCancellationRequested(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "thumb_width": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { int rval; // int.TryParse is local aware, so it can be probamatic, force us culture if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval)) { width = rval; } } break; } case "thumb_height": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { int rval; // int.TryParse is local aware, so it can be probamatic, force us culture if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval)) { height = rval; } } break; } case "filename": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { url = TVUtils.BannerUrl + val; } break; } default: reader.Skip(); break; } } } } } if (string.IsNullOrEmpty(url)) { return(null); } return(new RemoteImageInfo { Width = width, Height = height, ProviderName = Name, Url = url, Type = ImageType.Primary }); }