jellyfin-server/MediaBrowser.ServerApplication/Native/WindowsApp.cs

228 lines
6.4 KiB
C#
Raw Normal View History

2016-04-24 03:03:49 +00:00
using System;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Startup.Common;
using MediaBrowser.ServerApplication.Networking;
using System.Collections.Generic;
2016-04-24 03:03:49 +00:00
using System.Diagnostics;
2016-04-03 17:34:52 +00:00
using System.IO;
using System.Reflection;
2016-04-23 18:38:36 +00:00
using System.Windows.Forms;
2015-10-04 04:23:11 +00:00
using CommonIO;
using MediaBrowser.Controller.Power;
2016-05-01 21:48:37 +00:00
using MediaBrowser.Server.Implementations.Persistence;
2016-04-02 04:29:48 +00:00
using MediaBrowser.Server.Startup.Common.FFMpeg;
2016-04-24 03:03:49 +00:00
using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem;
namespace MediaBrowser.ServerApplication.Native
{
public class WindowsApp : INativeApp
{
private readonly IFileSystem _fileSystem;
2016-01-21 17:45:42 +00:00
private readonly ILogger _logger;
2016-01-21 17:45:42 +00:00
public WindowsApp(IFileSystem fileSystem, ILogger logger)
{
_fileSystem = fileSystem;
2016-01-21 17:45:42 +00:00
_logger = logger;
}
public List<Assembly> GetAssembliesWithParts()
{
var list = new List<Assembly>();
2015-10-12 19:09:56 +00:00
if (!System.Environment.Is64BitProcess)
{
2016-01-06 16:57:15 +00:00
//list.Add(typeof(PismoIsoManager).Assembly);
2015-10-12 19:09:56 +00:00
}
list.Add(GetType().Assembly);
2016-04-02 04:29:48 +00:00
return list;
}
2016-03-26 17:51:27 +00:00
public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
{
2016-03-26 17:51:27 +00:00
ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory);
}
public NativeEnvironment Environment
{
get
{
return new NativeEnvironment
{
OperatingSystem = OperatingSystem.Windows,
2014-11-23 23:10:41 +00:00
SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X86_X64 : Architecture.X86,
OperatingSystemVersionString = System.Environment.OSVersion.VersionString
};
}
}
public bool SupportsLibraryMonitor
{
get { return true; }
}
public bool SupportsRunningAsService
{
get
{
return true;
}
}
public bool IsRunningAsService
{
get;
set;
}
public bool CanSelfRestart
{
get
{
return MainStartup.CanSelfRestart;
}
}
public bool SupportsAutoRunAtStartup
{
get
{
return true;
}
}
public bool CanSelfUpdate
{
get
{
return MainStartup.CanSelfUpdate;
}
}
public void Shutdown()
{
MainStartup.Shutdown();
}
2015-06-05 14:27:01 +00:00
public void Restart(StartupOptions startupOptions)
{
MainStartup.Restart();
}
public void ConfigureAutoRun(bool autorun)
{
2016-04-03 17:34:52 +00:00
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
if (autorun)
{
//Copy our shortut into the startup folder for this user
var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");
_fileSystem.CreateDirectory(Path.GetDirectoryName(targetPath));
File.Copy(shortcutPath, targetPath, true);
}
else
{
//Remove our shortcut from the startup folder for this user
_fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
}
}
public INetworkManager CreateNetworkManager(ILogger logger)
{
return new NetworkManager(logger);
}
public void PreventSystemStandby()
{
2016-04-23 18:38:36 +00:00
MainStartup.Invoke(Standby.PreventSleep);
}
public void AllowSystemStandby()
{
MainStartup.Invoke(Standby.AllowSleep);
}
public IPowerManagement GetPowerManagement()
{
2016-01-21 17:45:42 +00:00
return new WindowsPowerManagement(_logger);
}
2016-04-02 04:29:48 +00:00
public FFMpegInstallInfo GetFfmpegInstallInfo()
{
var info = new FFMpegInstallInfo();
info.FFMpegFilename = "ffmpeg.exe";
info.FFProbeFilename = "ffprobe.exe";
2016-05-10 16:18:05 +00:00
info.Version = "20160410";
2016-04-02 04:29:48 +00:00
info.ArchiveType = "7z";
info.DownloadUrls = GetDownloadUrls();
return info;
}
2016-04-24 03:03:49 +00:00
public void LaunchUrl(string url)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = url
},
EnableRaisingEvents = true,
};
process.Exited += ProcessExited;
try
{
process.Start();
}
catch (Exception ex)
{
_logger.ErrorException("Error launching url: {0}", ex, url);
throw;
}
}
2016-05-01 21:48:37 +00:00
public IDbConnector GetDbConnector()
{
return new DbConnector(_logger);
}
2016-04-24 03:03:49 +00:00
/// <summary>
/// Processes the exited.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
2016-04-02 04:29:48 +00:00
private string[] GetDownloadUrls()
{
switch (Environment.SystemArchitecture)
{
case Architecture.X86_X64:
2016-05-09 03:13:38 +00:00
return new[]
{
2016-05-10 16:18:05 +00:00
"https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20160409-git-0c90b2e-win64-static.7z"
2016-05-09 03:13:38 +00:00
};
2016-04-02 04:29:48 +00:00
case Architecture.X86:
2016-05-09 03:13:38 +00:00
return new[]
{
2016-05-10 16:18:05 +00:00
"https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20160409-git-0c90b2e-win32-static.7z"
2016-05-09 03:13:38 +00:00
};
2016-04-02 04:29:48 +00:00
}
return new string[] { };
}
}
}