Beispiel #1
0
        public void Load(string strFile)
        {
            // Open palm database

            PalmDatabase pdb = new PalmDatabase();

            pdb.Load(strFile);

            // Load directory entries

            ArrayList         alsRecordData = pdb.GetRecordData();
            CompressionHeader coh;

            DirEntry[] ade = ParseDirectoryRecord(UnpackRecord((byte[])alsRecordData[0], out coh));

            // Read in the file data

            m_alsFiles.Clear();
            foreach (DirEntry de in ade)
            {
                // Decompress and write out bytes

                ArrayList alsFileBytes = new ArrayList();
                for (int i = 0; i < de.crec; i++)
                {
                    byte[] ab = UnpackRecord((byte[])alsRecordData[i + de.irec], out coh);
                    alsFileBytes.AddRange(ab);
                }

                File file = new File(de.strFile, (byte[])alsFileBytes.ToArray(typeof(byte)), coh.fCompressed, coh.cbCompressed);
                m_alsFiles.Add(file);
            }
        }
Beispiel #2
0
        static bool MergeFiles(string [] args)
        {
            if (args.Length < 4) {
                Console.WriteLine("Must specify input prc, output prc and at least one pdb.");
                return false;
            }

            // Read input prc.

            PalmDatabase pdb = new PalmDatabase();
            pdb.Load(args[2]);

            // Read pdbs.

            PalmDatabase [] apdb = new PalmDatabase[args.Length - 3];

            for (int iarg = 3; iarg < args.Length; iarg++) {
                apdb[iarg - 3] = new PalmDatabase();
                apdb[iarg - 3].Load(args[iarg]);
            }

            // Merge.

            PdbPacker.MergePdbs(pdb, apdb);

            // Write the output.

            pdb.Save(args[1]);

            return true;
        }
Beispiel #3
0
        public static void MergePdbs(PalmDatabase pdb, PalmDatabase [] apdb)
        {
            // Create directory entry.

            int irec = pdb.Count + 1;             // plus one for directory

            ArrayList alsPdbDirEntries = new ArrayList();

            for (int ipdb = 0; ipdb < apdb.Length; ipdb++)
            {
                byte [] abFilename = new byte[28];
                for (int ich = 0; ich < apdb[ipdb].Name.Length; ich++)
                {
                    abFilename[ich] = (byte)apdb[ipdb].Name[ich];
                }

                alsPdbDirEntries.AddRange(abFilename);
                alsPdbDirEntries.Add((byte)((irec >> 8) & 0xff));
                alsPdbDirEntries.Add((byte)(irec & 0xff));
                alsPdbDirEntries.Add((byte)((apdb[ipdb].Count >> 8) & 0xff));
                alsPdbDirEntries.Add((byte)(apdb[ipdb].Count & 0xff));

                irec += apdb[ipdb].Count;
            }

            alsPdbDirEntries.Add((byte)0);        // end of directory marker

            uint uiType = 0x5041434b;             // PACK

            irec = 0;
            pdb.Add((byte[])alsPdbDirEntries.ToArray(typeof(byte)), (ushort)irec, uiType);

            for (int ipdb = 0; ipdb < apdb.Length; ipdb++)
            {
                for (int irecAdd = 0; irecAdd < apdb[ipdb].Count; irecAdd++)
                {
                    irec += 1;
                    pdb.Add(apdb[ipdb][irecAdd].Data, (ushort)irec, uiType);
                }
            }
        }
        public static void MergePdbs(PalmDatabase pdb, PalmDatabase [] apdb)
        {
            // Create directory entry.

            int irec = pdb.Count + 1; // plus one for directory

            ArrayList alsPdbDirEntries = new ArrayList();
            for (int ipdb = 0; ipdb < apdb.Length; ipdb++) {

                byte [] abFilename = new byte[28];
                for (int ich = 0; ich < apdb[ipdb].Name.Length; ich++)
                    abFilename[ich] = (byte)apdb[ipdb].Name[ich];

                alsPdbDirEntries.AddRange(abFilename);
                alsPdbDirEntries.Add((byte)((irec >> 8) & 0xff));
                alsPdbDirEntries.Add((byte)(irec & 0xff));
                alsPdbDirEntries.Add((byte)((apdb[ipdb].Count >> 8) & 0xff));
                alsPdbDirEntries.Add((byte)(apdb[ipdb].Count & 0xff));

                irec += apdb[ipdb].Count;
            }

            alsPdbDirEntries.Add((byte)0); // end of directory marker

            uint uiType = 0x5041434b; // PACK

            irec = 0;
            pdb.Add((byte[])alsPdbDirEntries.ToArray(typeof(byte)), (ushort)irec, uiType);

            for (int ipdb = 0; ipdb < apdb.Length; ipdb++) {
                for (int irecAdd = 0; irecAdd < apdb[ipdb].Count; irecAdd++) {
                    irec += 1;
                    pdb.Add(apdb[ipdb][irecAdd].Data, (ushort)irec, uiType);
                }
            }
        }
        public void Save(string strFilePdb, string strCreatorId, string strTypeId)
        {
            // First sort all the files by name

            string[] astrFileNames = new string[m_alsFiles.Count];
            for (int iFile = 0; iFile < m_alsFiles.Count; iFile++) {
                File file = (File)m_alsFiles[iFile];
                astrFileNames[iFile] = file.str.ToLower();
            }
            File[] afile = (File[])m_alsFiles.ToArray(typeof(File));
            Array.Sort(astrFileNames, afile, new FilenameComparer());

            // Create the record bytes

            ArrayList alsDirEntries = new ArrayList();
            ArrayList alsRecords = new ArrayList();
            ushort irec = 1;
            foreach (File file in afile) {
                // Get filename only, check length

                string strFile = file.str.ToLower();
                if (strFile.Length >= s_cbFilenameMax)
                    throw new Exception("The file " + strFile + " is too long. Must be " + (s_cbFilenameMax - 1) + "chars max.");

                // Read the file into chunks

                BinaryReader brdr = new BinaryReader(new MemoryStream(file.ab));
                byte crec = 0;
                while (brdr.BaseStream.Position < brdr.BaseStream.Length) {
                    int cbLeft = (int)(brdr.BaseStream.Length - brdr.BaseStream.Position);
                    int cbRead = cbLeft < s_cbRecordMax ? cbLeft : s_cbRecordMax;
                    byte[] abChunk = brdr.ReadBytes(cbRead);
                    alsRecords.Add(PackRecord(abChunk, file.fCompress));
                    crec++;
                }
                brdr.Close();

                // Make a directory entry for this file

                DirEntry de = new DirEntry();
                de.strFile = strFile;
                de.irec = irec;
                de.crec = crec;
                alsDirEntries.Add(de);
                irec += de.crec;

            #if false
                Console.WriteLine(de.strFile + ", " + de.crec + " recs");
            #endif
            }

            // Insert the record for the directory entries

            alsRecords.Insert(0, PackRecord(MakeDirectoryRecord(alsDirEntries), false));

            // Create and save a .pdb around these records

            PalmDatabase pdb = new PalmDatabase();
            pdb.SetRecordData(alsRecords);
            pdb.Name = Path.GetFileName(Path.GetFullPath(strFilePdb));
            pdb.CreatorId = IdFromString(strCreatorId);
            pdb.TypeId = IdFromString(strTypeId);
            pdb.Save(strFilePdb);
        }
        public void Load(string strFile)
        {
            // Open palm database

            PalmDatabase pdb = new PalmDatabase();
            pdb.Load(strFile);

            // Load directory entries

            ArrayList alsRecordData = pdb.GetRecordData();
            CompressionHeader coh;
            DirEntry[] ade = ParseDirectoryRecord(UnpackRecord((byte[])alsRecordData[0], out coh));

            // Read in the file data

            m_alsFiles.Clear();
            foreach (DirEntry de in ade) {
                // Decompress and write out bytes

                ArrayList alsFileBytes = new ArrayList();
                for (int i = 0; i < de.crec; i++) {
                    byte[] ab = UnpackRecord((byte[])alsRecordData[i + de.irec], out coh);
                    alsFileBytes.AddRange(ab);
                }

                File file = new File(de.strFile, (byte[])alsFileBytes.ToArray(typeof(byte)), coh.fCompressed, coh.cbCompressed);
                m_alsFiles.Add(file);
            }
        }
Beispiel #7
0
        public void Save(string strFilePdb, string strCreatorId, string strTypeId)
        {
            // First sort all the files by name

            string[] astrFileNames = new string[m_alsFiles.Count];
            for (int iFile = 0; iFile < m_alsFiles.Count; iFile++)
            {
                File file = (File)m_alsFiles[iFile];
                astrFileNames[iFile] = file.str.ToLower();
            }
            File[] afile = (File[])m_alsFiles.ToArray(typeof(File));
            Array.Sort(astrFileNames, afile, new FilenameComparer());

            // Create the record bytes

            ArrayList alsDirEntries = new ArrayList();
            ArrayList alsRecords    = new ArrayList();
            ushort    irec          = 1;

            foreach (File file in afile)
            {
                // Get filename only, check length

                string strFile = file.str.ToLower();
                if (strFile.Length >= s_cbFilenameMax)
                {
                    throw new Exception("The file " + strFile + " is too long. Must be " + (s_cbFilenameMax - 1) + "chars max.");
                }

                // Read the file into chunks

                BinaryReader brdr = new BinaryReader(new MemoryStream(file.ab));
                byte         crec = 0;
                while (brdr.BaseStream.Position < brdr.BaseStream.Length)
                {
                    int    cbLeft  = (int)(brdr.BaseStream.Length - brdr.BaseStream.Position);
                    int    cbRead  = cbLeft < s_cbRecordMax ? cbLeft : s_cbRecordMax;
                    byte[] abChunk = brdr.ReadBytes(cbRead);
                    alsRecords.Add(PackRecord(abChunk, file.fCompress));
                    crec++;
                }
                brdr.Close();

                // Make a directory entry for this file

                DirEntry de = new DirEntry();
                de.strFile = strFile;
                de.irec    = irec;
                de.crec    = crec;
                alsDirEntries.Add(de);
                irec += de.crec;

#if false
                Console.WriteLine(de.strFile + ", " + de.crec + " recs");
#endif
            }

            // Insert the record for the directory entries

            alsRecords.Insert(0, PackRecord(MakeDirectoryRecord(alsDirEntries), false));

            // Create and save a .pdb around these records

            PalmDatabase pdb = new PalmDatabase();
            pdb.SetRecordData(alsRecords);
            pdb.Name      = Path.GetFileName(Path.GetFullPath(strFilePdb));
            pdb.CreatorId = IdFromString(strCreatorId);
            pdb.TypeId    = IdFromString(strTypeId);
            pdb.Save(strFilePdb);
        }