|
@@ -1,3 +1,5 @@
|
|
|
|
+#nullable enable
|
|
|
|
+
|
|
using System;
|
|
using System;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
@@ -21,8 +23,8 @@ namespace Emby.Server.Implementations.Library
|
|
/// <param name="fileSystem">The file system.</param>
|
|
/// <param name="fileSystem">The file system.</param>
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
/// <param name="directoryService">The directory service.</param>
|
|
/// <param name="directoryService">The directory service.</param>
|
|
- /// <exception cref="ArgumentException">Item must have a path</exception>
|
|
|
|
- public static void SetInitialItemValues(BaseItem item, Folder parent, IFileSystem fileSystem, ILibraryManager libraryManager, IDirectoryService directoryService)
|
|
|
|
|
|
+ /// <exception cref="ArgumentException">Item must have a path.</exception>
|
|
|
|
+ public static void SetInitialItemValues(BaseItem item, Folder? parent, IFileSystem fileSystem, ILibraryManager libraryManager, IDirectoryService directoryService)
|
|
{
|
|
{
|
|
// This version of the below method has no ItemResolveArgs, so we have to require the path already being set
|
|
// This version of the below method has no ItemResolveArgs, so we have to require the path already being set
|
|
if (string.IsNullOrEmpty(item.Path))
|
|
if (string.IsNullOrEmpty(item.Path))
|
|
@@ -43,9 +45,9 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
|
|
// Make sure DateCreated and DateModified have values
|
|
// Make sure DateCreated and DateModified have values
|
|
var fileInfo = directoryService.GetFile(item.Path);
|
|
var fileInfo = directoryService.GetFile(item.Path);
|
|
- SetDateCreated(item, fileSystem, fileInfo);
|
|
|
|
|
|
+ SetDateCreated(item, fileInfo);
|
|
|
|
|
|
- EnsureName(item, item.Path, fileInfo);
|
|
|
|
|
|
+ EnsureName(item, fileInfo);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -72,9 +74,9 @@ namespace Emby.Server.Implementations.Library
|
|
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
|
|
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
|
|
|
|
|
|
// Make sure the item has a name
|
|
// Make sure the item has a name
|
|
- EnsureName(item, item.Path, args.FileInfo);
|
|
|
|
|
|
+ EnsureName(item, args.FileInfo);
|
|
|
|
|
|
- item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
|
|
|
|
+ item.IsLocked = item.Path.Contains("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) ||
|
|
item.GetParents().Any(i => i.IsLocked);
|
|
item.GetParents().Any(i => i.IsLocked);
|
|
|
|
|
|
// Make sure DateCreated and DateModified have values
|
|
// Make sure DateCreated and DateModified have values
|
|
@@ -84,28 +86,15 @@ namespace Emby.Server.Implementations.Library
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Ensures the name.
|
|
/// Ensures the name.
|
|
/// </summary>
|
|
/// </summary>
|
|
- private static void EnsureName(BaseItem item, string fullPath, FileSystemMetadata fileInfo)
|
|
|
|
|
|
+ private static void EnsureName(BaseItem item, FileSystemMetadata fileInfo)
|
|
{
|
|
{
|
|
// If the subclass didn't supply a name, add it here
|
|
// If the subclass didn't supply a name, add it here
|
|
- if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(fullPath))
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path))
|
|
{
|
|
{
|
|
- var fileName = fileInfo == null ? Path.GetFileName(fullPath) : fileInfo.Name;
|
|
|
|
-
|
|
|
|
- item.Name = GetDisplayName(fileName, fileInfo != null && fileInfo.IsDirectory);
|
|
|
|
|
|
+ item.Name = fileInfo.IsDirectory ? fileInfo.Name : Path.GetFileNameWithoutExtension(fileInfo.Name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets the display name.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="path">The path.</param>
|
|
|
|
- /// <param name="isDirectory">if set to <c>true</c> [is directory].</param>
|
|
|
|
- /// <returns>System.String.</returns>
|
|
|
|
- private static string GetDisplayName(string path, bool isDirectory)
|
|
|
|
- {
|
|
|
|
- return isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Ensures DateCreated and DateModified have values.
|
|
/// Ensures DateCreated and DateModified have values.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -114,21 +103,6 @@ namespace Emby.Server.Implementations.Library
|
|
/// <param name="args">The args.</param>
|
|
/// <param name="args">The args.</param>
|
|
private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args)
|
|
private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args)
|
|
{
|
|
{
|
|
- if (fileSystem == null)
|
|
|
|
- {
|
|
|
|
- throw new ArgumentNullException(nameof(fileSystem));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (item == null)
|
|
|
|
- {
|
|
|
|
- throw new ArgumentNullException(nameof(item));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (args == null)
|
|
|
|
- {
|
|
|
|
- throw new ArgumentNullException(nameof(args));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// See if a different path came out of the resolver than what went in
|
|
// See if a different path came out of the resolver than what went in
|
|
if (!fileSystem.AreEqual(args.Path, item.Path))
|
|
if (!fileSystem.AreEqual(args.Path, item.Path))
|
|
{
|
|
{
|
|
@@ -136,7 +110,7 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
|
|
if (childData != null)
|
|
if (childData != null)
|
|
{
|
|
{
|
|
- SetDateCreated(item, fileSystem, childData);
|
|
|
|
|
|
+ SetDateCreated(item, childData);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -144,17 +118,17 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
|
|
if (fileData.Exists)
|
|
if (fileData.Exists)
|
|
{
|
|
{
|
|
- SetDateCreated(item, fileSystem, fileData);
|
|
|
|
|
|
+ SetDateCreated(item, fileData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- SetDateCreated(item, fileSystem, args.FileInfo);
|
|
|
|
|
|
+ SetDateCreated(item, args.FileInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemMetadata info)
|
|
|
|
|
|
+ private static void SetDateCreated(BaseItem item, FileSystemMetadata? info)
|
|
{
|
|
{
|
|
var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
|
|
var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
|
|
|
|
|
|
@@ -163,7 +137,7 @@ namespace Emby.Server.Implementations.Library
|
|
// directoryService.getFile may return null
|
|
// directoryService.getFile may return null
|
|
if (info != null)
|
|
if (info != null)
|
|
{
|
|
{
|
|
- var dateCreated = fileSystem.GetCreationTimeUtc(info);
|
|
|
|
|
|
+ var dateCreated = info.CreationTimeUtc;
|
|
|
|
|
|
if (dateCreated.Equals(DateTime.MinValue))
|
|
if (dateCreated.Equals(DateTime.MinValue))
|
|
{
|
|
{
|