Esempio n. 1
0
 public void AddFile(BlobContent content)
 {
     _contents.Add(content);
 }
Esempio n. 2
0
        private void extractWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[]    files;
            string      ext;
            string      directory = (string)e.Argument;
            int         count     = 0;
            int         percent;
            BlobFile    blobFile;
            Blob        blob;
            BlobContent content;

            byte[]            buffer;
            CfsFile           cfsFile;
            BackgroundWorker  worker  = (BackgroundWorker)sender;
            ExtractionResults results = new ExtractionResults();

            files = Directory.GetFiles(directory);
            foreach (string file in files)
            {
                count++;
                percent = (int)((count / (double)files.Length) * 100.0);


                ext = Path.GetExtension(file);
                if (!ext.Equals(".blo", StringComparison.CurrentCultureIgnoreCase) &&
                    !ext.Equals(".lvb", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                try {
                    blobFile       = new BlobFile(file);
                    blob           = new Blob();
                    blob.Name      = Path.GetFileNameWithoutExtension(file);
                    blob.Path      = Path.GetDirectoryName(file);
                    blob.Version   = blobFile.Version;
                    blob.FileSize  = (int)new FileInfo(file).Length;
                    blob.Extention = Path.GetExtension(file);
                    results.AddBlob(blob);

                    foreach (BlobEntry entry in blobFile)
                    {
                        ext = Path.GetExtension(entry.Filename);
                        results.ContentCount++;

                        content      = new BlobContent();
                        content.Size = entry.Size;

                        if (ext.Equals(".cfs", StringComparison.CurrentCultureIgnoreCase))
                        {
                            content.Type = FileType.Cfs;
                            content.Name = Path.GetFileNameWithoutExtension(entry.Filename);
                            buffer       = blobFile.ExtractBytes(entry);

                            try {
                                //cfsFile = CfsFile.Read(buffer, 0, buffer.Length);
                                cfsFile = null;

                                if (cfsFile.Version == 3)
                                {
                                    results.CfsVersion3Files++;
                                }
                                else if (cfsFile.Version == 4)
                                {
                                    results.CfsVersion4Files++;
                                }
                                else // should never happen, but why not
                                {
                                    results.CfsVersionUnknownFiles++;
                                }
                            }
                            catch (Exception) {
                                results.CfsVersionUnknownFiles++;
                            }

                            blob.AddFile(content);
                        }
                        else if (ext.Equals(".wav", StringComparison.CurrentCultureIgnoreCase))
                        {
                            content.Type = FileType.Wav;
                            content.Name = Path.GetFileNameWithoutExtension(entry.Filename);
                            results.WavFiles++;

                            blob.AddFile(content);
                        }
                        else
                        {
                            results.UnknownFiles++;
                        }
                    }
                }
                catch (Exception) {
                }

                if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                worker.ReportProgress(percent, results);
            }

            worker.ReportProgress(100, results);
            e.Result = results;
        }