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

52 lines
1.8 KiB
C#
Raw Normal View History

using MediaBrowser.Common.IO;
using System;
2013-09-25 00:54:51 +00:00
using System.IO;
2015-10-04 04:23:11 +00:00
using CommonIO;
2013-09-25 00:54:51 +00:00
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Autorun
/// </summary>
public static class Autorun
{
/// <summary>
/// Configures the specified autorun.
/// </summary>
/// <param name="autorun">if set to <c>true</c> [autorun].</param>
/// <param name="fileSystem">The file system.</param>
public static void Configure(bool autorun, IFileSystem fileSystem)
2013-09-25 00:54:51 +00:00
{
var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
2015-05-23 20:44:15 +00:00
if (!Directory.Exists(Path.GetDirectoryName(shortcutPath)))
{
shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
}
var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
2015-05-23 20:44:15 +00:00
// Remove lnk from old name
try
{
fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Media Browser Server.lnk"));
}
catch
{
}
2013-09-25 00:54:51 +00:00
if (autorun)
{
//Copy our shortut into the startup folder for this user
2015-05-23 20:44:15 +00:00
File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true);
2013-09-25 00:54:51 +00:00
}
else
{
//Remove our shortcut from the startup folder for this user
2015-05-23 20:44:15 +00:00
fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
2013-09-25 00:54:51 +00:00
}
}
}
}