Пример #1
0
        /* Methods */

        private void FireMessageEvent(ProgressDialogEventArgs message)
        {
            if (Message != null)
            {
                //ProgressDialogEventArgs status = new ProgressDialogEventArgs();
                // message.DialogText = message;
                Message(this, message);
            }
        }
Пример #2
0
 private void MessageRevieved(Archive a, ProgressDialogEventArgs e)
 {
     if (Controller == null)
     {
         Console.WriteLine(e.DialogText);
     }
     else
     {
         if (e.DialogText != null)
         {
             Controller.SetMessage(e.DialogText);
         }
         if (e.DialogTitle != null)
         {
             Controller.SetTitle(e.DialogTitle);
         }
     }
 }
Пример #3
0
        public CompressionResults ProcessArchive(string[] allowedExtensions)
        {
            CompressionResults crs = new CompressionResults(ArchivePath);

            // if file does not exist
            if (!File.Exists(ArchivePath))
            {
                return(null);
            }

            // mount the archive

            try
            {
                using (Stream archiveStream = File.OpenRead(ArchivePath))
                {
                    using (var ar = new SevenZipExtractor(archiveStream))
                    {
                        var structure = ar.ArchiveFileData;

                        List <ArchiveFileInfo> allowedFiles = new List <ArchiveFileInfo>();

                        foreach (var s in structure)
                        {
                            if (s.IsDirectory == true)
                            {
                                continue;
                            }

                            string fileName  = s.FileName;
                            string extension = Path.GetExtension(fileName);

                            if (allowedExtensions == null)
                            {
                                allowedFiles.Add(s);
                                continue;
                            }

                            foreach (var ext in allowedExtensions)
                            {
                                if (ext == extension)
                                {
                                    allowedFiles.Add(s);
                                    break;
                                }
                            }
                        }

                        AllowedFilesDetected = allowedFiles.Count();

                        // now we should have a list of allowed files
                        foreach (var file in allowedFiles)
                        {
                            CompressionResult cr = new CompressionResult();
                            cr.ArchivePath  = ArchivePath;
                            cr.InternalPath = file.FileName.Replace("\\", "/");
                            cr.FileName     = cr.InternalPath.Split('/').LastOrDefault();
                            cr.CRC32        = file.Crc.ToString("X");
                            cr.Extension    = Path.GetExtension(cr.FileName);
                            cr.RomName      = cr.FileName.Replace(cr.Extension, "");

                            //cr.CalculateDBPathString();

                            /*
                             * if (Path.GetExtension(ArchivePath).ToLower() == ".zip")
                             * {
                             *  // calculate md5 hash
                             *  using (var stream = new MemoryStream())
                             *  {
                             *      ar.ExtractFile(file.Index, stream);
                             *      byte[] data = new byte[stream.Length];
                             *      data = StreamTools.ReadToEnd(stream);
                             *
                             *      using (var md5 = MD5.Create())
                             *      {
                             *          string hash = BitConverter.ToString(md5.ComputeHash(data)).Replace("-", string.Empty);
                             *          cr.MD5 = hash;
                             *      }
                             *  }
                             * }
                             */

                            // 7zip and zip extraction too slow, use CRC32 instead
                            cr.MD5 = cr.CRC32;

                            crs.Results.Add(cr);

                            // build status message
                            StringBuilder sb1 = new StringBuilder();
                            sb1.Append("Scanning: " + Path.GetFileName(ArchivePath) + "\n\n");
                            sb1.Append("Processing: " + cr.InternalPath);

                            ProgressDialogEventArgs eva = new ProgressDialogEventArgs();
                            eva.DialogText = sb1.ToString();
                            FireMessageEvent(eva);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // problem with archive?
                string exceptionMsg = ex.ToString();
            }



            // var ar = new SevenZipExtractor(ArchivePath);


            return(crs);
        }
Пример #4
0
 private void MessageRevieved(Archive a, ProgressDialogEventArgs e)
 {
     Console.WriteLine(e.DialogText);
 }