private string __ParseZip(string fPath) { stCore.stZipStorer zip = null; try { if (!File.Exists(fPath)) { this.Fire_ProcessLog( new RevErrorEventArgs( new Exception(Properties.Resources.txtZipNotFound), MethodBase.GetCurrentMethod().Name ) ); return(String.Empty); } zip = stZipStorer.Open(fPath, System.IO.FileAccess.Read); foreach (stZipStorer.ZipFileEntry entry in (List <stZipStorer.ZipFileEntry>)zip.ReadCentralDir()) { #if SHOW_PROGRESSBAR this._progressBar(++_pbCounter); #endif if (Path.GetFileName(entry.FilenameInZip).Equals(_watchList[1])) { string opath = Path.Combine( _rootPath, _watchList[1] ); if (!Directory.Exists(Path.GetDirectoryName(opath))) { Directory.CreateDirectory(Path.GetDirectoryName(opath)); } __delTmpFileName(opath); zip.ExtractFile(entry, opath); return(opath); } } Exception e = new Exception(Properties.Resources.txtZipEntryNotFound); this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(String.Empty); } catch (Exception e) { this.Fire_ProcessLog(new RevErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(String.Empty); } finally { if (zip != null) { zip.Close(); zip.Dispose(); } } }
public static bool unzipMaxmindData(string path, string zipName, string archName) { stCore.stZipStorer zip = null; try { string pathSource = Path.Combine( path, zipName ); if (!File.Exists(pathSource)) { throw new FileNotFoundException( string.Format( Properties.Resources.GeoMaxMindFileNotFound, zipName ) ); } zip = stCore.stZipStorer.Open(pathSource, System.IO.FileAccess.Read); foreach (stCore.stZipStorer.ZipFileEntry entry in (List <stCore.stZipStorer.ZipFileEntry>)zip.ReadCentralDir()) { if (Path.GetFileName(entry.FilenameInZip).Equals(archName)) { pathSource = Path.Combine( path, archName ); zip.ExtractFile(entry, pathSource); return(true); } } return(false); } catch (Exception e) { throw new ArgumentException(e.Message); } finally { if (zip != null) { zip.Close(); zip.Dispose(); } } }