Inheritance: java.lang.Object
Ejemplo n.º 1
2
        private Stream ReadDataFile( FileInfo dataFile )
        {
            Stream stream;
            if( dataFile.Extension == _CsvExt )
            {
                stream = dataFile.OpenRead();
            }
            else if( dataFile.Extension == _ZipExt )
            {
                if( dataFile.Length == 0 )
                    throw new Exception( "DataFile size is 0 bytes." );

                //раззиповать файл
                string csvFileName = Path.ChangeExtension( dataFile.FullName, ".csv" );
                ZipFile zf = new ZipFile( dataFile.FullName );
                try
                {
                    string csvEntry = dataFile.GetNameOnly() + _CsvExt;
                    ZipEntry ze = zf.getEntry( csvEntry );
                    if( ze == null ) throw new Exception(
                         csvEntry + " entry not found in " + dataFile.Name );
                    var zipStream = zf.getInputStream( ze );
                    try
                    {
                        using( FileStream stm = new FileStream( csvFileName, FileMode.Create, FileAccess.Write ) )
                        {
                            int len;
                            byte[] buf = new byte[ _BufferSize ];
                            sbyte[] sbuf = new sbyte[ _BufferSize ];
                            while( ( len = zipStream.read( sbuf ) ) > 0 )
                            {
                                Buffer.BlockCopy( sbuf, 0, buf, 0, len );
                                stm.Write( buf, 0, len );
                            }
                        }
                    }
                    finally
                    {
                        zipStream.close();
                    }
                }
                finally
                {
                    zf.close();
                }

                //прочитать раззипованный файл
                stream = new FileStream( csvFileName, FileMode.Open, FileAccess.Read );
            }
            else
            {
                throw new Exception( "Unknown data file extension: " + dataFile.Extension );
            }

            return stream;
        }
Ejemplo n.º 2
1
        public void UnZip(string zipFileLocation, string destinationRootFolder, string zipRootToRemove)
        {
            try
            {
                var zipFile = new ZipFile(zipFileLocation);
                var zipFileEntries = zipFile.entries();
                
                while (zipFileEntries.hasMoreElements())
                {
                    var zipEntry = (ZipEntry)zipFileEntries.nextElement();

                    var name = zipEntry.getName().Replace(zipRootToRemove, "").Replace("/", "\\").TrimStart('/').TrimStart('\\');
                    var p = this.fileSystem.Path.Combine(destinationRootFolder, name);

                    if (zipEntry.isDirectory())
                    {
                        if (!this.fileSystem.Directory.Exists(p))
                        {
                            this.fileSystem.Directory.CreateDirectory(p);
                        };
                    }
                    else
                    {
                        using (var bis = new BufferedInputStream(zipFile.getInputStream(zipEntry)))
                        {
                            var buffer = new byte[2048];
                            var count = buffer.GetLength(0);
                            using (var fos = new FileOutputStream(p))
                            {
                                using (var bos = new BufferedOutputStream(fos, count))
                                {
                                    int size;
                                    while ((size = bis.read(buffer, 0, count)) != -1)
                                    {
                                        bos.write(buffer, 0, size);
                                    }

                                    bos.flush();
                                    bos.close();
                                }
                            }

                            bis.close();
                        }
                    }
                }

                zipFile.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            catch (Exception e)
            {
                var t = e.ToString();
            }
        }
Ejemplo n.º 3
0
    public static void expandIkvmClasses(object _zipFile, object _entries)
    {
#if !FIRST_PASS
        java.util.zip.ZipFile   zipFile = (java.util.zip.ZipFile)_zipFile;
        java.util.LinkedHashMap entries = (java.util.LinkedHashMap)_entries;

        try
        {
            string path = zipFile.getName();
            java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)entries.get(JVM.JarClassList);
            if (entry != null && VirtualFileSystem.IsVirtualFS(path))
            {
                using (VirtualFileSystem.ZipEntryStream stream = new VirtualFileSystem.ZipEntryStream(zipFile, entry))
                {
                    entries.remove(entry.name);
                    BinaryReader br    = new BinaryReader(stream);
                    int          count = br.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        java.util.zip.ClassStubZipEntry classEntry = new java.util.zip.ClassStubZipEntry(path, br.ReadString());
                        classEntry.setMethod(java.util.zip.ClassStubZipEntry.STORED);
                        classEntry.setTime(entry.getTime());
                        entries.put(classEntry.name, classEntry);
                    }
                }
            }
        }
        catch (java.io.IOException)
        {
        }
        catch (IOException)
        {
        }
#endif
    }
Ejemplo n.º 4
0
    public static string[] getMetaInfEntryNames(object thisJarFile)
    {
#if FIRST_PASS
        return(null);
#else
        java.util.zip.ZipFile zf      = (java.util.zip.ZipFile)thisJarFile;
        java.util.Enumeration entries = zf.entries();
        List <string>         list    = null;
        while (entries.hasMoreElements())
        {
            java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)entries.nextElement();
            if (entry.getName().StartsWith("META-INF/", StringComparison.OrdinalIgnoreCase))
            {
                if (list == null)
                {
                    list = new List <string>();
                }
                list.Add(entry.getName());
            }
        }
        return(list == null ? null : list.ToArray());
#endif
    }
Ejemplo n.º 5
0
        public void ProcessZipFile(string directory, FileInfo logFile)
        {
            ZipFile zipfile = new ZipFile(Path.Combine(directory + "\\", logFile.Name));
            try
            {
                List<ZipEntry> zipFiles = GetZipFiles(zipfile);

                foreach (ZipEntry zipEntry in zipFiles)
                {
                    if (!zipEntry.isDirectory())
                    {
                        string zipFileName = zipEntry.getName().Substring(zipEntry.getName().LastIndexOf("/") + 1, zipEntry.getName().Length - zipEntry.getName().LastIndexOf("/") - 1);
                        string zipFileNamePath = zipEntry.getName().Substring(zipEntry.getName().IndexOf("/") + 1, zipEntry.getName().Length - zipEntry.getName().IndexOf("/") - 1);
                        string tempZipFileName = Path.Combine(directory + "\\", zipFileName + ".tmp");
                        try
                        {
                            if (matchPerfLog.Match(zipFileName).Success)
                            {
                                DebugMessage(String.Format("Extracting {0}", zipEntry.getName()));
                                ExtractFile(zipfile, zipEntry, tempZipFileName);
                                FileInfo file = new FileInfo(tempZipFileName);
                                ConsumePerfLog(file);
                            }
                            if (matchIISLog.Match(zipFileName).Success)
                            {
                                DebugMessage(String.Format("Extracting {0}", zipEntry.getName()));
                                ExtractFile(zipfile, zipEntry, tempZipFileName);
                                FileInfo file = new FileInfo(tempZipFileName);
                                ConsumeIISLog(file);
                            }
                        }
                        catch (Exception e)
                        {
                            DebugMessage(e);
                            return;
                        }
                        finally
                        {//clean up after finished processing
                            if (System.IO.File.Exists(tempZipFileName))
                                System.IO.File.Delete(tempZipFileName);
                        }
                    }
                }
            }
            finally
            {

                zipfile.close();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Ejemplo n.º 6
0
 public static void AddToZip(string zipFile, string[] newFiles, bool flattenHierarchy)
 {
     java.util.zip.ZipFile file = new java.util.zip.ZipFile(zipFile);
     AddEntries(file, "", newFiles, flattenHierarchy);
     file.close();
 }
Ejemplo n.º 7
0
 public static void ZipFiles(string outputName, string rootDirectory, string[] files, bool flattenHierarchy)
 {
     FileOutputStream @out = new FileOutputStream(outputName);
     new ZipOutputStream(@out).close();
     java.util.zip.ZipFile file = new java.util.zip.ZipFile(outputName);
     AddEntries(file, rootDirectory, files, flattenHierarchy);
 }
Ejemplo n.º 8
0
 public static bool ZipContainsFile(string zipFile, string searchFile)
 {
     bool flag;
     java.util.zip.ZipFile file = new java.util.zip.ZipFile(zipFile);
     try
     {
         foreach (ZipEntry entry in GetZippedItems(file))
         {
             if (!entry.isDirectory() && entry.getName().EndsWith(searchFile))
             {
                 return true;
             }
         }
         flag = false;
     }
     finally
     {
         if (file != null)
         {
             file.close();
         }
     }
     return flag;
 }
Ejemplo n.º 9
0
 public static void Unzip(string zipFile, string[] targetFiles, string output)
 {
     java.util.zip.ZipFile file = new java.util.zip.ZipFile(zipFile);
     try
     {
         using (List<ZipEntry>.Enumerator enumerator = GetZippedItems(file).GetEnumerator())
         {
             Predicate<string> match = null;
             ZipEntry entry;
             while (enumerator.MoveNext())
             {
                 entry = enumerator.Current;
                 if ((targetFiles != null) && (targetFiles.Length > 0))
                 {
                     if (match == null)
                     {
                         match = delegate (string s) {
                             return entry.getName().ToLower().EndsWith(s.ToLower().Replace(@"\", "/").TrimStart("/".ToCharArray()));
                         };
                     }
                     if (Array.FindIndex<string>(targetFiles, match) < 0)
                     {
                         continue;
                     }
                 }
                 if (!entry.isDirectory())
                 {
                     InputStream source = file.getInputStream(entry);
                     try
                     {
                         string fileName;
                         string directoryName;
                         if (Path.HasExtension(output) && !Directory.Exists(output))
                         {
                             fileName = Path.GetFileName(output);
                             directoryName = Path.GetDirectoryName(output);
                         }
                         else
                         {
                             fileName = Path.GetFileName(entry.getName());
                             directoryName = Path.GetDirectoryName(entry.getName());
                             directoryName = output + @"\" + directoryName;
                         }
                         Directory.CreateDirectory(directoryName);
                         FileOutputStream destination = new FileOutputStream(Path.Combine(directoryName, fileName));
                         try
                         {
                             CopyStream(source, destination);
                         }
                         finally
                         {
                             destination.close();
                         }
                         continue;
                     }
                     finally
                     {
                         source.close();
                     }
                 }
             }
         }
     }
     finally
     {
         if (file != null)
         {
             file.close();
         }
     }
 }
Ejemplo n.º 10
0
 public static void RemoveFromZipFile(string zipFile, string[] items)
 {
     java.util.zip.ZipFile file = new java.util.zip.ZipFile(zipFile);
     RemoveEntries(file, items);
     file.close();
 }
Ejemplo n.º 11
0
        private void RefreshFileCount()
        {
            if (base.LocalFilePath.EndsWith(".zip"))
            {
                ZipFile file = null;
                try
                {
                    file = new ZipFile(base.LocalFilePath);
                    Enumeration enumeration = file.entries();
                    List<ZipEntry> list = new List<ZipEntry>();
                    while (enumeration.hasMoreElements())
                    {
                        list.Add(enumeration.nextElement() as ZipEntry);
                    }
                    int num = 0;
                    foreach (ZipEntry entry in list)
                    {
                        if (!entry.isDirectory())
                        {
                            num++;
                        }
                        if (entry.getName().EndsWith(".exe"))
                        {
                            base.Name = Path.GetFileName(entry.getName());
                            this.ExeName = base.Name;
                            base.Name = base.Name.Remove(base.Name.Length - ".exe".Length, ".exe".Length);
                        }
                    }
                    this.NumberOfFiles = num;
                }
                finally
                {
                    file.close();
                }
            }
            else
            {
                switch (this.PackagingMethod)
                {
                    case PackagingMethods.TargetOnly:
                        this.NumberOfFiles = 1;
                        return;

                    case PackagingMethods.TargetDirectory:
                        this.NumberOfFiles = Directory.GetFiles(Path.GetDirectoryName(base.LocalFilePath), "*.*", SearchOption.TopDirectoryOnly).Length;
                        return;

                    case PackagingMethods.TargetDirectoryRecursive:
                        this.NumberOfFiles = Directory.GetFiles(Path.GetDirectoryName(base.LocalFilePath), "*.*", SearchOption.AllDirectories).Length;
                        return;
                }
            }
        }
Ejemplo n.º 12
0
 public static Image ExtractZippedImage(string zipFile, string mappath)
 {
     InputStream stream = null;
     ZipFile file = null;
     Image image;
     try
     {
         file = new ZipFile(zipFile);
         Enumeration enumeration = file.entries();
         List<ZipEntry> list = new List<ZipEntry>();
         while (enumeration.hasMoreElements())
         {
             list.Add(enumeration.nextElement() as ZipEntry);
         }
         foreach (ZipEntry entry in list)
         {
             if (entry.getName().EndsWith(Path.GetFileName(mappath)))
             {
                 stream = file.getInputStream(entry);
                 break;
             }
         }
         if (stream == null)
         {
             return ExtractImage(zipFile, mappath);
         }
         Bitmap bitmap = new Bitmap(0x100, 0x100);
         byte[] buffer = new byte[0x40000];
         int index = 0;
         stream.read(new sbyte[0xa5], 0, 0xa5);
         while (index < 0x40000)
         {
             for (int i = 0; i < 0x1000; i++)
             {
                 buffer[index + i] = (byte) stream.read();
             }
             index += 0x1000;
         }
         index = 0;
         int x = 0;
         int y = 0;
         while (index < 0x40000)
         {
             Color color = Color.FromArgb(buffer[index], buffer[index + 3], buffer[index + 2], buffer[index + 1]);
             bitmap.SetPixel(x, y, color);
             x++;
             if (x > 0xff)
             {
                 x = 0;
                 y++;
             }
             index += 4;
         }
         image = bitmap;
     }
     catch (Exception exception)
     {
         ErrorLog.WriteLine(exception);
         image = null;
     }
     finally
     {
         if (stream != null)
         {
             stream.close();
         }
         if (file != null)
         {
             file.close();
         }
     }
     return image;
 }
Ejemplo n.º 13
0
 public bool FromLocalFile(string file, out IAdditionalContent content)
 {
     Exception exception;
     if (!base.ContentType.CurrentUserCanUpload)
     {
         content = null;
         return false;
     }
     try
     {
         byte[] buffer;
         int num2;
         string extension = Path.GetExtension(file);
         string contents = "";
         XmlDocument document = null;
         switch (extension)
         {
             case ".scd":
             case ".zip":
             {
                 ZipFile file2 = null;
                 try
                 {
                     file2 = new ZipFile(file);
                     Enumeration enumeration = file2.entries();
                     List<ZipEntry> list = new List<ZipEntry>();
                     while (enumeration.hasMoreElements())
                     {
                         list.Add(enumeration.nextElement() as ZipEntry);
                     }
                     bool flag = false;
                     foreach (ZipEntry entry in list)
                     {
                         if (entry.getName().EndsWith("_scenario.lua"))
                         {
                             string fileName = Path.GetFileName(entry.getName());
                             this.mMapName = fileName.Remove(fileName.IndexOf("_scenario.lua"), "_scenario.lua".Length);
                             InputStream stream = null;
                             try
                             {
                                 string str5;
                                 stream = file2.getInputStream(entry);
                                 buffer = new byte[0x1000];
                                 bool flag2 = false;
                                 while (!flag2)
                                 {
                                     num2 = 0;
                                     while (num2 < buffer.Length)
                                     {
                                         int num = stream.read();
                                         if (num < 0)
                                         {
                                             flag2 = true;
                                             break;
                                         }
                                         buffer[num2] = (byte) num;
                                         num2++;
                                     }
                                     contents = contents + Encoding.UTF8.GetString(buffer, 0, num2);
                                 }
                                 string tempFileName = Path.GetTempFileName();
                                 System.IO.File.WriteAllText(tempFileName, contents);
                                 if (!LuaUtil.VerifyScenario(tempFileName, out str5))
                                 {
                                     ErrorLog.WriteLine("Error loading custom map file {0}: {1}", new object[] { Path.GetFileName(tempFileName), str5 });
                                     content = null;
                                     return false;
                                 }
                                 new XmlDocument().LoadXml(LuaUtil.ScenarioToXml(tempFileName));
                                 System.IO.File.Delete(tempFileName);
                                 base.LocalFilePath = file;
                                 flag = true;
                                 break;
                             }
                             finally
                             {
                                 if (stream != null)
                                 {
                                     stream.close();
                                 }
                             }
                         }
                     }
                     if (!flag)
                     {
                         content = null;
                         return false;
                     }
                 }
                 finally
                 {
                     file2.close();
                 }
                 goto Label_03C3;
             }
             default:
             {
                 if (!(extension == ".lua"))
                 {
                     goto Label_03C3;
                 }
                 if (!file.EndsWith("_scenario.lua"))
                 {
                     content = null;
                     return false;
                 }
                 this.mMapName = Path.GetFileName(file);
                 this.mMapName = this.mMapName.Remove(this.mMapName.IndexOf("_scenario.lua"), "_scenario.lua".Length);
                 document = new XmlDocument();
                 document.LoadXml(LuaUtil.ScenarioToXml(file));
                 FileStream stream2 = null;
                 for (num2 = 0; num2 < 3; num2++)
                 {
                     try
                     {
                         bool flag4;
                         base.LocalFilePath = Path.GetDirectoryName(file);
                         stream2 = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
                         buffer = new byte[0x1000];
                         int count = 0;
                         goto Label_034E;
                     Label_0316:
                         count = stream2.Read(buffer, 0, buffer.Length);
                         if (count < 1)
                         {
                             break;
                         }
                         contents = contents + Encoding.UTF8.GetString(buffer, 0, count);
                     Label_034E:
                         flag4 = true;
                         goto Label_0316;
                     }
                     catch (Exception exception1)
                     {
                         exception = exception1;
                         ErrorLog.WriteLine(exception);
                         Thread.Sleep(0x3e8);
                     }
                     finally
                     {
                         if (stream2 != null)
                         {
                             stream2.Close();
                         }
                     }
                 }
                 break;
             }
         }
         if ((contents == null) || (contents.Length < 1))
         {
             content = null;
             return false;
         }
     Label_03C3:
         if (document == null)
         {
             content = null;
             return false;
         }
         base.Name = document["scenario"]["name"].InnerText;
         this.mMapDescription = document["scenario"]["description"].InnerText;
         this.mWidth = int.Parse(document["scenario"]["size"]["width"].InnerText);
         this.mHeight = int.Parse(document["scenario"]["size"]["height"].InnerText);
         this.mSize = (this.Width + this.Height) / 2;
         this.mMaxPlayers = int.Parse(document["scenario"]["max_players"].InnerText);
         string innerText = document["scenario"]["map"].InnerText;
         if ((extension == ".scd") || (extension == ".zip"))
         {
             this.mPreviewImage256 = ExtractZippedImage(file, innerText);
         }
         else
         {
             this.mPreviewImage256 = ExtractImage(file, innerText);
         }
         this.mPreviewImage50 = null;
         this.mPreviewImage128 = null;
         content = this;
         return true;
     }
     catch (Exception exception2)
     {
         exception = exception2;
         ErrorLog.WriteLine(exception);
         content = null;
         return false;
     }
 }
Ejemplo n.º 14
0
 public virtual bool StartsWithLocHeader(ZipFile zip)
 {
     return(zip.StartsWithLocHeader());
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Get the list of files in the zip file
 /// </summary>
 /// <param name="zipFileName"></param>
 /// <returns></returns>
 public static System.Collections.ArrayList GetZipEntries(string zipFileName)
 {
     System.Collections.ArrayList arrZipEntries = new System.Collections.ArrayList();
     ZipFile zipfile = new ZipFile(zipFileName);
     List<ZipEntry> zipFiles = getZippedFiles(zipfile);
     foreach (ZipEntry zipFile in zipFiles)
     {
         arrZipEntries.Add(zipFile.getName());
     }
     zipfile.close();
     System.Collections.ArrayList arrZipEntriesInside = new System.Collections.ArrayList();
     foreach (string strZipFile in arrZipEntries)
     {
         if (string.Compare(Path.GetExtension(strZipFile), ".zip", true) == 0)
         {
             ExtractSingleFile(zipFileName, Path.GetDirectoryName(zipFileName), Path.GetFileName(strZipFile));
             ZipFile zipfileinside = new ZipFile(Path.GetDirectoryName(zipFileName) + Path.DirectorySeparatorChar + strZipFile);
             List<ZipEntry> zipFilesInside = getZippedFiles(zipfileinside);
             foreach (ZipEntry zipFile in zipFilesInside)
             {
                 arrZipEntriesInside.Add(zipFile.getName());
             }
             zipfileinside.close();
         }
     }
     foreach (string strFilesInsideZip in arrZipEntriesInside)
     {
         arrZipEntries.Add(strFilesInsideZip);
     }
     return arrZipEntries;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Return a list of zip entries (compressed files meta data)
 /// </summary>
 /// <param name="zipFile"></param>
 /// <returns></returns>
 private static List<ZipEntry> getZippedFiles(ZipFile zipFile)
 {
     List<ZipEntry> zipEntries = new List<ZipEntry>();
     java.util.Enumeration zipEnum = zipFile.entries();
     while (zipEnum.hasMoreElements())
     {
         ZipEntry zip = (ZipEntry)zipEnum.nextElement();
         zipEntries.Add(zip);
     }
     return zipEntries;
 }
Ejemplo n.º 17
0
        private void ExtractFile(ZipFile zipFile, ZipEntry zipEntry, string tempFileName)
        {
            InputStream s = zipFile.getInputStream(zipEntry);
            try
            {
                FileOutputStream dest = new FileOutputStream(tempFileName);
                try
                {
                    int len = 0;
                    sbyte[] buffer = new sbyte[7168];
                    while ((len = s.read(buffer)) >= 0)
                    {
                        dest.write(buffer, 0, len);
                    }
                }
                finally
                {
                    dest.close();
                }
            }
            finally
            {
                s.close();
            }

        }
Ejemplo n.º 18
0
 public ZipEntryIterator(ZipFile outerInstance)
 {
     this.OuterInstance = outerInstance;
     outerInstance.EnsureOpen();
 }
Ejemplo n.º 19
0
 private List<ZipEntry> GetZipFiles(ZipFile zipfil)
 {
     List<ZipEntry> lstZip = new List<ZipEntry>();
     Enumeration zipEnum = zipfil.entries();
     while (zipEnum.hasMoreElements())
     {
         ZipEntry zip = (ZipEntry)zipEnum.nextElement();
         lstZip.Add(zip);
     }
     return lstZip;
 }
Ejemplo n.º 20
0
 public bool FromLocalFile(string file, out IAdditionalContent content)
 {
     if (!base.ContentType.CurrentUserCanUpload)
     {
         content = null;
         return false;
     }
     if (file.EndsWith(".exe"))
     {
         base.Name = Path.GetFileName(file);
         this.ExeName = base.Name;
         base.Name = base.Name.Remove(base.Name.Length - ".exe".Length, ".exe".Length);
         this.NumberOfFiles = Directory.GetFiles(Path.GetDirectoryName(file), "*.*", SearchOption.AllDirectories).Length;
     }
     else if (file.EndsWith(".zip"))
     {
         ZipFile file2 = null;
         base.Name = Path.GetFileName(file);
         base.Name = base.Name.Remove(base.Name.Length - ".zip".Length, ".zip".Length);
         try
         {
             file2 = new ZipFile(file);
             Enumeration enumeration = file2.entries();
             List<ZipEntry> list = new List<ZipEntry>();
             while (enumeration.hasMoreElements())
             {
                 list.Add(enumeration.nextElement() as ZipEntry);
             }
             bool flag = false;
             int num = 0;
             foreach (ZipEntry entry in list)
             {
                 if (!entry.isDirectory())
                 {
                     num++;
                 }
                 if (entry.getName().EndsWith(".exe") || entry.getName().EndsWith(".bat"))
                 {
                     this.ExeName = entry.getName();
                     flag = true;
                 }
             }
             if (!flag)
             {
                 content = null;
                 return false;
             }
             this.NumberOfFiles = num;
         }
         finally
         {
             file2.close();
         }
     }
     base.LocalFilePath = file;
     content = this;
     return true;
 }
Ejemplo n.º 21
0
 public bool FromLocalFile(string file, out IAdditionalContent content)
 {
     if (!base.ContentType.CurrentUserCanUpload)
     {
         content = null;
         return false;
     }
     try
     {
         string tempFileName;
         string str6;
         string str7;
         string extension = Path.GetExtension(file);
         XmlDocument document = null;
         switch (extension)
         {
             case ".scd":
             case ".zip":
             {
                 ZipFile file2 = null;
                 try
                 {
                     file2 = new ZipFile(file);
                     Enumeration enumeration = file2.entries();
                     List<ZipEntry> list = new List<ZipEntry>();
                     while (enumeration.hasMoreElements())
                     {
                         list.Add(enumeration.nextElement() as ZipEntry);
                     }
                     foreach (ZipEntry entry in list)
                     {
                         if (!entry.isDirectory())
                         {
                             this.NumberOfFiles++;
                         }
                         if (entry.getName().ToLower().EndsWith("mod_info.lua"))
                         {
                             string path = entry.getName();
                             string directoryName = Path.GetDirectoryName(path);
                             if ((directoryName == null) || (directoryName.Length < 1))
                             {
                                 directoryName = Path.GetDirectoryName(file);
                             }
                             this.mModName = new DirectoryInfo(directoryName).Name;
                             path = Path.GetFileName(path);
                             InputStream stream = null;
                             try
                             {
                                 stream = file2.getInputStream(entry);
                                 byte[] bytes = new byte[0x1000];
                                 bool flag = false;
                                 string contents = "";
                                 while (!flag)
                                 {
                                     int index = 0;
                                     while (index < bytes.Length)
                                     {
                                         int num = stream.read();
                                         if (num < 0)
                                         {
                                             flag = true;
                                             break;
                                         }
                                         bytes[index] = (byte) num;
                                         index++;
                                     }
                                     contents = contents + Encoding.UTF8.GetString(bytes, 0, index);
                                 }
                                 tempFileName = Path.GetTempFileName();
                                 System.IO.File.WriteAllText(tempFileName, contents);
                                 str7 = LuaUtil.ModToXml(tempFileName, out str6);
                                 if ((str6 != null) && (str6.Length > 0))
                                 {
                                     ErrorLog.WriteLine("Error parsing Mod file: {0}", new object[] { str6 });
                                     content = null;
                                     return false;
                                 }
                                 document = new XmlDocument();
                                 document.LoadXml(str7);
                                 base.LocalFilePath = file;
                                 System.IO.File.Delete(tempFileName);
                             }
                             finally
                             {
                                 if (stream != null)
                                 {
                                     stream.close();
                                 }
                             }
                         }
                     }
                 }
                 finally
                 {
                     file2.close();
                 }
                 break;
             }
             default:
                 if (extension == ".lua")
                 {
                     if (!file.EndsWith("mod_info.lua"))
                     {
                         content = null;
                         return false;
                     }
                     str7 = LuaUtil.ModToXml(file, out str6);
                     if ((str6 != null) && (str6.Length > 0))
                     {
                         ErrorLog.WriteLine("Error parsing Mod file: {0}", new object[] { str6 });
                         content = null;
                         return false;
                     }
                     document = new XmlDocument();
                     document.LoadXml(str7);
                     base.LocalFilePath = Path.GetDirectoryName(file);
                     this.mNumberOfFiles = Directory.GetFiles(base.LocalFilePath, "*.*", SearchOption.AllDirectories).Length;
                     this.mModName = new DirectoryInfo(Path.GetDirectoryName(file)).Name;
                 }
                 break;
         }
         if (document == null)
         {
             content = null;
             return false;
         }
         base.Name = document["mod"]["name"].InnerText;
         base.Description = document["mod"]["description"].InnerText;
         if (document["mod"]["copyright"] != null)
         {
             this.Copyright = document["mod"]["copyright"].InnerText.Replace("\x00a9", "").Replace("\x00ef\x00bf\x00bd", "");
         }
         if (document["mod"]["author"] != null)
         {
             this.DeveloperName = document["mod"]["author"].InnerText;
         }
         if (document["mod"]["url"] != null)
         {
             this.Website = document["mod"]["url"].InnerText;
         }
         this.Exclusive = this.ParseBool(document["mod"]["exclusive"].InnerText);
         this.UIOnly = new bool?(this.ParseBool(document["mod"]["ui_only"].InnerText));
         this.Guid = document["mod"]["uid"].InnerText;
         if (document["mod"]["requires"] != null)
         {
             this.mRequirements = document["mod"]["requires"].InnerText;
         }
         if (document["mod"]["requiresNames"] != null)
         {
             this.mRequirementNames = document["mod"]["requiresNames"].InnerText;
         }
         if (document["mod"]["conflicts"] != null)
         {
             this.mConflicts = document["mod"]["conflicts"].InnerText;
         }
         if (((document["mod"]["icon"] != null) && (document["mod"]["icon"].InnerText != null)) && (document["mod"]["icon"].InnerText.Length > 0))
         {
             string targetFile = document["mod"]["icon"].InnerText.Replace("/", @"\");
             if (extension == ".lua")
             {
                 if (targetFile.IndexOf(this.ModName) >= 0)
                 {
                     targetFile = targetFile.Remove(0, targetFile.IndexOf(this.ModName)).TrimStart(@"\".ToCharArray());
                 }
                 string str9 = Path.GetDirectoryName(base.LocalFilePath);
                 string str10 = targetFile;
                 string str11 = Path.Combine(str9, str10);
                 if (Path.GetExtension(str11) == ".dds")
                 {
                     this.mPreviewImage50 = ConvertDDS.ToBitmap(str11);
                 }
                 else
                 {
                     this.mPreviewImage50 = Image.FromFile(str11);
                 }
             }
             else
             {
                 tempFileName = Path.GetTempFileName();
                 Compression.Unzip(file, targetFile, tempFileName);
                 if (Path.GetExtension(targetFile) == ".dds")
                 {
                     this.mPreviewImage50 = ConvertDDS.ToBitmap(tempFileName);
                 }
                 else
                 {
                     this.mPreviewImage50 = Image.FromFile(tempFileName);
                 }
                 System.IO.File.Delete(tempFileName);
             }
             this.mHasPreview = true;
         }
         else
         {
             this.mPreviewImage50 = null;
         }
         content = this;
         return true;
     }
     catch (Exception exception)
     {
         ErrorLog.WriteLine(exception);
         content = null;
         return false;
     }
 }
Ejemplo n.º 22
0
 internal ZipFileInflaterInputStream(ZipFile outerInstance, ZipFileInputStream zfin, Inflater inf, int size) : base(zfin, inf, size)
 {
     this.OuterInstance = outerInstance;
     this.Zfin          = zfin;
 }