aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Native/Autorun.cs
blob: c384d046021a1b994d5d5c0ba248d84d3f6bf567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using MediaBrowser.Common.IO;
using System;
using System.IO;
using CommonIO;

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)
        {
            var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");

            var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            if (autorun)
            {
                //Copy our shortut into the startup folder for this user
                File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true);
            }
            else
            {
                //Remove our shortcut from the startup folder for this user
                fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
            }
        }
    }
}