public static void ExtractHfs(string filename)
        {
            string basep = Path.GetDirectoryName(filename);
            string plain = Path.GetFileNameWithoutExtension(filename);

            using (HfsFile hfs = new HfsFile(filename))
                using (ZipFile zip = ZipFile.Create(basep + @"\" + plain + ".zip")) {
                    zip.BeginUpdate();

                    foreach (HfsEntry hfsEntry in hfs)
                    {
                        Console.WriteLine("Processing " + hfsEntry.Name);


                        try {
                            Stream read = hfs.GetInputStream(hfsEntry);

                            zip.Add(new StreamLocalSourceZip(read), hfsEntry.Name);
                        }
                        catch (Exception e) {
                            Console.WriteLine("Couldn't process " + hfsEntry.Name + ": " + e.Message);
                        }
                    }

                    if (hfs.ObfuscationKey != 0)
                    {
                        zip.SetComment("extra_obscure");
                    }

                    //Console.WriteLine("Compressing..");
                    zip.CommitUpdate();
                }

            //Console.WriteLine("Wrote to " + basep + @"\" + plain + "_.zip");
        }
Example #2
0
 public static bool ExtractAllHfsFindFile(string dir, string filename, string path = null)
 {
     string[] files = Directory.GetFiles(dir);
     if (files != null)
     {
         if (path == null)
         {
             path = Path.GetDirectoryName(dir);
         }
         foreach (string file in files)
         {
             try{
                 using (HfsFile hfs = new HfsFile(file)){
                     foreach (HfsEntry hfsEntry in hfs)
                     {
                         if (filename == hfsEntry.Name || filename + ".comp" == hfsEntry.Name)
                         {
                             using (Stream read = hfs.GetInputStream(hfsEntry)){
                                 string fullname = PathHelper.Combine(path, filename);
                                 string fullpath = Path.GetDirectoryName(fullname);
                                 if (!Directory.Exists(fullpath))
                                 {
                                     Directory.CreateDirectory(fullpath);
                                 }
                                 using (FileStream fs = new FileStream(
                                            fullname, FileMode.Create)){
                                     byte[] data  = new byte[4096];
                                     long   count = read.Length;
                                     long   max   = count / data.Length;
                                     for (long i = 0; i < max; i++)
                                     {
                                         read.Read(data, 0, data.Length);
                                         fs.Write(data, 0, data.Length);
                                     }
                                     if (max * data.Length < count)
                                     {
                                         int c = (int)(count - (max * data.Length));
                                         read.Read(data, 0, c);
                                         fs.Write(data, 0, c);
                                     }
                                 }
                             }
                             return(true);
                         }
                     }
                 }
             }catch (Exception e) {
                 Console.WriteLine("Couldn't process " + e.Message);
             }
         }
     }
     return(false);
 }