예제 #1
0
        object extractZip(object zipFileName, string rootDirectory, IStringFilter nf, IStringFilter df)
        {
            object ret = null;
            WindowsNameTransform      extractNameTransform = new WindowsNameTransform(rootDirectory);
            Dictionary <string, bool> dirs = new Dictionary <string, bool>(StringComparer.InvariantCultureIgnoreCase);

            Stream str;

            if (zipFileName is byte[])
            {
                str = new MemoryStream((byte[])zipFileName);
            }
            else
            {
                str = new SeekableStream(Context.OpenStream(zipFileName.ToString()), true);
            }
            using (ZipFile zip = new ZipFile(str))
            {
                if (Password != null)
                {
                    zip.Password = Context.TransformStr(Password, Transform);
                }

                foreach (ZipEntry entry in zip)
                {
                    string targetName = null;
                    if (entry.IsFile)
                    {
                        targetName = extractNameTransform.TransformFile(entry.Name);
                        if (!UsePath)
                        {
                            targetName = Path.Combine(rootDirectory, Path.GetFileName(targetName));
                        }
                    }
                    else if (entry.IsDirectory)
                    {
                        if (UsePath)
                        {
                            targetName = extractNameTransform.TransformDirectory(entry.Name);
                        }
                        else
                        {
                            targetName = rootDirectory;
                        }
                    }
                    if (string.IsNullOrEmpty(targetName))
                    {
                        continue;
                    }
                    if (!Hidden)
                    {
                        if (isDos(entry) && (((FileAttributes)entry.ExternalFileAttributes) & (FileAttributes.Hidden)) != 0)
                        {
                            continue;
                        }
                    }
                    if (string.IsNullOrEmpty(entry.Name))
                    {
                        continue;
                    }
                    var n = new ZipFSEntry(entry, ZipTime);
                    if ((entry.IsFile && df.IsMatch(Path.GetDirectoryName(n.FullName)) && nf.IsMatch(n.Name)) ||
                        (entry.IsDirectory && df.IsMatch(n.FullName)))
                    {
                        object r = extract(zip, rootDirectory, targetName, entry, dirs);
                        if (r != null)
                        {
                            return(r);
                        }
                    }
                }
            }
            return(ret);
        }
예제 #2
0
파일: UnZip.cs 프로젝트: xsharper/xsharper
        object extractZip(   object zipFileName, string rootDirectory,IStringFilter nf, IStringFilter df)
        {
            object ret = null;
            WindowsNameTransform extractNameTransform = new WindowsNameTransform(rootDirectory);
            Dictionary<string, bool> dirs = new Dictionary<string, bool>(StringComparer.InvariantCultureIgnoreCase);

            Stream str;
            if (zipFileName is byte[])
                str = new MemoryStream((byte[])zipFileName);
            else
                str=new SeekableStream(Context.OpenStream(zipFileName.ToString()),true);
            using (ZipFile zip = new ZipFile(str))
            {
                if (Password != null)
                    zip.Password = Context.TransformStr(Password, Transform);

                foreach (ZipEntry entry in zip)
                {

                    string targetName = null;
                    if (entry.IsFile)
                    {
                        targetName = extractNameTransform.TransformFile(entry.Name);
                        if (!UsePath)
                            targetName = Path.Combine(rootDirectory, Path.GetFileName(targetName));
                    }
                    else if (entry.IsDirectory)
                    {
                        if (UsePath)
                            targetName = extractNameTransform.TransformDirectory(entry.Name);
                        else
                            targetName = rootDirectory;
                    }
                    if (string.IsNullOrEmpty(targetName))
                        continue;
                    if (!Hidden)
                    {
                        if (isDos(entry) && (((FileAttributes) entry.ExternalFileAttributes) & (FileAttributes.Hidden)) != 0)
                            continue;
                    }
                    if (string.IsNullOrEmpty(entry.Name))
                        continue;
                    var n = new ZipFSEntry(entry, ZipTime);
                    if ((entry.IsFile && df.IsMatch(Path.GetDirectoryName(n.FullName)) && nf.IsMatch(n.Name)) ||
                        (entry.IsDirectory && df.IsMatch(n.FullName)))
                    {
                        object r = extract(zip, rootDirectory, targetName, entry, dirs);
                        if (r!=null)
                            return r;
                    }
                }
            }
            return ret;
        }