Ejemplo n.º 1
0
        private void lvwUpdates_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            ListView            lvwchange     = (ListView)sender;
            List <ListViewItem> selecteditems = new List <ListViewItem>();

            foreach (ListViewItem lvix in lvwchange.Items)
            {
                if (lvix.Selected)
                {
                    selecteditems.Add(lvix);
                }
            }

            if (selecteditems.Count == 1)
            {
                ListViewItem selitem = selecteditems.First();
                lvwUpdates.ContextMenuStrip = StripContext;
                BCUpdate.UpdateInfo uinfo = selitem.Tag as BCUpdate.UpdateInfo;
                if (completeddownloads.Contains(uinfo))
                {
                    cancelToolStripMenuItem.Enabled = false;
                    openContainingFolderToolStripMenuItem.Enabled = true;
                }
                else
                {
                    cancelToolStripMenuItem.Enabled = true;
                    openContainingFolderToolStripMenuItem.Enabled = true;
                }
            }
            else
            {
                lvwUpdates.ContextMenuStrip = null;
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        private void cancelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem selitem = lvwUpdates.SelectedItems[0];

            BCUpdate.UpdateInfo uinfo = selitem.Tag as BCUpdate.UpdateInfo;
            uinfo.CancelDownload();
        }
Ejemplo n.º 4
0
        private void lvwUpdates_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            //
            ListViewItem thisitem = e.Item;

            BCUpdate.UpdateInfo upinfo      = (BCUpdate.UpdateInfo)thisitem.Tag;
            DrawItemData        usedrawdata = (DrawItemData)upinfo.Tag;
            //upinfo.DrawSubItem(sender, e)

            DrawItemData drawdata = (DrawItemData)upinfo.Tag;

            if (e.ColumnIndex == 3)
            {
                StringFormat centeralign = new StringFormat();
                centeralign.Alignment = StringAlignment.Center;
                e.DrawDefault         = false;
                e.DrawBackground();
                int usepercent;
                int.TryParse(e.SubItem.Text, out usepercent);
                double percentfraction = (double)usepercent / 100;
                e.Graphics.DrawRectangle(new Pen(Color.Black), e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4);


                ThemePaint.DrawProgress(lvwUpdates.Handle, e.Graphics, e.Bounds, (float)percentfraction, ThemePaint.FILLSTATES.PBFS_NORMAL);



                e.Graphics.DrawString(drawdata.StringDraw, new Font("Consolas", 10), Brushes.Black,
                                      e.Bounds, centeralign);
            }
            else
            {
                e.DrawDefault = true;
            }
        }
Ejemplo n.º 5
0
 public frmUpdates(BCUpdate.UpdateInfo DownloadUpdate, bool TerminateonUpdate)
 {
     Debug.Print("frmUpdates MUpdateInfo constructor");
     //switch mode to immediate..
     mUpdateMode     = EUpdateMode.Update_Immediate;
     immediateupdate = DownloadUpdate;
     InitializeComponent();
     FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
 }
Ejemplo n.º 6
0
        private void openContainingFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem selitem = lvwUpdates.SelectedItems[0];

            BCUpdate.UpdateInfo upinfo = (BCUpdate.UpdateInfo)selitem.Tag;
            //upinfo.DownloadedFilename
            String execname = "Explorer.exe";

            String parameters = "/" + upinfo.DownloadedFilename.Substring(upinfo.DownloadedFilename.Length - Path.GetFileName(upinfo.DownloadedFilename).Length) + "\"";


            parameters += " /select \"" + upinfo.DownloadedFilename + "\"";
        }
Ejemplo n.º 7
0
        private void completionroutine(BCUpdate.UpdateInfo updateobject, AsyncCompletedEventArgs args)
        {
            AllSamples = new List <long>();
            if (mUpdateMode == EUpdateMode.Update_Full)
            {
                ListViewItem upobj = lookupinfo[updateobject];
                Debug.Print("Completed download of " + updateobject.DlName);
                if (args.Error != null)
                {
                    ((DrawItemData)updateobject.Tag).DownloadError = args.Error;
                }


                {
                    completeddownloads.Add(updateobject);
                }
                alldownloads--;
                upobj.Checked = false;



                if (alldownloads == 0)
                {
                    Debug.Print("All Downloads Finished.");
                    Text = "Installing...";
                    InstallDownloaded_Thread();
                }
            }
            else
            {
                //Immediate mode update, completed, so start the installer and exit.
                //updateobject.DownloadedFilename
                lblImmAction.Text = "Installing...";
                string installfile = updateobject.DownloadedFilename;
                try
                {
                    Process executableProgram = Process.Start(installfile);
                    //terminate this one during the update.
                    if (terminateonupdate)
                    {
                        Application.Exit();
                    }
                }
                catch (Exception p)
                {
                    MessageBox.Show("failed to run update:" + p.Message);
                }
            }
        }
Ejemplo n.º 8
0
 public frmUpdates(BCUpdate.UpdateInfo DownloadUpdate) : this(DownloadUpdate, true)
 {
 }
Ejemplo n.º 9
0
        private void progressroutine(BCUpdate.UpdateInfo updateobject, DownloadProgressChangedEventArgs args)
        {
            if (mUpdateMode == EUpdateMode.Update_Full)
            {
                ListViewItem upobj = lookupinfo[updateobject];

                updateprogressforitem(upobj, args);

                //we want to invalidate the areas we want to repaint.

                lvwUpdates.Invalidate(upobj.SubItems[3].Bounds);

                lvwUpdates.Update();

                //calculate the average % complete of all items.
                float  percentshow = getAverageCompletion();
                String usetitle    = String.Format("{0:0.0}% of {1} Items", percentshow, updatingItems.Count);
                Text = usetitle;
                if (percentshow > 0)
                {
                    if (isWin7())
                    {
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.
                        SetProgressValue((int)(percentshow), 100);
                    }
                }
            }
            else
            {
                TimeSpan interval = DateTime.Now - lastprogress;

                long currentspeed = args.BytesReceived - prevDownloadAmount;
                //immediate
                if ((DateTime.Now - lastprogress).TotalSeconds >= 1)
                {
                    numperiods++;
                    if (numperiods == 5)
                    {
                        numperiods = 1;
                    }
                }
                float percentcomplete = (float)(args.BytesReceived) / (float)(args.TotalBytesToReceive);
                float percentshow     = Math.Min(percentcomplete * 100, 100);
                if (isWin7())
                {
                    Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.
                    SetProgressValue((int)(percentshow), 100);
                }
                Debug.Print("Received " + args.BytesReceived.ToString() + " of " + args.TotalBytesToReceive.ToString() + "(" + percentcomplete + "%" + ")");
                lblImmAction.Text = "Downloading" + CreateString('.', numperiods);
                //place the two sizes in an array...
                long[] sizes          = new long[] { args.BytesReceived, args.TotalBytesToReceive };
                long   persecondspeed = interpolatepersecond(interval, currentspeed);

                String scurrentspeed = persecondspeed > 0?ByteSizeFormatter.FormatSize(persecondspeed):"(Please wait...)";
                //call the formatting routine..
                String[] formattedsizes = ByteSizeFormatter.FormatSizes(sizes).ToArray();

                lblImmProgress.Text = String.Format("{0} of {1} ({2:0.0}%)", formattedsizes[0], formattedsizes[1], percentshow);

                if (lastaveragebyterate == -1)
                {
                    lastaveragebyterate = persecondspeed;
                }
                long avgspeed = lastaveragebyterate / 2 + persecondspeed / 2;
                AllSamples.Add(avgspeed);
                avgspeed          = (int)(AllSamples.Average());
                lblRemaining.Text = FormatTimeSpan(PredictETA(avgspeed, sizes[0], sizes[1]));
                lblDlRate.Text    = ByteSizeFormatter.FormatSize(avgspeed) + "/s";
                Text = String.Format("Updating...{0:0.0}%", percentshow);
                prevDownloadAmount  = args.BytesReceived;
                pbarImmediate.Value = (int)(percentshow);
                pbarImmediate.Invoke((MethodInvoker)(() => { pbarImmediate.Invalidate(); pbarImmediate.Update(); }));
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 10
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();
                    }
                }
            }
        }