Advertisement
cafreak

unrar with sharpCompress

Aug 18th, 2014
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. if (!SharpCompress.Archive.Rar.RarArchive.IsRarFile(textBox1.Text))
  2.             {
  3.                 MessageBox.Show("File is not a rar file");
  4.             }
  5.             else
  6.             {
  7.                 try
  8.                 {
  9.  
  10.                     String s = textBox1.Text;
  11.                     String[] fileName = Regex.Split(s, "\\\\");
  12.  
  13.                     foreach (String chars in fileName)
  14.                     {
  15.                        
  16.                         if(chars.ToLower().Contains(".rar")){
  17.                             s = chars.ToLower().Replace(".rar",null);
  18.                             break;
  19.                         }
  20.                     }
  21.  
  22.                     using (Stream stream = File.OpenRead(textBox1.Text))
  23.                     {
  24.                         var reader = ReaderFactory.Open(stream);
  25.                         while (reader.MoveToNextEntry())
  26.                         {
  27.                             String sReplaced = reader.Entry.FilePath.Replace(s, null).Replace("\\\\", null);
  28.                             Boolean bEncrypt = reader.Entry.IsEncrypted;
  29.                             String sItem = sReplaced + " Encrypted: " + bEncrypt;
  30.                            
  31.                             if (sReplaced != String.Empty)
  32.                             {
  33.                                 listBox1.Items.Add(sItem);
  34.                             }
  35.                            
  36.  
  37.                             for (int i = 0; i <= (listBox1.Items.Count - 1); i++)
  38.                             {
  39.                                 if (listBox1.Items[i].ToString() == String.Empty)
  40.                                 {
  41.                                     listBox1.Items.RemoveAt(i);
  42.                                 }
  43.                             }
  44.                                 reader.WriteEntryToDirectory(textBox2.Text, ExtractOptions.Overwrite);
  45.                         }
  46.                     }
  47.                 }catch (Exception EX){
  48.                     MessageBox.Show(EX.Message);
  49.                 }
  50.  
  51.                
  52.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement