commit
90406d842b
|
@ -419,6 +419,25 @@ namespace Emby.Common.Implementations.IO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetReadOnly(string path, bool isReadOnly)
|
||||||
|
{
|
||||||
|
var info = GetFileInfo(path);
|
||||||
|
|
||||||
|
if (info.Exists && info.IsReadOnly != isReadOnly)
|
||||||
|
{
|
||||||
|
if (isReadOnly)
|
||||||
|
{
|
||||||
|
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.ReadOnly);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FileAttributes attributes = File.GetAttributes(path);
|
||||||
|
attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
|
||||||
|
File.SetAttributes(path, attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
|
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
|
||||||
{
|
{
|
||||||
return attributes & ~attributesToRemove;
|
return attributes & ~attributesToRemove;
|
||||||
|
@ -564,6 +583,20 @@ namespace Emby.Common.Implementations.IO
|
||||||
|
|
||||||
public void DeleteFile(string path)
|
public void DeleteFile(string path)
|
||||||
{
|
{
|
||||||
|
var fileInfo = GetFileInfo(path);
|
||||||
|
|
||||||
|
if (fileInfo.Exists)
|
||||||
|
{
|
||||||
|
if (fileInfo.IsHidden)
|
||||||
|
{
|
||||||
|
SetHidden(path, false);
|
||||||
|
}
|
||||||
|
if (fileInfo.IsReadOnly)
|
||||||
|
{
|
||||||
|
SetReadOnly(path, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
<Compile Include="Devices\DeviceManager.cs" />
|
<Compile Include="Devices\DeviceManager.cs" />
|
||||||
<Compile Include="Dto\DtoService.cs" />
|
<Compile Include="Dto\DtoService.cs" />
|
||||||
<Compile Include="EntryPoints\AutomaticRestartEntryPoint.cs" />
|
<Compile Include="EntryPoints\AutomaticRestartEntryPoint.cs" />
|
||||||
|
<Compile Include="EntryPoints\KeepServerAwake.cs" />
|
||||||
<Compile Include="EntryPoints\LibraryChangedNotifier.cs" />
|
<Compile Include="EntryPoints\LibraryChangedNotifier.cs" />
|
||||||
<Compile Include="EntryPoints\LoadRegistrations.cs" />
|
<Compile Include="EntryPoints\LoadRegistrations.cs" />
|
||||||
<Compile Include="EntryPoints\RecordingNotifier.cs" />
|
<Compile Include="EntryPoints\RecordingNotifier.cs" />
|
||||||
|
@ -187,6 +188,7 @@
|
||||||
<Compile Include="Session\SessionManager.cs" />
|
<Compile Include="Session\SessionManager.cs" />
|
||||||
<Compile Include="Session\SessionWebSocketListener.cs" />
|
<Compile Include="Session\SessionWebSocketListener.cs" />
|
||||||
<Compile Include="Session\WebSocketController.cs" />
|
<Compile Include="Session\WebSocketController.cs" />
|
||||||
|
<Compile Include="Social\SharingManager.cs" />
|
||||||
<Compile Include="Sorting\AiredEpisodeOrderComparer.cs" />
|
<Compile Include="Sorting\AiredEpisodeOrderComparer.cs" />
|
||||||
<Compile Include="Sorting\AirTimeComparer.cs" />
|
<Compile Include="Sorting\AirTimeComparer.cs" />
|
||||||
<Compile Include="Sorting\AlbumArtistComparer.cs" />
|
<Compile Include="Sorting\AlbumArtistComparer.cs" />
|
||||||
|
|
65
Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs
Normal file
65
Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
using MediaBrowser.Controller;
|
||||||
|
using MediaBrowser.Controller.Plugins;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using MediaBrowser.Model.System;
|
||||||
|
using MediaBrowser.Model.Threading;
|
||||||
|
|
||||||
|
namespace Emby.Server.Implementations.EntryPoints
|
||||||
|
{
|
||||||
|
public class KeepServerAwake : IServerEntryPoint
|
||||||
|
{
|
||||||
|
private readonly ISessionManager _sessionManager;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private ITimer _timer;
|
||||||
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
private readonly ITimerFactory _timerFactory;
|
||||||
|
private readonly IPowerManagement _powerManagement;
|
||||||
|
|
||||||
|
public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost, ITimerFactory timerFactory, IPowerManagement powerManagement)
|
||||||
|
{
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
_logger = logger;
|
||||||
|
_appHost = appHost;
|
||||||
|
_timerFactory = timerFactory;
|
||||||
|
_powerManagement = powerManagement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run()
|
||||||
|
{
|
||||||
|
_timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimerCallback(object state)
|
||||||
|
{
|
||||||
|
var now = DateTime.UtcNow;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
||||||
|
{
|
||||||
|
_powerManagement.PreventSystemStandby();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_powerManagement.AllowSystemStandby();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error resetting system standby timer", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_timer != null)
|
||||||
|
{
|
||||||
|
_timer.Dispose();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -177,6 +177,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
||||||
inputModifiers = "-ss " + _mediaEncoder.GetTimeParameter(startTimeTicks) + " " + inputModifiers;
|
inputModifiers = "-ss " + _mediaEncoder.GetTimeParameter(startTimeTicks) + " " + inputModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var analyzeDurationSeconds = 5;
|
||||||
|
var analyzeDuration = " -analyzeduration " +
|
||||||
|
(analyzeDurationSeconds * 1000000).ToString(CultureInfo.InvariantCulture);
|
||||||
|
inputModifiers += analyzeDuration;
|
||||||
|
|
||||||
commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam);
|
commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam);
|
||||||
|
|
||||||
return inputModifiers + " " + commandLineArgs;
|
return inputModifiers + " " + commandLineArgs;
|
||||||
|
|
|
@ -7,16 +7,16 @@ using MediaBrowser.Model.Social;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Social
|
namespace Emby.Server.Implementations.Social
|
||||||
{
|
{
|
||||||
public class SharingManager : ISharingManager
|
public class SharingManager : ISharingManager
|
||||||
{
|
{
|
||||||
private readonly SharingRepository _repository;
|
private readonly ISharingRepository _repository;
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
|
||||||
public SharingManager(SharingRepository repository, IServerConfigurationManager config, ILibraryManager libraryManager, IServerApplicationHost appHost)
|
public SharingManager(ISharingRepository repository, IServerConfigurationManager config, ILibraryManager libraryManager, IServerApplicationHost appHost)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_config = config;
|
_config = config;
|
|
@ -1892,19 +1892,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
if (info.IsLocalFile)
|
if (info.IsLocalFile)
|
||||||
{
|
{
|
||||||
// Delete the source file
|
FileSystem.DeleteFile(info.Path);
|
||||||
var currentFile = FileSystem.GetFileInfo(info.Path);
|
|
||||||
|
|
||||||
// Deletion will fail if the file is hidden so remove the attribute first
|
|
||||||
if (currentFile.Exists)
|
|
||||||
{
|
|
||||||
if (currentFile.IsHidden)
|
|
||||||
{
|
|
||||||
FileSystem.SetHidden(currentFile.FullName, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSystem.DeleteFile(currentFile.FullName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||||
|
|
|
@ -226,9 +226,12 @@ namespace MediaBrowser.LocalMetadata.Savers
|
||||||
if (file.IsHidden)
|
if (file.IsHidden)
|
||||||
{
|
{
|
||||||
FileSystem.SetHidden(path, false);
|
FileSystem.SetHidden(path, false);
|
||||||
|
|
||||||
wasHidden = true;
|
wasHidden = true;
|
||||||
}
|
}
|
||||||
|
if (file.IsReadOnly)
|
||||||
|
{
|
||||||
|
FileSystem.SetReadOnly(path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
|
using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
|
||||||
|
|
|
@ -8,6 +8,9 @@ namespace MediaBrowser.Model.Configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ServerConfiguration : BaseApplicationConfiguration
|
public class ServerConfiguration : BaseApplicationConfiguration
|
||||||
{
|
{
|
||||||
|
public const int DefaultHttpPort = 8096;
|
||||||
|
public const int DefaultHttpsPort = 8920;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether [enable u pn p].
|
/// Gets or sets a value indicating whether [enable u pn p].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -225,10 +228,10 @@ namespace MediaBrowser.Model.Configuration
|
||||||
EnableExternalContentInSuggestions = true;
|
EnableExternalContentInSuggestions = true;
|
||||||
|
|
||||||
ImageSavingConvention = ImageSavingConvention.Compatible;
|
ImageSavingConvention = ImageSavingConvention.Compatible;
|
||||||
PublicPort = 8096;
|
PublicPort = DefaultHttpPort;
|
||||||
PublicHttpsPort = 8920;
|
PublicHttpsPort = DefaultHttpsPort;
|
||||||
HttpServerPortNumber = 8096;
|
HttpServerPortNumber = DefaultHttpPort;
|
||||||
HttpsPortNumber = 8920;
|
HttpsPortNumber = DefaultHttpsPort;
|
||||||
EnableHttps = false;
|
EnableHttps = false;
|
||||||
EnableDashboardResponseCaching = true;
|
EnableDashboardResponseCaching = true;
|
||||||
EnableDashboardResourceMinification = true;
|
EnableDashboardResourceMinification = true;
|
||||||
|
|
|
@ -305,6 +305,7 @@ namespace MediaBrowser.Model.IO
|
||||||
IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
|
IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
|
||||||
|
|
||||||
void SetHidden(string path, bool isHidden);
|
void SetHidden(string path, bool isHidden);
|
||||||
|
void SetReadOnly(string path, bool isHidden);
|
||||||
|
|
||||||
char DirectorySeparatorChar { get; }
|
char DirectorySeparatorChar { get; }
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,9 @@
|
||||||
<Compile Include="Net\IUdpSocket.cs" />
|
<Compile Include="Net\IUdpSocket.cs" />
|
||||||
<Compile Include="Net\SocketReceiveResult.cs" />
|
<Compile Include="Net\SocketReceiveResult.cs" />
|
||||||
<Compile Include="Services\IHttpResult.cs" />
|
<Compile Include="Services\IHttpResult.cs" />
|
||||||
|
<Compile Include="Social\ISharingRepository.cs" />
|
||||||
<Compile Include="System\IEnvironmentInfo.cs" />
|
<Compile Include="System\IEnvironmentInfo.cs" />
|
||||||
|
<Compile Include="System\IPowerManagement.cs" />
|
||||||
<Compile Include="Text\ITextEncoding.cs" />
|
<Compile Include="Text\ITextEncoding.cs" />
|
||||||
<Compile Include="Extensions\LinqExtensions.cs" />
|
<Compile Include="Extensions\LinqExtensions.cs" />
|
||||||
<Compile Include="FileOrganization\SmartMatchInfo.cs" />
|
<Compile Include="FileOrganization\SmartMatchInfo.cs" />
|
||||||
|
|
15
MediaBrowser.Model/Social/ISharingRepository.cs
Normal file
15
MediaBrowser.Model/Social/ISharingRepository.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Model.Social
|
||||||
|
{
|
||||||
|
public interface ISharingRepository
|
||||||
|
{
|
||||||
|
Task CreateShare(SocialShareInfo info);
|
||||||
|
Task DeleteShare(string id);
|
||||||
|
SocialShareInfo GetShareInfo(string id);
|
||||||
|
}
|
||||||
|
}
|
9
MediaBrowser.Model/System/IPowerManagement.cs
Normal file
9
MediaBrowser.Model/System/IPowerManagement.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
namespace MediaBrowser.Model.System
|
||||||
|
{
|
||||||
|
public interface IPowerManagement
|
||||||
|
{
|
||||||
|
void PreventSystemStandby();
|
||||||
|
void AllowSystemStandby();
|
||||||
|
}
|
||||||
|
}
|
|
@ -265,6 +265,10 @@ namespace MediaBrowser.Providers.Manager
|
||||||
{
|
{
|
||||||
_fileSystem.SetHidden(file.FullName, false);
|
_fileSystem.SetHidden(file.FullName, false);
|
||||||
}
|
}
|
||||||
|
if (file.IsReadOnly)
|
||||||
|
{
|
||||||
|
_fileSystem.SetReadOnly(path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
||||||
|
|
|
@ -134,8 +134,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||||
base.OnConfigLoad();
|
base.OnConfigLoad();
|
||||||
|
|
||||||
Config.HandlerFactoryPath = null;
|
Config.HandlerFactoryPath = null;
|
||||||
|
|
||||||
Config.MetadataRedirectPath = "metadata";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override ServiceController CreateServiceController(params Assembly[] assembliesWithServices)
|
protected override ServiceController CreateServiceController(params Assembly[] assembliesWithServices)
|
||||||
|
@ -574,7 +572,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||||
{
|
{
|
||||||
httpRes.StatusCode = 302;
|
httpRes.StatusCode = 302;
|
||||||
httpRes.AddHeader(HttpHeaders.Location, url);
|
httpRes.AddHeader(HttpHeaders.Location, url);
|
||||||
httpRes.EndRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,6 @@
|
||||||
<Compile Include="Persistence\IDbConnector.cs" />
|
<Compile Include="Persistence\IDbConnector.cs" />
|
||||||
<Compile Include="Persistence\MediaStreamColumns.cs" />
|
<Compile Include="Persistence\MediaStreamColumns.cs" />
|
||||||
<Compile Include="Serialization\JsonSerializer.cs" />
|
<Compile Include="Serialization\JsonSerializer.cs" />
|
||||||
<Compile Include="Social\SharingManager.cs" />
|
|
||||||
<Compile Include="Social\SharingRepository.cs" />
|
<Compile Include="Social\SharingRepository.cs" />
|
||||||
<Compile Include="Persistence\SqliteFileOrganizationRepository.cs" />
|
<Compile Include="Persistence\SqliteFileOrganizationRepository.cs" />
|
||||||
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
|
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
|
||||||
|
|
|
@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Social
|
namespace MediaBrowser.Server.Implementations.Social
|
||||||
{
|
{
|
||||||
public class SharingRepository : BaseSqliteRepository
|
public class SharingRepository : BaseSqliteRepository, ISharingRepository
|
||||||
{
|
{
|
||||||
public SharingRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector dbConnector)
|
public SharingRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector dbConnector)
|
||||||
: base(logManager, dbConnector)
|
: base(logManager, dbConnector)
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Native\BaseMonoApp.cs" />
|
<Compile Include="Native\BaseMonoApp.cs" />
|
||||||
<Compile Include="Native\DbConnector.cs" />
|
<Compile Include="Native\DbConnector.cs" />
|
||||||
|
<Compile Include="Native\PowerManagement.cs" />
|
||||||
<Compile Include="Networking\CertificateGenerator.cs" />
|
<Compile Include="Networking\CertificateGenerator.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -68,16 +68,6 @@ namespace MediaBrowser.Server.Mono.Native
|
||||||
get { return false; }
|
get { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PreventSystemStandby()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AllowSystemStandby()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Assembly> GetAssembliesWithParts()
|
public List<Assembly> GetAssembliesWithParts()
|
||||||
{
|
{
|
||||||
var list = new List<Assembly>();
|
var list = new List<Assembly>();
|
||||||
|
|
15
MediaBrowser.Server.Mono/Native/PowerManagement.cs
Normal file
15
MediaBrowser.Server.Mono/Native/PowerManagement.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using MediaBrowser.Model.System;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Server.Mono.Native
|
||||||
|
{
|
||||||
|
public class PowerManagement : IPowerManagement
|
||||||
|
{
|
||||||
|
public void PreventSystemStandby()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AllowSystemStandby()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -80,7 +80,7 @@ namespace MediaBrowser.Server.Mono
|
||||||
|
|
||||||
var nativeApp = new NativeApp(options, logManager.GetLogger("App"));
|
var nativeApp = new NativeApp(options, logManager.GetLogger("App"));
|
||||||
|
|
||||||
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "emby.mono.zip", nativeApp);
|
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, nativeApp, new PowerManagement(), "emby.mono.zip");
|
||||||
|
|
||||||
if (options.ContainsOption("-v"))
|
if (options.ContainsOption("-v"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -114,10 +114,12 @@ using Emby.Server.Implementations.Playlists;
|
||||||
using Emby.Server.Implementations.Security;
|
using Emby.Server.Implementations.Security;
|
||||||
using Emby.Server.Implementations.ServerManager;
|
using Emby.Server.Implementations.ServerManager;
|
||||||
using Emby.Server.Implementations.Session;
|
using Emby.Server.Implementations.Session;
|
||||||
|
using Emby.Server.Implementations.Social;
|
||||||
using Emby.Server.Implementations.Sync;
|
using Emby.Server.Implementations.Sync;
|
||||||
using Emby.Server.Implementations.TV;
|
using Emby.Server.Implementations.TV;
|
||||||
using Emby.Server.Implementations.Updates;
|
using Emby.Server.Implementations.Updates;
|
||||||
using MediaBrowser.Model.Activity;
|
using MediaBrowser.Model.Activity;
|
||||||
|
using MediaBrowser.Model.Configuration;
|
||||||
using MediaBrowser.Model.Dlna;
|
using MediaBrowser.Model.Dlna;
|
||||||
using MediaBrowser.Model.Globalization;
|
using MediaBrowser.Model.Globalization;
|
||||||
using MediaBrowser.Model.Net;
|
using MediaBrowser.Model.Net;
|
||||||
|
@ -259,26 +261,24 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
|
|
||||||
internal INativeApp NativeApp { get; set; }
|
internal INativeApp NativeApp { get; set; }
|
||||||
|
|
||||||
|
internal IPowerManagement PowerManagement { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
|
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="applicationPaths">The application paths.</param>
|
|
||||||
/// <param name="logManager">The log manager.</param>
|
|
||||||
/// <param name="options">The options.</param>
|
|
||||||
/// <param name="fileSystem">The file system.</param>
|
|
||||||
/// <param name="releaseAssetFilename">The release asset filename.</param>
|
|
||||||
/// <param name="nativeApp">The native application.</param>
|
|
||||||
public ApplicationHost(ServerApplicationPaths applicationPaths,
|
public ApplicationHost(ServerApplicationPaths applicationPaths,
|
||||||
ILogManager logManager,
|
ILogManager logManager,
|
||||||
StartupOptions options,
|
StartupOptions options,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
string releaseAssetFilename,
|
INativeApp nativeApp,
|
||||||
INativeApp nativeApp)
|
IPowerManagement powerManagement,
|
||||||
|
string releaseAssetFilename)
|
||||||
: base(applicationPaths, logManager, fileSystem)
|
: base(applicationPaths, logManager, fileSystem)
|
||||||
{
|
{
|
||||||
_startupOptions = options;
|
_startupOptions = options;
|
||||||
_releaseAssetFilename = releaseAssetFilename;
|
_releaseAssetFilename = releaseAssetFilename;
|
||||||
NativeApp = nativeApp;
|
NativeApp = nativeApp;
|
||||||
|
PowerManagement = powerManagement;
|
||||||
|
|
||||||
SetBaseExceptionMessage();
|
SetBaseExceptionMessage();
|
||||||
}
|
}
|
||||||
|
@ -484,6 +484,13 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
|
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
|
||||||
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
|
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
|
||||||
|
|
||||||
|
// Safeguard against invalid configuration
|
||||||
|
if (HttpPort == HttpsPort)
|
||||||
|
{
|
||||||
|
HttpPort = ServerConfiguration.DefaultHttpPort;
|
||||||
|
HttpsPort = ServerConfiguration.DefaultHttpsPort;
|
||||||
|
}
|
||||||
|
|
||||||
return base.Init(progress);
|
return base.Init(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +541,8 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
{
|
{
|
||||||
await base.RegisterResources(progress).ConfigureAwait(false);
|
await base.RegisterResources(progress).ConfigureAwait(false);
|
||||||
|
|
||||||
|
RegisterSingleInstance(PowerManagement);
|
||||||
|
|
||||||
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager, CryptographyProvider);
|
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager, CryptographyProvider);
|
||||||
RegisterSingleInstance(SecurityManager);
|
RegisterSingleInstance(SecurityManager);
|
||||||
|
|
||||||
|
@ -998,13 +1007,13 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
{
|
{
|
||||||
Logger.ErrorException("Error starting http server", ex);
|
Logger.ErrorException("Error starting http server", ex);
|
||||||
|
|
||||||
if (HttpPort == 8096)
|
if (HttpPort == ServerConfiguration.DefaultHttpPort)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpPort = 8096;
|
HttpPort = ServerConfiguration.DefaultHttpPort;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Controller.Plugins;
|
|
||||||
using MediaBrowser.Controller.Session;
|
|
||||||
using MediaBrowser.Model.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using MediaBrowser.Server.Startup.Common.Threading;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
|
||||||
{
|
|
||||||
public class KeepServerAwake : IServerEntryPoint
|
|
||||||
{
|
|
||||||
private readonly ISessionManager _sessionManager;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
private PeriodicTimer _timer;
|
|
||||||
private readonly IServerApplicationHost _appHost;
|
|
||||||
|
|
||||||
public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost)
|
|
||||||
{
|
|
||||||
_sessionManager = sessionManager;
|
|
||||||
_logger = logger;
|
|
||||||
_appHost = appHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Run()
|
|
||||||
{
|
|
||||||
_timer = new PeriodicTimer(obj =>
|
|
||||||
{
|
|
||||||
var now = DateTime.UtcNow;
|
|
||||||
var nativeApp = ((ApplicationHost)_appHost).NativeApp;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
|
||||||
{
|
|
||||||
nativeApp.PreventSystemStandby();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nativeApp.AllowSystemStandby();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error resetting system standby timer", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_timer != null)
|
|
||||||
{
|
|
||||||
_timer.Dispose();
|
|
||||||
_timer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -88,13 +88,6 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
/// <returns>INetworkManager.</returns>
|
/// <returns>INetworkManager.</returns>
|
||||||
INetworkManager CreateNetworkManager(ILogger logger);
|
INetworkManager CreateNetworkManager(ILogger logger);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prevents the system stand by.
|
|
||||||
/// </summary>
|
|
||||||
void PreventSystemStandby();
|
|
||||||
|
|
||||||
void AllowSystemStandby();
|
|
||||||
|
|
||||||
FFMpegInstallInfo GetFfmpegInstallInfo();
|
FFMpegInstallInfo GetFfmpegInstallInfo();
|
||||||
|
|
||||||
void LaunchUrl(string url);
|
void LaunchUrl(string url);
|
||||||
|
|
|
@ -75,7 +75,6 @@
|
||||||
<Compile Include="ApplicationHost.cs" />
|
<Compile Include="ApplicationHost.cs" />
|
||||||
<Compile Include="ApplicationPathHelper.cs" />
|
<Compile Include="ApplicationPathHelper.cs" />
|
||||||
<Compile Include="Browser\BrowserLauncher.cs" />
|
<Compile Include="Browser\BrowserLauncher.cs" />
|
||||||
<Compile Include="EntryPoints\KeepServerAwake.cs" />
|
|
||||||
<Compile Include="EntryPoints\StartupWizard.cs" />
|
<Compile Include="EntryPoints\StartupWizard.cs" />
|
||||||
<Compile Include="FFMpeg\FFMpegLoader.cs" />
|
<Compile Include="FFMpeg\FFMpegLoader.cs" />
|
||||||
<Compile Include="FFMpeg\FFMpegInstallInfo.cs" />
|
<Compile Include="FFMpeg\FFMpegInstallInfo.cs" />
|
||||||
|
@ -90,7 +89,6 @@
|
||||||
<Compile Include="StartupOptions.cs" />
|
<Compile Include="StartupOptions.cs" />
|
||||||
<Compile Include="SystemEvents.cs" />
|
<Compile Include="SystemEvents.cs" />
|
||||||
<Compile Include="TextLocalizer.cs" />
|
<Compile Include="TextLocalizer.cs" />
|
||||||
<Compile Include="Threading\PeriodicTimer.cs" />
|
|
||||||
<Compile Include="UnhandledExceptionWriter.cs" />
|
<Compile Include="UnhandledExceptionWriter.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.Win32;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Startup.Common.Threading
|
|
||||||
{
|
|
||||||
public class PeriodicTimer : IDisposable
|
|
||||||
{
|
|
||||||
public Action<object> Callback { get; set; }
|
|
||||||
private Timer _timer;
|
|
||||||
private readonly object _state;
|
|
||||||
private readonly object _timerLock = new object();
|
|
||||||
private readonly TimeSpan _period;
|
|
||||||
|
|
||||||
public PeriodicTimer(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period)
|
|
||||||
{
|
|
||||||
if (callback == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("callback");
|
|
||||||
}
|
|
||||||
|
|
||||||
Callback = callback;
|
|
||||||
_period = period;
|
|
||||||
_state = state;
|
|
||||||
|
|
||||||
StartTimer(dueTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Mode == PowerModes.Resume)
|
|
||||||
{
|
|
||||||
DisposeTimer();
|
|
||||||
StartTimer(Timeout.InfiniteTimeSpan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TimerCallback(object state)
|
|
||||||
{
|
|
||||||
Callback(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartTimer(TimeSpan dueTime)
|
|
||||||
{
|
|
||||||
lock (_timerLock)
|
|
||||||
{
|
|
||||||
_timer = new Timer(TimerCallback, _state, dueTime, _period);
|
|
||||||
|
|
||||||
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DisposeTimer()
|
|
||||||
{
|
|
||||||
Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
|
|
||||||
|
|
||||||
lock (_timerLock)
|
|
||||||
{
|
|
||||||
if (_timer != null)
|
|
||||||
{
|
|
||||||
_timer.Dispose();
|
|
||||||
_timer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
DisposeTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -320,8 +320,9 @@ namespace MediaBrowser.ServerApplication
|
||||||
logManager,
|
logManager,
|
||||||
options,
|
options,
|
||||||
fileSystem,
|
fileSystem,
|
||||||
"emby.windows.zip",
|
nativeApp,
|
||||||
nativeApp);
|
new PowerManagement(),
|
||||||
|
"emby.windows.zip");
|
||||||
|
|
||||||
var initProgress = new Progress<double>();
|
var initProgress = new Progress<double>();
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@
|
||||||
<Compile Include="Native\LnkShortcutHandler.cs" />
|
<Compile Include="Native\LnkShortcutHandler.cs" />
|
||||||
<Compile Include="Native\DbConnector.cs" />
|
<Compile Include="Native\DbConnector.cs" />
|
||||||
<Compile Include="Native\LoopbackUtil.cs" />
|
<Compile Include="Native\LoopbackUtil.cs" />
|
||||||
|
<Compile Include="Native\PowerManagement.cs" />
|
||||||
<Compile Include="Native\Standby.cs" />
|
<Compile Include="Native\Standby.cs" />
|
||||||
<Compile Include="Native\ServerAuthorization.cs" />
|
<Compile Include="Native\ServerAuthorization.cs" />
|
||||||
<Compile Include="Native\WindowsApp.cs" />
|
<Compile Include="Native\WindowsApp.cs" />
|
||||||
|
|
17
MediaBrowser.ServerApplication/Native/PowerManagement.cs
Normal file
17
MediaBrowser.ServerApplication/Native/PowerManagement.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using MediaBrowser.Model.System;
|
||||||
|
|
||||||
|
namespace MediaBrowser.ServerApplication.Native
|
||||||
|
{
|
||||||
|
public class PowerManagement : IPowerManagement
|
||||||
|
{
|
||||||
|
public void PreventSystemStandby()
|
||||||
|
{
|
||||||
|
MainStartup.Invoke(Standby.PreventSleep);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AllowSystemStandby()
|
||||||
|
{
|
||||||
|
MainStartup.Invoke(Standby.AllowSleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -139,16 +139,6 @@ namespace MediaBrowser.ServerApplication.Native
|
||||||
return new NetworkManager(logger);
|
return new NetworkManager(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PreventSystemStandby()
|
|
||||||
{
|
|
||||||
MainStartup.Invoke(Standby.PreventSleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AllowSystemStandby()
|
|
||||||
{
|
|
||||||
MainStartup.Invoke(Standby.AllowSleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FFMpegInstallInfo GetFfmpegInstallInfo()
|
public FFMpegInstallInfo GetFfmpegInstallInfo()
|
||||||
{
|
{
|
||||||
var info = new FFMpegInstallInfo();
|
var info = new FFMpegInstallInfo();
|
||||||
|
|
|
@ -221,6 +221,10 @@ namespace MediaBrowser.XbmcMetadata.Savers
|
||||||
|
|
||||||
wasHidden = true;
|
wasHidden = true;
|
||||||
}
|
}
|
||||||
|
if (file.IsReadOnly)
|
||||||
|
{
|
||||||
|
FileSystem.SetReadOnly(path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
|
using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user