|
|
@ -29,7 +29,7 @@ namespace MediaBrowser.Dlna
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, DeviceProfile> _profiles = new Dictionary<string, DeviceProfile>(StringComparer.Ordinal);
|
|
|
|
private readonly Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>> _profiles = new Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>>(StringComparer.Ordinal);
|
|
|
|
|
|
|
|
|
|
|
|
public DlnaManager(IXmlSerializer xmlSerializer,
|
|
|
|
public DlnaManager(IXmlSerializer xmlSerializer,
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
IFileSystem fileSystem,
|
|
|
@ -45,50 +45,40 @@ namespace MediaBrowser.Dlna
|
|
|
|
_appHost = appHost;
|
|
|
|
_appHost = appHost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<DeviceProfile> GetProfiles()
|
|
|
|
public void InitProfiles()
|
|
|
|
{
|
|
|
|
|
|
|
|
ExtractProfilesIfNeeded();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = GetProfiles(UserProfilesPath, DeviceProfileType.User)
|
|
|
|
|
|
|
|
.OrderBy(i => i.Name)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System)
|
|
|
|
|
|
|
|
.OrderBy(i => i.Name));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool _extracted;
|
|
|
|
|
|
|
|
private readonly object _syncLock = new object();
|
|
|
|
|
|
|
|
private void ExtractProfilesIfNeeded()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!_extracted)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_syncLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!_extracted)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ExtractSystemProfiles();
|
|
|
|
ExtractSystemProfiles();
|
|
|
|
|
|
|
|
LoadProfiles();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ErrorException("Error extracting DLNA profiles.", ex);
|
|
|
|
_logger.ErrorException("Error extracting DLNA profiles.", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_extracted = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void LoadProfiles()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var list = GetProfiles(UserProfilesPath, DeviceProfileType.User)
|
|
|
|
|
|
|
|
.OrderBy(i => i.Name)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System)
|
|
|
|
|
|
|
|
.OrderBy(i => i.Name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<DeviceProfile> GetProfiles()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_profiles)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var list = _profiles.Values.ToList();
|
|
|
|
|
|
|
|
return list.Select(i => i.Item2).OrderBy(i => i.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceProfile GetDefaultProfile()
|
|
|
|
public DeviceProfile GetDefaultProfile()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ExtractProfilesIfNeeded();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new DefaultProfile();
|
|
|
|
return new DefaultProfile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -304,20 +294,20 @@ namespace MediaBrowser.Dlna
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_profiles)
|
|
|
|
lock (_profiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DeviceProfile profile;
|
|
|
|
Tuple<InternalProfileInfo, DeviceProfile> profileTuple;
|
|
|
|
if (_profiles.TryGetValue(path, out profile))
|
|
|
|
if (_profiles.TryGetValue(path, out profileTuple))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return profile;
|
|
|
|
return profileTuple.Item2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
|
|
|
|
var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
|
|
|
|
|
|
|
|
|
|
|
|
profile.Id = path.ToLower().GetMD5().ToString("N");
|
|
|
|
profile.Id = path.ToLower().GetMD5().ToString("N");
|
|
|
|
profile.ProfileType = type;
|
|
|
|
profile.ProfileType = type;
|
|
|
|
|
|
|
|
|
|
|
|
_profiles[path] = profile;
|
|
|
|
_profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);
|
|
|
|
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -344,13 +334,15 @@ namespace MediaBrowser.Dlna
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<InternalProfileInfo> GetProfileInfosInternal()
|
|
|
|
private IEnumerable<InternalProfileInfo> GetProfileInfosInternal()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ExtractProfilesIfNeeded();
|
|
|
|
lock (_profiles)
|
|
|
|
|
|
|
|
{
|
|
|
|
return GetProfileInfos(UserProfilesPath, DeviceProfileType.User)
|
|
|
|
var list = _profiles.Values.ToList();
|
|
|
|
.Concat(GetProfileInfos(SystemProfilesPath, DeviceProfileType.System))
|
|
|
|
return list
|
|
|
|
|
|
|
|
.Select(i => i.Item1)
|
|
|
|
.OrderBy(i => i.Info.Type == DeviceProfileType.User ? 0 : 1)
|
|
|
|
.OrderBy(i => i.Info.Type == DeviceProfileType.User ? 0 : 1)
|
|
|
|
.ThenBy(i => i.Info.Name);
|
|
|
|
.ThenBy(i => i.Info.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<DeviceProfileInfo> GetProfileInfos()
|
|
|
|
public IEnumerable<DeviceProfileInfo> GetProfileInfos()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -363,17 +355,7 @@ namespace MediaBrowser.Dlna
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _fileSystem.GetFiles(path)
|
|
|
|
return _fileSystem.GetFiles(path)
|
|
|
|
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
|
|
|
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
|
|
|
.Select(i => new InternalProfileInfo
|
|
|
|
.Select(i => GetInternalProfileInfo(i, type))
|
|
|
|
{
|
|
|
|
|
|
|
|
Path = i.FullName,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Info = new DeviceProfileInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = i.FullName.ToLower().GetMD5().ToString("N"),
|
|
|
|
|
|
|
|
Name = _fileSystem.GetFileNameWithoutExtension(i),
|
|
|
|
|
|
|
|
Type = type
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
.ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
@ -382,6 +364,21 @@ namespace MediaBrowser.Dlna
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new InternalProfileInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path = file.FullName,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Info = new DeviceProfileInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = file.FullName.ToLower().GetMD5().ToString("N"),
|
|
|
|
|
|
|
|
Name = _fileSystem.GetFileNameWithoutExtension(file),
|
|
|
|
|
|
|
|
Type = type
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ExtractSystemProfiles()
|
|
|
|
private void ExtractSystemProfiles()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var assembly = GetType().Assembly;
|
|
|
|
var assembly = GetType().Assembly;
|
|
|
@ -427,6 +424,11 @@ namespace MediaBrowser.Dlna
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_fileSystem.DeleteFile(info.Path);
|
|
|
|
_fileSystem.DeleteFile(info.Path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lock (_profiles)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_profiles.Remove(info.Path);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateProfile(DeviceProfile profile)
|
|
|
|
public void CreateProfile(DeviceProfile profile)
|
|
|
@ -441,7 +443,7 @@ namespace MediaBrowser.Dlna
|
|
|
|
var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml";
|
|
|
|
var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml";
|
|
|
|
var path = Path.Combine(UserProfilesPath, newFilename);
|
|
|
|
var path = Path.Combine(UserProfilesPath, newFilename);
|
|
|
|
|
|
|
|
|
|
|
|
SaveProfile(profile, path);
|
|
|
|
SaveProfile(profile, path, DeviceProfileType.User);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateProfile(DeviceProfile profile)
|
|
|
|
public void UpdateProfile(DeviceProfile profile)
|
|
|
@ -468,14 +470,14 @@ namespace MediaBrowser.Dlna
|
|
|
|
_fileSystem.DeleteFile(current.Path);
|
|
|
|
_fileSystem.DeleteFile(current.Path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SaveProfile(profile, path);
|
|
|
|
SaveProfile(profile, path, DeviceProfileType.User);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveProfile(DeviceProfile profile, string path)
|
|
|
|
private void SaveProfile(DeviceProfile profile, string path, DeviceProfileType type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_profiles)
|
|
|
|
lock (_profiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_profiles[path] = profile;
|
|
|
|
_profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_xmlSerializer.SerializeToFile(profile, path);
|
|
|
|
_xmlSerializer.SerializeToFile(profile, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|