Example #1
0
        private void DoSevenZip(FileInfo finfo)
        {
            using (SevenZipArchive sevenZipArchive = SevenZipArchive.Open(finfo.FullName))
            {
                using (var reader = sevenZipArchive.ExtractAllEntries())
                {
                    UpdateList("Opening " + reader.ArchiveType + ": " + finfo.FullName);
                    PeekReader(reader, finfo);
                }
            }

            GC.Collect();
        }
Example #2
0
        private static string UpdateUpdater(string url, string updaterpackname, int remoterev)
        {
            // Check if updater is running...
            try
            {
                Process[] processes = Process.GetProcesses();

                // Abort if it's running...
                foreach (Process process in processes)
                {
                    if (process.ProcessName == "Updater" &&
                        Path.GetDirectoryName(process.MainModule.FileName) == Application.StartupPath)
                    {
                        return("Updater.exe is already running.");
                    }
                }
            }
            catch (Exception e)
            {
                return("failed to check Updater process: " + e.Message);
            }

            // Check local revision
            int localrev = FileVersionInfo.GetVersionInfo("Updater.exe").ProductPrivatePart;

            if (localrev < remoterev)
            {
                // Download update
                MemoryStream stream = DownloadWebFile(Path.Combine(url, updaterpackname));
                if (stream == null)
                {
                    return("failed to download Updater package.");
                }

                // Unpack update
                try
                {
                    using (SevenZipArchive arc = SevenZipArchive.Open(stream))
                    {
                        if (!arc.IsComplete)
                        {
                            return("downloaded Updater package is not complete.");
                        }
                        IReader reader = arc.ExtractAllEntries();

                        // Unpack all
                        while (reader.MoveToNextEntry())
                        {
                            if (reader.Entry.IsDirectory)
                            {
                                continue;                                                      // Shouldn't be there, but who knows...
                            }
                            reader.WriteEntryToDirectory(General.AppPath, new ExtractionOptions()
                            {
                                ExtractFullPath = true, Overwrite = true
                            });
                        }
                    }
                }
                catch (Exception e)
                {
                    return("failed to unpack the Updater: " + e.Message);
                }
            }

            return(string.Empty);
        }
Example #3
0
    public static void Un7Zip(string inputPath, string extractionPath = null)
    {
        if (File.Exists(inputPath))
        {
            Debug.Log("Un7Zip File eist : " + inputPath);
            //if(SevenZipArchive.IsSevenZipFile(inputPath))
            //{
            //    Debug.Log(string.Format("{0} is a 7Zip File"));
            //    //using (Stream stream = File.OpenRead(inputPath))
            //    //{

            //    //    var reader = SevenZipArchive.Open(stream);
            //    //    //while (reader.MoveToNextEntry())
            //    //    //    {
            //    //    //        string dir, file;
            //    //    //        if (reader.Entry.IsDirectory)
            //    //    //        {
            //    //    //            dir = reader.Entry.Key;
            //    //    //            Debug.Log("its a directory : " + dir);
            //    //    //            continue;
            //    //    //        }
            //    //    //        if (!reader.Entry.IsDirectory)
            //    //    //        {
            //    //    //            //Debug.Log(reader.Entry.Key);
            //    //    //            //reader.WriteEntryToDirectory(@"C:\temp", new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
            //    //    //            file = reader.Entry.Key;

            //    //    //            Debug.Log("its a file : " + file);
            //    //    //            continue;
            //    //    //        }
            //    //    //    }
            //    //    reader.Dispose();
            //    //}

            //    using (SevenZipArchive sa = SevenZipArchive.Open(inputPath))
            //    {

            //    }

            //}
            //else
            //{
            //    Debug.Log(string.Format("{0} is not a 7Zip File"));
            //}

            using (SevenZipArchive sa = SevenZipArchive.Open(inputPath))
            {
                Debug.Log("seven zip archive opened , total size is : " + sa.TotalSize);

                using (SevenZipArchive.SevenZipReader reader = (SevenZipArchive.SevenZipReader)sa.ExtractAllEntries())
                {
                    //reader.WriteAllToDirectory(extractionPath, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });   //extract all file to a specific directory

                    while (reader.MoveToNextEntry())
                    {
                        string dir, file;
                        if (reader.Entry.IsDirectory)
                        {
                            dir = reader.Entry.Key;
                            Debug.Log("its a directory : " + dir);
                            string directoryName = (extractionPath != null && extractionPath != "") ? Path.Combine(extractionPath, dir) : dir;
                            if (!Directory.Exists(directoryName))
                            {
                                Debug.Log(string.Format("creating Directory : {0}", directoryName));
                                Directory.CreateDirectory(directoryName);
                            }
                            continue;
                        }
                        if (!reader.Entry.IsDirectory)
                        {
                            //Debug.Log(reader.Entry.Key);
                            //reader.WriteEntryToDirectory(@"C:\temp", new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
                            file = reader.Entry.Key;
                            Debug.Log("its a file : " + file);
                            string directoryName = (extractionPath != null && extractionPath != "") ? Path.Combine(extractionPath, Path.GetDirectoryName(file)) : Path.GetDirectoryName(file);
                            if (!Directory.Exists(directoryName))
                            {
                                Debug.Log(string.Format("creating Directory Before extracting File : {0}", directoryName));
                                Directory.CreateDirectory(directoryName);
                            }
                            string fileName = (Path.GetFileName(file) != string.Empty) ? (extractionPath != null && extractionPath != "") ? Path.Combine(directoryName, Path.GetFileName(file)) : Path.GetFileName(file) : string.Empty;

                            if (fileName.Length > 0)
                            {
                                Debug.Log(string.Format("Extracting File To : {0}", fileName));


                                //reader.WriteEntryToDirectory();
                                //reader.WriteEntryTo(fileName);
                                reader.WriteEntryToFile(fileName, new ExtractionOptions()
                                {
                                    ExtractFullPath = true, Overwrite = true
                                });
                            }



                            continue;
                        }
                    }
                }
            }
        }
    }
Example #4
0
        public void EnumerateFiles(List <DataSource> dataSources)
        {
            _popup.Show();

            _popup.Text = "Starting the parse";


            var dic = new Dictionary <string, Func <string, List <FileReadObject> > >();

            //SevenZipExtractor.SetLibraryPath(Application.ExecutablePath + @"\7z.dll");

            int i = 1;

            foreach (var source in dataSources)
            {
                PacketCounter = 0;
                PacketTotal   = source.Packets;

                string pre = i + "/" + dataSources.Count + " ";
                _popup.Text = pre + "Reading from " + source.FileInfo.Name;

                if (source.SourceType == SourceType.PCAP)
                {
                    pcapReader.Read(source.FileInfo.FullName);
                }
                else if (source.SourceType == SourceType.PCAPNG)
                {
                    pcapngReader.Read(source.FileInfo.FullName);
                }
                else if (source.SourceType == SourceType.Zip)
                {
                    if (SevenZipArchive.IsSevenZipFile(source.FileInfo.FullName))
                    {
                        using (SevenZipArchive sevenZipArchive = SevenZipArchive.Open(source.FileInfo.FullName))
                        {
                            using (var reader = sevenZipArchive.ExtractAllEntries())
                            {
                                ZipReader(reader, source);
                            }
                        }

                        GC.Collect();
                    }
                    else
                    {
                        try
                        {
                            using (var filestream = File.OpenRead(source.FileInfo.FullName))
                            {
                                using (var reader = ReaderFactory.Open(filestream))
                                {
                                    ZipReader(reader, source);
                                }
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                        }

                        GC.Collect();
                    }
                }
            }

            _popup.Close();
        }