aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
blob: 08c8a4dea1a3dff53f2d881658bf4802a2a16713 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Logging;
using System.Diagnostics;
using System.IO;

namespace MediaBrowser.ServerApplication.Updates
{
    /// <summary>
    /// Update the specified application using the specified archive
    /// </summary>
    public class ApplicationUpdater
    {
        private const string UpdaterExe = "Mediabrowser.Updater.exe";
        private const string UpdaterDll = "Mediabrowser.InstallUtil.dll";
        public void UpdateApplication(IApplicationPaths appPaths, string archive, ILogger logger, string restartServiceName)
        {
            // First see if there is a version file and read that in
            var version = "Unknown";
            if (File.Exists(archive + ".ver"))
            {
                version = File.ReadAllText(archive + ".ver");
            }

            var systemPath = appPaths.ProgramSystemPath;
            var tempPath = Path.GetTempPath();

            // Use our installer passing it the specific archive
            // We need to copy to a temp directory and execute it there
            var source = Path.Combine(systemPath, UpdaterExe);

            logger.Info("Copying updater to temporary location");
            var tempUpdater = Path.Combine(tempPath, UpdaterExe);
            File.Copy(source, tempUpdater, true);
            source = Path.Combine(systemPath, UpdaterDll);
            var tempUpdaterDll = Path.Combine(tempPath, UpdaterDll);

            logger.Info("Copying updater dependencies to temporary location");
            File.Copy(source, tempUpdaterDll, true);
            var product = "server";
            // Our updater needs SS and ionic
            source = Path.Combine(systemPath, "ServiceStack.Text.dll");
            File.Copy(source, Path.Combine(tempPath, "ServiceStack.Text.dll"), true);
            source = Path.Combine(systemPath, "SharpCompress.dll");
            File.Copy(source, Path.Combine(tempPath, "SharpCompress.dll"), true);

            logger.Info("Starting updater process.");

            // installpath = program data folder
            // startpath = executable to launch
            // systempath = folder containing installation
            var args = string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3} service={4} installpath=\"{5}\" startpath=\"{6}\" systempath=\"{7}\"",
                    product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty, appPaths.ProgramDataPath, appPaths.ApplicationPath, systemPath);

            logger.Info("Args: {0}", args);
            Process.Start(tempUpdater, args);

            // That's it.  The installer will do the work once we exit
        }
    }
}