Skip to content

Commit c2f8ed8

Browse files
committed
Add a RAM wipe option
1 parent dcbb2bc commit c2f8ed8

File tree

4 files changed

+119
-64
lines changed

4 files changed

+119
-64
lines changed

Rsc/PIMSync_Rsc.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/* pilrc generated file. Do not edit!*/
2-
#define AboutVersionLabel 1022
3-
#define AboutDescriptionLabel 1021
4-
#define AboutOKButton 1020
5-
#define AboutForm 1019
6-
#define DEBUG_ALERT 1018
7-
#define DELETE_ALERT 1017
8-
#define MainHelpButton 1016
9-
#define MainFromSDSubtitleLabel 1015
10-
#define MainFromSDTitleLabel 1014
11-
#define MainFromSDButton 1013
12-
#define MainToSDSubtitleLabel 1012
13-
#define MainToSDTitleLabel 1011
14-
#define MainToSDButton 1010
15-
#define MainSubtitleLabel 1009
16-
#define MainTitleLabel 1008
17-
#define MainForm 1007
18-
#define RomIncompatibleAlert 1006
19-
#define OptionsAbout 1005
2+
#define AboutVersionLabel 1024
3+
#define AboutDescriptionLabel 1023
4+
#define AboutOKButton 1022
5+
#define AboutForm 1021
6+
#define DEBUG_ALERT 1020
7+
#define WIPE_ALERT 1019
8+
#define DELETE_ALERT 1018
9+
#define MainHelpButton 1017
10+
#define MainFromSDSubtitleLabel 1016
11+
#define MainFromSDTitleLabel 1015
12+
#define MainFromSDButton 1014
13+
#define MainToSDSubtitleLabel 1013
14+
#define MainToSDTitleLabel 1012
15+
#define MainToSDButton 1011
16+
#define MainSubtitleLabel 1010
17+
#define MainTitleLabel 1009
18+
#define MainForm 1008
19+
#define RomIncompatibleAlert 1007
20+
#define OptionsAbout 1006
21+
#define OptionsWipe 1005
2022
#define MainMenuBar 1004
2123
#define ToSDBitmapFamily 1003
2224
#define FromSDBitmapFamily 1002

Rsc/PIMSync_Rsc.rcp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DATA "code" ID 1 "code0001.bin"
88
GENERATEHEADER "Rsc/PIMSync_Rsc.h"
99

1010
APPLICATIONICONNAME ID 1000 "PIMSync"
11-
VERSION ID 1 "0.2"
11+
VERSION ID 1 "0.3"
1212

1313
RESETAUTOID 1000
1414

@@ -30,11 +30,15 @@ END
3030

3131
MENU ID MainMenuBar
3232
BEGIN
33-
PULLDOWN "Options"
33+
PULLDOWN "Danger"
3434
BEGIN
35-
MENUITEM "About" ID OptionsAbout
35+
MENUITEM "Wipe PIM in RAM" ID OptionsWipe
3636
END
3737

38+
PULLDOWN "About"
39+
BEGIN
40+
MENUITEM "Help" ID OptionsAbout
41+
END
3842
END
3943

4044
ALERT ID RomIncompatibleAlert
@@ -73,6 +77,14 @@ BEGIN
7377
BUTTONS "Yes" "No"
7478
END
7579

80+
ALERT ID WIPE_ALERT
81+
WARNING
82+
BEGIN
83+
TITLE "Danger"
84+
MESSAGE "This will DELETE all the memos, todos, addresses and datebook records in RAM! Are you mad?"
85+
BUTTONS "Yes, continue" "No, cancel"
86+
END
87+
7688
ALERT ID DEBUG_ALERT
7789
CONFIRMATION
7890
BEGIN
@@ -89,6 +101,6 @@ BEGIN
89101
BUTTON "OK" ID AboutOKButton AT (55 142 40 12)
90102
FORMBITMAP AT (50 86) BITMAP PIMSyncBitmapFamily
91103
LABEL "PIMSync allows you to use the SD\rcard to transfer the memo, address\rbook, todo and datebook databases\rfrom your Palm OS device and back.\rYou can use this workflow with\rprograms like J-Pilot on the PC." ID AboutDescriptionLabel AT (5 16)
92-
LABEL "V: 0.2" ID AboutVersionLabel AT (132 145)
104+
LABEL "V: 0.3" ID AboutVersionLabel AT (132 145)
93105
END
94106

Src/Main.c

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,23 @@ static Boolean MainFormDoCommand(UInt16 command)
3030
break;
3131
}
3232

33+
case OptionsWipe:
34+
{
35+
HandleWipe();
36+
handled = true;
37+
break;
38+
}
39+
3340
case MainFromSDButton:
3441
{
35-
handleFromSD();
42+
HandleFromSD();
3643
handled = true;
3744
break;
3845
}
3946

4047
case MainToSDButton:
4148
{
42-
handleToSD();
49+
HandleToSD();
4350
handled = true;
4451
break;
4552
}
@@ -179,9 +186,8 @@ static void CopyFromSDDir( UInt16 volRefNum, Char* dir, Messager Message, UInt32
179186
UInt32 type;
180187
Char dbName[ dmDBNameLength ];
181188
Char fileName[ MAX_FILENAME ];
182-
LocalID id;
183189
UInt16 card;
184-
Int16 i;
190+
LocalID id;
185191

186192
err = VFSDirEntryEnumerate( dirRef, &iterator, &info );
187193

@@ -225,39 +231,7 @@ static void CopyFromSDDir( UInt16 volRefNum, Char* dir, Messager Message, UInt32
225231

226232
VFSFileClose( fileRef );
227233

228-
for ( i = MemNumCards() - 1 ; 0 <= i ; i-- ) {
229-
id = DmFindDatabase( i, dbName );
230-
if ( id != NULL ) {
231-
232-
if ( errNone != DmDeleteDatabase( i, id ) ) {
233-
SysNotifyDBInfoType d;
234-
Boolean deleted = false;
235-
236-
if ( errNone == DmDatabaseInfo( i, id, d.dbName, &( d.attributes ), NULL, NULL,
237-
NULL, NULL, NULL, NULL, NULL, &d.type, &d.creator ) ) {
238-
SysNotifyParamType n;
239-
240-
MemSet( &n, sizeof( n ), 0 );
241-
n.notifyType = sysNotifyDeleteProtectedEvent;
242-
n.broadcaster = appFileCreator;
243-
d.dbID = id;
244-
d.cardNo = i;
245-
n.notifyDetailsP = &d;
246-
247-
SysNotifyBroadcast( &n );
248-
249-
if ( errNone == DmDeleteDatabase( i, id ) ) {
250-
deleted = true;;
251-
}
252-
}
253-
if ( ! deleted ) {
254-
if ( missingP != NULL )
255-
*missingP = true;
256-
continue;
257-
}
258-
}
259-
}
260-
}
234+
DeleteDB(dbName, missingP);
261235

262236
err = VFSImportDatabaseFromFile(
263237
volRefNum,
@@ -376,7 +350,57 @@ void CopyFromSD( UInt16 vol, Messager Message, UInt32 cookie, Boolean* copiedP,
376350
}
377351
}
378352

379-
void handleFromSD()
353+
void DeleteDB( Char* dbName, Boolean* missingP )
354+
{
355+
LocalID id;
356+
Int16 i;
357+
358+
for ( i = MemNumCards() - 1 ; 0 <= i ; i-- ) {
359+
id = DmFindDatabase( i, dbName );
360+
if ( id != NULL ) {
361+
362+
if ( errNone != DmDeleteDatabase( i, id ) ) {
363+
SysNotifyDBInfoType d;
364+
Boolean deleted = false;
365+
366+
if ( errNone == DmDatabaseInfo( i, id, d.dbName, &( d.attributes ), NULL, NULL,
367+
NULL, NULL, NULL, NULL, NULL, &d.type, &d.creator ) ) {
368+
SysNotifyParamType n;
369+
370+
MemSet( &n, sizeof( n ), 0 );
371+
n.notifyType = sysNotifyDeleteProtectedEvent;
372+
n.broadcaster = appFileCreator;
373+
d.dbID = id;
374+
d.cardNo = i;
375+
n.notifyDetailsP = &d;
376+
377+
SysNotifyBroadcast( &n );
378+
379+
if ( errNone == DmDeleteDatabase( i, id ) ) {
380+
deleted = true;;
381+
}
382+
}
383+
if ( ! deleted ) {
384+
if ( missingP != NULL )
385+
*missingP = true;
386+
continue;
387+
}
388+
}
389+
}
390+
}
391+
}
392+
393+
void WipeInRAM( Messager Message, UInt32 cookie, Boolean* missingP )
394+
{
395+
Char *dbsToWipe[NUM_DBS+1] = DBS_TO_COPY;
396+
397+
for ( UInt32 i = 0; i < NUM_DBS; i++) {
398+
DeleteDB(dbsToWipe[i], missingP);
399+
}
400+
Message("Wiped", cookie);
401+
}
402+
403+
void HandleFromSD()
380404
{
381405
Boolean copied;
382406
Boolean missing;
@@ -388,11 +412,22 @@ void handleFromSD()
388412
}
389413
}
390414

391-
void handleToSD()
415+
void HandleToSD()
392416
{
393417
Boolean copied;
394418
Boolean missing;
395419
StatusMessage("Copying the PIM files...", 0);
396420
CopyToSD( ALL_VOLUMES, StatusMessage, 0, &copied, &missing );
397421
}
398422

423+
void HandleWipe()
424+
{
425+
UInt8 selection;
426+
Boolean missing;
427+
428+
selection = FrmAlert( WIPE_ALERT );
429+
if ( selection == 0 ) {
430+
WipeInRAM(StatusMessage, 0, &missing);
431+
}
432+
}
433+

Src/PIMSync.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#define appFileCreator 'PIMS'
2222
#define appName "PIMSync"
23-
#define appVersionNum 0x01
23+
#define appVersionNum 0x03
2424
#define appPrefID 0x00
2525
#define appPrefVersionNum 0x01
2626

@@ -33,9 +33,15 @@ Boolean MainFormHandleEvent(EventType * eventP);
3333
void OpenAboutDialog();
3434

3535
#define ALL_VOLUMES 0xFFFF
36+
3637
typedef void (*Messager)( const Char* s, UInt32 cookie );
3738
static void StatusMessage( const Char* s, UInt32 cookie );
39+
3840
static void CopyFromSDDir( UInt16 volRefNum, Char* dir, Messager Message, UInt32 cookie, Boolean* copiedP, Boolean* missingP );
3941
void CopyToSD( UInt16 vol, Messager Message, UInt32 cookie, Boolean* copiedP, Boolean* missingP );
40-
void handleFromSD();
41-
void handleToSD();
42+
void WipeInRAM( Messager Message, UInt32 cookie, Boolean* missingP );
43+
void DeleteDB( Char* dbName, Boolean* missingP );
44+
45+
void HandleFromSD();
46+
void HandleToSD();
47+
void HandleWipe();

0 commit comments

Comments
 (0)