コード例 #1
0
        private void btnTrim_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lsvPP.Items)
            {
                item.SubItems[2].Text = " ";
            }

            prgMajor.Value = 0;
            var items = lsvPP.Items.Cast <ListViewItem>().Where(x => x.Checked);

            prgMajor.Maximum = items.Count();
            foreach (ListViewItem item in items)
            {
                FileInfo fi           = item.Tag as FileInfo;
                long     originalSize = fi.Length;

                ppParser pp = new ppParser(fi.FullName);

                BackgroundWorker bb = new BackgroundWorker();
                bb.DoWork += (s, ev) => {
                    foreach (UserControl uc in panelPlugins.Controls)
                    {
                        ucPlugin ucp = uc as ucPlugin;
                        ucp.Invoke(new MethodInvoker(() =>
                        {
                            ucp.Execute(pp);
                        }));
                    }
                };

                bb.RunWorkerAsync();

                while (bb.IsBusy)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(50);
                }

                bb = pp.WriteArchive(pp.FilePath, false);
                bb.ProgressChanged += (s, ev) =>
                {
                    prgMinor.Value = ev.ProgressPercentage;
                };

                bb.RunWorkerAsync();

                while (bb.IsBusy)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(50);
                }

                prgMinor.Value = 100;
                fi             = new FileInfo(fi.FullName);
                long offsetSize = originalSize - fi.Length;
                item.SubItems[2].Text = BytesToString(offsetSize);

                prgMajor.Value++;
            }
        }
コード例 #2
0
        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lsvPP.Items)
            {
                item.SubItems[2].Text = " ";
            }

            prgMajor.Value = 0;
            var items = lsvPP.Items.Cast <ListViewItem>().Where(x => x.Checked).ToList();

            prgMajor.Maximum = items.Count();
            long totalsavings = 0;

            BackgroundWorker bb = new BackgroundWorker();

            bb.DoWork += (s, ev) => {
                foreach (ListViewItem item in items)
                {
                    FileInfo fi      = item.Tag as FileInfo;
                    long     savings = 0;

                    ppParser pp;
                    try
                    {
                        pp = new ppParser(fi.FullName);
                    }
                    catch (InvalidDataException)
                    {
                        continue;
                    }

                    foreach (UserControl uc in panelPlugins.Controls)
                    {
                        ucPlugin ucp = uc as ucPlugin;
                        savings += ucp.Analyze(pp);
                    }

                    totalsavings += savings;

                    this.Invoke(new MethodInvoker(() =>
                    {
                        prgMinor.Value        = 100;
                        item.SubItems[2].Text = BytesToString(savings);
                        prgMajor.Value++;
                    }));
                }
                this.Invoke(new MethodInvoker(() =>
                {
                    lblSavings.Text = "Total savings: " + BytesToString(totalsavings);
                }));
            };

            bb.RunWorkerAsync();
        }
コード例 #3
0
        public void ReloadPlugins()
        {
            panelPlugins.Controls.Clear();

#warning actually load plugins here
            List <ITrimPlugin> plugins = InternalPlugins.AllInternalPlugins;

            foreach (ITrimPlugin itp in plugins)
            {
                UserControl uc = new ucPlugin(itp);
                uc.Dock = DockStyle.Top;
                panelPlugins.Controls.Add(uc);
                uc.SendToBack();
            }
        }