Exemple #1
0
        public void CloseArchive()
        {
            mbFileOpen = false;
            mCurFile   = null;

            mFileList.Items.Clear();
        }
Exemple #2
0
        public void OpenArchive(string name)
        {
            if (mCurFile != null)
            {
                mCurFile.Close();
            }

            mFileList.Items.Clear();

            ProgWnd progWnd = new ProgWnd();

            progWnd.Location = new Point(this.Location.X + ((this.Width / 2) - progWnd.Width / 2), this.Location.Y + ((this.Height / 2) - progWnd.Height / 2));
            progWnd.SetLabel("Loading...");
            progWnd.Show();

            ArrayList itemArr = new ArrayList();

            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;
            worker.DoWork += new DoWorkEventHandler((object sender, DoWorkEventArgs e) => {
                worker.ReportProgress(0);
                mCurFile = new bf.BFFile();

                try {
                    mCurFile.Open(name);
                } catch (IOException ex) {
                    MessageBox.Show("Could not open file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (worker.CancellationPending)
                {
                    mCurFile.Close();
                    return;
                }

                worker.ReportProgress(20);

                mbFileOpen = true;

                // 20% -> 80%
                for (int i = 0; i < mCurFile.GetFileCount(); i++)
                {
                    var record = mCurFile.GetFileRecord(i);

                    ListViewItem item = new ListViewItem();
                    item.Text         = record.name;
                    item.Tag          = i;            // Tag the item with the position in the archive itself
                    item.SubItems.Add(Path.GetExtension(record.name));

                    // File size
                    StringBuilder sb = new StringBuilder(256);
                    StrFormatByteSize(record.fileSize, sb, 256);

                    item.SubItems.Add(sb.ToString());

                    item.SubItems.Add(String.Format("0x{0:X}", record.fileOffset.ToString("X8")));
                    itemArr.Add(item);

                    worker.ReportProgress((int)Math.Floor(20.0 + (((double)i / mCurFile.GetFileCount()) * 60.0)));
                    if (worker.CancellationPending)
                    {
                        mbFileOpen = false;
                        mCurFile.Close();
                    }
                }
            });

            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((object sender, RunWorkerCompletedEventArgs e) => {
                // 80% -> 100%
                mFileList.BeginUpdate();
                foreach (ListViewItem item in itemArr)
                {
                    mFileList.Items.Add(item);
                }
                mFileList.EndUpdate();

                progWnd.SetProgress(100);

                progWnd.Close();
            });

            worker.ProgressChanged += new ProgressChangedEventHandler((object sender, ProgressChangedEventArgs e) => {
                progWnd.SetProgress(e.ProgressPercentage);
            });

            worker.RunWorkerAsync();
        }