> I'm trying write an application which can copy an existing file (PRC or PDB) > in a Palm device. > Here I'm using Beaming technology used in Palm OS, namely ExgDBRead, and > ExgDBWrite. > Although this technology is used, the app will be run in a single device. I > found that this would be the easiest method to read a file since I do not > know the record structure of the file to be copied.
What are you trying to do? It seems like you're trying to duplicate a database on the device, giving the duplicate a different database name, type, and creator ID. I'm not sure why you want to do this. You don't need to change the type or creator ID. The only uniqueness criterion for databases is the database name. You can have multiple databases with the same type and creator, but you can only have one database with a given name, even if you use different types and creators. To duplicate an arbitrary database using ExgDBRead and ExgDBWrite, you probably want to use a FileStream to buffer the PDB or PRC. You can modify the database name as the PDB or PRC is being written or as it's being read. Let's assume the latter; it doesn't really matter. Keep track of how many bytes you've read using a global variable. Every time your callback reads data out of the FileStream, add the number of bytes read to this global variable. If the range of offsets overlaps [0..31], then you need to modify a portion of the buffer before you return. (The database name occupies the first 32 bytes of the PDB or PRC.) You shouldn't assume that the entire database name will be read in a single call to your callback, although in practice it always will be. One problem with this approach is that you need about 200K free to duplicate a 100K database. This is true even if you use destructive read mode on the FileStream because of a bug in ExgDBRead. An alternative approach is to copy the database record by record (or resource by resource). You start by creating a database with the appropriate name. Then you use DmDatabaseInfo and DmSetDatabaseInfo to copy the database attributes. If the database has a sort info block or app info block, you'll need to copy these. Finally, you create records or resources corresponding to the originals, using DmWrite to copy the contents and DmRecordInfo and DmSetRecordInfo to copy the attributes, including the unique IDs if you want. (There are similar APIs for resources.) This approach will probably take more code, but it'll run faster and it won't require any extra space. Which approach to use depends on the application - it's a trade-off. > but there seems to be a problem with the code I written. You're using a database to buffer the data. This is needlessly complex; use a FileStream instead. Also, you're not returning the number of bytes requested, but the number of bytes in the next record of your buffer database. You should always return what your callback is asked for, unless you run out of data. You're counting calls to your callback rather than bytes. As I explained above, this is risky. You're modifying a byte at offset 0, which is the database name. That's good. You're also modifying 5 bytes at offset 60, which is the type and the first byte of the creator. This isn't needed. -- Danny @ Palm -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
