Exemplo n.º 1
0
        /* methods */

        /// <summary>
        /// Process the selected archive
        /// Identified the first allowed file based on systemid and populates FileName and MD5Hash properties
        /// </summary>
        public void ProcessArchive()
        {
            // determine archive type
            if (ArchiveExtension == ".zip")
            {
                using (ZipArchive zip = ZipFile.OpenRead(ArchivePath))
                {
                    foreach (ZipArchiveEntry entry in zip.Entries)
                    {
                        if (GameScanner.IsFileAllowed(entry.FullName, SystemId) == true)
                        {
                            IsAllowed = true;

                            using (var md5 = MD5.Create())
                            {
                                using (var stream = entry.Open())
                                {
                                    string h = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
                                    MD5Hash  = h;
                                    FileName = entry.FullName;
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }

            if (ArchiveExtension == ".7z")
            {
                var archive = ArchiveFactory.Open(ArchivePath);
                foreach (SevenZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    if (GameScanner.IsFileAllowed(entry.Key, SystemId) == true && !entry.IsDirectory)
                    {
                        IsAllowed = true;

                        using (var md5 = MD5.Create())
                        {
                            using (var stream = entry.OpenEntryStream())
                            {
                                string h = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
                                MD5Hash  = h;
                                FileName = entry.Key;
                                FileSize = entry.Size;
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }