Exemplo n.º 1
0
        static bool UnpackFiles(string strFilePdb)
        {
            // Open pack pdb

            PdbPacker pdbp = new PdbPacker(strFilePdb);

            // For each file...

            for (int iFile = 0; iFile < pdbp.Count; iFile++)
            {
                PdbPacker.File file = pdbp[iFile];
                BinaryWriter   bwtr = new BinaryWriter(new FileStream(file.str, FileMode.Create, FileAccess.Write, FileShare.None));
                bwtr.Write(file.ab);
                bwtr.Close();
                Console.WriteLine("Wrote " + file.str + ", " + file.ab.Length + " bytes.");
            }

            return(true);
        }
Exemplo n.º 2
0
        static bool ViewFiles(string strFilePdb)
        {
            // Open pack pdb

            PdbPacker pdbp = new PdbPacker(strFilePdb);

            // For each file...

            for (int iFile = 0; iFile < pdbp.Count; iFile++)
            {
                PdbPacker.File file            = pdbp[iFile];
                int            cbCompressed    = file.GetCompressedSize();
                int            cbUncompressed  = (int)file.ab.Length;
                int            nPercentSavings = ((cbUncompressed - cbCompressed) * 100 + cbCompressed / 2) / cbCompressed;
                Console.WriteLine(file.str + ", " + cbUncompressed + " bytes, " + cbCompressed + " bytes compressed, " + nPercentSavings + "% savings");
            }

            return(true);
        }
Exemplo n.º 3
0
        public static void ImportExpansionPdb(string strFile)
        {
            PdbPacker pdbp = new PdbPacker(strFile);

            ArrayList alsTileSets = new ArrayList();

            for (int i = 0; i < pdbp.Count; i++)
            {
                PdbPacker.File file = pdbp[i];
                if (!file.str.EndsWith(".lvl"))
                {
                    continue;
                }

                // Load up the pieces

                Ini     ini = Ini.LoadBinary(new MemoryStream(file.ab));
                string  strTileMapFilename = ini["General"]["TileMap"].Value;
                TileMap tmap = TileMap.Load(new MemoryStream(pdbp[strTileMapFilename].ab));


                // First, tell the active LevelDoc not to switch its templates based on the following
                // template load

                LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = false;
                }

                // If the TileSet for this level is not yet available, load it now

                TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(tmap.Filename.Replace(".tset", ".tc"));
                TileSet     tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.FileName == tmap.Filename)
                    {
                        tset = tsetT;
                        break;
                    }
                }
                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmap.Filename);
                    alsTileSets.Add(tset);
                }

                // Re-enable template switching

                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = true;
                }

                // Create a new level description, and deduce which templates are in it, with what visibility

                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                lvld.OutputFilename = file.str;
                ImportTileMap(tmap, tset, tmpd, lvld);

                // Walls are stored in the terrain map. Load them.
                string     strTrmapFilename = ini["General"]["TerrainMap"].Value;
                TerrainMap trmap            = TerrainMap.Load(new MemoryStream(pdbp[strTrmapFilename].ab));
                ImportWalls(trmap, lvld);

                // Load everything else
                lvld.LoadIni(ini);
            }
        }
Exemplo n.º 4
0
        static bool PackFiles(string[] args)
        {
            // Parse parameters, validate.

            if (args[1].Length > 4)
            {
                Console.WriteLine("Creator id " + args[1] + " must be 4 chars or less.");
                return(false);
            }
            string strCreatorId   = args[1];
            string strFullPathPdb = Path.GetFullPath(args[2]);
            string strFilePdb     = Path.GetFileName(strFullPathPdb);
            string strDirPdb      = Path.GetDirectoryName(strFullPathPdb);

            if (strDirPdb == "")
            {
                strDirPdb = ".";
            }
            if (strFilePdb.Length > 31)
            {
                Console.WriteLine("Pdb filename " + strFilePdb + " must be 31 characters or less.");
                return(false);
            }
            string strFileSpec;

            if (args.Length == 3)
            {
                strFileSpec = ".\\*.*";
            }
            else
            {
                strFileSpec = args[3];
            }

            // Get list of files to add

            string strFileFileSpecAdd = Path.GetFileName(strFileSpec);
            string strDirFileSpecAdd  = Path.GetDirectoryName(strFileSpec);

            if (strDirFileSpecAdd == "")
            {
                strDirFileSpecAdd = ".";
            }
            string[] astrFilesAdd = Directory.GetFiles(strDirFileSpecAdd, strFileFileSpecAdd);

            // File types not to compress

            ArrayList alsStrFilesNoCompress = new ArrayList();

            if (args.Length > 4)
            {
                if (args[4] == "-nocompress")
                {
                    for (int i = 5; i < args.Length; i++)
                    {
                        string[] astrFiles = Directory.GetFiles(strDirFileSpecAdd, args[i]);
                        foreach (string str in astrFiles)
                        {
                            alsStrFilesNoCompress.Add(Path.GetFullPath(str));
                        }
                    }
                }
            }

            // Print status

            Console.Write("Packing files... ");
            PdbPacker pdbp = new PdbPacker();

            foreach (string strFileAdd in astrFilesAdd)
            {
                // Don't add the .pdb we're building

                string strFullPathAdd = Path.GetFullPath(strFileAdd);
                if (strFullPathPdb.ToLower() == strFullPathAdd.ToLower())
                {
                    continue;
                }

                // Get filename only, check length

                string strFile = Path.GetFileName(strFullPathAdd).ToLower();
                if (strFile.Length >= s_cbFilenameMax)
                {
                    Console.WriteLine("The file " + strFile + " is too long. Must be " + (s_cbFilenameMax - 1) + "chars max.");
                    return(false);
                }

                // Compress or not?

                bool fCompress = true;
                foreach (string strFileNoCompress in alsStrFilesNoCompress)
                {
                    if (strFullPathAdd.ToLower() == strFileNoCompress.ToLower())
                    {
                        fCompress = false;
                        break;
                    }
                }

                // Read the file

                Stream         stm  = new FileStream(strFullPathAdd, FileMode.Open, FileAccess.Read);
                BinaryReader   brdr = new BinaryReader(stm);
                PdbPacker.File file = new PdbPacker.File(strFile, brdr.ReadBytes((int)brdr.BaseStream.Length), fCompress);
                brdr.Close();
                pdbp.Add(file);
            }

            // Save out

            pdbp.Save(strFullPathPdb, strCreatorId);
            return(true);
        }