Ejemplo n.º 1
0
        public void Compress()
        {
            //压缩
            byte[] byteData = System.Text.Encoding.UTF8.GetBytes("ul{\"state\":1,\"nick\":\"小龙\",\"sex\":true,\"email\":\"[email protected]\",\"exp\":109040,\"isguest\":false,\"hotpoint\":26,\"money\":7099,\"styletype\":\"stand\",\"style\":\"2/2/2/1\",\"id\":\"2ef38760-9000-4f10-b96b-af4da8c656ae\",\"vertify\":1,\"level\":12,\"sign\":\"小龙\",\"score\":6323}");
            MemoryStream ms = new MemoryStream();
            Stream s = new ZOutputStream(ms, 9);

            s.Write(byteData, 0, byteData.Length);
            s.Close();
            byte[] compressData = (byte[])ms.ToArray();
            ms.Flush();
            ms.Close();
            Console.WriteLine(compressData.Length);

            //解压
            MemoryStream md = new MemoryStream();
            Stream d = new ZOutputStream(md);
            d.Write(compressData, 0, compressData.Length);
            d.Close();
            byte[] dompressData = (byte[])md.ToArray();
            md.Flush();
            md.Close();

            Console.WriteLine(dompressData.Length);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Zip compress data with offset and length.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 public static byte[] Compress(byte[] src, int offset, int length)
 {
     MemoryStream ms = new MemoryStream();
     Stream s = new ZOutputStream(ms, 9);
     s.Write(src, offset, length);
     s.Close();
     return (byte[])ms.ToArray();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Zip uncompress data.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 public static byte[] Uncompress(byte[] src)
 {
     MemoryStream md = new MemoryStream();
     Stream d = new ZOutputStream(md);
     d.Write(src, 0, src.Length);
     d.Close();
     return (byte[])md.ToArray();
 }
Ejemplo n.º 4
0
        public void SendChunk(Chunk chunk)
        {
            Transmit(PacketType.PreChunk, chunk.ChunkX, chunk.ChunkZ, (sbyte) 1);

            byte[] uncompressed = chunk.GetBytes();
            MemoryStream mem = new MemoryStream();
            ZOutputStream stream = new ZOutputStream(mem, zlibConst.Z_BEST_COMPRESSION);
            stream.Write(uncompressed, 0, uncompressed.Length);
            stream.Close();
            byte[] data = mem.ToArray();

            Transmit(PacketType.MapChunk, 16 * chunk.ChunkX, (short) 0, 16 * chunk.ChunkZ,
                (sbyte) 15, (sbyte) 127, (sbyte) 15, data.Length, data);
        }
Ejemplo n.º 5
0
        //导出
        private void exportBtn_Click(object sender, EventArgs e)
        {
            int index = swfListBox.SelectedIndex;
            SwfClass swf = ProcessHandle.getInstence().getSwfClassByIndex(index);

            if (saveFileDialog.ShowDialog() == DialogResult.OK){
                string localFilePath = saveFileDialog.FileName;

                if(checkBox.Checked == false){
                    byte[] fileByte = swf.fileByte;
                    FileStream file = new FileStream(localFilePath, FileMode.Create);
                    file.Write(fileByte, 0, swf.size);
                    file.Flush();
                    file.Close();
                }
                else
                {
                    MemoryStream mStream = new MemoryStream(swf.fileByte.Length);
                    mStream.WriteByte(0x43);
                    mStream.Write(swf.fileByte, 1, 7);

                    MemoryStream getStream = new MemoryStream(swf.fileByte.Length);

                    //ZipOutputStream outPut = new ZipOutputStream(getStream);
                    //ZipEntry entry = new ZipEntry("");
                    //entry.CompressionMethod = CompressionMethod.WinZipAES
                    //outPut.PutNextEntry(entry);
                    //outPut.Write(swf.fileByte, 8, swf.fileByte.Length - 8);
                    //outPut.Finish();

                    ZOutputStream outPut = new ZOutputStream(getStream,zlib.zlibConst.Z_DEFAULT_COMPRESSION);
                    outPut.Write(swf.fileByte, 8, swf.fileByte.Length - 8);
                    outPut.finish();

                    getStream.WriteTo(mStream);

                    outPut.Close();

                    FileStream file = new FileStream(localFilePath, FileMode.Create);
                    file.Write(mStream.ToArray(), 0,(int)mStream.Length);
                    file.Flush();
                    file.Close();

                    MessageBox.Show("导出swf成功,路径:" + localFilePath,"成功");
                }

            }
        }
Ejemplo n.º 6
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     //Compression.LZW.TestCompress();
     System.IO.FileStream output  = new System.IO.FileStream("CompressedZ1.txt", System.IO.FileMode.Create);
     zlib.ZOutputStream   outputZ = new zlib.ZOutputStream(output, zlib.zlibConst.Z_DEFAULT_COMPRESSION);
     System.IO.FileStream input   = new System.IO.FileStream("InputZ1.txt", System.IO.FileMode.Open);
     try
     {
         CopyStream(input, outputZ);
     }
     finally
     {
         outputZ.Close();
         output.Close();
         input.Close();
     }
 }
Ejemplo n.º 7
0
    public static string Compress(string param)
    {
        byte[] data = System.Text.Encoding.UTF8.GetBytes(param);
        //byte[] data = Convert.FromBase64String(param);
        MemoryStream ms     = new MemoryStream();
        Stream       stream = new zlib.ZOutputStream(ms);

        try
        {
            stream.Write(data, 0, data.Length);
        }
        finally
        {
            stream.Close();
            ms.Close();
        }
        return(Convert.ToBase64String(ms.ToArray()));
    }
Ejemplo n.º 8
0
    public void Decompress()
    {
        long         msPos = m_memoryStream.Position;
        MemoryStream outMS = new MemoryStream();

        zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outMS);

        CopyStream(m_memoryStream, outZStream);
        outZStream.finish();

        outMS.Position          = 0;
        m_memoryStream.Position = msPos;
        CopyStream(outMS, m_memoryStream);
        m_memoryStream.Position = msPos;

        outMS.Close();
        outZStream.Close();
    }
Ejemplo n.º 9
0
 public static byte[] compress(byte[] data)
 {
     for (int l = zlib.zlibConst.Z_BEST_COMPRESSION; l > 0; l--)
     {
         MemoryStream o = new MemoryStream();
         ZOutputStream z = new ZOutputStream(o, l);
         MemoryStream i = new MemoryStream(data);
         CopyStream(i, z);
         z.finish();
         o.Position = 0;
         byte[] res = o.ToArray();
         i.Close();
         z.Close();
         o.Close();
         if (res.Length > 2)
             return res;
     }
     return data;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// zlib.net 压缩函数
        /// </summary>
        /// <param name="strSource">待压缩数据</param>
        /// <returns>压缩后数据</returns>
        public static byte[] Compress(byte[] bytes)
        {
            MemoryStream outms = new MemoryStream();
            MemoryStream inms  = new MemoryStream(bytes);

            zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outms, zlib.zlibConst.Z_DEFAULT_COMPRESSION);
            try
            {
                CopyStream(inms, outZStream, bytes);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                outZStream.Close();
            }
            return(outms.ToArray());
        }
Ejemplo n.º 11
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Compression.LZW.TestDecompres();
            //System.IO.FileStream outFileStream = new System.IO.FileStream("DecompressedZ1.txt", System.IO.FileMode.Create);
            //zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream);
            //System.IO.FileStream inFileStream = new System.IO.FileStream("CompressedZ1.txt", System.IO.FileMode.Open);
            System.IO.FileStream outFileStream = new System.IO.FileStream("DecompressedZ2.bin", System.IO.FileMode.Create);
            zlib.ZOutputStream   outZStream    = new zlib.ZOutputStream(outFileStream);
            System.IO.FileStream inFileStream  = new System.IO.FileStream("219outCompressed.bin", System.IO.FileMode.Open);

            try
            {
                CopyStream(inFileStream, outZStream);
            }
            finally
            {
                outZStream.Close();
                outFileStream.Close();
                inFileStream.Close();
            }
        }
Ejemplo n.º 12
0
        public override void Read(NetworkReader reader)
        {
            ChunkX = reader.ReadInt32();
            ChunkY = reader.ReadInt16();
            ChunkZ = reader.ReadInt32();
            Width = reader.ReadByte() + 1;
            Height = reader.ReadByte() + 1;
            Depth = reader.ReadByte() + 1;

            byte[] data = new byte[reader.ReadInt32()];
            reader.Read(data, 0, data.Length);
            var uncompressed = new MemoryStream(data.Length); // TODO: use better guess here
            var zlib = new ZOutputStream(uncompressed);
            zlib.Write(data, 0, data.Length);
            zlib.Flush();
            zlib.finish();
            Data = new byte[zlib.TotalOut];
            uncompressed.Read(Data, 0, Data.Length);
            zlib.Close();
            uncompressed.Close();
        }
Ejemplo n.º 13
0
        public override void Write(NetworkWriter writer)
        {
            writer.WriteInt32(ChunkX);
            writer.WriteInt16(ChunkY);
            writer.WriteInt32(ChunkZ);
            writer.WriteByte((byte)(Width - 1));
            writer.WriteByte((byte)(Height - 1));
            writer.WriteByte((byte)(Depth - 1));

            var compressed = new MemoryStream(Data.Length); // TODO: use better guess here
            var zlib = new ZOutputStream(compressed, zlibConst.Z_DEFAULT_COMPRESSION);
            zlib.Write(Data, 0, Data.Length);
            zlib.Flush();
            zlib.finish();
            writer.WriteInt32((int)zlib.TotalOut);
            writer.Write(compressed.GetBuffer(), 0, (int)zlib.TotalOut);
            zlib.Close();
            compressed.Close();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Softlynx.XDelta.Wrapper.Encode(
                        @"C:\temp\test\src",
                        @"C:\temp\test\dst",
                        @"C:\temp\test\patch1");
            Softlynx.XDelta.Wrapper.Decode(
                        @"C:\temp\test\src",
                        @"C:\temp\test\patch1",
                        @"C:\temp\test\dst.new");


            return;

            Stream src=File.Open(@"C:\temp\test\src",FileMode.Open);
            Stream bzpart = File.Open(@"C:\temp\test\src.bz.1", FileMode.Create);
            //BZip2.Compress(src, bzpart, false, 9);
            
            PipeStream bzfile=new PipeStream(bzpart);
            Stream bzfilter = new ZOutputStream(bzfile,9);
            //StreamCopy(src, bzfilter);
            SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
            encoder.WriteCoderProperties(bzfile);
            encoder.Code(src, bzfile, 0, 0, null);
            //bzfilter.Flush();
            src.Close();
            bzpart.Close();
            src = File.Open(@"C:\temp\test\dst", FileMode.Open);
            bzpart = File.Open(@"C:\temp\test\src.bz.2", FileMode.Create);
            bzfile.SwitchStream(bzpart);
            encoder.Code(src, bzfile, 0, 0, null);
            //StreamCopy(src, bzfilter);
            bzfilter.Close();
            
            src.Close();
            bzpart.Close();




            
            /*
            VDiffEncoder.BzipEncode(
                        @"C:\temp\test\src",
                        @"C:\temp\test\dst",
                        @"C:\temp\test\patch1");

            VDiffDecoder.BzipDecode(
            @"C:\temp\test\src",
            @"C:\temp\test\patch1",
            @"C:\temp\test\dst.new");
            */
            return;
            /*
            Softlynx.BSDiffTools.Patch.Create(
               @"C:\temp\test\src",
               @"C:\temp\test\dst",
               @"C:\temp\test\patch");
            Softlynx.BSDiffTools.Patch.Apply(
               @"C:\temp\test\src",
               @"C:\temp\test\dst.newa",
               @"C:\temp\test\patch");
            SoftLynx.BSDiffSharp.BSPatch.Apply(
               @"C:\temp\test\src",
               @"C:\temp\test\dst.newb",
               @"C:\temp\test\patch");
                     */
        }
 private string Compress(string ToCompress)
 {
     byte[] bytData = Encoding.UTF8.GetBytes(ToCompress);
     MemoryStream ms = new MemoryStream();
     Stream s = new ZOutputStream(ms, rnd.Next(1, 9));
     s.Write(bytData, 0, bytData.Length);
     s.Close();
     byte[] compressedData = ms.ToArray();
     return Convert.ToBase64String(compressedData);
 }
Ejemplo n.º 16
0
        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd = null;

            using (MemoryStream msSinkCompressed = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed))
                {
                    CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut);
                    msSinkCompressed.Seek(0L, SeekOrigin.Begin);
                    osd = OSD.FromBinary(msSinkCompressed.ToArray());
                    zOut.Close();
                }

            }

            return osd;
        }
Ejemplo n.º 17
0
 public void Compress()
 {
     byte[] buffer = m_Stream.GetBuffer();
     ZOutputStream zs = new ZOutputStream(m_Stream);
     zs.Write(buffer, 0, buffer.Length);
     zs.Close();
     Init();
 }
Ejemplo n.º 18
0
        private bool LoadBluRaySubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show(this._language.NoSupportEncryptedVobSub);
            }

            this.ShowStatus(this._language.ParsingMatroskaFile);
            this.Refresh();
            Cursor.Current = Cursors.WaitCursor;
            var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, this.MatroskaProgress);
            TaskbarList.SetProgressState(this.Handle, TaskbarButtonProgressFlags.NoProgress);
            Cursor.Current = Cursors.Default;

            int noOfErrors = 0;
            string lastError = string.Empty;
            this.MakeHistoryForUndo(this._language.BeforeImportFromMatroskaFile);
            this._subtitleListViewIndex = -1;
            this._subtitle.Paragraphs.Clear();
            var subtitles = new List<BluRaySupParser.PcsData>();
            var log = new StringBuilder();
            foreach (var p in sub)
            {
                byte[] buffer = null;
                if (matroskaSubtitleInfo.ContentEncodingType == 0)
                {
                    // compressed with zlib
                    MemoryStream outStream = new MemoryStream();
                    var outZStream = new ZOutputStream(outStream);
                    MemoryStream inStream = new MemoryStream(p.Data);
                    try
                    {
                        CopyStream(inStream, outZStream);
                        buffer = new byte[outZStream.TotalOut];
                        outStream.Position = 0;
                        outStream.Read(buffer, 0, buffer.Length);
                    }
                    catch (Exception exception)
                    {
                        var tc = new TimeCode(p.Start);
                        lastError = tc + ": " + exception.Message + ": " + exception.StackTrace;
                        noOfErrors++;
                    }
                    finally
                    {
                        outZStream.Close();
                        inStream.Close();
                    }
                }
                else
                {
                    buffer = p.Data;
                }

                if (buffer != null && buffer.Length > 100)
                {
                    MemoryStream ms = new MemoryStream(buffer);
                    var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
                    foreach (var sup in list)
                    {
                        sup.StartTime = (long)((p.Start - 1) * 90.0);
                        sup.EndTime = (long)((p.End - 1) * 90.0);
                        subtitles.Add(sup);

                        // fix overlapping
                        if (subtitles.Count > 1 && sub[subtitles.Count - 2].End > sub[subtitles.Count - 1].Start)
                        {
                            subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
                        }
                    }

                    ms.Close();
                }
                else if (subtitles.Count > 0)
                {
                    var lastSub = subtitles[subtitles.Count - 1];
                    if (lastSub.StartTime == lastSub.EndTime)
                    {
                        lastSub.EndTime = (long)((p.Start - 1) * 90.0);
                        if (lastSub.EndTime - lastSub.StartTime > 1000000)
                        {
                            lastSub.EndTime = lastSub.StartTime;
                        }
                    }
                }
            }

            if (noOfErrors > 0)
            {
                MessageBox.Show(string.Format("{0} error(s) occured during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, matroska.Path);
                if (this._loading)
                {
                    formSubOcr.Icon = (Icon)this.Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }

                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    this.MakeHistoryForUndo(this._language.BeforeImportingDvdSubtitle);

                    this._subtitle.Paragraphs.Clear();
                    this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    this._subtitle.WasLoadedWithFrameNumbers = false;
                    this._subtitle.CalculateFrameNumbersFromTimeCodes(this.CurrentFrameRate);
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        this._subtitle.Paragraphs.Add(p);
                    }

                    this.ShowSource();
                    this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                    this._subtitleListViewIndex = -1;
                    this.SubtitleListview1.FirstVisibleIndex = -1;
                    this.SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    this._fileName = string.Empty;
                    this.Text = this.Title;

                    Configuration.Settings.Save();
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 19
0
        private bool LoadVobSubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show(this._language.NoSupportEncryptedVobSub);
            }

            this.ShowStatus(this._language.ParsingMatroskaFile);
            this.Refresh();
            Cursor.Current = Cursors.WaitCursor;
            var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, this.MatroskaProgress);
            TaskbarList.SetProgressState(this.Handle, TaskbarButtonProgressFlags.NoProgress);
            Cursor.Current = Cursors.Default;

            this.MakeHistoryForUndo(this._language.BeforeImportFromMatroskaFile);
            this._subtitleListViewIndex = -1;
            this._subtitle.Paragraphs.Clear();

            List<VobSubMergedPack> mergedVobSubPacks = new List<VobSubMergedPack>();
            Idx idx = new Idx(matroskaSubtitleInfo.CodecPrivate.SplitToLines());
            foreach (var p in sub)
            {
                if (matroskaSubtitleInfo.ContentEncodingType == 0)
                {
                    // compressed with zlib
                    bool error = false;
                    MemoryStream outStream = new MemoryStream();
                    var outZStream = new ZOutputStream(outStream);
                    MemoryStream inStream = new MemoryStream(p.Data);
                    byte[] buffer = null;
                    try
                    {
                        CopyStream(inStream, outZStream);
                        buffer = new byte[outZStream.TotalOut];
                        outStream.Position = 0;
                        outStream.Read(buffer, 0, buffer.Length);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
                        error = true;
                    }
                    finally
                    {
                        outZStream.Close();
                        inStream.Close();
                    }

                    if (!error && buffer.Length > 2)
                    {
                        mergedVobSubPacks.Add(new VobSubMergedPack(buffer, TimeSpan.FromMilliseconds(p.Start), 32, null));
                    }
                }
                else
                {
                    mergedVobSubPacks.Add(new VobSubMergedPack(p.Data, TimeSpan.FromMilliseconds(p.Start), 32, null));
                }

                if (mergedVobSubPacks.Count > 0)
                {
                    mergedVobSubPacks[mergedVobSubPacks.Count - 1].EndTime = TimeSpan.FromMilliseconds(p.End);
                }

                // fix overlapping (some versions of Handbrake makes overlapping time codes - thx Hawke)
                if (mergedVobSubPacks.Count > 1 && mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime > mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime)
                {
                    mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime = TimeSpan.FromMilliseconds(mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime.TotalMilliseconds - 1);
                }
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(mergedVobSubPacks, idx.Palette, Configuration.Settings.VobSubOcr, null); // TODO: language???
                if (this._loading)
                {
                    formSubOcr.Icon = (Icon)this.Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }

                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    this.ResetSubtitle();
                    this._subtitle.Paragraphs.Clear();
                    this._subtitle.WasLoadedWithFrameNumbers = false;
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        this._subtitle.Paragraphs.Add(p);
                    }

                    this.ShowSource();
                    this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                    this._subtitleListViewIndex = -1;
                    this.SubtitleListview1.FirstVisibleIndex = -1;
                    this.SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    this._fileName = Path.GetFileNameWithoutExtension(matroska.Path);
                    this._converted = true;
                    this.Text = this.Title;

                    Configuration.Settings.Save();
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            Console.WriteLine("**********************************************************************");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**  AO Item and Nano Extractor/Serializer v0.85beta                  **");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**********************************************************************");

            Console.WriteLine();

            string AOPath = string.Empty;
            bool foundAO = false;
            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return;
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception)
                {
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath = Path.Combine(AOPath, "cd_image\\data\\db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            TextWriter tw = new StreamWriter("itemnames.sql", false, Encoding.GetEncoding("windows-1252"));
            tw.WriteLine("DROP TABLE IF EXISTS `itemnames`;");
            tw.WriteLine("CREATE TABLE `itemnames` (");
            tw.WriteLine("  `AOID` int(10) NOT NULL,");
            tw.WriteLine("  `Name` varchar(250) NOT NULL,");
            tw.WriteLine("  PRIMARY KEY (`AOID`)");
            tw.WriteLine(") ENGINE=MyIsam DEFAULT CHARSET=latin1;");
            tw.WriteLine();
            tw.Close();

            Console.WriteLine("Number of Items to extract: " + extractor.GetRecordInstances(0xF4254).Length);

            // ITEM RECORD TYPE
            Console.WriteLine("Number of Nanos to extract: " + extractor.GetRecordInstances(0xFDE85).Length);

            // NANO RECORD TYPE

            // Console.WriteLine(extractor.GetRecordInstances(0xF4241).Length); // Playfields
            // Console.WriteLine(extractor.GetRecordInstances(0xF4266).Length); // Nano Strains
            // Console.WriteLine(extractor.GetRecordInstances(0xF4264).Length); // Perks

            // GetData(@"D:\c#\extractor serializer\data\items\",0xf4254);
            // GetData(@"D:\c#\extractor serializer\data\nanos\",0xfde85);
            // GetData(@"D:\c#\extractor serializer\data\playfields\",0xf4241);
            // GetData(@"D:\c#\extractor serializer\data\nanostrains\",0xf4266);
            // GetData(@"D:\c#\extractor serializer\data\perks\",0xf4264);
            var np = new NewParser();
            var rawItemList = new List<ItemTemplate>();
            var rawNanoList = new List<NanoFormula>();
            int counter = 0;
            foreach (int recnum in extractor.GetRecordInstances(0xFDE85))
            {
                if (counter == 0)
                {
                    counter = recnum;
                }

                rawNanoList.Add(np.ParseNano(0xFDE85, recnum, extractor.GetRecordData(0xFDE85, recnum), "temp.sql"));
                if ((counter % 1000) == 0)
                {
                    Console.Write("\rNano ID: " + recnum.ToString().PadLeft(9));
                }

                counter++;
            }

            Console.Write("\rNano ID: " + rawNanoList[rawNanoList.Count - 1].ID.ToString().PadLeft(9));

            File.Delete("temp.sql");
            Console.WriteLine();
            Console.WriteLine("Nanos extracted: " + rawNanoList.Count);

            List<string> ItemNamesSql = new List<string>();

            counter = 0;
            foreach (int recnum in extractor.GetRecordInstances(0xF4254))
            {
                Console.Write("\rItem ID: " + recnum.ToString().PadLeft(9));
                rawItemList.Add(np.ParseItem(0xF4254, recnum, extractor.GetRecordData(0xF4254, recnum), ItemNamesSql));
                if ((counter % 1000) == 0)
                {
                    Console.Write("\rItem ID: " + recnum.ToString().PadLeft(9));
                }

                counter++;
            }

            Console.Write("\rItem ID: " + rawItemList[rawItemList.Count - 1].ID.ToString().PadLeft(9));

            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Compacting itemnames.sql");
            TextWriter itnsql = new StreamWriter("itemnames.sql", true, Encoding.GetEncoding("windows-1252"));
            while (ItemNamesSql.Count > 0)
            {
                int count = 0;
                string toWrite = string.Empty;
                while ((count < 20) && (ItemNamesSql.Count > 0))
                {
                    if (toWrite.Length > 0)
                    {
                        toWrite += ",";
                    }

                    toWrite += ItemNamesSql[0];
                    ItemNamesSql.RemoveAt(0);
                    count++;
                }

                if (toWrite != string.Empty)
                {
                    itnsql.WriteLine("INSERT INTO itemnames VALUES " + toWrite + ";");
                }
            }

            itnsql.Close();

            // SerializationContext.Default.Serializers.Register(new AOFunctionArgumentsSerializer());
            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Creating serialized nano data file - please wait");
            Stream sf = new FileStream("nanos.dat", FileMode.Create);

            var ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            var sm = new MemoryStream();
            MessagePackSerializer<List<NanoFormula>> bf = MessagePackSerializer.Create<List<NanoFormula>>();

            var nanoList2 = new List<NanoFormula>();

            int maxnum = 5000;
            string version = GetVersion(AOPath);
            if (version == "")
            {
                return;
            }
            byte[] versionbuffer = ASCIIEncoding.ASCII.GetBytes(version);
            sm.WriteByte((byte)(versionbuffer.Length));
            sm.Write(versionbuffer, 0, versionbuffer.Length);

            byte[] buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (NanoFormula nanos in rawNanoList)
            {
                nanoList2.Add(nanos);
                if (nanoList2.Count == maxnum)
                {
                    bf.Pack(sm, nanoList2);
                    sm.Flush();
                    nanoList2.Clear();
                }
            }

            bf.Pack(sm, nanoList2);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Nanos...");
            Console.WriteLine();
            NanoHandler.CacheAllNanos("nanos.dat");
            Console.WriteLine();
            Console.WriteLine("Nanos: " + NanoHandler.NanoList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating serialized item data file - please wait");

            sf = new FileStream("items.dat", FileMode.Create);

            ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            sm = new MemoryStream();
            MessagePackSerializer<List<ItemTemplate>> bf2 = MessagePackSerializer.Create<List<ItemTemplate>>();

            List<ItemTemplate> items = new List<ItemTemplate>();

            maxnum = 5000;
            sm.WriteByte((byte)(versionbuffer.Length));
            sm.Write(versionbuffer, 0, versionbuffer.Length);

            buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (ItemTemplate it in rawItemList)
            {
                items.Add(it);
                if (items.Count == maxnum)
                {
                    bf2.Pack(sm, items);
                    sm.Flush();
                    items.Clear();
                }
            }

            bf2.Pack(sm, items);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Items...");
            Console.WriteLine();

            ItemLoader.CacheAllItems("items.dat");

            Console.WriteLine();
            Console.WriteLine("Items: " + ItemLoader.ItemList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine("Further Instructions:");
            Console.WriteLine("- Copy items.dat and nanos.dat into your CellAO folder and overwrite.");
            Console.WriteLine("- Apply itemnames.sql to your database");
            Console.WriteLine("Press Enter to exit and have fun with CellAO");
            Console.ReadLine();
        }