示例#1
0
 void Decompress_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter = "All Files (*.*)|*.*";
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
         openFileDialog1.FileName.Length > 0)
     {
         Type comp = (Type)((MenuItem)sender).Tag;
         CompressionFormatBase c = (CompressionFormatBase)comp.InvokeMember("", BindingFlags.CreateInstance, null, null, new object[0]);
         byte[] result           = null;
         try
         {
             result = c.Decompress(File.ReadAllBytes(openFileDialog1.FileName));
         }
         catch (Exception /*ee*/)
         {
             MessageBox.Show("An error occured while trying to decompress! The file might not be in this compression type or not compressed at all!");
             return;
         }
         saveFileDialog1.Filter   = "All Files (*.*)|*.*";
         saveFileDialog1.FileName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + "_dec" + Path.GetExtension(openFileDialog1.FileName);
         if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
             saveFileDialog1.FileName.Length > 0)
         {
             File.Create(saveFileDialog1.FileName).Close();
             File.WriteAllBytes(saveFileDialog1.FileName, result);
         }
     }
 }
        protected void PrepareDataForUse(byte[] FileData)
        {
            List <Type> Compressions = new List <Type>();

            foreach (dynamic p in EveryFileExplorerUtil.Program.PluginManager.Plugins)
            {
                foreach (Type t in p.CompressionTypes)
                {
                    dynamic c = new LibEveryFileExplorer.StaticDynamic(t);
                    if (c.Identifier.IsFormat(FileData))
                    {
                        Compressions.Add(t);
                    }
                }
            }
            IsCompressed      = false;
            CompressionFormat = null;
            if (Compressions.Count == 1)
            {
                CompressionFormatBase c = (CompressionFormatBase)Compressions[0].InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]);
                try
                {
                    byte[] Result = c.Decompress(FileData);
                    IsCompressed      = true;
                    CompressionFormat = c;
                    FileData          = Result;
                }
                catch { }
            }
            else if (Compressions.Count > 1)
            {
                foreach (Type t in Compressions)
                {
                    CompressionFormatBase c = (CompressionFormatBase)t.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]);
                    try
                    {
                        byte[] Result = c.Decompress(FileData);
                        IsCompressed      = true;
                        CompressionFormat = c;
                        FileData          = Result;
                        break;
                    }
                    catch { }
                }
            }
            Data = FileData;
        }