Instead of my application deleting itself while running, my application renames itself to MyCoolApp_deleteme and then launches the version on the card. After being launched from the card, my application always checks for and deletes MyCoolApp_deleteme. Here's the code. Although it won't compile as-is, it should be enough to write your own:

bool checkExecutable(const char *executableName, const char *applicationName) {

        // Don't mess with this on the emulator.
        if (HostGetHostID() != hostIDPalmOS)
                return true;

        Err err;

        // Always delete the backup name first.
        char *backupName = StrDuplicate(applicationName);
        backupName = StrAppend(backupName, " Backup");
        LocalID backupLid = DmFindDatabase(0, backupName);
        if (backupLid != 0) {
                err = DmDeleteDatabase(0, backupLid);
                palmError(err);
                }

        LocalID lid = DmFindDatabase(0, applicationName);
        error(lid == 0);

        UInt32 flashDate;
err = DmDatabaseInfo(0, lid, NULL, NULL, NULL, &flashDate, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        palmError(err);

        char *path = StrDuplicate("/Palm/Launcher/");
        path = StrAppend(path, executableName);
        FileRef file = vfsFileOpen(cardno, path, vfsModeRead);

        UInt32 cardDate;
err = VFSFileDBInfo(file, NULL, NULL, NULL, &cardDate, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        palmError(err);

        vfsFileClose(file);

        // Comparing dates isn't a very reliable way to see
        // if things have changed, but it works for my situation.
        if (flashDate != cardDate) {
                const char *str = "Copying from the card...";
                WinDrawChars(str, StrLen(str), 0, 0);

err = DmSetDatabaseInfo(0, lid, backupName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
                palmError(err);
                UInt16 cardNo;
                LocalID newLid;
                err = VFSImportDatabaseFromFile(cardno, path, &cardNo, &newLid);
                palmError(err);

                err = SysUIAppSwitch(cardNo, newLid, 
sysAppLaunchCmdNormalLaunch, NULL);
                palmError(err);
                }

        delete [] path;
        delete [] backupName;

        return flashDate == cardDate;

}


// in handleNormalLaunch:
    if (!checkExecutable("MyCoolApp.prc", "My Cool App")) {

                // I don't remember why this is important, but it was
                // crashing regularly if I just returned from
                // handleNormalLaunch without clearing out the
                // event loop.
                EventType event;
                do {
                        EvtGetEvent(&event, evtWaitForever);
                        SysHandleEvent(&event);
                        } while (event.eType != appStopEvent);
                return;
                }


Ben Combee wrote:
At 09:12 PM 11/7/2005, you wrote:

Yes there is a reset when someone pulls the card and the program can no longer access the files it needs, so what you are describing is what I'm seeing. So back to the original question, I guess the answer is that if it is not deleted from system memory then I must assume that it is the result of the above, and I should delete it. So to delete a file from system memory what API do I use?


DmDeleteDatabase is the usual API... however, you'll have a hard time doing that from your program, as you'll be trying to delete yourself. You'll need some sort of helper application... however, you'll have to figure out from your app whether you were run off the card or run from main memory, which can be done based on launch codes, but gets complicated.


-- Ben Combee, Senior Software Engineer, Palm, Inc.
   "Combee on Palm OS" weblog: http://palmos.combee.net/
   Developer Forum Archives:   http://news.palmos.com/read/all_forums/





--
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to