Steve Chaplin wrote:
The Palm does not seem to copy applications from the SD card
if they already reside in memory. Is there a way to force the
application to be copied from the SD card every time?

As far as I know, there is no way to simply tell Palm OS that
you want it to do this.

So, if you want to do it, you'll have to do it manually.

Doing it manually is a tricky proposition, you don't want to
mistakenly do any of the following in the process:

  * delete the in-RAM version if a version doesn't exist
    on SD Card or can't be successfully read from SD Card
  * delete a newer version in RAM if a newer version exists
    there than exists on the SD Card
  * go into an infinite loop (obviously, but it is something
    that's possible since you must exit the app to delete it
    and then come back in)

Anyway, I think I have a method that should work.

There are some key things that work in your favor:
(1)  You can't delete the app from within itself, but you
     can launch another app that will do it, and then
     you can have that one launch the app again (although
     launching from the card may be a bit difficult)
(2)  You can create another app by putting its PRC (in the
     normal desktop format) into a resource record in your
     app and then doing DmCreateDatabaseFromImage().
(3)  You can distinguish between a card launch and an in-memory
     launch because you get either sysAppLaunchCmdCardLaunch
     or sysAppLaunchCmdNormalLaunch launch code depending on
     the type of launch.

Therefore, if you have gotten a sysAppLaunchCmdCardLaunch,
then you know there's a chance you are running a stale copy,
and you should then check.

The exact sequence you should go through seems a little
tricky.  You don't want an infinite loop where you launch
from card and then switch to the app that deletes your app
from memory, then it deletes you, and then relaunches you
from card, and then you start the process over again.

So, I believe the following should work:
1.  When you get the sysAppLaunchCmdCardLaunch, use
    DmCreateDatabaseFromImage() to extract the app that
    is supposed to delete your app.
3.  Use SysUIAppSwitch() to switch to that other app.
4.  In that other app, removes the main app's database
    with DmDeleteDatabase().
5.  The other app then re-copies the database from the card
    to storage heap using the pathname supplied in the
    parameter block that came with sysAppLaunchCmdCardLaunch
    (you will have to stash this info somewhere) and the
    VFSImportDatabaseFromFile() function.
6.  The other app then launches your app with SysUIAppSwitch()
    and a custom launch code that means "hey, you are running
    from card, but don't worry about being a stale copy, because
    that's already taken care of".
7.  When, in the regular app, you get the custom launch code,
    you just behave like a regular launch, except you also
    delete the other secondary app, since it has served
    its purpose and you don't want it cluttering up the device.

I'm not 100% sure precisely whether the above process is going to
cause your main app to be deleted from memory after it exits.
I *think* the cleanup after a card launch happens in the launcher
(not in the system), but I wouldn't swear to it.  If it happens
in the launcher, it might be that the launcher won't find out
that your app has exited until control returns to the launcher,
and maybe it will delete your main app for you.  Or, it might
not.  The difficulty is that it's hard to delete the main app
after it exits:  when it's time for the main app to exit, it's
because someone has requested for another app to start, and if
you go exiting the main app and then trying to launch a secondary
app to clean up the main app (which is the only method I can
think of), it seems like that might throw off the process of
launching the app that the user requested (which is what
caused you to have to exit in the first place).

Wow, there really seems to be no clean solution to this...  :-)

  - Logan

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

Reply via email to