Example #1
0
        /// <summary>
        /// Build a PDB file.
        /// </summary>
        /// <param name="dstDir">Destination Directory.</param>
        /// <param name="key">Index key.</param>
        /// <param name="list">Index list.</param>
        /// <returns>Returns the full path to the file.</returns>
        public string BuildPDBFile(string dstDir, int key, ArrayList list)
        {
            string      prevSurname = null, pdbName = "index" + hexChars[((key >> 4) & 0xf)] + hexChars[(key & 0x0f)];
            ByteBuilder bb     = new ByteBuilder(8192);
            int         recIdx = 0;
            Person      p;
            PDB         pdb;

            wizard.cStatus.Text = "Creating PDB file: " + pdbName;
            wizard.cProgressBar.PerformStep();
            Application.DoEvents();

            pdb = new PDB(pdbName);
            for (int i = 0; i < list.Count; i++)
            {
                p = (Person)list[i];
                if (prevSurname == null)
                {
                    prevSurname = p.iSurname;
                    bb.Append(p.iSurname);
                    bb.Append(0);
                    AppendPerson(recIdx, key, bb, p);
                }
                else if (p.iSurname.CompareTo(prevSurname) == 0)
                {
                    AppendPerson(recIdx, key, bb, p);
                }
                else
                {
                    pdb.AddRecord(bb.ToBytes());
                    recIdx++;
                    bb.Reset();
                    prevSurname = p.iSurname;
                    bb.Append(p.iSurname);
                    bb.Append(0);
                    AppendPerson(recIdx, key, bb, p);
                }
            }

            if (bb.Count > 0)
            {
                pdb.AddRecord(bb.ToBytes());
            }

            pdb.Write(dstDir);
            return(pdb.fullPath);
        }
Example #2
0
        /// <summary>
        /// Compact a string representation of a Phone number to packed bytes.
        /// </summary>
        /// <param name="bb">ByteBuilder.</param>
        /// <param name="src">Source (with phone no.#).</param>
        /// <returns>The bytearray with the packed number.</returns>
        private byte[] CrunchPhone(ByteBuilder bb, string src)
        {
            StringBuilder sb  = new StringBuilder();
            bool          ext = false;
            int           idx;
            char          c;
            byte          b;

            for (idx = 0; idx < src.Length; idx++)
            {
                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    sb.Append(c);
                }
                else if (c == ' ' || c == '+')
                {
                    continue;
                }
                else if (ext == false)
                {
                    sb.Append('e');
                    ext = true;
                }
            }

            src = sb.ToString();

            bb.Reset();

            idx = src.Length - 1;
            while (idx > -1)
            {
                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    b = (byte)((c - '0') << 4);
                }
                else
                {
                    b = 176;
                }

                idx--;
                if (idx < 0)
                {
                    b |= 12;
                    bb.Append(b);
                    break;
                }

                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    b |= (byte)(c - '0');
                }
                else
                {
                    b |= 11;
                }

                bb.Append(b);
                idx--;
            }

            if (bb.Count > 0)
            {
                return(bb.ToBytes(255));
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Write the phone databases.
        /// <param name="dstDir">Destination directory.</param>
        /// </summary>
        public void WritePhoneDBs(string dstDir)
        {
            string      prevKey = "", curKey;
            ByteBuilder bb = new ByteBuilder(32);
            SortedList  sl;
            int         i, j, x;
            Person      p;
            string      phone;
            PDB         pdb;
            int         idx;
            byte        b;

            for (i = 0; i < 10; i++)
            {
                sl = slPhones[i];

                if (sl.Count == 0)
                {
                    continue;
                }

                wizard.cStatus.Text = "Writing Phone database " + (i + 1);
                wizard.cProgressBar.PerformStep();

                pdb = new PDB("phones" + (char)(i + '0'));
                bb.Reset();

                for (j = 0; j < sl.Count; j++)
                {
                    Application.DoEvents();
                    if (fWizard.appStopped)
                    {
                        return;
                    }

                    phone = (string)sl.GetKey(j);
                    p     = (Person)sl.GetByIndex(j);

                    curKey = phone.Substring(1, 2);
                    phone  = phone.Substring(3);

                    if ((curKey != prevKey) || (bb.Count > 64000))
                    {
                        if (bb.Count > 0)
                        {
                            pdb.AddRecord(bb.ToBytes());
                            bb.Reset();
                        }
                        prevKey = curKey;
                        bb.Append(curKey);
                    }

                    bb.Append((ushort)p.pRecIndex);
                    bb.Append((ushort)p.pOffset);
                    bb.Append((byte)p.pKey);

                    idx = phone.Length >> 1;
                    if ((phone.Length & 1) == 1)
                    {
                        idx++;
                    }
                    bb.Append((byte)idx);

                    for (idx = 0; idx < ((phone.Length >> 1) << 1);)
                    {
                        x  = (phone[idx++] - '0') << 4;
                        b  = (byte)x;
                        x  = (phone[idx++] - '0');
                        b |= (byte)x;
                        bb.Append(b);
                    }

                    if (idx < phone.Length)
                    {
                        bb.Append((byte)((phone[idx] - '0') << 4));
                    }
                }

                if (bb.Count > 0)
                {
                    pdb.AddRecord(bb.ToBytes());
                }

                pdb.Write(dstDir);
                InstallFile(wizard.config.palmProfile, pdb.fullPath);
            }
        }