Ejemplo n.º 1
0
        private static void FindPrimaryOutStreamIndex(CFolder folderInfo, out int primaryCoderIndex,
                                                      out int primaryOutStreamIndex)
        {
            bool foundPrimaryOutStream = false;

            primaryCoderIndex     = -1;
            primaryOutStreamIndex = -1;

            for (int outStreamIndex = 0, coderIndex = 0;
                 coderIndex < folderInfo.Coders.Count;
                 coderIndex++)
            {
                for (int coderOutStreamIndex = 0;
                     coderOutStreamIndex < folderInfo.Coders[coderIndex].NumOutStreams;
                     coderOutStreamIndex++, outStreamIndex++)
                {
                    if (folderInfo.FindBindPairForOutStream(outStreamIndex) < 0)
                    {
                        if (foundPrimaryOutStream)
                        {
                            throw new NotSupportedException("Multiple output streams.");
                        }

                        foundPrimaryOutStream = true;
                        primaryCoderIndex     = coderIndex;
                        primaryOutStreamIndex = outStreamIndex;
                    }
                }
            }

            if (!foundPrimaryOutStream)
            {
                throw new NotSupportedException("No output stream.");
            }
        }
Ejemplo n.º 2
0
            internal override IEnumerable <SevenZipEntry> GetEntries(Stream stream)
            {
                List <SevenZipArchiveEntry> source = Enumerable.ToList <SevenZipArchiveEntry>(this.archive.Entries);

                stream.Position = 0L;
                foreach (SevenZipArchiveEntry iteratorVariable1 in Enumerable.Where <SevenZipArchiveEntry>(source, delegate(SevenZipArchiveEntry x) {
                    return(x.IsDirectory);
                }))
                {
                    yield return(iteratorVariable1);
                }
                foreach (IGrouping <CFolder, SevenZipArchiveEntry> iteratorVariable2 in Enumerable.GroupBy <SevenZipArchiveEntry, CFolder>(Enumerable.Where <SevenZipArchiveEntry>(source, delegate(SevenZipArchiveEntry x) {
                    return(!x.IsDirectory);
                }), delegate(SevenZipArchiveEntry x) {
                    return(x.FilePart.Folder);
                }))
                {
                    this.currentFolder = iteratorVariable2.Key;
                    if (iteratorVariable2.Key == null)
                    {
                        this.currentStream = Stream.Null;
                    }
                    else
                    {
                        this.currentStream = this.archive.database.GetFolderStream(stream, this.currentFolder, null);
                    }
                    foreach (SevenZipArchiveEntry iteratorVariable3 in iteratorVariable2)
                    {
                        this.currentItem = iteratorVariable3.FilePart.Header;
                        yield return(iteratorVariable3);
                    }
                }
            }
Ejemplo n.º 3
0
        public static CFolder GetSelectedFolder(CRoot root, TreeNode tn)
        {
            ArrayList index = new ArrayList();

            while (tn != null)
            {
                index.Add(tn.Index);
                tn = tn.Parent;
            }

            index.Reverse();

            CFolder ccf = root.Collection[int.Parse(index[1].ToString())][int.Parse(index[2].ToString())];

            index.RemoveAt(0);
            index.RemoveAt(0);
            index.RemoveAt(0);

            for (int j = 0; j < index.Count; j++)
            {
                ccf = ccf.Folders[(int)index[j]];
            }

            return(ccf);
        }
Ejemplo n.º 4
0
            internal override IEnumerable <SevenZipEntry> GetEntries(Stream stream)
            {
                List <SevenZipArchiveEntry> entries = archive.Entries.ToList();

                stream.Position = 0;
                foreach (var dir in entries.Where(x => x.IsDirectory))
                {
                    yield return(dir);
                }
                foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder))
                {
                    currentFolder = group.Key;
                    if (group.Key == null)
                    {
                        currentStream = Stream.Null;
                    }
                    else
                    {
                        currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
                    }
                    foreach (var entry in group)
                    {
                        currentItem = entry.FilePart.Header;
                        yield return(entry);
                    }
                }
            }
Ejemplo n.º 5
0
        private static void FindPrimaryOutStreamIndex(CFolder folderInfo, out int primaryCoderIndex, out int primaryOutStreamIndex)
        {
            bool flag = false;

            primaryCoderIndex     = -1;
            primaryOutStreamIndex = -1;
            int outStreamIndex = 0;

            for (int i = 0; i < folderInfo.Coders.Count; i++)
            {
                int num3 = 0;
                while (num3 < folderInfo.Coders[i].NumOutStreams)
                {
                    if (folderInfo.FindBindPairForOutStream(outStreamIndex) < 0)
                    {
                        if (flag)
                        {
                            throw new NotSupportedException("Multiple output streams.");
                        }
                        flag = true;
                        primaryCoderIndex     = i;
                        primaryOutStreamIndex = outStreamIndex;
                    }
                    num3++;
                    outStreamIndex++;
                }
            }
            if (!flag)
            {
                throw new NotSupportedException("No output stream.");
            }
        }
Ejemplo n.º 6
0
        public static CFolder GetFolder(string FileName)
        {
            if (FileName.Substring(FileName.Length - 4, 4).ToLower() != ".rar")
            {
                throw new Exception("File type did not match this Plugins!");
            }

            char[]   sp         = { '\\' };
            string[] TempStrs   = FileName.Split(sp);
            CFolder  TempFolder = new CFolder();

            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + " (x86)"))
            {
                Unrar64 rar = new Unrar64(FileName);
                rar.Open(Unrar64.OpenMode.List);

                TempFolder.Name = TempStrs[TempStrs.Length - 1];
                Array.Clear(TempStrs, 0, TempStrs.Length);

                while (rar.ReadHeader())
                {
                    //if (!rar.CurrentFile.IsDirectory)
                    //{
                    TempStrs = rar.CurrentFile.FileName.Split(sp);
                    FillFolder(FileName, TempStrs, 0, TempFolder, rar.CurrentFile);
                    //}
                    rar.Skip();
                }

                rar.Close();
                rar = null;
            }
            else
            {
                Unrar rar = new Unrar(FileName);
                rar.Open(Unrar.OpenMode.List);

                TempFolder.Name = TempStrs[TempStrs.Length - 1];
                Array.Clear(TempStrs, 0, TempStrs.Length);

                while (rar.ReadHeader())
                {
                    //if (!rar.CurrentFile.IsDirectory)
                    //{
                    TempStrs = rar.CurrentFile.FileName.Split(sp);
                    FillFolder(FileName, TempStrs, 0, TempFolder, rar.CurrentFile);
                    //}
                    rar.Skip();
                }

                rar.Close();
                rar = null;
            }

            TempFolder.SpecialItem = true;
            TempFolder.CreatedTime = (new FileInfo(FileName)).CreationTimeUtc;

            return(TempFolder);
        }
Ejemplo n.º 7
0
        public static void FillTreeView(CFolder cf, TreeNodeCollection tnc)
        {
            foreach (CFolder c1 in cf.Folders)
            {
                FillTreeView(c1, tnc.Add(c1.Name, c1.Name, c1.IconIndex, c1.IconIndex).Nodes);
            }

            foreach (CFile c2 in cf.Files)
            {
                tnc.Add(c2.Name, c2.Name, c2.IconIndex, c2.IconIndex);
            }
        }
Ejemplo n.º 8
0
 private static int FindCoderIndexForOutStreamIndex(CFolder folderInfo, int outStreamIndex)
 {
     for (int i = 0; i < folderInfo.Coders.Count; i++)
     {
         CCoderInfo info = folderInfo.Coders[i];
         outStreamIndex -= info.NumOutStreams;
         if (outStreamIndex < 0)
         {
             return(i);
         }
     }
     throw new InvalidOperationException("Could not link output stream to coder.");
 }
Ejemplo n.º 9
0
        private static int FindCoderIndexForOutStreamIndex(CFolder folderInfo, int outStreamIndex)
        {
            for (int coderIndex = 0; coderIndex < folderInfo.Coders.Count; coderIndex++)
            {
                var coderInfo = folderInfo.Coders[coderIndex];
                outStreamIndex -= coderInfo.NumOutStreams;
                if (outStreamIndex < 0)
                {
                    return(coderIndex);
                }
            }

            throw new InvalidOperationException("Could not link output stream to coder.");
        }
Ejemplo n.º 10
0
        private static void FillFolder(string[] TempStr, CFolder zipfolder, ZipEntry ZE, bool isfile)
        {
            string[] temp = new string[1];
            Array.Copy(TempStr, 0, temp, 0, 1);
            int i = 0;

            while (temp.Length != TempStr.Length)
            {
                if (!zipfolder.Folders.Contains(temp[i]))
                {
                    zipfolder             = zipfolder.Folders[zipfolder.Folders.Add(temp[i])];
                    zipfolder.CreatedTime = ZE.DateTime;
                }
                else
                {
                    zipfolder = zipfolder.Folders[temp[i]];
                }

                i++;
                Array.Resize(ref temp, temp.Length + 1);
                Array.Copy(TempStr, i, temp, i, 1);
            }

            string str = temp[temp.Length - 1];

            if (isfile)
            {
                zipfolder.Files.Add(str);
                zipfolder.Files[zipfolder.Files.Count - 1].Size             = ZE.Size;
                zipfolder.Files[zipfolder.Files.Count - 1].LastModifiedTime = ZE.DateTime;
                zipfolder.Files[zipfolder.Files.Count - 1].Extension        = "." +
                                                                              (str.IndexOf('.') != -1 ? str.Split('.')[str.Split('.').Length - 1] : str);
            }
            else
            {
                if (!zipfolder.Folders.Contains(str))
                {
                    zipfolder.Folders[zipfolder.Folders.Add(str)].CreatedTime = ZE.DateTime;
                }
                else
                {
                    zipfolder.Folders[str].CreatedTime = ZE.DateTime;
                }
            }
        }
Ejemplo n.º 11
0
        public static CFolder FolderInfo2CFolder(DirectoryInfo di)
        {
            CFolder cf = new CFolder(di);

            foreach (FileInfo fi in di.GetFiles())
            {
                CFile cfile = new CFile(fi);
                cf.Size += cfile.Size;
                cf.Files.Add(cfile);
            }

            foreach (DirectoryInfo d in di.GetDirectories())
            {
                cf.Size += cf.Folders.Add2(FolderInfo2CFolder(d));
            }

            return(cf);
        }
Ejemplo n.º 12
0
        public static long GetFolderSize(CFolder folder)
        {
            long size = 0;

            for (int i = 0; i < folder.Folders.Count; i++)
            {
                if (folder.Folders[i].SpecialItem)
                {
                    continue;
                }
                else
                {
                    size += folder.Folders[i].Size;
                }
            }
            for (int i = 0; i < folder.Files.Count; i++)
            {
                size += folder.Files[i].Size;
            }

            return(size);
        }
Ejemplo n.º 13
0
        public static CFolder GetFolder(string FileName)
        {
            if (FileName.Substring(FileName.Length - 4, 4).ToLower() != ".zip")
            {
                throw new Exception("File type did not match this Plugins!");
            }

            CFolder zipfolder = new CFolder();
            ZipFile zip       = new ZipFile(FileName);
            long    size      = 0;

            zipfolder.Name        = FileName.Substring(FileName.LastIndexOf(@"\") + 1);
            zipfolder.CreatedTime = new FileInfo(FileName).CreationTimeUtc;

            try
            {
                for (int i = 0; i < zip.Count; i++)
                {
                    if (zip[i].IsFile)
                    {
                        size += zip[i].Size;
                        FillFolder(zip[i].Name.Split('/'), zipfolder, zip[i], true);
                    }
                    else
                    {
                        string[] names = zip[i].Name.Split('/');
                        Array.Resize(ref names, names.Length - 1);
                        FillFolder(names, zipfolder, zip[i], false);
                    }
                }
            }
            catch {}

            zipfolder.Size        = size;
            zipfolder.SpecialItem = true;

            return(zipfolder);
        }
Ejemplo n.º 14
0
        private static void FillFolder(string Path, string[] Names, int index, CFolder rarfolder, RARFileInfo RE)
        {
            if (!(rarfolder.Folders.Contains(Names[index])))
            {
                if ((Names.Length <= index + 1) && (!RE.IsDirectory))
                {
                    rarfolder.Files.Add(Names[index]);
                    rarfolder.Files[rarfolder.Files.Count - 1].Size             = RE.UnpackedSize;
                    rarfolder.Files[rarfolder.Files.Count - 1].LastModifiedTime = RE.FileTime;
                }
                else
                {
                    rarfolder.Folders[rarfolder.Folders.Add(Names[index])].CreatedTime = RE.FileTime;
                }
            }

            index++;
            if (Names.Length <= index)
            {
                return;
            }
            FillFolder(Path, Names, index, rarfolder.Folders[Names[index - 1]], RE);
        }
Ejemplo n.º 15
0
        public static object GetSelectedItem(CRoot root, ListViewItem lvi, bool isfile)
        {
            string[]  temp  = lvi.Name.Split('|');
            ArrayList index = new ArrayList();

            for (int i = 1; i < temp.Length; i++)
            {
                index.Add(int.Parse(temp[i]));
            }

            int index1 = (int)index[1];
            int index2 = (int)index[2];

            CFolder ccf = root.Collection[index1][index2];

            index.RemoveAt(0);
            index.RemoveAt(0);
            index.RemoveAt(0);

            for (int j = 0; j < index.Count; j++)
            {
                if (j == index.Count - 1)
                {
                    if (isfile)
                    {
                        return(ccf.Files[(int)index[j]]);
                    }
                    else
                    {
                        return(ccf.Folders[(int)index[j]]);
                    }
                }
                ccf = ccf.Folders[(int)index[j]];
            }

            return(ccf);
        }
Ejemplo n.º 16
0
        internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo,
                                                   IPasswordProvider pass)
        {
            if (!folderInfo.CheckStructure())
            {
                throw new NotSupportedException("Unsupported stream binding structure.");
            }

            Stream[] inStreams = new Stream[folderInfo.PackStreams.Count];
            for (int j = 0; j < folderInfo.PackStreams.Count; j++)
            {
                inStreams[j] = new ReadOnlySubStream(inStream, startPos, packSizes[j]);
                startPos    += packSizes[j];
            }

            Stream[] outStreams = new Stream[folderInfo.UnpackSizes.Count];

            int primaryCoderIndex, primaryOutStreamIndex;

            FindPrimaryOutStreamIndex(folderInfo, out primaryCoderIndex, out primaryOutStreamIndex);
            return(CreateDecoderStream(inStreams, packSizes, outStreams, folderInfo, primaryCoderIndex, pass));
        }
Ejemplo n.º 17
0
        private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams,
                                                  CFolder folderInfo, int coderIndex, IPasswordProvider pass)
        {
            var coderInfo = folderInfo.Coders[coderIndex];

            if (coderInfo.NumOutStreams != 1)
            {
                throw new NotSupportedException("Multiple output streams are not supported.");
            }

            int inStreamId = 0;

            for (int i = 0; i < coderIndex; i++)
            {
                inStreamId += folderInfo.Coders[i].NumInStreams;
            }

            int outStreamId = 0;

            for (int i = 0; i < coderIndex; i++)
            {
                outStreamId += folderInfo.Coders[i].NumOutStreams;
            }

            Stream[] inStreams = new Stream[coderInfo.NumInStreams];

            for (int i = 0; i < inStreams.Length; i++, inStreamId++)
            {
                int bindPairIndex = folderInfo.FindBindPairForInStream(inStreamId);
                if (bindPairIndex >= 0)
                {
                    int pairedOutIndex = folderInfo.BindPairs[bindPairIndex].OutIndex;

                    if (outStreams[pairedOutIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }

                    int otherCoderIndex = FindCoderIndexForOutStreamIndex(folderInfo, pairedOutIndex);
                    inStreams[i] = CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, otherCoderIndex,
                                                       pass);
                    //inStreamSizes[i] = folderInfo.UnpackSizes[pairedOutIndex];

                    if (outStreams[pairedOutIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }

                    outStreams[pairedOutIndex] = inStreams[i];
                }
                else
                {
                    int index = folderInfo.FindPackStreamArrayIndex(inStreamId);
                    if (index < 0)
                    {
                        throw new NotSupportedException("Could not find input stream binding.");
                    }

                    inStreams[i] = packStreams[index];
                    //inStreamSizes[i] = packSizes[index];
                }
            }

            long unpackSize = folderInfo.UnpackSizes[outStreamId];

            return(DecoderRegistry.CreateDecoderStream(coderInfo.MethodId, inStreams, coderInfo.Props, pass, unpackSize));
        }
Ejemplo n.º 18
0
        internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo,
                                                   IPasswordProvider pass)
        {
            if (!folderInfo.CheckStructure())
            {
                throw new NotSupportedException("Unsupported stream binding structure.");
            }

            // We have multiple views into the same stream which will be used by several threads - need to sync those.
            object sync = new object();

            Stream[] inStreams = new Stream[folderInfo.PackStreams.Count];
            for (int j = 0; j < folderInfo.PackStreams.Count; j++)
            {
                inStreams[j] = new SyncStreamView(sync, inStream, startPos, packSizes[j]);
                startPos    += packSizes[j];
            }

            Stream[] outStreams = new Stream[folderInfo.UnpackSizes.Count];

            int primaryCoderIndex, primaryOutStreamIndex;

            FindPrimaryOutStreamIndex(folderInfo, out primaryCoderIndex, out primaryOutStreamIndex);
            return(CreateDecoderStream(inStreams, packSizes, outStreams, folderInfo, primaryCoderIndex, pass));
        }
Ejemplo n.º 19
0
 public FolderAddedEventArgs(CFolder folder)
 {
     Folder = folder;
 }
Ejemplo n.º 20
0
        private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams, CFolder folderInfo, int coderIndex, IPasswordProvider pass)
        {
            int        num2;
            CCoderInfo info = folderInfo.Coders[coderIndex];

            if (info.NumOutStreams != 1)
            {
                throw new NotSupportedException("Multiple output streams are not supported.");
            }
            int inStreamIndex = 0;

            for (num2 = 0; num2 < coderIndex; num2++)
            {
                inStreamIndex += folderInfo.Coders[num2].NumInStreams;
            }
            int num3 = 0;

            for (num2 = 0; num2 < coderIndex; num2++)
            {
                num3 += folderInfo.Coders[num2].NumOutStreams;
            }
            Stream[] inStreams = new Stream[info.NumInStreams];
            num2 = 0;
            while (num2 < inStreams.Length)
            {
                int num4 = folderInfo.FindBindPairForInStream(inStreamIndex);
                if (num4 >= 0)
                {
                    int outIndex = folderInfo.BindPairs[num4].OutIndex;
                    if (outStreams[outIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }
                    int num6 = FindCoderIndexForOutStreamIndex(folderInfo, outIndex);
                    inStreams[num2] = CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, num6, pass);
                    if (outStreams[outIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }
                    outStreams[outIndex] = inStreams[num2];
                }
                else
                {
                    int index = folderInfo.FindPackStreamArrayIndex(inStreamIndex);
                    if (index < 0)
                    {
                        throw new NotSupportedException("Could not find input stream binding.");
                    }
                    inStreams[num2] = packStreams[index];
                }
                num2++;
                inStreamIndex++;
            }
            long limit = folderInfo.UnpackSizes[num3];

            return(DecoderRegistry.CreateDecoderStream(info.MethodId, inStreams, info.Props, pass, limit));
        }
Ejemplo n.º 21
0
        public static void FolderInfo2CFolder(CFileCollection files, CFolderCollection folders, DirectoryInfo di, CommVar.Plugins[] Plugins, bool getpath)
        {
            foreach (DirectoryInfo d in di.GetDirectories())
            {
                try
                {
                    if (!IsNormalFileSystem(d.Attributes))
                    {
                        continue;
                    }
                    CFolder cf = new CFolder();
                    cf.Name        = d.Name;
                    cf.CreatedTime = d.CreationTimeUtc;
                    FolderInfo2CFolder(cf.Files, cf.Folders, d, Plugins, getpath);
                    folders.Add(cf);
                    OnFolderAdded(null, new FolderAddedEventArgs(cf));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("A___" + ex.Message);
                }
            }

            foreach (FileInfo fi in di.GetFiles())
            {
                if (!IsNormalFileSystem(fi.Attributes))
                {
                    continue;
                }

                try
                {
                    CFile cfile = new CFile(fi);
                    if (getpath)
                    {
                        cfile.Path = fi.FullName;
                    }
                    files.Add(cfile);
                    OnFileAdded(null, new FileAddedEventArgs(cfile));

                    bool setplugins = false;
                    for (int i = 0; i < Plugins.Length; i++)
                    {
                        try
                        {
                            switch (Plugins[i].pt)
                            {
                            case CommVar.PluginsType.Extract:
                            {
                                CFolder temp =
                                    (CFolder)Plugins[i].mi.Invoke(null, new object[] { fi.FullName });
                                temp.AssociateIconExtension = cfile.Extension;
                                temp.Size         = cfile.Size;
                                temp.FolderType   = CommVar.FolderType.ExtractFolder;
                                temp.SpecialItem  = true;
                                cfile.SpecialItem = true;
                                folders.Add(temp);
                                setplugins = true;
                            }
                            break;
                            }

                            if (setplugins)
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("B___" + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("C___" + ex.Message);
                }
            }
        }
Ejemplo n.º 22
0
        internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo, IPasswordProvider pass)
        {
            int num2;
            int num3;

            if (!folderInfo.CheckStructure())
            {
                throw new NotSupportedException("Unsupported stream binding structure.");
            }
            Stream[] packStreams = new Stream[folderInfo.PackStreams.Count];
            for (int i = 0; i < folderInfo.PackStreams.Count; i++)
            {
                packStreams[i] = new ReadOnlySubStream(inStream, new long?(startPos), packSizes[i]);
                startPos      += packSizes[i];
            }
            Stream[] outStreams = new Stream[folderInfo.UnpackSizes.Count];
            FindPrimaryOutStreamIndex(folderInfo, out num2, out num3);
            return(CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, num2, pass));
        }