aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Emby.Server/ApplicationPathHelper.cs11
-rw-r--r--src/Emby.Server/CoreAppHost.cs2
-rw-r--r--src/Emby.Server/Program.cs213
-rw-r--r--src/Emby.Server/project.json8
4 files changed, 41 insertions, 193 deletions
diff --git a/src/Emby.Server/ApplicationPathHelper.cs b/src/Emby.Server/ApplicationPathHelper.cs
index 4da87b6a0..c611ff372 100644
--- a/src/Emby.Server/ApplicationPathHelper.cs
+++ b/src/Emby.Server/ApplicationPathHelper.cs
@@ -8,7 +8,7 @@ namespace Emby.Server
{
public class ApplicationPathHelper
{
- public static string GetProgramDataPath(string applicationPath)
+ public static string GetProgramDataPath(string appDirectory)
{
var useDebugPath = false;
@@ -27,14 +27,7 @@ namespace Emby.Server
// If it's a relative path, e.g. "..\"
if (!Path.IsPathRooted(programDataPath))
{
- var path = Path.GetDirectoryName(applicationPath);
-
- if (string.IsNullOrEmpty(path))
- {
- throw new Exception("Unable to determine running assembly location");
- }
-
- programDataPath = Path.Combine(path, programDataPath);
+ programDataPath = Path.Combine(appDirectory, programDataPath);
programDataPath = Path.GetFullPath(programDataPath);
}
diff --git a/src/Emby.Server/CoreAppHost.cs b/src/Emby.Server/CoreAppHost.cs
index 1a1526513..21f6ae445 100644
--- a/src/Emby.Server/CoreAppHost.cs
+++ b/src/Emby.Server/CoreAppHost.cs
@@ -51,7 +51,7 @@ namespace Emby.Server
return list;
}
- protected override void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory)
+ protected override void AuthorizeServer()
{
}
diff --git a/src/Emby.Server/Program.cs b/src/Emby.Server/Program.cs
index 64fc423a1..6f871990d 100644
--- a/src/Emby.Server/Program.cs
+++ b/src/Emby.Server/Program.cs
@@ -28,8 +28,6 @@ namespace Emby.Server
private static ILogger _logger;
- private static bool _isRunningAsService = false;
- private static bool _canRestartService = false;
private static bool _appHostDisposed;
[DllImport("kernel32.dll", SetLastError = true)]
@@ -41,39 +39,33 @@ namespace Emby.Server
public static void Main(string[] args)
{
var options = new StartupOptions();
- _isRunningAsService = options.ContainsOption("-service");
-
- if (_isRunningAsService)
- {
- //_canRestartService = CanRestartWindowsService();
- }
var currentProcess = Process.GetCurrentProcess();
-
- var applicationPath = currentProcess.MainModule.FileName;
+
+ var baseDirectory = System.AppContext.BaseDirectory;
//var architecturePath = Path.Combine(Path.GetDirectoryName(applicationPath), Environment.Is64BitProcess ? "x64" : "x86");
//Wand.SetMagickCoderModulePath(architecturePath);
//var success = SetDllDirectory(architecturePath);
- var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService);
+ var appPaths = CreateApplicationPaths(baseDirectory);
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Debug);
logManager.AddConsoleOutput();
var logger = _logger = logManager.GetLogger("Main");
-
+
ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- if (IsAlreadyRunning(applicationPath, currentProcess))
- {
- logger.Info("Shutting down because another instance of Emby Server is already running.");
- return;
- }
+ //if (IsAlreadyRunning(applicationPath, currentProcess))
+ //{
+ // logger.Info("Shutting down because another instance of Emby Server is already running.");
+ // return;
+ //}
if (PerformUpdateIfNeeded(appPaths, logger))
{
@@ -81,14 +73,7 @@ namespace Emby.Server
return;
}
- try
- {
- RunApplication(appPaths, logManager, _isRunningAsService, options);
- }
- finally
- {
- OnServiceShutdown();
- }
+ RunApplication(appPaths, logManager, options);
}
/// <summary>
@@ -139,34 +124,17 @@ namespace Emby.Server
}
}
- if (!_isRunningAsService)
- {
- return false;
- }
-
return false;
}
/// <summary>
/// Creates the application paths.
/// </summary>
- /// <param name="applicationPath">The application path.</param>
- /// <param name="runAsService">if set to <c>true</c> [run as service].</param>
- /// <returns>ServerApplicationPaths.</returns>
- private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, bool runAsService)
+ private static ServerApplicationPaths CreateApplicationPaths(string appDirectory)
{
- var resourcesPath = Path.GetDirectoryName(applicationPath);
-
- if (runAsService)
- {
- var systemPath = Path.GetDirectoryName(applicationPath);
-
- var programDataPath = Path.GetDirectoryName(systemPath);
-
- return new ServerApplicationPaths(programDataPath, applicationPath, resourcesPath);
- }
+ var resourcesPath = appDirectory;
- return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), applicationPath, resourcesPath);
+ return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(appDirectory), appDirectory, resourcesPath);
}
/// <summary>
@@ -177,14 +145,7 @@ namespace Emby.Server
{
get
{
- if (_isRunningAsService)
- {
- return _canRestartService;
- }
- else
- {
- return true;
- }
+ return true;
}
}
@@ -196,14 +157,7 @@ namespace Emby.Server
{
get
{
- if (_isRunningAsService)
- {
- return _canRestartService;
- }
- else
- {
- return true;
- }
+ return false;
}
}
@@ -214,9 +168,8 @@ namespace Emby.Server
/// </summary>
/// <param name="appPaths">The app paths.</param>
/// <param name="logManager">The log manager.</param>
- /// <param name="runService">if set to <c>true</c> [run service].</param>
/// <param name="options">The options.</param>
- private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
+ private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
{
var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true);
@@ -240,29 +193,19 @@ namespace Emby.Server
var initProgress = new Progress<double>();
- if (!runService)
- {
- // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
- SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
- ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
- }
+ // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
+ SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
+ ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
var task = _appHost.Init(initProgress);
Task.WaitAll(task);
task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);
- if (runService)
- {
- StartService(logManager);
- }
- else
- {
- Task.WaitAll(task);
+ Task.WaitAll(task);
- task = ApplicationTaskCompletionSource.Task;
- Task.WaitAll(task);
- }
+ task = ApplicationTaskCompletionSource.Task;
+ Task.WaitAll(task);
}
private static void GenerateCertificate(string certPath, string certHost)
@@ -271,31 +214,6 @@ namespace Emby.Server
}
/// <summary>
- /// Starts the service.
- /// </summary>
- private static void StartService(ILogManager logManager)
- {
- }
-
- /// <summary>
- /// Handles the Disposed event of the service control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- static void service_Disposed(object sender, EventArgs e)
- {
- ApplicationTaskCompletionSource.SetResult(true);
- OnServiceShutdown();
- }
-
- private static void OnServiceShutdown()
- {
- _logger.Info("Shutting down");
-
- DisposeAppHost();
- }
-
- /// <summary>
/// Handles the UnhandledException event of the CurrentDomain control.
/// </summary>
/// <param name="sender">The source of the event.</param>
@@ -306,10 +224,7 @@ namespace Emby.Server
new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
- if (!_isRunningAsService)
- {
- ShowMessageBox("Unhandled exception: " + exception.Message);
- }
+ ShowMessageBox("Unhandled exception: " + exception.Message);
if (!Debugger.IsAttached)
{
@@ -325,29 +240,6 @@ namespace Emby.Server
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private static bool PerformUpdateIfNeeded(ServerApplicationPaths appPaths, ILogger logger)
{
- // Look for the existence of an update archive
- var updateArchive = Path.Combine(appPaths.TempUpdatePath, "MBServer" + ".zip");
- if (File.Exists(updateArchive))
- {
- logger.Info("An update is available from {0}", updateArchive);
-
- // Update is there - execute update
- try
- {
- //var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty;
- //new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName);
-
- // And just let the app exit so it can update
- return true;
- }
- catch (Exception e)
- {
- logger.ErrorException("Error starting updater.", e);
-
- ShowMessageBox(string.Format("Error attempting to update application.\n\n{0}\n\n{1}", e.GetType().Name, e.Message));
- }
- }
-
return false;
}
@@ -358,37 +250,25 @@ namespace Emby.Server
public static void Shutdown()
{
- if (_isRunningAsService)
- {
- ShutdownWindowsService();
- }
- else
- {
- DisposeAppHost();
+ DisposeAppHost();
- ShutdownWindowsApplication();
- }
+ //_logger.Info("Calling Application.Exit");
+ //Application.Exit();
+
+ _logger.Info("Calling Environment.Exit");
+ Environment.Exit(0);
+
+ _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
+ ApplicationTaskCompletionSource.SetResult(true);
}
public static void Restart()
{
DisposeAppHost();
- if (_isRunningAsService)
- {
- RestartWindowsService();
- }
- else
- {
- //_logger.Info("Hiding server notify icon");
- //_serverNotifyIcon.Visible = false;
+ // todo: start new instance
- _logger.Info("Starting new instance");
- //Application.Restart();
- Process.Start(_appHost.ServerConfigurationManager.ApplicationPaths.ApplicationPath);
-
- ShutdownWindowsApplication();
- }
+ Shutdown();
}
private static void DisposeAppHost()
@@ -402,31 +282,6 @@ namespace Emby.Server
}
}
- private static void ShutdownWindowsApplication()
- {
- //_logger.Info("Calling Application.Exit");
- //Application.Exit();
-
- _logger.Info("Calling Environment.Exit");
- Environment.Exit(0);
-
- _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
- ApplicationTaskCompletionSource.SetResult(true);
- }
-
- private static void ShutdownWindowsService()
- {
- }
-
- private static void RestartWindowsService()
- {
- }
-
- private static bool CanRestartWindowsService()
- {
- return false;
- }
-
/// <summary>
/// Sets the error mode.
/// </summary>
diff --git a/src/Emby.Server/project.json b/src/Emby.Server/project.json
index c64db844f..55acee514 100644
--- a/src/Emby.Server/project.json
+++ b/src/Emby.Server/project.json
@@ -12,10 +12,10 @@
"version": "1.0.1"
},
"Mono.Nat": "1.0.0-*",
- "Microsoft.Win32.Registry": "4.0.0",
- "System.Runtime.Extensions": "4.1.0",
- "System.Diagnostics.Process": "4.1.0",
- "Microsoft.Data.SQLite": "1.0.0"
+ "Microsoft.Win32.Registry": "4.0.0",
+ "System.Runtime.Extensions": "4.1.0",
+ "System.Diagnostics.Process": "4.1.0",
+ "Microsoft.Data.SQLite": "1.1.0-preview1-final"
},
"frameworks": {