diff --git a/palm-client/Makefile b/palm-client/Makefile index a439161..0fbaaa4 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -11,7 +11,7 @@ APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c +SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c OBJS = $(SRCS:src/%.c=build/%.o) CC = m68k-palmos-gcc diff --git a/palm-client/src/app.h b/palm-client/src/app.h index 5d244cf..264ba6e 100644 --- a/palm-client/src/app.h +++ b/palm-client/src/app.h @@ -19,7 +19,9 @@ void AppOpenConversation(const VmConv *conv); /* * Loads/saves the link choice (USB or serial, so the app reconnects the same way) - * and the UTC offset (the Visor's clock has no time zone). + * and the UTC offset (the Visor's clock has no time zone). AppLoadPrefs also + * loads every module's own prefs (sounds, mutes, scopes, pins): the + * closed-app check (BgCheckRun) relies on it, so add new ones there. */ void AppLoadPrefs(void); void AppSavePrefs(void); diff --git a/palm-client/src/channels.c b/palm-client/src/channels.c index b98c7d8..b9d9428 100644 --- a/palm-client/src/channels.c +++ b/palm-client/src/channels.c @@ -1,4 +1,5 @@ #include +#include "db.h" #include "protocol.h" #include "session.h" #include "channels.h" @@ -14,28 +15,12 @@ static void RefileMessages(UInt16 oldCount, UInt8 maxChannels) VM_SECT2; static Char DB_NAME[] = "VisorMeshChannels"; static Char kEmpty[] = ""; #define DB_TYPE 'chan' -#define DB_CREATOR 'VMsh' static DmOpenRef gDb = 0; Err ChannelsOpen(void) { - LocalID id; - Err err; - - if (gDb) - return errNone; - id = DmFindDatabase(0, DB_NAME); - if (!id) { - err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false); - if (err != errNone) - return err; - id = DmFindDatabase(0, DB_NAME); - if (!id) - return DmGetLastErr(); - } - gDb = DmOpenDatabase(0, id, dmModeReadWrite); - return gDb ? errNone : DmGetLastErr(); + return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb); } void ChannelsClose(void) diff --git a/palm-client/src/contacts.c b/palm-client/src/contacts.c index 0aafaaf..2019695 100644 --- a/palm-client/src/contacts.c +++ b/palm-client/src/contacts.c @@ -1,4 +1,5 @@ #include +#include "db.h" #include "protocol.h" #include "session.h" #include "contacts.h" @@ -12,33 +13,13 @@ static Err UpsertContact(const VmContact *c, void *ctx) VM_SECT4; /* a data array, not a literal: this module is in the second code segment (sections.h) */ static Char DB_NAME[] = "VisorMeshContacts"; #define DB_TYPE 'cont' -#define DB_CREATOR 'VMsh' static DmOpenRef gDb = 0; static UInt32 gLastMod = 0; /* newest lastmod of the last download in this run; 0: none yet */ Err ContactsOpen(void) { - LocalID id; - UInt16 attrs; - Err err; - - if (gDb) - return errNone; - id = DmFindDatabase(0, DB_NAME); - if (!id) { - err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false); - if (err != errNone) - return err; - id = DmFindDatabase(0, DB_NAME); - if (!id) - return DmGetLastErr(); - DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - attrs |= dmHdrAttrBackup; - DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - } - gDb = DmOpenDatabase(0, id, dmModeReadWrite); - return gDb ? errNone : DmGetLastErr(); + return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb); } void ContactsClose(void) diff --git a/palm-client/src/db.c b/palm-client/src/db.c new file mode 100644 index 0000000..ea9c0aa --- /dev/null +++ b/palm-client/src/db.c @@ -0,0 +1,25 @@ +#include +#include "app.h" +#include "db.h" + +Err DbOpen(const Char *name, UInt32 type, DmOpenRef *db) +{ + LocalID id = DmFindDatabase(0, name); + UInt16 attrs; + Err err; + + *db = 0; + if (!id) { + err = DmCreateDatabase(0, name, VM_CREATOR, type, false); + if (err != errNone) + return err; + id = DmFindDatabase(0, name); + if (!id) + return DmGetLastErr(); + DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + attrs |= dmHdrAttrBackup; + DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + } + *db = DmOpenDatabase(0, id, dmModeReadWrite); + return *db ? errNone : DmGetLastErr(); +} diff --git a/palm-client/src/db.h b/palm-client/src/db.h new file mode 100644 index 0000000..38557db --- /dev/null +++ b/palm-client/src/db.h @@ -0,0 +1,14 @@ +/* + * The app's record databases (messages, contacts, channels): open one, + * creating it with the backup bit (HotSync keeps a copy) the first time. + */ +#ifndef VM_DB_H +#define VM_DB_H + +#include +#include "sections.h" + +/* Opens name read/write into *db (0 on error), creating it with VM_CREATOR and type if missing. */ +Err DbOpen(const Char *name, UInt32 type, DmOpenRef *db) VM_SECT4; + +#endif diff --git a/palm-client/src/messages.c b/palm-client/src/messages.c index 143e994..db6535d 100644 --- a/palm-client/src/messages.c +++ b/palm-client/src/messages.c @@ -1,4 +1,5 @@ #include +#include "db.h" #include "protocol.h" #include "ui/text.h" #include "messages.h" @@ -14,7 +15,6 @@ static void TagChannel(VmConv *conv) VM_SECT2; /* a data array, not a literal: this module is in the second code segment (sections.h) */ static Char DB_NAME[] = "VisorMeshMessages"; #define DB_TYPE 'msgs' -#define DB_CREATOR 'VMsh' #define TEXT_MAX (VM_MAX_FRAME + 1) static DmOpenRef gDb = 0; @@ -27,26 +27,7 @@ static UInt32 gNextAckDeadline = 1; Err MessagesOpen(void) { - LocalID id; - UInt16 attrs; - Err err; - - if (gDb) - return errNone; - id = DmFindDatabase(0, DB_NAME); - if (!id) { - err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false); - if (err != errNone) - return err; - id = DmFindDatabase(0, DB_NAME); - if (!id) - return DmGetLastErr(); - DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - attrs |= dmHdrAttrBackup; - DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - } - gDb = DmOpenDatabase(0, id, dmModeReadWrite); - return gDb ? errNone : DmGetLastErr(); + return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb); } void MessagesClose(void) diff --git a/palm-client/src/session.c b/palm-client/src/session.c index a75d194..f8db1d3 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -1,3 +1,8 @@ +/* + * In the first code segment, and it must stay there: the reply-code tables + * are static const inside functions, which read as garbage from an extra + * segment (sections.h). It's also on the closed-app check's path. + */ #include #include "protocol.h" #include "transport.h"