Ejemplo n.º 1
0
        bool m_InterProcess_RegisterRequestedEvent(object sender, ApplicationInstanceEventArgs e)
        {
            Cache c = new Cache(false);

            if (c.Exists("locked") && c.Get <bool>("locked"))
            {
                return(false);
            }

            if (!c.Exists("instances"))
            {
                c.Set <ApplicationInstanceList>("instances", new ApplicationInstanceList());
            }
            ApplicationInstanceList list = c.Get <ApplicationInstanceList>("instances");

            if (list.Count(v => v.FilesystemPath == e.LocalPath) > 0)
            {
                return(false);
            }
            list.Add(new ApplicationInstance
            {
                LastCheckTime  = new DateTime(1970, 1, 1),
                FilesystemPath = e.LocalPath,
                UpdateUrl      = e.UpdateURI.ToString()
            });
            c.Set <ApplicationInstanceList>("instances", list);
            return(true);
        }
Ejemplo n.º 2
0
        private void PerformUpdate(bool initial)
        {
            Cache c = new Cache(false);

            this.m_DualLog.WriteEntry("Periodic update check has started.");

            // Find all application instances.
            try
            {
                if (!c.Exists("instances"))
                {
                    c.Set <ApplicationInstanceList>("instances", new ApplicationInstanceList());
                }
                ApplicationInstanceList list = c.Get <ApplicationInstanceList>("instances");
                this.m_DualLog.WriteEntry("Application instance list retrieved with " + list.Count + " applications to check.");
                for (int i = 0; i < list.Count; i++)
                {
                    if (initial || (DateTime.Now - list[i].LastCheckTime).TotalHours >= 3)
                    {
                        this.PerformUpdateSingle(list[i].FilesystemPath);
                    }
                    else
                    {
                        this.m_DualLog.WriteEntry("The application at " + list[i].UpdateUrl + " has been checked in the last 3 hours.");
                    }
                }

                this.m_DualLog.WriteEntry("Periodic update check has finished.");
            }
            catch (Exception e)
            {
                this.m_DualLog.WriteException("Periodic update check failed with exception:", e);
            }
        }
Ejemplo n.º 3
0
        private bool HasUpdateSingle(string localPath)
        {
            this.m_DualLog.WriteEntry("Checking whether updates exist for " + localPath + ".");
            Cache c = new Cache(false);
            ApplicationInstanceList list = c.Get <ApplicationInstanceList>("instances");

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].FilesystemPath == localPath)
                {
                    // Perform update check.
                    Application a = new Application(c, new Uri(list[i].UpdateUrl), list[i].FilesystemPath);
                    list[i].LastCheckTime = DateTime.Now;
                    try
                    {
                        if (a.Check())
                        {
                            this.m_DualLog.WriteEntry("Updates exist for " + localPath + ".");
                            return(true);
                        }
                        else
                        {
                            this.m_DualLog.WriteEntry("No updates available for " + localPath + ".");
                            return(false);
                        }
                    }
                    catch (WebException)
                    {
                        this.m_DualLog.WriteEntry("Unable to check " + list[i].UpdateUrl + " for updates.  The server is not responding.", EventLogEntryType.Warning);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private void PerformUpdateSingle(string localPath, string restartPath = null)
        {
            Cache c = new Cache(false);

            c.Set <bool>("locked", true);
            ApplicationInstanceList list = c.Get <ApplicationInstanceList>("instances");

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].FilesystemPath == localPath)
                {
                    this.m_DualLog.WriteEntry("Now checking " + list[i].UpdateUrl + " for updates.");

                    // Perform update check.
                    string      result = "";
                    Application a      = new Application(c, new Uri(list[i].UpdateUrl), list[i].FilesystemPath);
                    list[i].LastCheckTime = DateTime.Now;
                    try
                    {
                        a.Update((status, info) =>
                        {
                            switch (status)
                            {
                            case Application.UpdateStatus.Starting:
                                result += "Update is starting...\r\n";
                                break;

                            case Application.UpdateStatus.RetrievingFileList:
                                result += "Retrieving file list... ";
                                break;

                            case Application.UpdateStatus.RetrievedFileList:
                                result += "done (" + info + " files to scan).\r\n";
                                break;

                            case Application.UpdateStatus.DeletionStart:
                                result += "Deleting " + info + "... ";
                                break;

                            case Application.UpdateStatus.DownloadNewStart:
                            case Application.UpdateStatus.DownloadFreshStart:
                                result += "Downloading " + info + "... ";
                                break;

                            case Application.UpdateStatus.PatchStart:
                                result += "Patching " + info + "... ";
                                break;

                            case Application.UpdateStatus.PatchApplied:
                                result += info + ". ";
                                break;

                            case Application.UpdateStatus.Complete:
                                result += "Update is complete.\r\n";
                                break;

                            case Application.UpdateStatus.DeletionFinish:
                            case Application.UpdateStatus.DownloadNewFinish:
                            case Application.UpdateStatus.DownloadFreshFinish:
                            case Application.UpdateStatus.PatchFinish:
                                result += "done.\r\n";
                                break;
                            }
                        });

                        this.m_DualLog.WriteEntry(list[i].UpdateUrl + " has been checked for updates.\r\n\r\n" + result);
                    }
                    catch (WebException)
                    {
                        this.m_DualLog.WriteEntry("Unable to check " + list[i].UpdateUrl + " for updates.  The server is not responding.", EventLogEntryType.Warning);
                    }
                }
            }
            c.Set <ApplicationInstanceList>("instances", list);
            c.Set <bool>("locked", false);

            // Restart game if possible.
            if (restartPath != null)
            {
                WindowsNative.LaunchPathAsUser(restartPath);
            }
        }