aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/Updates/ApplicationUpdater.cs
blob: c01430026d1e8ee1d345f7a499cc22f8b7d16a76 (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
using MediaBrowser.Common.Configuration;
using System.Diagnostics;
using System.IO;

namespace MediaBrowser.Common.Implementations.Updates
{
    public enum MBApplication
    {
        MBServer,
        MBTheater
    }

    /// <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(MBApplication app, IApplicationPaths appPaths, string archive)
        {
            // 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");
            }

            // Use our installer passing it the specific archive
            // We need to copy to a temp directory and execute it there
            var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
            var tempUpdater = Path.Combine(Path.GetTempPath(), UpdaterExe);
            File.Copy(source, tempUpdater, true);
            source = Path.Combine(appPaths.ProgramSystemPath, UpdaterDll);
            var tempUpdaterDll = Path.Combine(Path.GetTempPath(), UpdaterDll);
            File.Copy(source, tempUpdaterDll, true);
            var product = app == MBApplication.MBTheater ? "mbt" : "server";
            // Our updater needs SS and ionic
            source = Path.Combine(appPaths.ProgramSystemPath, "ServiceStack.Text.dll");
            File.Copy(source, Path.Combine(Path.GetTempPath(), "ServiceStack.Text.dll"), true);
            source = Path.Combine(appPaths.ProgramSystemPath, "Ionic.Zip.dll");
            File.Copy(source, Path.Combine(Path.GetTempPath(), "Ionic.Zip.dll"), true);
            Process.Start(tempUpdater, string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3}", product, archive, Process.GetCurrentProcess().Id, version));

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