Ejemplo n.º 1
0
        public static void AddOrReplace(string hfsfile, string file, string filename = null)
        {
            if (string.IsNullOrEmpty(filename))
            {
                filename = Path.GetFileName(file);
            }
            if (!filename.EndsWith(".comp"))
            {
                filename += ".comp";
            }
            string basep = Path.GetDirectoryName(filename);
            string plain = Path.GetFileNameWithoutExtension(filename);

            using (HfsFile hfs = new HfsFile(hfsfile)){
                foreach (HfsEntry hfsEntry in hfs)
                {
                    if (filename != hfsEntry.Name)
                    {
                        Console.WriteLine("skip " + hfsEntry.Name);
                        continue;
                    }
                    hfs.BeginUpdate();
                    Console.WriteLine("hfs rm " + filename);
                    hfs.Delete(hfsEntry);
                    Console.WriteLine("hfs add " + filename);
                    hfs.Add(file, filename);
                    hfs.CommitUpdate();
                    break;
                }
                Console.WriteLine("completed...");
            }
        }
Ejemplo n.º 2
0
        public static void ConvertZip(string filename)
        {
            string basep = Path.GetDirectoryName(filename);
            string plain = Path.GetFileNameWithoutExtension(filename);

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

                    if (zip.ZipFileComment == "extra_obscure")
                    {
                        // could be better implemented
                        hfs.ObfuscationKey = -1;
                    }

                    foreach (ZipEntry zipEntry in zip)
                    {
                        Console.WriteLine("Processing " + zipEntry.Name);

                        Stream read = zip.GetInputStream(zipEntry);


                        hfs.Add(new StreamLocalSourceHfs(read), zipEntry.Name);
                    }

                    Console.WriteLine("Compressing..");
                    hfs.CommitUpdate();
                }

            Console.WriteLine("Wrote to " + basep + @"\" + plain + "_.hfs");
        }