easier user library setup

This commit is contained in:
Luke Pulverenti
2014-02-21 00:04:11 -05:00
parent a91c676565
commit 7cd41a6ed6
17 changed files with 863 additions and 1068 deletions

View File

@@ -19,35 +19,6 @@ namespace MediaBrowser.Controller.Entities
public static IUserManager UserManager { get; set; }
public static IXmlSerializer XmlSerializer { get; set; }
/// <summary>
/// Gets the root folder path.
/// </summary>
/// <value>The root folder path.</value>
[IgnoreDataMember]
public string RootFolderPath
{
get
{
var path = Configuration.UseCustomLibrary ? GetRootFolderPath(Name) : ConfigurationManager.ApplicationPaths.DefaultUserViewsPath;
Directory.CreateDirectory(path);
return path;
}
}
/// <summary>
/// Gets the root folder path based on a given username
/// </summary>
/// <param name="username">The username.</param>
/// <returns>System.String.</returns>
private string GetRootFolderPath(string username)
{
var safeFolderName = FileSystem.GetValidFilename(username);
return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.RootFolderPath, safeFolderName);
}
/// <summary>
/// Gets or sets the password.
/// </summary>
@@ -97,24 +68,16 @@ namespace MediaBrowser.Controller.Entities
}
}
/// <summary>
/// The _root folder
/// </summary>
private UserRootFolder _rootFolder;
/// <summary>
/// Gets the root folder.
/// </summary>
/// <value>The root folder.</value>
[IgnoreDataMember]
public UserRootFolder RootFolder
public Folder RootFolder
{
get
{
return _rootFolder ?? (LibraryManager.GetUserRootFolder(RootFolderPath));
}
private set
{
_rootFolder = value;
return LibraryManager.GetUserRootFolder();
}
}
@@ -165,22 +128,6 @@ namespace MediaBrowser.Controller.Entities
}
}
/// <summary>
/// Reloads the root media folder
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public async Task ValidateMediaLibrary(IProgress<double> progress, CancellationToken cancellationToken)
{
Logger.Info("Validating media library for {0}", Name);
await RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
await RootFolder.ValidateChildren(progress, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Renames the user.
/// </summary>
@@ -215,29 +162,10 @@ namespace MediaBrowser.Controller.Entities
{
Directory.CreateDirectory(newConfigDirectory);
}
var customLibraryPath = GetRootFolderPath(Name);
// Move the root folder path if using a custom library
if (Directory.Exists(customLibraryPath))
{
var newRootFolderPath = GetRootFolderPath(newName);
if (Directory.Exists(newRootFolderPath))
{
Directory.Delete(newRootFolderPath, true);
}
Directory.Move(customLibraryPath, newRootFolderPath);
}
}
Name = newName;
// Force these to be lazy loaded again
RootFolder = null;
// Kick off a task to validate the media library
Task.Run(() => ValidateMediaLibrary(new Progress<double>(), CancellationToken.None));
return RefreshMetadata(new MetadataRefreshOptions
{
ReplaceAllMetadata = true,
@@ -318,16 +246,8 @@ namespace MediaBrowser.Controller.Entities
throw new ArgumentNullException("config");
}
var customLibraryChanged = config.UseCustomLibrary != Configuration.UseCustomLibrary;
Configuration = config;
SaveConfiguration(serializer);
// Force these to be lazy loaded again
if (customLibraryChanged)
{
RootFolder = null;
}
}
}
}