Exemple #1
0
        private static void InitializeVersionInformation(Session session, out Uri downloadUri)
        {
            onlineVersion    = GetOnlineVersion(out downloadUri);
            packagedVersion  = new Version(InstallerDatabase.GetProductProperty(session, "WifiRemotePackagedVersion"));
            installedVersion = GetCurrentlyInstalledVersion();

            Log.Write("WifiRemote: We packaged {0}, {1} is available online and {2} is installed", packagedVersion, onlineVersion, installedVersion);
        }
Exemple #2
0
        private static WifiRemoteState GetWifiRemoteVersionInfo(Session session, out Uri downloadLast)
        {
            downloadLast = null;
            string xmlData;

            // download update.xml
            try
            {
                Log.Write("WifiRemote: Downloading update.xml from {0}", UPDATE_FILE);
                using (WebClient client = new WebClient())
                {
                    xmlData = client.DownloadString(UPDATE_FILE);
                }
            }
            catch (Exception ex)
            {
                Log.Write("WifiRemote: Failed to download update.xml: {0}", ex.Message);
                return(WifiRemoteState.Error);
            }

            // parse it
            try
            {
                XElement updateFile = XElement.Parse(xmlData);

                // set uri
                string uri = updateFile.Element("Items").Element("PackageClass").Element("GeneralInfo").Element("OnlineLocation").Value.ToString();
                downloadLast = new Uri(uri);

                // get wifiremote version
                XElement versionNode   = updateFile.Element("Items").Element("PackageClass").Element("GeneralInfo").Element("Version");
                Version  remoteVersion = new Version(
                    Int32.Parse(versionNode.Element("Major").Value),
                    Int32.Parse(versionNode.Element("Minor").Value),
                    Int32.Parse(versionNode.Element("Build").Value),
                    Int32.Parse(versionNode.Element("Revision").Value)
                    );
                Version ourVersion = new Version(InstallerDatabase.GetProductProperty(session, "WifiRemotePackagedVersion"));
                Log.Write("WifiRemote: We packaged {0} and {1} is available online", ourVersion.ToString(), remoteVersion.ToString());

                // compare and return
                int compare = ourVersion.CompareTo(remoteVersion);
                if (compare == 0)
                {
                    return(WifiRemoteState.SameVersion);
                }
                return(compare < 0 ? WifiRemoteState.NewerVersionAvailable : WifiRemoteState.OlderVersionAvailable);
            }
            catch (Exception ex)
            {
                Log.Write("WifiRemote: Failed to parse update.xml: {0}\r\n{1}\r\n{2}", ex.Message, ex.ToString(), ex.StackTrace.ToString());
                return(WifiRemoteState.Error);
            }
        }
Exemple #3
0
        public static ActionResult Install(Session session)
        {
            // download WifiRemote update information
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote update information...", ""));
            Uri             downloadUri;
            WifiRemoteState infoState = GetWifiRemoteVersionInfo(session, out downloadUri);
            Dictionary <WifiRemoteState, string> messages = new Dictionary <WifiRemoteState, string>()
            {
                { WifiRemoteState.Error, "WifiRemote: failed to download update information, using packaged version" },
                { WifiRemoteState.OlderVersionAvailable, "WifiRemote: older version available online then we shipped... strange, using packaged version" },
                { WifiRemoteState.SameVersion, "WifiRemote: last version packaged, installing from MSI" },
                { WifiRemoteState.NewerVersionAvailable, "WifiRemote: newer version available, downloading it" }
            };

            Log.Write(messages[infoState]);

            // download newer WifiRemote if needed
            string mpeiPackagePath = Path.GetTempFileName();
            bool   downloadFailed  = false;

            if (infoState == WifiRemoteState.NewerVersionAvailable)
            {
                session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote installer...", ""));
                if (!DownloadWifiRemote(downloadUri, mpeiPackagePath))
                {
                    Log.Write("WifiRemote: failed to download it, continuing with extracting from MSI");
                    downloadFailed = true;
                }
            }

            // else extract from package
            if (infoState != WifiRemoteState.NewerVersionAvailable || downloadFailed)
            {
                Log.Write("WifiRemote: extracting package from MSI");
                if (!InstallerDatabase.ExtractBinaryToFile(session, "WifiRemoteInstallerBin", mpeiPackagePath))
                {
                    Log.Write("WifiRemote: failed to extract from MSI");
                    return(ActionResult.Failure);
                }
            }
            Log.Write("WifiRemote: got WifiRemote installer in {0}", mpeiPackagePath);

            // lookup MPEI installer location
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Installing WifiRemote MediaPortal plugin with MPEI...", ""));
            string mpei = LookupMPEI();

            if (mpei == null)
            {
                return(ActionResult.NotExecuted);
            }
            Log.Write("WifiRemote: found MPEI at {0}", mpei);

            // execute
            ProcessStartInfo param = new ProcessStartInfo();

            param.FileName  = mpei;
            param.Arguments = mpeiPackagePath + " /S";
            Log.Write("WifiRemote: starting MPEI with arguments {0}", param.Arguments);
            Process proc = new Process();

            proc.StartInfo = param;
            proc.Start();
            proc.WaitForExit();
            Log.Write("WifiRemote: MPEI finished with exit code {0}", proc.ExitCode);

            // cleanup
            File.Delete(mpeiPackagePath);
            return(ActionResult.Success);
        }
Exemple #4
0
        public static ActionResult Install(Session session)
        {
            // download version information
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote update information...", ""));
            Uri downloadUri;

            InitializeVersionInformation(session, out downloadUri);

            // bail out if installed version is the newest one
            if (installedVersion != null && installedVersion.CompareTo(onlineVersion) >= 0 && installedVersion.CompareTo(packagedVersion) >= 0)
            {
                Log.Write("WifiRemote: Installed version is the last one, doing nothing...");
                return(ActionResult.Success);
            }

            // setup for installation
            string mpeiPackagePath = Path.GetTempFileName();
            bool   extractFromMSI  = false;

            // should we download a newer version?
            if (onlineVersion != null && packagedVersion.CompareTo(onlineVersion) < 0)
            {
                Log.Write("WifiRemote: Downloading newer version from update site");

                session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote installer...", ""));
                if (!DownloadWifiRemote(downloadUri, mpeiPackagePath))
                {
                    Log.Write("WifiRemote: Failed to download it, continuing with extracting from MSI");
                    extractFromMSI = true;
                }
            }
            else
            {
                Log.Write("WifiRemote: Not downloading version from update site");
                extractFromMSI = true;
            }

            // else extract from package
            if (extractFromMSI)
            {
                Log.Write("WifiRemote: Extracting package from MSI");
                if (!InstallerDatabase.ExtractBinaryToFile(session, "WifiRemoteInstallerBin", mpeiPackagePath))
                {
                    Log.Write("WifiRemote: Failed to extract from MSI");
                    return(ActionResult.Failure);
                }
            }
            Log.Write("WifiRemote: Got WifiRemote installer in {0}", mpeiPackagePath);

            // lookup MPEI installer location
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Installing WifiRemote MediaPortal plugin with MPEI...", ""));
            string mpei = LookupMPEI();

            if (mpei == null)
            {
                return(ActionResult.NotExecuted);
            }
            Log.Write("WifiRemote: Found MPEI at {0}", mpei);

            // execute
            ProcessStartInfo param = new ProcessStartInfo();

            param.FileName  = mpei;
            param.Arguments = mpeiPackagePath + " /S";
            Log.Write("WifiRemote: Starting MPEI with arguments {0}", param.Arguments);
            Process proc = new Process();

            proc.StartInfo = param;
            proc.Start();
            proc.WaitForExit();
            Log.Write("WifiRemote: MPEI finished with exit code {0}", proc.ExitCode);

            // cleanup
            File.Delete(mpeiPackagePath);
            return(ActionResult.Success);
        }