diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index a6a059496..5cc51d6a1 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; +using MediaBrowser.Common.Json; using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Events; @@ -23,7 +24,6 @@ namespace MediaBrowser.Controller public static Kernel Instance { get; private set; } public ItemController ItemController { get; private set; } - public UserController UserController { get; private set; } public IEnumerable Users { get; private set; } public Folder RootFolder { get; private set; } @@ -38,6 +38,14 @@ namespace MediaBrowser.Controller } } + private string UsersPath + { + get + { + return Path.Combine(ProgramDataPath, "Users"); + } + } + /// /// Gets the list of currently registered entity resolvers /// @@ -53,7 +61,6 @@ namespace MediaBrowser.Controller Instance = this; ItemController = new ItemController(); - UserController = new UserController(Path.Combine(ProgramDataPath, "Users")); DirectoryWatchers = new DirectoryWatchers(); ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; @@ -117,7 +124,7 @@ namespace MediaBrowser.Controller private void ReloadUsers() { - Users = UserController.GetAllUsers(); + Users = GetAllUsers(); } /// @@ -422,5 +429,64 @@ namespace MediaBrowser.Controller return list; } + /// + /// Gets all users within the system + /// + private IEnumerable GetAllUsers() + { + if (!Directory.Exists(UsersPath)) + { + Directory.CreateDirectory(UsersPath); + } + + List list = new List(); + + foreach (string folder in Directory.GetDirectories(UsersPath, "*", SearchOption.TopDirectoryOnly)) + { + User item = GetFromDirectory(folder); + + if (item != null) + { + list.Add(item); + } + } + + return list; + } + + /// + /// Gets a User from it's directory + /// + private User GetFromDirectory(string path) + { + string file = Path.Combine(path, "user.js"); + + return JsonSerializer.DeserializeFromFile(file); + } + + /// + /// Creates a User with a given name + /// + public User CreateUser(string name) + { + var now = DateTime.Now; + + User user = new User() + { + Name = name, + Id = Guid.NewGuid(), + DateCreated = now, + DateModified = now + }; + + user.Path = Path.Combine(UsersPath, user.Id.ToString()); + + Directory.CreateDirectory(user.Path); + + JsonSerializer.SerializeToFile(user, Path.Combine(user.Path, "user.js")); + + return user; + } + } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 8ee013063..d0ad18e26 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -54,7 +54,6 @@ - diff --git a/MediaBrowser.Controller/UserController.cs b/MediaBrowser.Controller/UserController.cs deleted file mode 100644 index c53397a31..000000000 --- a/MediaBrowser.Controller/UserController.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using MediaBrowser.Model.Users; -using MediaBrowser.Common.Json; - -namespace MediaBrowser.Controller -{ - /// - /// Manages users within the system - /// - public class UserController - { - /// - /// Gets or sets the path to folder that contains data for all the users - /// - public string UsersPath { get; set; } - - public UserController(string usersPath) - { - UsersPath = usersPath; - } - - /// - /// Gets all users within the system - /// - public IEnumerable GetAllUsers() - { - if (!Directory.Exists(UsersPath)) - { - Directory.CreateDirectory(UsersPath); - } - - List list = new List(); - - foreach (string folder in Directory.GetDirectories(UsersPath, "*", SearchOption.TopDirectoryOnly)) - { - User item = GetFromDirectory(folder); - - if (item != null) - { - list.Add(item); - } - } - - return list; - } - - /// - /// Gets a User from it's directory - /// - private User GetFromDirectory(string path) - { - string file = Path.Combine(path, "user.js"); - - return JsonSerializer.DeserializeFromFile(file); - } - - /// - /// Creates a User with a given name - /// - public User CreateUser(string name) - { - var now = DateTime.Now; - - User user = new User() - { - Name = name, - Id = Guid.NewGuid(), - DateCreated = now, - DateModified = now - }; - - user.Path = Path.Combine(UsersPath, user.Id.ToString()); - - Directory.CreateDirectory(user.Path); - - JsonSerializer.SerializeToFile(user, Path.Combine(user.Path, "user.js")); - - return user; - } - } -}