Example #1
0
 private static extern int PropVariantClear(ref PropVariant pvar);
Example #2
0
 private string ExtractFile(string fileName)
 {
     if (isMono)
         return fileName;
     SystemState old = state;
     state = SystemState.SystemPause;
     string ext = Path.GetExtension(fileName).ToLower();
     if (ext == ".7z" || ext == ".zip" || ext == ".rar")
     {
         string sevenZ = this.config["7z"];
         if (IntPtr.Size == 8)
             sevenZ = this.config["7z64"]; //replace this with installer logic maybe?
         SevenZipFormat Format = new SevenZipFormat(sevenZ);
         KnownSevenZipFormat fileType;
         switch (ext)
         {
             default:
             case ".7z":
                 fileType = KnownSevenZipFormat.SevenZip;
                 break;
             case ".zip":
                 fileType = KnownSevenZipFormat.Zip;
                 break;
             case ".rar":
                 fileType = KnownSevenZipFormat.Rar;
                 break;
         }
         IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(fileType));
         try
         {
             InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(fileName));
             ulong checkPos = 32 * 1024;
             Archive.Open(ArchiveStream, ref checkPos, null);
             uint count = Archive.GetNumberOfItems();
             string[] archiveContent = new string[count];
             for (uint i = 0; i < count; i++)
             {
                 PropVariant name = new PropVariant();
                 Archive.GetProperty(i, ItemPropId.kpidPath, ref name);
                 archiveContent[i] = name.GetObject().ToString();
             }
             if (count == 1)
             {
                 fileName = Path.Combine(this.config["tmpDir"], Path.GetFileNameWithoutExtension(archiveContent[0]) + ".tmp" + Path.GetExtension(archiveContent[0]));
                 Archive.Extract(new uint[] { 0 }, 1, 0, new ArchiveCallback(0, fileName));
             }
             else
             {
                 ArchiveViewer viewer = new ArchiveViewer(archiveContent);
                 if (viewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     fileName = Path.Combine(this.config["tmpDir"], Path.GetFileNameWithoutExtension(archiveContent[viewer.selectedFile]) + ".tmp" + Path.GetExtension(archiveContent[0]));
                     Archive.Extract(new uint[] { (uint)viewer.selectedFile }, 1, 0, new ArchiveCallback((uint)viewer.selectedFile, fileName));
                 }
                 else
                 {
                     fileName = "";
                 }
             }
             ArchiveStream.Dispose();
         }
         finally
         {
             Archive.Close();
             Marshal.ReleaseComObject(Archive);
         }
         Format.Dispose();
     }
     state = old;
     return fileName;
 }