コード例 #1
1
        public static void Determine_Parser(System.IO.FileInfo fi, uint level)
        {
            string ext = fi.Extension.ToString();
            if (ext.CompareTo(".txt") == 0)
            {
                try
                {
                    StreamReader textFile = new StreamReader(fi.FullName);
                    string text = textFile.ReadToEnd();
                    textFile.Close();
                   // MessageBox.Show(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".rtf") == 0)
            {
                try
                {
                    RichTextBox rtb = new RichTextBox();
                    rtb.Rtf = System.IO.File.ReadAllText(fi.FullName);
                    string text = rtb.Text;
                    //Console.WriteLine(s);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pdf") == 0)
            {
                try
                {
                    String text = PDFParser.Parser.ParsePDFtoString(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                    WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".doc") == 0 || ext.CompareTo(".xls") == 0 || ext.CompareTo(".ppt") == 0)
            {
                try
                {
                    TextReader reader = new FilterReader(fi.FullName);
                    String text = "";
                    using (reader) { text = reader.ReadToEnd(); }
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".docx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.docxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    }
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            else if (ext.CompareTo(".xlsx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.xlsxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pptx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.pptxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".odt") == 0 || ext.CompareTo(".ods") == 0 || ext.CompareTo(".odp") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.openOfficeParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".xml") == 0)
            {
                try
                {
                    String text = XMLParser.Parser.ParseXMLtoString(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pst") == 0)
            {

            }
            else if (ext.CompareTo(".zip") == 0 || ext.CompareTo(".7z") == 0 || ext.CompareTo(".xz") == 0 || ext.CompareTo(".bzip2") == 0 ||
                ext.CompareTo(".gzip") == 0 || ext.CompareTo(".tar") == 0 || ext.CompareTo(".wim") == 0 || ext.CompareTo(".arj") == 0 ||
                ext.CompareTo(".cab") == 0 || ext.CompareTo(".chm") == 0 || ext.CompareTo(".cpio") == 0 || ext.CompareTo(".cramfs") == 0 ||
                ext.CompareTo(".deb") == 0 || ext.CompareTo(".fat") == 0 || ext.CompareTo(".hfs") == 0 || ext.CompareTo(".iso") == 0 ||
                ext.CompareTo(".lzh") == 0 || ext.CompareTo(".lzma") == 0 || ext.CompareTo(".mbr") == 0 || ext.CompareTo(".msi") == 0 ||
                ext.CompareTo(".nsis") == 0 || ext.CompareTo(".ntfs") == 0 || ext.CompareTo(".rar") == 0 || ext.CompareTo(".rpm") == 0 ||
                ext.CompareTo(".squashfs") == 0 || ext.CompareTo(".udf") == 0 || ext.CompareTo(".vhd") == 0 || ext.CompareTo(".xar") == 0 ||
                ext.CompareTo(".z") == 0)
            {
                //extract code
                SevenZipExtractor extractor = null;
                try
                {
                    //path to the systems temporary folder
                    String tempFolderPath = Path.GetTempPath();
                    tempFolderPath += "temp_dir\\";
                    //create a directory to dump everything into inside the temp folder
                    Directory.CreateDirectory(tempFolderPath);

                    //set the path of the 7z.dll (it needs to be in the debug folder)
                    SevenZipExtractor.SetLibraryPath("7z.dll");
                    extractor = new SevenZipExtractor(fi.FullName);

                    //Extract the entire file
                    extractor.ExtractArchive(tempFolderPath);
                    extractor.Dispose();

                    //Count how many files in archive
                    int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length;

                    // traverse files
                    string[] fileEntries = Directory.GetFiles(tempFolderPath);
                    foreach (string fileName in fileEntries)
                    {
                        //Console.WriteLine("IN ARCHIVE: " + fileName);
                    }

                    //delete the temporary directory we created at the beginning
                    Directory.Delete(tempFolderPath, true);
                }
                catch (Exception e)
                {
                    //get rid of the object because it is unmanaged
                    extractor.Dispose();
                    Console.WriteLine(e.Message);
                }
            }
        }
コード例 #2
0
        public static String docxParser(String filename)
        {
            //path to the systems temporary folder
            String tempFolderPath = Path.GetTempPath();

            //set the path of the 7z.dll (it needs to be in the debug folder)
            SevenZipExtractor.SetLibraryPath("7z.dll");

            SevenZipExtractor extractor = new SevenZipExtractor(filename);

            //create a filestream for the file we are going to extract
            FileStream f = new FileStream(tempFolderPath + "document.xml", FileMode.Create);

            //extract the document.xml
            extractor.ExtractFile("word\\document.xml", f);

            //get rid of the object because it is unmanaged
            extractor.Dispose();

            //close the filestream
            f.Close();

            //send document.xml that we extracted from the .docx to the xml parser
            String result = XMLParser.Parser.ParseXMLtoString(tempFolderPath + "document.xml");

            //delete the extracted file from the temp folder
            File.Delete(tempFolderPath + "document.xml");

            return result;
        }
コード例 #3
0
ファイル: ArchiveHandler.cs プロジェクト: se5a/PBWAutoClient
        public static int extractArchive(string inFileName, string extractPath)
        {
            // extract input archive
            FileStream fileStream;
            SevenZipExtractor extractor = null;
            try
            {
                extractor = new SevenZipExtractor(File.OpenRead(inFileName));

                foreach (var fileName in extractor.ArchiveFileNames)
                {
                    // you of course can extract to a file stream instead of a memory stream if you want :)
                    //var memoryStream = new MemoryStream();
                    //extractor.ExtractFile(fileName, memoryStream);
                    // do what you want with your file here :)
                    fileStream = File.Create(Path.Combine(extractPath, fileName));

                    extractor.ExtractFile(fileName, fileStream);

                    int buffersize = 1024;
                    byte[] buffer = new byte[buffersize];
                    int bytesRead = 0;

                    while ((bytesRead = fileStream.Read(buffer, 0, buffersize)) != 0)
                    {
                        fileStream.Write(buffer, 0, bytesRead);
                    } // end while
                    fileStream.Close();
                }
                extractor.Dispose();

            }
            catch (Exception ex)
            {
                Logger.Logwrite(ex.Message);
                Console.Error.WriteLine("Error: Could not open input archive: " + inFileName);
                Console.Error.WriteLine("\t" + ex.Message);

            }
            finally
            {

            }
            return 1;
        }
コード例 #4
0
        private string extractBundledResourcesFromFile(string filename)
        {
            string sourceFile     = Path.Combine(resourcesDir, "bundled", filename);
            string timestampFile  = Path.Combine(extractedResourcesDir, Path.ChangeExtension(filename, "timestamp"));

            string destinationDir = Path.Combine(extractedResourcesDir, Path.GetFileNameWithoutExtension(filename));

            if (!File.Exists(timestampFile) || File.GetLastWriteTimeUtc(sourceFile) > File.GetLastWriteTimeUtc(timestampFile))
            {
                DeleteRecursivelyWithMagicDust(destinationDir);

                var extractor = new SevenZipExtractor(sourceFile);

                // we typically have a properly-named root dir inside .7z itself, so extracting into destinationDir doesn't work
                extractor.ExtractArchive(extractedResourcesDir);
                extractor.Dispose();

                File.WriteAllBytes(timestampFile, new byte[0]);
            }

            return destinationDir;
        }
コード例 #5
0
        public static String pptxParser(String filename)
        {
            //path to the systems temporary folder
            String tempFolderPath = Path.GetTempPath();
            tempFolderPath += "excelTemp\\";
            //create a directory to dump everything into inside the temp folder
            Directory.CreateDirectory(tempFolderPath);

            //set the path of the 7z.dll (it needs to be in the debug folder)
            SevenZipExtractor.SetLibraryPath("7z.dll");

            SevenZipExtractor extractor = new SevenZipExtractor(filename);

            //Extract the entrie excel file
            extractor.ExtractArchive(tempFolderPath);
            extractor.Dispose();

            //Count how many slides there are in the presentation
            int count = Directory.GetFiles(tempFolderPath + "ppt\\slides", "*.xml", SearchOption.TopDirectoryOnly).Length;

            //Create an array of filenames based off how many slides we counted
            String[] files = new String[count];
            for (int i = 1; i <= count; i++)
            {
                files[i - 1] = "ppt\\slides\\slide" + i + ".xml";
            }

            //send the slides to the xml parser
            String result = "";
            foreach (String s in files)
                result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + s);

            //delete the temporary directory we created at the beginning
            Directory.Delete(tempFolderPath, true);

            return result;
        }
コード例 #6
0
        private async void unzip(string path)
        {
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Value   = 0;
            progressBar1.Visible = true;

            var progressHandler = new Progress <byte>(
                percentDone => progressBar1.Value = percentDone);
            var progress     = progressHandler as IProgress <byte>;
            var sevenZipPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7za.dll");

            SevenZipBase.SetLibraryPath(sevenZipPath);


            var file = new SevenZip.SevenZipExtractor(path);


            file.Extracting += (sender, args) =>
            {
                progress.Report(args.PercentDone);
            };
            file.ExtractionFinished += (sender, args) =>
            {
                // Do stuff when done
                loadlbl.Text = "Successfully Fixed!";
                try
                {
                    if (File.Exists(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.bin1")))
                    {
                        File.Delete(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.bin1"));
                    }

                    if (File.Exists(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.bin2")))
                    {
                        File.Delete(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.bin2"));
                    }

                    if (File.Exists(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.7z")))
                    {
                        File.Delete(Path.Combine(System.IO.Path.GetTempPath(), @"ddf.7z"));
                    }
                }
                catch (SystemException)
                {
                }
                KryptonMessageBox.Show("Operation Success! This was easier than we thought.. ROFL");
                this.Close();
            };
            //Extract the stuff
            string xpath = Path.Combine(AoE2GamePath, @"Data");

            try
            {
                file.ExtractArchive(xpath);
                file.Dispose();
            }
            catch (SystemException)
            {
            }
        }
コード例 #7
0
 public void Dispose()
 {
     _extractor.Dispose();
 }
コード例 #8
0
		/// <summary>
		/// The run method of the thread on which the <see cref="SevenZipExtractor"/> is created.
		/// </summary>
		/// <remarks>
		/// This method creates a <see cref="SevenZipExtractor"/> and then watches for events to execute.
		/// Other methods signal the thread that an action needs to be taken, and this thread executes said
		/// actions.
		/// </remarks>
		protected void RunThread()
		{
			m_szeExtractor = String.IsNullOrEmpty(m_strPath) ? new SevenZipExtractor(m_stmArchive) : new SevenZipExtractor(m_strPath);
			try
			{
				ActionPackage apkStartEvent = m_queEvents.Dequeue();
				apkStartEvent.DoneEvent.Set();
				while (true)
				{
					m_mreEvent.WaitOne();
					ActionPackage apkEvent = m_queEvents.Dequeue();
					if (apkEvent.Action == null)
						break;
					try
					{
						apkEvent.Action();
					}
					catch (Exception e)
					{
						apkEvent.Exception = e;
					}
					m_mreEvent.Reset();
					apkEvent.DoneEvent.Set();
				}
			}
			finally
			{
				m_szeExtractor.Dispose();
			}
		}
コード例 #9
0
ファイル: FormMain.cs プロジェクト: ibright/ClipUpload
        void CompareFiles()
        {
            string rarfilename = "Update" + this.Version + ".rar";
            string path = Path.GetDirectoryName(Path.GetFullPath(rarfilename));
            SevenZipExtractor extr = new SevenZipExtractor(rarfilename);

            for (int i = 0; i < extr.ArchiveFileNames.Count; i++) {
                ArchiveFileInfo fileinfo = extr.ArchiveFileData[i];
                string filename = extr.ArchiveFileNames[i];
                bool updateFile = false;

                if (!fileinfo.IsDirectory) {
                    if (!File.Exists(filename)) {
                        updateFile = true;
                    } else {
                        if (Resources.Blacklist.Split(',').Contains(Path.GetFileName(filename)))
                            continue;

                        uint currentHash = Crc32.Compute(File.ReadAllBytes(filename));
                        uint updateHash = extr.ArchiveFileData[i].Crc;

                        if (currentHash != updateHash)
                            updateFile = true;
                    }
                } else {
                    if (!Directory.Exists(filename))
                        Directory.CreateDirectory(filename);
                    continue;
                }

                if (!updateFile)
                    continue;

                string pth = Path.GetDirectoryName(filename);
                if (pth != "") {
                    if (!Directory.Exists(pth))
                        Directory.CreateDirectory(pth);
                    if (File.Exists(filename))
                        File.Delete(filename);
                }

                AddLog("Updating " + filename + "...");

                FileStream fs = File.Create(filename);
                extr.ExtractFile(filename, fs);
                fs.Close();
                fs.Dispose();

                AddLine(RepeatString(" ", 73 - filename.Length) + " DONE");
            }

            if (bool.Parse(Resources.SettingsKeySet)) {
                appSettings.SetString("Version", this.Version);
                appSettings.Save();
            }

            extr.Dispose();

            if (File.Exists(rarfilename))
                File.Delete(rarfilename);

            buttonUpdate.Text = "Run " + Resources.Product;

            AddLine("Updating finished!");
        }
コード例 #10
0
 /// <summary>
 /// The run method of the thread on which the <see cref="SevenZipExtractor"/> is created.
 /// </summary>
 /// <remarks>
 /// This method creates a <see cref="SevenZipExtractor"/> and then watches for events to execute.
 /// Other methods signal the thread that an action needs to be taken, and this thread executes said
 /// actions.
 /// </remarks>
 protected void RunThread()
 {
     m_szeExtractor = String.IsNullOrEmpty(m_strPath) ? new SevenZipExtractor(m_stmArchive) : new SevenZipExtractor(m_strPath);
     try
     {
         KeyValuePair<Action<object>, ManualResetEvent> kvpStartEvent = m_queEvents.Dequeue();
         kvpStartEvent.Value.Set();
         while (true)
         {
             m_mreEvent.WaitOne();
             KeyValuePair<Action<object>, ManualResetEvent> kvpEvent = m_queEvents.Dequeue();
             if (kvpEvent.Key == null)
                 break;
             kvpEvent.Key(null);
             m_mreEvent.Reset();
             kvpEvent.Value.Set();
         }
     }
     finally
     {
         m_szeExtractor.Dispose();
     }
 }
コード例 #11
0
    private void DoCheck() {
      string FileName = _ShellListView.GetFirstSelectedItem().ParsingName;
      var extractor = new SevenZipExtractor(FileName);
      if (!extractor.Check())
        MessageBox.Show("Not Pass");
      else
        MessageBox.Show("Pass");

      extractor.Dispose();
    }
コード例 #12
0
        private void DoCheck()
        {

            SevenZipExtractor extractor = new SevenZipExtractor(archive.ParsingName);
            if (!extractor.Check())
                MessageBox.Show("Not Pass");
            else
                MessageBox.Show("Pass");

            extractor.Dispose();
        }
コード例 #13
0
ファイル: frmUpdate.cs プロジェクト: jeffboulanger/connectuo
        private void update_ProgressCompleted(object sender, ProgressCompletedEventArgs e)
        {
            if (e.Cancelled)
                return;

            Invoke((MethodInvoker)delegate
            {
                if (e.ExceptionObject != null)
                {
                    Program.Status = UpdateStatus.Failure;
                    txtChangeLog.Text = string.Format("The following error occured while trying to get the lastest ConnectUO version information: \n {0}", ((Exception)e.ExceptionObject).Message);
                    Complete();
                    return;
                }

                pbProgress.Value = 100;
                lblStatus.Text = string.Format("Status: Extracting...");

                System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o)
                {
                    _extractor = new SevenZipExtractor(_destinationFile);

                    _extractor.Extracting += new EventHandler<SevenZip.ProgressEventArgs>(extractor_Extracting);
                    _extractor.ExtractionFinished += new EventHandler(extractor_ExtractionFinished);
                    _extractor.ExtractArchive(_destinationDirectory);
                    _extractor.Dispose();
                });
            });
        }
コード例 #14
0
        public static String XlsxParser(String filename)
        {
            SevenZipExtractor extractor = null;
            String result = null;
            try
            {
                //path to the systems temporary folder
                String tempFolderPath = Path.GetTempPath();
                tempFolderPath += "excelTemp\\";
                //create a directory to dump everything into inside the temp folder
                Directory.CreateDirectory(tempFolderPath);

                //set the path of the 7z.dll (it needs to be in the debug folder)
                SevenZipExtractor.SetLibraryPath("7z.dll");

                extractor = new SevenZipExtractor(filename);

                //Extract the entrie excel file
                extractor.ExtractArchive(tempFolderPath);
                extractor.Dispose();

                //Count how many sheets there are in the workbook
                int count = Directory.GetFiles(tempFolderPath + "xl\\worksheets", "*.xml", SearchOption.TopDirectoryOnly).Length;

                //Create an array of filenames based off how many sheets we counted
                String[] files = new String[count];
                for (int i = 1; i <= count; i++)
                {
                    files[i - 1] = "xl\\worksheets\\sheet" + i + ".xml";
                }

                //send the worksheets to the xml parser
                foreach (String s in files)
                    result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + s);

                result += " " + XMLParser.Parser.ParseXMLtoString(tempFolderPath + "xl\\sharedStrings.xml");

                //delete the temporary directory we created at the beginning
                Directory.Delete(tempFolderPath, true);
            }
            catch (Exception)
            {
                //get rid of the object because it is unmanaged
                extractor.Dispose();
            }

            return result;
        }
コード例 #15
0
        /*
         * Determines if a file is an archive or not. If it's an archive it is extracted to the System temp forlder for processing.
         * If it is not an archive it is passed to ProcessNonArchive.
         *
         * fInfo: Incoming FileInfo object to be processed
         * returns: void
         */
        public static void ProcessFile(Delimon.Win32.IO.FileInfo fInfo)
        {
            string extention = Path.GetExtension(fInfo.FullName);

            if (extention == null)
                extention = "";

            if (IsArchive(extention))
            {
                //extract code
                SevenZipExtractor extractor = null;
                try
                {
                    //path to the systems temporary folder
                    String tempFolderPath = Path.GetTempPath();
                    tempFolderPath += "temp_dir\\";
                    //create a directory to dump everything into inside the temp folder
                    Directory.CreateDirectory(tempFolderPath);

                    //set the path of the 7z.dll (it needs to be in the debug folder)
                    SevenZipExtractor.SetLibraryPath("7z.dll");
                    extractor = new SevenZipExtractor(fInfo.FullName);

                    //Extract the entire file
                    extractor.ExtractArchive(tempFolderPath);
                    extractor.Dispose();

                    bool arcs = true;

                    while (arcs)
                    {
                        arcs = false;
                        // traverse files
                        string[] fileEntries = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories);
                        foreach (string fileName in fileEntries)
                        {
                            //Console.WriteLine("IN ARCHIVE: " + fileName);
                            FileInfo archive = new FileInfo(fileName);
                            if (IsArchive(archive.Extension.ToString()))
                            {
                                arcs = true;
                                extractor = new SevenZipExtractor(fileName);
                                extractor.ExtractArchive(tempFolderPath);
                                File.Delete(fileName);
                            }
                        }
                    }

                    int[][] totals = {new int[5], new int[9]}; //totals[0] count; totals[1] results;
                    string[] fileEntries2 = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories);
                    foreach (string fileName in fileEntries2)
                    {
                        int[][] results = ProcessNonArchive(new Delimon.Win32.IO.FileInfo(fileName), true);
                        if (MainForm.socialSecurityMode)
                        {
                            totals[0][0] += results[0][0];
                            if (results[0][1] > totals[0][1])
                                totals[0][1] = results[0][1];
                        }
                        if (MainForm.creditCardMode)
                        {
                            totals[1][0] += results[1][0];
                            if (results[1][1] > totals[1][1])
                                totals[1][1] = results[1][1];
                        }
                    }
                    //Count how many files in archive
                    //int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length;
                    //delete the temporary directory we created at the beginning
                    Directory.Delete(tempFolderPath, true);
                    if (totals[0][1] > 0)
                    {
                        //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + (ScanData.Code)totals[1]);
                        if (MainForm.socialSecurityMode)
                        {
                            ScanData returnedData = new ScanData(totals[0][0], totals[0][1], totals[0][3], totals[0][4]);
                            Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData);
                            try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); }
                            catch (InvalidOperationException) { }
                        }
                        if (MainForm.creditCardMode)
                        {
                            CreditData ccReturnedData = new CreditData(totals[1][0], totals[1][1], totals[1][3], totals[1][4], totals[1][5], totals[1][6], totals[1][7], totals[1][8]);
                            Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData);
                            try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); }
                            catch (InvalidOperationException) { }
                        }

                    }
                }
                catch (Exception e)
                {
                    //get rid of the object because it is unmanaged
                    extractor.Dispose();
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                int[][] ignore = ProcessNonArchive(fInfo, false);
            }
        }
コード例 #16
0
        /// <summary>
        /// Loads the comic book.
        /// </summary>
        /// <param name="files">The files.</param>
        /// <returns></returns>
        public LoadedFilesData LoadComicBook(string[] files)
        {
            LoadedFiles = 0;
            LoadedFilesData returnValue = new LoadedFilesData();
            returnValue.ComicBook = new ComicBook();
            Comic.ComicFile comicFile = new Comic.ComicFile();

            Array.Sort(files);

            string infoTxt = "";
            MemoryStream ms = new MemoryStream();
            SevenZipExtractor extractor;
            Boolean nextFile = false;

            foreach (String file in files)
            {
                if (!System.IO.File.Exists(file))
                {
                    returnValue.Error = "One or more archives where not found";
                    return returnValue;
                }
            }

            try
            {
                TotalFiles = files.Length;
                foreach (string file in files)
                {
                    //open archive
                    extractor = new SevenZipExtractor(file);
                    string[] fileNames = extractor.ArchiveFileNames.ToArray();
                    Array.Sort(fileNames);

                    //create ComicFiles for every single archive
                    for (int i = 0; i < extractor.FilesCount; i++)
                    {
                        for (int x = 0; x < Enum.GetNames(typeof(SupportedImages)).Length; x++)
                        {
                            //if it is an image add it to array list
                            if (Utils.ValidateImageFileExtension(fileNames[i]))
                            {
                                ms = new MemoryStream();
                                extractor.ExtractFile(fileNames[i], ms);
                                ms.Position = 0;
                                try
                                {
                                    comicFile.Add(ms.ToArray());
                                }
                                catch (Exception)
                                {
                                    ms.Close();
                                    returnValue.Error = "One or more files are corrupted, and where skipped";
                                    return returnValue;
                                }

                                ms.Close();
                                nextFile = true;
                            }

                            //if it is a txt file set it as InfoTxt
                            else if (Utils.ValidateTextFileExtension(fileNames[i]))
                            {
                                ms = new MemoryStream();
                                extractor.ExtractFile(fileNames[i], ms);
                                ms.Position = 0;
                                try
                                {
                                    StreamReader sr = new StreamReader(ms);
                                    infoTxt = sr.ReadToEnd();
                                }
                                catch (Exception)
                                {
                                    ms.Close();
                                    returnValue.Error = "One or more files are corrupted, and where skipped";
                                    return returnValue;
                                }

                                ms.Close();
                                nextFile = true;
                            }

                            if (nextFile)
                            {
                                nextFile = false;
                                x = Enum.GetNames(typeof(SupportedImages)).Length;
                            }
                        }
                    }

                    //unlock files again
                    extractor.Dispose();

                    //Add a ComicFile
                    if (comicFile.Count > 0)
                    {
                        comicFile.Location = file;
                        comicFile.InfoText = infoTxt;
                        returnValue.ComicBook.Add(comicFile);
                        infoTxt = "";
                    }
                    comicFile = new ComicFile();
                    LoadedFiles++;
                }

                //return the ComicBook on success
                return returnValue;
            }
            catch (Exception e)
            {
                //show error and return nothing
                returnValue.Error = e.Message;
                return returnValue;
            }
        }
コード例 #17
0
        private SevenZipExtractor InstanciateZipExctractorWithPassword(string FileName, IEventListener iel)
        {
            SevenZipExtractor Sex = new SevenZipExtractor(FileName);

            bool valid = Sex.Check();

            if (valid == false)
            {
                Sex.Dispose();

                foreach (string psw in _IUnrarUserSettings.EnumerableRarPasswords)
                {                     
                      Sex = new SevenZipExtractor(FileName, psw);
                      if (Sex.Check())
                      {
                          Trace.WriteLine(string.Format("Find Password in list: {0}", psw));
                          return Sex;
                      }
                      else
                        Sex.Dispose();
                }

                string same = Path.GetFileName(FileName);
                CorruptedRarOrMissingPasswordArgs cr = new CorruptedRarOrMissingPasswordArgs(same, _AddRar);

                OnErrorUserExit(iel, cr);

                while ((!valid) && (cr.accept == true))
                {                      
                    Sex = new SevenZipExtractor(FileName, cr.Password);

                    valid = Sex.Check();
                    if (valid == false)
                    {
                        Sex.Dispose();
                        cr = new CorruptedRarOrMissingPasswordArgs(same, cr.SavePassword);

                        OnErrorUserExit(iel, cr);
                    } 
                }

                if (valid == false)
                    return null;
               
            }

            return Sex;
        }
コード例 #18
0
        private void DoCheck()
        {

            string FileName = Explorer.SelectedItems[0].ParsingName;
            SevenZipExtractor extractor = new SevenZipExtractor(FileName);
            if (!extractor.Check())
                MessageBox.Show("Not Pass");
            else
                MessageBox.Show("Pass");

            extractor.Dispose();
        }
コード例 #19
0
        /// <summary>
        /// Loads the comic book.
        /// </summary>
        /// <param name="files">The files.</param>
        /// <returns></returns>
        public LoadedFilesData LoadComicBook(string[] files)
        {
            LoadedFiles = 0;
            LoadedFilesData returnValue = new LoadedFilesData {ComicBook = new ComicBook()};
            var comicFile = new ComicFile();

            Array.Sort(files);

            string infoTxt = "";
            SevenZipExtractor extractor = null;

            if (files.Any(file => !System.IO.File.Exists(file)))
            {
                returnValue.Error = "One or more archives were not found";
                return returnValue;
            }

            try
            {
                foreach (string file in files)
                {
                    //open archive
                    extractor = new SevenZipExtractor(file);
                    string[] fileNames = extractor.ArchiveFileNames.ToArray();

                    // 20140901 Sort using numeric rules
                    NumericalSort(fileNames);

                    //create ComicFiles for every single archive
                    for (int i = 0; i < extractor.FilesCount; i++)
                    {
                        //if it is an image add it to array list
                        if (Utils.ValidateImageFileExtension(fileNames[i]))
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                extractor.ExtractFile(fileNames[i], ms);
                                ms.Position = 0;
                                try
                                {
                                    comicFile.Add(ms.ToArray());
                                }
                                catch (Exception)
                                {
                                    returnValue.Error = "One or more files are corrupted, and were skipped";
                                    return returnValue;
                                }
                            }
                        }

                        //if it is a txt file set it as InfoTxt
                        if (Utils.ValidateTextFileExtension(fileNames[i]))
                        {
                            var ms = new MemoryStream();
                            extractor.ExtractFile(fileNames[i], ms);
                            ms.Position = 0;
                            StreamReader sr = null;
                            try
                            {
                                sr = new StreamReader(ms);
                                infoTxt = sr.ReadToEnd();
                            }
                            catch (Exception)
                            {
                                returnValue.Error = "One or more files are corrupted, and were skipped";
                                return returnValue;
                            }
                            finally
                            {
                                if (sr != null)
                                    sr.Dispose();
                                ms.Dispose();
                            }
                        }
                    }

                    //unlock files again
                    extractor.Dispose();
                    extractor = null;

                    //Add a ComicFile
                    if (comicFile.Count > 0)
                    {
                        comicFile.Location = file;
                        comicFile.InfoText = infoTxt;
                        returnValue.ComicBook.Add(comicFile);
                        infoTxt = "";
                    }
                    comicFile = new ComicFile();
                    LoadedFiles++;
                }

                //return the ComicBook on success
                return returnValue;
            }
            catch (Exception e)
            {
                //show error and return nothing
                returnValue.Error = e.Message;
                return returnValue;
            }
            finally
            {
                if (extractor != null) extractor.Dispose();
            }
        }