当前位置: 首页>>代码示例>>C#>>正文


C# ZipInputStream.Dispose方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipInputStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ZipInputStream.Dispose方法的具体用法?C# ZipInputStream.Dispose怎么用?C# ZipInputStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.ZipInputStream的用法示例。


在下文中一共展示了ZipInputStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetInputStream

    public override Stream GetInputStream(UploadedFile file)
    {
        FileStream fileS = null;
        ZipInputStream zipS = null;

        try
        {
            string path = GetZipPath(file);

            fileS = File.OpenRead(path);
            zipS = new ZipInputStream(fileS);

            zipS.GetNextEntry();

            return zipS;
        }
        catch
        {
            if (fileS != null)
                fileS.Dispose();

            if (zipS != null)
                zipS.Dispose();

            return null;
        }
    }
开发者ID:bmsolutions,项目名称:mvc2inaction,代码行数:27,代码来源:ZipUploadStreamProviderCS.cs

示例2: UnPackFiles

        public static bool UnPackFiles(string path, string filePath)
        {
            try
            {

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = Path.GetDirectoryName(path);
                ZipInputStream zstream = new ZipInputStream(File.OpenRead(filePath));
                ZipEntry entry;
                while ((entry = zstream.GetNextEntry()) != null)
                {
                    if (!string.IsNullOrEmpty(entry.Name))
                    {
                        string upath = path + "\\" + entry.Name;
                        if (entry.IsDirectory)
                        {
                            Directory.CreateDirectory(upath);
                        }
                        else if (entry.CompressedSize > 0)
                        {
                            FileStream fs = File.Create(upath);
                            int size = 2048;
                            byte[] data = new byte[size];
                            while (true)
                            {
                                size = zstream.Read(data, 0, data.Length);
                                if (size > 0)
                                {
                                    fs.Write(data, 0, size);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            fs.Dispose();
                            fs.Close();
                        }
                    }
                }
                zstream.Dispose();
                zstream.Close();
                return true;
            }
            catch
            {
                throw;
            }

        }
开发者ID:LeehanLee,项目名称:L.W,代码行数:53,代码来源:CompressHelper.cs

示例3: OpenFirstZipEntry

 private static Stream OpenFirstZipEntry(Stream rawStream)
 {
     var zipStream = new ZipInputStream(rawStream);
     try
     {
         zipStream = new ZipInputStream(rawStream);
         zipStream.GetNextEntry();
         return zipStream;
     }
     catch
     {
         zipStream.Dispose();
         throw;
     }
 }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:15,代码来源:UpdateBillingData.cs

示例4: Extract

        public static int Extract(string sourceFile, string destinationPath)
        {
            ZipInputStream zinstream = null; // used to read from the zip file
            int numFileUnzipped = 0; // number of files extracted from the zip file

            try
            {
                // create a zip input stream from source zip file
                zinstream = new ZipInputStream(File.OpenRead(sourceFile));

                // we need to extract to a folder so we must create it if needed
                if (Directory.Exists(destinationPath) == false)
                    Directory.CreateDirectory(destinationPath);

                ZipEntry theEntry; // an entry in the zip file which could be a file or directory

                // now, walk through the zip file entries and copy each file/directory
                while ((theEntry = zinstream.GetNextEntry()) != null)
                {
                    string dirname = Path.GetDirectoryName(theEntry.Name); // the file path
                    string fname = Path.GetFileName(theEntry.Name);      // the file name

                    // if a path name exists we should create the directory in the destination folder
                    string target = destinationPath + Path.DirectorySeparatorChar + dirname;
                    if (dirname.Length > 0 && !Directory.Exists(target))
                        Directory.CreateDirectory(target);

                    // now we know the proper path exists in the destination so copy the file there
                    if (fname != String.Empty)
                    {
                        DecompressAndWriteFile(destinationPath + Path.DirectorySeparatorChar + theEntry.Name, zinstream);
                        numFileUnzipped++;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                zinstream.Dispose();
                zinstream.Close();
            }
            return numFileUnzipped;
        }
开发者ID:ModernSteward,项目名称:ModernSteward,代码行数:46,代码来源:ZipManager.cs

示例5: GetReadStream

        public override Stream GetReadStream(UploadedFile file)
        {
            FileStream fileS = null;
            ZipInputStream zipS = null;

            try
            {
                fileS = File.OpenRead(file.ServerLocation);
                zipS = new ZipInputStream(fileS);

                zipS.GetNextEntry();

                return zipS;
            }
            catch
            {
                if (zipS != null)
                    zipS.Dispose();
                if (fileS != null)
                    fileS.Dispose();

                throw;
            } 
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:24,代码来源:ZipUploadStreamProvider.cs

示例6: Deserialize

 /// <summary>
 /// Create a temporary XML file that will be send to SAP application
 /// </summary>
 /// <param name="m"></param>
 /// <param name="filePath"></param>
 internal void Deserialize(string filePath)
 {
     Stream stream = new MemoryStream();
     System.Windows.Forms.Cursor cursor = System.Windows.Forms.Cursor.Current;
     try
     {
         byte[] buffer = new byte[8192];
         if (".xml".Equals(Path.GetExtension(filePath).ToLower()))
         {
             FileStream fReader = File.OpenRead(filePath);
             Deserialize(fReader);
             fReader.Close();
         }
         else
         {
             FileStream fs = File.OpenRead(filePath);
             BinaryFormatter bformatter = new BinaryFormatter();
             string version = (string)bformatter.Deserialize(fs); //"version=7.14"
             if ("version=7.14".CompareTo(version) > 0)
             {
                 fs.Close();
                 string translate = System.Windows.Forms.Application.StartupPath + "\\Translate.exe";
                 if (File.Exists(translate))
                 {
                     string msg = string.Format("El archivo {0} es para una versión anterior de Treu Structure. ¿Desea traducirlo a la versión actual? Se guardará una copia del original en {0}.bak", filePath);
                     System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(msg,
                         "Actualización", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
                     if (result == System.Windows.Forms.DialogResult.Yes)
                     {
                         System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(translate);
                         start.Arguments = "\"" + filePath + "\"";
                         start.UseShellExecute = false;
                         start.RedirectStandardOutput = true;
                         System.Diagnostics.Process p = System.Diagnostics.Process.Start(start);
                         p.WaitForExit(60000);
                         string output = p.StandardOutput.ReadToEnd();
                         if (p.HasExited && p.ExitCode == 0)
                             Deserialize(filePath);
                         else
                         {
                             msg = "Ocurrió un error y no se pudo actualizar el archivo. Favor de contactar a Soporte Técnico o a [email protected]";
                             System.Windows.Forms.MessageBox.Show(msg, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                         }
                     }
                     else
                         throw new Exception("File cannot be opened");
                 }
                 else
                     throw new Exception("File cannot be opened");
             }
             else
             {
                 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                 using (ZipInputStream s = new ZipInputStream(fs))
                 {
                     try
                     {
                         s.Password = "mnloaw7ur4hlu.awdebnc7loy2hq3we89";
                         if (s.GetNextEntry() != null)
                         {
                             StreamUtils.Copy(s, stream, buffer);
                             stream.Position = 0;
                             Deserialize(stream);
                         }
                     }
                     finally
                     {
                         s.Close();
                         s.Dispose();
                     }
                 }
             }
         }
     }
     finally
     {
         stream.Close();
         System.Windows.Forms.Cursor.Current = cursor;
     }
 }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:85,代码来源:Deserializer.cs

示例7: BindGrid


//.........这里部分代码省略.........
                                        var doc = new XPathDocument(new StringReader(manifest));
                                        XPathNavigator rootNav = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                        string packageType = String.Empty;
                                        if (rootNav.Name == "dotnetnuke")
                                        {
                                            packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                        }
                                        else if (rootNav.Name.ToLower() == "languagepack")
                                        {
                                            packageType = "LanguagePack";
                                        }
                                        XPathNavigator nav = null;
                                        switch (packageType.ToLower())
                                        {
                                            case "package":
                                                nav = rootNav.SelectSingleNode("packages/package");
                                                break;
                                            case "module":
                                            case "languagepack":
                                            case "skinobject":
                                                nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                                break;
                                        }

                                        if (nav != null)
                                        {
                                            package.Name = XmlUtils.GetAttributeValue(nav, "name");
                                            package.PackageType = XmlUtils.GetAttributeValue(nav, "type");
                                            package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                            package.Version = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                            package.FriendlyName = XmlUtils.GetNodeValue(nav, "friendlyName");
                                            if (String.IsNullOrEmpty(package.FriendlyName))
                                            {
                                                package.FriendlyName = package.Name;
                                            }
                                            package.Description = XmlUtils.GetNodeValue(nav, "description");
                                            package.FileName = file.Replace(installPath + "\\", "");

                                            XPathNavigator foldernameNav = null;
                                            switch (package.PackageType)
                                            {
                                                case "Module":
                                                case "Auth_System":
                                                    foldernameNav = nav.SelectSingleNode("components/component/files");
                                                    if (foldernameNav != null) package.FolderName = Util.ReadElement(foldernameNav, "basePath").Replace('\\', '/');
                                                    break;
                                                case "Container":
                                                    foldernameNav = nav.SelectSingleNode("components/component/containerFiles");
                                                    if (foldernameNav != null) package.FolderName = Globals.glbContainersPath + Util.ReadElement(foldernameNav, "containerName").Replace('\\', '/');
                                                    break;
                                                case "Skin":
                                                    foldernameNav = nav.SelectSingleNode("components/component/skinFiles");
                                                    if (foldernameNav != null) package.FolderName = Globals.glbSkinsPath + Util.ReadElement(foldernameNav, "skinName").Replace('\\', '/');
                                                    break;
                                                default:
                                                    break;
                                            }

                                            XPathNavigator iconFileNav = nav.SelectSingleNode("iconFile");
                                            if (package.FolderName != string.Empty && iconFileNav != null)
                                            {

                                                if ((iconFileNav.Value != string.Empty) && (package.PackageType == "Module" || package.PackageType == "Auth_System" || package.PackageType == "Container" || package.PackageType == "Skin"))
                                                {
                                                    package.IconFile = package.FolderName + "/" + iconFileNav.Value;
                                                    package.IconFile = (!package.IconFile.StartsWith("~/")) ? "~/" + package.IconFile : package.IconFile;
                                                }
                                            }

                                            packages.Add(package);
                                        }
                                    }

                                    break;
                                }
                            }
                            entry = unzip.GetNextEntry();
                        }
                    }
                    catch (Exception)
                    {
                        invalidPackages.Add(file);
                    }
                    finally
                    {
                        unzip.Close();
                        unzip.Dispose();
                    }
                }
            }

            if (invalidPackages.Count > 0)
            {
                var pkgErrorsMsg = invalidPackages.Aggregate(string.Empty, (current, pkg) => current + (pkg + "<br />"));
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("PackageErrors.Text", LocalResourceFile) + pkgErrorsMsg, ModuleMessage.ModuleMessageType.RedError);
            }

            grid.DataSource = packages;
            grid.DataBind();
        }
开发者ID:SiddharthMishraPersonal,项目名称:dnndev,代码行数:101,代码来源:AvailableExtensions.ascx.cs

示例8: UnzipResources

        public static void UnzipResources(ZipInputStream zipStream, string destPath)
        {
            try
            {
                ZipEntry objZipEntry;
                string LocalFileName;
                string RelativeDir;
                string FileNamePath;
                objZipEntry = zipStream.GetNextEntry();
                while (objZipEntry != null)
                {
                    LocalFileName = objZipEntry.Name;
                    RelativeDir = Path.GetDirectoryName(objZipEntry.Name);
                    if ((RelativeDir != string.Empty) && (!Directory.Exists(Path.Combine(destPath, RelativeDir))))
                    {
                        Directory.CreateDirectory(Path.Combine(destPath, RelativeDir));
                    }
                    if ((!objZipEntry.IsDirectory) && (!String.IsNullOrEmpty(LocalFileName)))
                    {
                        FileNamePath = Path.Combine(destPath, LocalFileName).Replace("/", "\\");
                        try
                        {
                            if (File.Exists(FileNamePath))
                            {
                                File.SetAttributes(FileNamePath, FileAttributes.Normal);
                                File.Delete(FileNamePath);
                            }
                            FileStream objFileStream = null;
                            try
                            {
                                objFileStream = File.Create(FileNamePath);
                                int intSize = 2048;
                                var arrData = new byte[2048];
                                intSize = zipStream.Read(arrData, 0, arrData.Length);
                                while (intSize > 0)
                                {
                                    objFileStream.Write(arrData, 0, intSize);
                                    intSize = zipStream.Read(arrData, 0, arrData.Length);
                                }
                            }
                            finally
                            {
                                if (objFileStream != null)
                                {
                                    objFileStream.Close();
                                    objFileStream.Dispose();
                                }
                            }
                        }
                        catch(Exception ex)
                        {
							DnnLog.Error(ex);
                        }
                    }
                    objZipEntry = zipStream.GetNextEntry();
                }
            }
            finally
            {
                if (zipStream != null)
                {
                    zipStream.Close();
                    zipStream.Dispose();
                }
            }
        }
开发者ID:biganth,项目名称:Curt,代码行数:66,代码来源:FileSystemUtils.cs

示例9: InitializeIcuData

		private static bool InitializeIcuData()
		{
			var icuDir = Icu.DefaultDirectory;
			ZipInputStream zipIn = null;
			try
			{
				try
				{
					var baseDir = FwDirectoryFinder.DataDirectory;
					zipIn = new ZipInputStream(File.OpenRead(Path.Combine(baseDir, string.Format("Icu{0}.zip", Icu.Version))));
				}
				catch (Exception e1)
				{
					MessageBoxUtils.Show("Something is wrong with the file you chose." + Environment.NewLine +
						" The file could not be opened. " + Environment.NewLine + Environment.NewLine +
						"   The error message was: '" + e1.Message);
				}
				if (zipIn == null)
					return false;
				Icu.Cleanup();
				foreach (string dir in Directory.GetDirectories(icuDir))
				{
					string subdir = Path.GetFileName(dir);
					if (subdir.Equals(string.Format("icudt{0}l", Icu.Version), StringComparison.OrdinalIgnoreCase))
						Directory.Delete(dir, true);
				}
				ZipEntry entry;
				while ((entry = zipIn.GetNextEntry()) != null)
				{
					string dirName = Path.GetDirectoryName(entry.Name);
					Match match = Regex.Match(dirName, @"^ICU\d\d[\\/]?(.*)$", RegexOptions.IgnoreCase);
					if (match.Success) // Zip file was built in a way that includes the root directory name.
						dirName = match.Groups[1].Value; // Strip it off. May leave empty string.
					string fileName = Path.GetFileName(entry.Name);
					bool fOk = UnzipFile(zipIn, fileName, entry.Size, Path.Combine(icuDir, dirName));
					if (!fOk)
						return false;
				}
				return true;
			}
			finally
			{
				if (zipIn != null)
					zipIn.Dispose();
			}
		}
开发者ID:sillsdev,项目名称:FieldWorks,代码行数:46,代码来源:PUAInstallerTests.cs

示例10: BindGrid

        private void BindGrid(string type, DataGrid grid, HtmlGenericControl noItemsControl)
        {
            var installPath = Globals.ApplicationMapPath + "\\Install\\" + type;
            var packages = new List<PackageInfo>();
            var invalidPackages = new List<string>();

            foreach (string file in Directory.GetFiles(installPath))
            {
                if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".resources"))
                {
                    Stream inputStream = new FileStream(file, FileMode.Open, FileAccess.Read);
                    var unzip = new ZipInputStream(inputStream);

                    try
                    {
                        ZipEntry entry = unzip.GetNextEntry();

                        while (entry != null)
                        {
                            if (!entry.IsDirectory)
                            {
                                var fileName = entry.Name;
                                string extension = Path.GetExtension(fileName);
                                if (extension.ToLower() == ".dnn" || extension.ToLower() == ".dnn5")
                                {
                                    //Manifest
                                    var manifestReader = new StreamReader(unzip);
                                    var manifest = manifestReader.ReadToEnd();

                                    var package = new PackageInfo();
                                    package.Manifest = manifest;
                                    if (!string.IsNullOrEmpty(manifest))
                                    {
                                        var doc = new XPathDocument(new StringReader(manifest));
                                        XPathNavigator rootNav = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                        string packageType = String.Empty;
                                        if (rootNav.Name == "dotnetnuke")
                                        {
                                            packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                        }
                                        else if (rootNav.Name.ToLower() == "languagepack")
                                        {
                                            packageType = "LanguagePack";
                                        }
                                        XPathNavigator nav = null;
                                        switch (packageType.ToLower())
                                        {
                                            case "package":
                                                nav = rootNav.SelectSingleNode("packages/package");
                                                break;

                                            case "languagepack":

                                                //nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                                break;
                                        }

                                        if (nav != null)
                                        {
                                            package.Name = XmlUtils.GetAttributeValue(nav, "name");
                                            package.PackageType = XmlUtils.GetAttributeValue(nav, "type");
                                            package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                            package.Version = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                            package.FriendlyName = XmlUtils.GetNodeValue(nav, "friendlyName");
                                            if (String.IsNullOrEmpty(package.FriendlyName))
                                            {
                                                package.FriendlyName = package.Name;
                                            }

                                            package.Description = XmlUtils.GetNodeValue(nav, "description");
                                            package.FileName = file.Replace(installPath + "\\", "");

                                            packages.Add(package);
                                        }
                                    }

                                    break;
                                }
                            }
                            entry = unzip.GetNextEntry();
                        }
                    }
                    catch (Exception)
                    {
                        invalidPackages.Add(file);
                    }
                    finally
                    {
                        unzip.Close();
                        unzip.Dispose();
                    }
                }
            }

            if (invalidPackages.Count > 0)
            {
                var pkgErrorsMsg = invalidPackages.Aggregate(string.Empty, (current, pkg) => current + (pkg + "<br />"));
                Skin.AddModuleMessage(this, Localization.GetString("PackageErrors.Text", LocalResourceFile) + pkgErrorsMsg, ModuleMessage.ModuleMessageType.RedError);
            }

//.........这里部分代码省略.........
开发者ID:RichardHowells,项目名称:dnnextensions,代码行数:101,代码来源:AdvancedSettings.ascx.cs

示例11: UnZip

        /// <summary> 
        /// 解压功能(解压压缩文件到指定目录) 
        /// </summary> 
        /// <param name="fileToUnZip">待解压的文件</param> 
        /// <param name="zipedFolder">指定解压目标目录</param> 
        /// <param name="password">密码</param> 
        /// <returns>解压结果</returns> 
        public static bool UnZip(string fileToUnZip, string zipedFolder, string password)
        {
            bool result = true;
            FileStream fs = null;
            ZipInputStream zipStream = null;
            ZipEntry ent = null;
            string fileName;

            if (!File.Exists(fileToUnZip))
                return false;

            if (!Directory.Exists(zipedFolder))
                Directory.CreateDirectory(zipedFolder);

            ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(fileToUnZip);
            //zipfile.
            try
            {
                zipStream = new ZipInputStream(File.OpenRead(fileToUnZip));
                if (!string.IsNullOrEmpty(password)) zipStream.Password = password;
                while ((ent = zipStream.GetNextEntry()) != null)
                {
                    if (!string.IsNullOrEmpty(ent.Name))
                    {
                        fileName = Path.Combine(zipedFolder, ent.Name);
                        fileName = fileName.Replace('/', '\\');//change by Mr.HopeGi

                        if (fileName.EndsWith("\\"))
                        {
                            Directory.CreateDirectory(fileName);
                            continue;
                        }

                        if (ent.Name == "config.json")
                        {
                            //Directory.CreateDirectory(fileName);
                            continue;
                        }

                        if (ent.IsFile)
                        {
                            //Directory.CreateDirectory(fileName);
                            if (!File.Exists(Common.BackupDicPath+ ent.Name))
                            {
                                FileInfo fi = new FileInfo(Common.MasterDicPath + ent.Name);
                                //fi.
                                string backuppath = (Common.BackupDicPath + ent.Name);
                                backuppath = backuppath.Remove(backuppath.LastIndexOf('/'));
                                if (!Directory.Exists(backuppath))
                                {
                                    Directory.CreateDirectory(backuppath);
                                }
                                File.Copy(Common.MasterDicPath + ent.Name, Common.BackupDicPath + ent.Name);
                            }
                            //continue;
                        }

                        fs = File.Create(fileName);
                        var s=zipfile.GetInputStream(ent);
                        //StreamWriter sw = new StreamWriter(fs);
                        //sw.Write()
                        int size = 2048;
                        byte[] data = new byte[size];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                                fs.Write(data, 0, data.Length);
                            else
                                break;
                        }
                    }
                }
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                }
                if (zipStream != null)
                {
                    zipStream.Close();
                    zipStream.Dispose();
                }
                if (ent != null)
                {
                    ent = null;
//.........这里部分代码省略.........
开发者ID:kkkkyue,项目名称:MgsVModsMananer,代码行数:101,代码来源:ZipHelper.cs

示例12: BindGrid

        private void BindGrid(string installPath, DataGrid grid)
        {
            var packages = new List<PackageInfo>();
            var invalidPackages = new List<string>();

            foreach (string file in Directory.GetFiles(installPath))
            {
                if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".resources"))
                {
                    Stream inputStream = new FileStream(file, FileMode.Open, FileAccess.Read);
                    var unzip = new ZipInputStream(inputStream);

                    try
                    {
                        ZipEntry entry = unzip.GetNextEntry();

                        while (entry != null)
                        {
                            if (!entry.IsDirectory)
                            {
                                string fileName = entry.Name;
                                string extension = Path.GetExtension(fileName);
                                if (extension.ToLower() == ".dnn" || extension.ToLower() == ".dnn5")
                                {
                                    //Manifest
                                    var manifestReader = new StreamReader(unzip);
                                    string manifest = manifestReader.ReadToEnd();

                                    var package = new PackageInfo();
                                    package.Manifest = manifest;
                                    if (!string.IsNullOrEmpty(manifest))
                                    {
                                        var doc = new XPathDocument(new StringReader(manifest));
                                        XPathNavigator rootNav = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                        string packageType = String.Empty;
                                        if (rootNav.Name == "dotnetnuke")
                                        {
                                            packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                        }
                                        else if (rootNav.Name.ToLower() == "languagepack")
                                        {
                                            packageType = "LanguagePack";
                                        }
                                        XPathNavigator nav = null;
                                        switch (packageType.ToLower())
                                        {
                                            case "package":
                                                nav = rootNav.SelectSingleNode("packages/package");
                                                break;

                                            case "languagepack":

                                                nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                                break;
                                        }

                                        if (nav != null)
                                        {
                                            package.Name = XmlUtils.GetAttributeValue(nav, "name");
                                            package.PackageType = XmlUtils.GetAttributeValue(nav, "type");
                                            package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                            package.Version = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                            package.FriendlyName = XmlUtils.GetNodeValue(nav, "friendlyName");
                                            if (String.IsNullOrEmpty(package.FriendlyName))
                                            {
                                                package.FriendlyName = package.Name;
                                            }
                                            package.Description = XmlUtils.GetNodeValue(nav, "description");
                                            package.FileName = file.Replace(installPath + "\\", "");

                                            packages.Add(package);
                                        }
                                    }

                                    break;
                                }
                            }
                            entry = unzip.GetNextEntry();
                        }
                    }
                    catch (Exception)
                    {
                        invalidPackages.Add(file);
                    }
                    finally
                    {
                        unzip.Close();
                        unzip.Dispose();
                    }
                }
            }

            //now add language packs from update service
            try
            {
                StreamReader myResponseReader = UpdateService.GetLanguageList();
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(myResponseReader);
                XmlNodeList languages = xmlDoc.SelectNodes("available/language");

//.........这里部分代码省略.........
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:101,代码来源:LanguagePacks.ascx.cs

示例13: GetSettings

        static XmlReaderSettings GetSettings(String release)
        {

            XmlReaderSettings retVal = null;
            if (ValidationSettings.TryGetValue(release, out retVal))
                return retVal;

            string tmpDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(tmpDir);

            Assembly asm = typeof(XMLValidator).Assembly;

            try
            {
                foreach (var item in asm.GetManifestResourceNames())
                {
                    if (!item.EndsWith("zip"))
                        continue;

                    string itemRelease = item.Replace("MARC.Everest.Test.Resources.", "").Replace(".zip", "");
                    if (itemRelease != release)
                        continue;

                    ZipInputStream zis = null;
                    Tracer.Trace(item);

                    try
                    {
                        zis = new ZipInputStream(asm.GetManifestResourceStream(item));
                        retVal = new XmlReaderSettings();

                        // Prepare the unzipping operation
                        ZipEntry entry = null;
                        String basePath = Path.Combine(tmpDir, item);
                        if (!Directory.Exists(basePath))
                            Directory.CreateDirectory(basePath);

                        List<String> files = new List<string>(10);

                        // Unzip the rmim package
                        while ((entry = zis.GetNextEntry()) != null)
                        {
                            if (entry.IsDirectory) // entry is a directory
                            {
                                string dirName = Path.Combine(basePath, entry.Name);
                                if (!Directory.Exists(dirName))
                                    Directory.CreateDirectory(dirName);
                            }
                            else if (entry.IsFile) // entry is file, so extract file.
                            {
                                string fName = Path.Combine(basePath, entry.Name);
                                FileStream fs = null;
                                try
                                {
                                    fs = File.Create(fName);
                                    byte[] buffer = new byte[2048]; // 2k buffer
                                    int szRead = 2048;
                                    while (szRead > 0)
                                    {
                                        szRead = zis.Read(buffer, 0, buffer.Length);
                                        if (szRead > 0)
                                            fs.Write(buffer, 0, szRead);
                                    }
                                }
                                finally
                                {
                                    if (fs != null)
                                        fs.Close();
                                }

                                if (fName.EndsWith(".xsd"))
                                    files.Add(fName);
                            }
                        }

                        foreach (var fName in files)
                            retVal.Schemas.Add("urn:hl7-org:v3", fName);

                        retVal.Schemas.ValidationEventHandler += new ValidationEventHandler(Schemas_ValidationEventHandler);
                        retVal.Schemas.Compile();
                        ValidationSettings.Add(release, retVal);
                        Directory.Delete(basePath, true);
                        return retVal;
                    }
                    catch (Exception e)
                    {
                        //Assert.Fail(e.ToString());
                        return retVal;
                    }
                    finally
                    {
                        if (zis != null)
                        {
                            zis.Close();
                            zis.Dispose();
                        }
                    }

                }
            }
//.........这里部分代码省略.........
开发者ID:oneminot,项目名称:everest,代码行数:101,代码来源:XMLValidator.cs

示例14: UnZip

    /// <summary> 
    /// 解压功能(解压压缩文件到指定目录) 
    /// </summary> 
    /// <param name="fileToUnZip">待解压的文件</param> 
    /// <param name="zipedFolder">指定解压目标目录</param> 
    /// <param name="password">密码</param> 
    /// <returns>解压结果</returns> 
    public static bool UnZip(string fileToUnZip, string zipedFolder, string password)
    {
        bool result = true;
        FileStream fs = null;
        ZipInputStream zipStream = null;
        ZipEntry ent = null;
        string fileName;

        if (!File.Exists(fileToUnZip))
            return false;

        if (!Directory.Exists(zipedFolder))
            Directory.CreateDirectory(zipedFolder);

        try
        {
            zipStream = new ZipInputStream(File.OpenRead(fileToUnZip));
            if (!string.IsNullOrEmpty(password)) zipStream.Password = password;
            while ((ent = zipStream.GetNextEntry()) != null)
            {
                if (!string.IsNullOrEmpty(ent.Name))
                {
                    fileName = Path.Combine(zipedFolder, ent.Name);
//                    fileName = fileName.Replace('/', '\\');//change by Mr.HopeGi 

                    if (fileName.EndsWith("/"))
                    {
                        Directory.CreateDirectory(fileName);
                        continue;
                    }

                    fs = File.Create(fileName);
                    int size = 2048;
                    byte[] data = new byte[size];
                    while (true)
                    {
                        size = zipStream.Read(data, 0, data.Length);
                        if (size > 0)
                            fs.Write(data, 0, size); ///< data.Length
                        else
                            break;
                    }
                }
            }
        }
        catch
        {
            result = false;
        }
        finally
        {
            if (fs != null)
            {
                fs.Close();
                fs.Dispose();
            }
            if (zipStream != null)
            {
                zipStream.Close();
                zipStream.Dispose();
            }
            if (ent != null)
            {
                ent = null;
            }
            GC.Collect();
            GC.Collect(1);
        }
        return result;
    }
开发者ID:sorpcboy,项目名称:moredo,代码行数:77,代码来源:ZipHelper.cs

示例15: ReadApkIcon

        Image ReadApkIcon(string path)
        {
            Image img = null;

            try
            {
                FileStream fs = File.Open(path, FileMode.Open);
                if (fs == null)
                    return img;
                ZipInputStream zipStream = new ZipInputStream(fs);
                ZipEntry entry = zipStream.GetNextEntry();
                while (entry != null)
                {
                    if (!entry.IsFile)
                    {
                        continue;
                    }
                    if (entry.Name.EndsWith("drawable/ic_launcher.png")
                        || entry.Name.EndsWith("drawable/icon.png")
                        || entry.Name.EndsWith("dpi/ic_launcher.png")
                        || entry.Name.EndsWith("dpi/icon.png"))
                    {
                        FileStream writer = File.Create(GlobalSys.tmpIconPath);//解压后的文件

                        int bufferSize = 1024; //缓冲区大小
                        int readCount = 0; //读入缓冲区的实际字节
                        byte[] buffer = new byte[bufferSize];
                        readCount = zipStream.Read(buffer, 0, bufferSize);
                        while (readCount > 0)
                        {
                            writer.Write(buffer, 0, readCount);
                            readCount = zipStream.Read(buffer, 0, bufferSize);
                        }

                        writer.Close();
                        writer.Dispose();
                        Bitmap bmp = new Bitmap(GlobalSys.tmpIconPath);
                        img = new Bitmap(bmp);
                        bmp.Dispose(); bmp = null;
                        break;
                    }
                    entry = zipStream.GetNextEntry();
                }
                fs.Close();
                zipStream.Close();
                zipStream.Dispose();
                zipStream = null;
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
            }

            return img;
        }
开发者ID:kanyun157,项目名称:adbfile,代码行数:55,代码来源:AppPanel.cs


注:本文中的ICSharpCode.SharpZipLib.Zip.ZipInputStream.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。