コード例 #1
0
ファイル: MainForm.cs プロジェクト: DrChat/FromDustHook
        private string ExtractFile(int id)
        {
            bf.BFFile.bffilerecord rec = mCurFile.GetFileRecord(id);

            var fn  = rec.name;
            var ext = Path.GetExtension(fn);

            string path = Path.Combine(new string[] { Path.GetTempPath(), fn });

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            int offset = 0;

            if (headerFiles.Contains(ext))
            {
                offset = 32;                 // 32 byte header at beginning of file
            }
            FileStream s = mCurFile.ExtractFile(id, path, offset);

            s.Close();

            // Now convert the file
            bf.IFileProvider prov = bf.FileProviderList.GetProvider(ext.Substring(1));
            if (prov != null)
            {
                path = prov.ConvertFile(path, rec.name, Path.GetTempPath());
            }

            // rename son files because they're .wav format
            if (ext == ".son")
            {
                string newPath = Path.Combine(new string[] { Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".wav" });
                if (File.Exists(newPath))
                {
                    File.Delete(newPath);
                }

                File.Move(path, newPath);

                path = newPath;
            }

            return(path);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: DrChat/FromDustHook
        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();
        }