Esempio n. 1
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (!lvwUpdates.Columns.ContainsKey("PROGRESS"))
            {
                lvwUpdates.Columns.Add("PROGRESS", "Progress");
            }
            foreach (ListViewItem loopitem in lvwUpdates.Items)
            {
                if (loopitem.Checked)
                {
                    alldownloads++;
                }
            }
            completeddownloads = new List <BCUpdate.UpdateInfo>();
            updatingItems      = new List <BCUpdate.UpdateInfo>();
            foreach (ListViewItem loopitem in lvwUpdates.Items)
            {
                if (!loopitem.Checked)
                {
                    continue;
                }

                BCUpdate.UpdateInfo upinfo = (BCUpdate.UpdateInfo)loopitem.Tag;
                // MessageBox.Show("DIAG:" + upinfo.ToString());
                upinfo.Tag = new DrawItemData("0%", null, loopitem);
                upinfo.DownloadUpdate(progressroutine, completionroutine);
                updatingItems.Add(upinfo);
            }
        }
Esempio n. 2
0
        private void frmUpdates_Load(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Debug.Print("frmUpdates Loaded");
                switch (mUpdateMode)
                {
                case EUpdateMode.Update_Full:


                    grpBasicUpdate.Visible = false;
tryagain:
                    updateobj = new BCUpdate();
                    lvwUpdates.Items.Clear();
                    lvwUpdates.Columns.Clear();
                    lvwUpdates.Columns.Add("NAME", "Name");
                    lvwUpdates.Columns.Add("INSTALLEDVER", "Installed");
                    lvwUpdates.Columns.Add("VERSION", "Version");
                    lvwUpdates.Columns.Add("PROGRESS", "Download Progress", 128);
                    lvwUpdates.Columns.Add("SIZE", "Size", 128);
                    lvwUpdates.Columns.Add("PATCH", "Patch For", 128);
                    lsorter = new GenericListViewSorter(lvwUpdates, sortproc);
                    lookupinfo.Clear();

                    //queued delegates to call after all other elements are added.
                    //this is used for adding patches last.
                    Queue <Action> DeferPatchItems = new Queue <Action>();
                    var            Typelookup      = new Dictionary <int, BCUpdate.UpdateInfo>();
                    try
                    {
                        foreach (BCUpdate.UpdateInfo looper in updateobj.LoadedUpdates)
                        {
                            var loopupdate = looper;
                            //we copy to a local variable because otherwise how a foreach control variable
                            //is closed over can be compiler specific.
                            Dictionary <int, BCUpdate.UpdateInfo> typelookup = Typelookup;
                            loopupdate.Tag = new DrawItemData("", null, null);

                            Action loopbody = (() =>
                            {
                                Color useForeColor = SystemColors.WindowText;
                                String usepatchString = "";
                                if (loopupdate.DownloadFor > 0)
                                {
                                    if (!typelookup.ContainsKey(loopupdate.DownloadFor))
                                    {
                                        usepatchString = "<Unknown>";
                                    }
                                    else
                                    {
                                        var appliedto = typelookup[loopupdate.DownloadFor];
                                        usepatchString = appliedto.DlName;
                                        if (updateobj.getinstalledVersion(appliedto.dlID) == "")
                                        {
                                            useForeColor = SystemColors.GrayText;
                                            usepatchString = "<" + appliedto.DlName + " Not Installed>";
                                        }
                                    }
                                }
                                string[] createdstrings = new string[] { loopupdate.DlName, updateobj.getinstalledVersion(loopupdate.dlID), loopupdate.UpdateVersion, "0", ByteSizeFormatter.FormatSize(loopupdate.FileSize), usepatchString };

                                ListViewItem newitem = new ListViewItem(createdstrings);
                                ((DrawItemData)loopupdate.Tag).lvwitem = newitem;
                                newitem.Tag = loopupdate;
                                newitem.ForeColor = useForeColor;
                                lookupinfo.Add(loopupdate, newitem);
                                lvwUpdates.Items.Add(newitem);
                                typelookup.Add(loopupdate.dlID, loopupdate);
                            });

                            //if we need to defer it, add it to the queue. Otherwise, call it now.
                            if (loopupdate.DownloadFor == 0)
                            {
                                loopbody();
                            }
                            else
                            {
                                DeferPatchItems.Enqueue(loopbody);
                            }
                        }

                        while (DeferPatchItems.Any())
                        {
                            DeferPatchItems.Dequeue()();
                        }
                    }
                    catch (Exception except)
                    {
                        switch (
                            MessageBox.Show(
                                "The Following Exception occured trying to retrieve update information:\n" +
                                except.ToString(), "Unexpected Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
                            )
                        {
                        case DialogResult.Retry:
                            goto tryagain;

                        case DialogResult.Cancel:
                            Close();
                            break;
                        }
                    }
                    break;

                case EUpdateMode.Update_Immediate:
                    //resize to Grp
                    Debug.Print("Immediate Update...");
                    //grpBasicUpdate.Location = new Point(ClientRectangle.Left, ClientRectangle.Top);
                    ClientSize = grpBasicUpdate.Size;
                    fraavailupdates.Hide();
                    MinimizeBox            = true;
                    terminateonupdate      = true;
                    grpBasicUpdate.Visible = true;
                    grpBasicUpdate.BringToFront();
                    this.Invalidate();
                    grpBasicUpdate.Invalidate();
                    grpBasicUpdate.Update();
                    this.Invalidate();
                    this.Update();
                    Debug.Print("grpBasicUpdate.Visible=" + grpBasicUpdate.Visible);
                    immediateupdate.CancelDownload();

                    String downloadresult = immediateupdate.DownloadUpdate(progressroutine, completionroutine);
                    if (updatingItems == null)
                    {
                        updatingItems = new List <BCUpdate.UpdateInfo>();
                    }
                    updatingItems.Add(immediateupdate);



                    break;
                }

                Cursor.Current = Cursors.Default;
            }
            catch (Exception exx)
            {
                panRefreshing.Visible = true;
                panRefreshing.BringToFront();
                panRefreshing.Location = new Point(0, 0);
                panRefreshing.Size     = new Size(ClientSize.Width, panLower.Top);
                lblrefreshing.Text     = "An Exception occured retrieving update information.";
                txtException.Text      = exx.ToString();

                btnDownload.Visible = false;
            }
        }
Esempio n. 3
0
        public static void RegisterApplication(String ApplicationName, int GameID, String InstalledVersion,
                                               String EXEPath, bool forceupdate)
        {
            //Applications using this library should call this routine at every startup. Basically, BCUpdate tries to keep track of the installed version of all
            //the software that uses it in a central location; in this case, a registry key. This is used later on in comparisons to see what the current installed version is.
            //The problem arises that this information can get outdated- uninstalling a program that uses it, for example, may leave registry data behind.
            //what we do is simply verify that the executable exists as well; if it doesn't exist, we say "not installed." or something.

            RegisteredApps = new Dictionary <string, ApplicationRegData>();
            RegistryKey RegAppKey;

            try
            {
                RegAppKey = Registry.CurrentUser.CreateSubKey(sRegAppKey);
            }
            catch (UnauthorizedAccessException ave)
            {
                //curses.
                throw ave;
            }
            var RegisteredKey = RegAppKey.CreateSubKey(ApplicationName);


            RegisteredKey.SetValue("Name", ApplicationName);
            RegisteredKey.SetValue("GameID", GameID);
            RegisteredKey.SetValue("InstalledVersion", InstalledVersion);
            RegisteredKey.SetValue("EXEPath", EXEPath);


            LoadRegisteredApps();


            //last, check for updates to this app.
            String UpdateText      = "An Update is available for {0}- Version {1}.\nUpdate now?";
            String ForceUpdateText = "An Update (for {0}) is being forced to version {1}. Continue?";

            String   UpdateWithSpecific      = "An Update is available for {0}- Version {1}.\n{2}\nUpdate Now?";
            String   ForceUpdateTextSpecific = "An Update (for {0}) is being forced to version {1}.\n{2}\n Continue?";
            BCUpdate updater = new BCUpdate();
            String   strid   = updater.CheckUpdate(GameID);

            if (forceupdate)
            {
                strid      = updater.getUpdateVersion(GameID);
                UpdateText = ForceUpdateText;
            }
            if (strid != "")
            {
                BCUpdate.UpdateInfo objupdate =
                    (from n in updater.LoadedUpdates where n.dlID == GameID select n).
                    First
                        ();


                if (objupdate.UpdateSpecific.Length > 0)
                {
                    UpdateText = forceupdate ? ForceUpdateText : UpdateText;
                }
                else
                {
                    UpdateText = forceupdate ? ForceUpdateTextSpecific : UpdateWithSpecific;
                }


                if (DialogResult.Yes ==
                    MessageBox.Show(String.Format(UpdateText, ApplicationName, strid, objupdate.UpdateSpecific), ApplicationName + " Update",
                                    MessageBoxButtons.YesNo))
                {
                    bool updatefinish = false;
                    objupdate.DownloadUpdate((g) => updatefinish = true);

                    //idle loop, then return.
                    while (!updatefinish)
                    {
                        Thread.Sleep(0);
                    }
                    if (objupdate.UpdateSuccessful)
                    {
                        Process.Start(objupdate.DownloadedFilename);
                        Application.Exit();
                    }
                }
            }
        }