mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-17 18:12:01 +01:00
complete conversion of old format dicts to new, including for those on
SD cards. Works now unless there are same-named files on both, in which case SD card one doesn't get converted but the question keeps getting asked.
This commit is contained in:
parent
1c70dd2bb3
commit
82ef3eba3b
1 changed files with 91 additions and 45 deletions
|
@ -31,10 +31,11 @@
|
||||||
#include "palmdict.h"
|
#include "palmdict.h"
|
||||||
#include "strutils.h"
|
#include "strutils.h"
|
||||||
#include "xwords4defines.h"
|
#include "xwords4defines.h"
|
||||||
|
#include "LocalizedStrIncludes.h"
|
||||||
|
|
||||||
#define TYPE_DAWG 'DAWG'
|
#define TYPE_DAWG 'DAWG'
|
||||||
#ifdef NODE_CAN_4
|
#ifdef NODE_CAN_4
|
||||||
# define TYPE_XWRDICT 'Xwr4'
|
# define TYPE_XWRDICT 'XwrD'
|
||||||
#else
|
#else
|
||||||
# define TYPE_XWRDICT 'Xwr3'
|
# define TYPE_XWRDICT 'Xwr3'
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,7 +52,7 @@ struct PalmDictList {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// Prototypes
|
// Prototypes
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
static PalmDictList* dictListMakePriv( MPFORMAL XP_U32 creator );
|
static PalmDictList* dictListMakePriv( MPFORMAL XP_U32 creatorSought );
|
||||||
|
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
|
@ -168,7 +169,7 @@ addEntry( MPFORMAL PalmDictList** dlp, DictListEntry* dle )
|
||||||
|
|
||||||
static void
|
static void
|
||||||
searchDir( MPFORMAL PalmDictList** dlp, UInt16 volNum, unsigned char separator,
|
searchDir( MPFORMAL PalmDictList** dlp, UInt16 volNum, unsigned char separator,
|
||||||
unsigned char* path, XP_U16 pathSize )
|
unsigned char* path, XP_U16 pathSize, XP_U32 creatorSought )
|
||||||
{
|
{
|
||||||
Err err;
|
Err err;
|
||||||
FileRef dirRef;
|
FileRef dirRef;
|
||||||
|
@ -195,7 +196,7 @@ searchDir( MPFORMAL PalmDictList** dlp, UInt16 volNum, unsigned char separator,
|
||||||
path[len] = separator;
|
path[len] = separator;
|
||||||
path[len+1] = '\0';
|
path[len+1] = '\0';
|
||||||
searchDir( MPPARM(mpool) dlp, volNum, separator,
|
searchDir( MPPARM(mpool) dlp, volNum, separator,
|
||||||
path, pathSize );
|
path, pathSize, creatorSought );
|
||||||
} else if ( (ext = (XP_UCHAR*)StrStr( (const char*)path, ".pdb" ))
|
} else if ( (ext = (XP_UCHAR*)StrStr( (const char*)path, ".pdb" ))
|
||||||
!= NULL ) {
|
!= NULL ) {
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ searchDir( MPFORMAL PalmDictList** dlp, UInt16 volNum, unsigned char separator,
|
||||||
VFSFileClose( fileRef );
|
VFSFileClose( fileRef );
|
||||||
|
|
||||||
if ( (err == errNone) && (type == TYPE_DAWG) &&
|
if ( (err == errNone) && (type == TYPE_DAWG) &&
|
||||||
(creator == TYPE_XWRDICT) ) {
|
(creator == creatorSought ) ) {
|
||||||
DictListEntry dl;
|
DictListEntry dl;
|
||||||
|
|
||||||
dl.path = copyString( MPPARM(mpool) path );
|
dl.path = copyString( MPPARM(mpool) path );
|
||||||
|
@ -239,7 +240,7 @@ searchDir( MPFORMAL PalmDictList** dlp, UInt16 volNum, unsigned char separator,
|
||||||
} /* searchDir */
|
} /* searchDir */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tryVFSSearch( MPFORMAL PalmDictList** dlp )
|
tryVFSSearch( MPFORMAL PalmDictList** dlp, XP_U32 creatorSought )
|
||||||
{
|
{
|
||||||
Err err;
|
Err err;
|
||||||
UInt16 volNum;
|
UInt16 volNum;
|
||||||
|
@ -262,7 +263,7 @@ tryVFSSearch( MPFORMAL PalmDictList** dlp )
|
||||||
if ( err == errNone ) {
|
if ( err == errNone ) {
|
||||||
pathStr[1] = '\0';
|
pathStr[1] = '\0';
|
||||||
searchDir( MPPARM(mpool) dlp, volNum, pathStr[0],
|
searchDir( MPPARM(mpool) dlp, volNum, pathStr[0],
|
||||||
pathStr, sizeof(pathStr) );
|
pathStr, sizeof(pathStr), creatorSought );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +283,7 @@ DictListMake( MPFORMAL_NOCOMMA )
|
||||||
}
|
}
|
||||||
|
|
||||||
static PalmDictList*
|
static PalmDictList*
|
||||||
dictListMakePriv( MPFORMAL XP_U32 creator )
|
dictListMakePriv( MPFORMAL XP_U32 creatorSought )
|
||||||
{
|
{
|
||||||
Err err;
|
Err err;
|
||||||
DmSearchStateType stateType;
|
DmSearchStateType stateType;
|
||||||
|
@ -296,7 +297,7 @@ dictListMakePriv( MPFORMAL XP_U32 creator )
|
||||||
/* first the DM case */
|
/* first the DM case */
|
||||||
while ( !found ) {
|
while ( !found ) {
|
||||||
err = DmGetNextDatabaseByTypeCreator( newSearch, &stateType, TYPE_DAWG,
|
err = DmGetNextDatabaseByTypeCreator( newSearch, &stateType, TYPE_DAWG,
|
||||||
creator/* APPID */,
|
creatorSought,
|
||||||
false,// onlyLatestVers,
|
false,// onlyLatestVers,
|
||||||
&cardNo, &dbID );
|
&cardNo, &dbID );
|
||||||
if ( err != 0 ) {
|
if ( err != 0 ) {
|
||||||
|
@ -325,13 +326,13 @@ dictListMakePriv( MPFORMAL XP_U32 creator )
|
||||||
/* then the VFS case */
|
/* then the VFS case */
|
||||||
err = FtrGet( sysFileCVFSMgr, vfsFtrIDVersion, &vers );
|
err = FtrGet( sysFileCVFSMgr, vfsFtrIDVersion, &vers );
|
||||||
if ( err == errNone ) {
|
if ( err == errNone ) {
|
||||||
tryVFSSearch( MPPARM(mpool) &dl );
|
tryVFSSearch( MPPARM(mpool) &dl, creatorSought );
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanList( &dl );
|
cleanList( &dl );
|
||||||
|
|
||||||
return dl;
|
return dl;
|
||||||
} /* DictListMake */
|
} /* dictListMakePriv */
|
||||||
|
|
||||||
void
|
void
|
||||||
DictListFree( MPFORMAL PalmDictList* dl )
|
DictListFree( MPFORMAL PalmDictList* dl )
|
||||||
|
@ -360,7 +361,7 @@ DictListCount( PalmDictList* dl )
|
||||||
|
|
||||||
#ifdef NODE_CAN_4
|
#ifdef NODE_CAN_4
|
||||||
|
|
||||||
static void
|
static XP_Bool
|
||||||
convertOneDict( UInt16 cardNo, LocalID dbID )
|
convertOneDict( UInt16 cardNo, LocalID dbID )
|
||||||
{
|
{
|
||||||
Err err;
|
Err err;
|
||||||
|
@ -370,24 +371,8 @@ convertOneDict( UInt16 cardNo, LocalID dbID )
|
||||||
dawg_header* header;
|
dawg_header* header;
|
||||||
dawg_header tmp;
|
dawg_header tmp;
|
||||||
XP_U16 siz;
|
XP_U16 siz;
|
||||||
|
unsigned char charTableRecNum;
|
||||||
#ifdef DEBUG
|
XP_U16 nChars;
|
||||||
err = DmDatabaseInfo( cardNo, dbID, NULL,
|
|
||||||
NULL, NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
&creator );
|
|
||||||
XP_ASSERT( creator == 'Xwr3' );
|
|
||||||
#endif
|
|
||||||
creator = 'Xwr4';
|
|
||||||
err = DmSetDatabaseInfo( cardNo, dbID, NULL,
|
|
||||||
NULL, NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
NULL, NULL,
|
|
||||||
&creator );
|
|
||||||
XP_ASSERT( err == errNone );
|
|
||||||
|
|
||||||
/* now modify the flags */
|
/* now modify the flags */
|
||||||
ref = DmOpenDatabase( cardNo, dbID, dmModeReadWrite );
|
ref = DmOpenDatabase( cardNo, dbID, dmModeReadWrite );
|
||||||
|
@ -399,12 +384,47 @@ convertOneDict( UInt16 cardNo, LocalID dbID )
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp.flags = 0x0002;
|
tmp.flags = 0x0002;
|
||||||
DmWrite( MemHandleLock(h), OFFSET_OF(dawg_header,flags), &tmp.flags,
|
header = (dawg_header*)MemHandleLock(h);
|
||||||
|
charTableRecNum = header->charTableRecNum;
|
||||||
|
DmWrite( header, OFFSET_OF(dawg_header,flags), &tmp.flags,
|
||||||
sizeof(tmp.flags) );
|
sizeof(tmp.flags) );
|
||||||
MemHandleUnlock(h);
|
MemHandleUnlock(h);
|
||||||
DmReleaseRecord( ref, 0, true );
|
DmReleaseRecord( ref, 0, true );
|
||||||
DmCloseDatabase( ref );
|
|
||||||
|
|
||||||
|
/* Now convert to 16-bit psuedo-unicode */
|
||||||
|
h = DmGetRecord( ref, charTableRecNum );
|
||||||
|
XP_ASSERT( !!h );
|
||||||
|
nChars = MemHandleSize( h );
|
||||||
|
err = MemHandleResize( h, nChars * 2 );
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
|
||||||
|
if ( err == errNone ) {
|
||||||
|
XP_U16 buf[MAX_UNIQUE_TILES+1];
|
||||||
|
XP_S16 i;
|
||||||
|
XP_U8* ptr = (XP_U8*)MemHandleLock( h );
|
||||||
|
for ( i = 0; i < nChars; ++i ) {
|
||||||
|
buf[i] = ptr[i];
|
||||||
|
}
|
||||||
|
DmWrite( ptr, 0, buf, nChars * sizeof(buf[0]) );
|
||||||
|
MemHandleUnlock(h);
|
||||||
|
}
|
||||||
|
err = DmReleaseRecord( ref, charTableRecNum, true );
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
|
||||||
|
err = DmCloseDatabase( ref );
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
|
||||||
|
if ( err == errNone ) {
|
||||||
|
creator = TYPE_XWRDICT;
|
||||||
|
err = DmSetDatabaseInfo( cardNo, dbID, NULL,
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
&creator );
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
}
|
||||||
|
return err == errNone;
|
||||||
} /* convertOneDict */
|
} /* convertOneDict */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -412,24 +432,50 @@ offerConvertOldDicts( PalmAppGlobals* globals )
|
||||||
{
|
{
|
||||||
PalmDictList* dl = dictListMakePriv( MPPARM(globals->mpool) 'Xwr3' );
|
PalmDictList* dl = dictListMakePriv( MPPARM(globals->mpool) 'Xwr3' );
|
||||||
XP_U16 count = DictListCount(dl);
|
XP_U16 count = DictListCount(dl);
|
||||||
|
Err err;
|
||||||
|
|
||||||
if ( count > 0 ) {
|
if ( count > 0 && palmaskFromStrId( globals, STR_CONFIRM_CONVERTDICT,
|
||||||
|
-1, STR_NO ) ) {
|
||||||
|
|
||||||
if ( palmask( globals,
|
XP_U16 i;
|
||||||
"Do you want to convert existing Crosswords "
|
for ( i = 0; i < count; ++i ) {
|
||||||
"dictionaries to the new format? "
|
DictListEntry* dle;
|
||||||
"The change is not reversible.",
|
if ( getNthDict( dl, i, &dle ) ) {
|
||||||
NULL, -1 ) ) {
|
|
||||||
|
|
||||||
XP_U16 i;
|
if ( dle->location == DL_STORAGE ) {
|
||||||
for ( i = 0; i < count; ++i ) {
|
convertOneDict( dle->u.dmData.cardNo,
|
||||||
DictListEntry* dle;
|
dle->u.dmData.dbID );
|
||||||
if ( getNthDict( dl, i, &dle ) ) {
|
} else {
|
||||||
|
UInt16 cardNo;
|
||||||
|
LocalID dbID;
|
||||||
|
UInt16 volRefNum = dle->u.vfsData.volNum;
|
||||||
|
|
||||||
if ( dle->location == DL_STORAGE ) {
|
XP_ASSERT( dle->location == DL_VFS );
|
||||||
convertOneDict( dle->u.dmData.cardNo, dle->u.dmData.dbID );
|
|
||||||
|
XP_LOGF( "trying %s", dle->path );
|
||||||
|
|
||||||
|
/* copy from SD card to storage, convert, copy back */
|
||||||
|
err = VFSImportDatabaseFromFile( volRefNum,
|
||||||
|
(const char*)dle->path,
|
||||||
|
&cardNo, &dbID );
|
||||||
|
XP_LOGF( "VFSImportDatabaseFromFile => %d", err );
|
||||||
|
if ( err == errNone && convertOneDict( cardNo, dbID ) ) {
|
||||||
|
|
||||||
|
err = VFSFileDelete( volRefNum, dle->path );
|
||||||
|
XP_LOGF( "VFSFileDelete=>%d", err );
|
||||||
|
if ( err == errNone ) {
|
||||||
|
|
||||||
|
err = VFSExportDatabaseToFile( volRefNum,
|
||||||
|
(const char*)dle->path,
|
||||||
|
cardNo, dbID );
|
||||||
|
|
||||||
|
XP_LOGF( "VFSExportDatabaseToFile => %d", err );
|
||||||
|
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
err = DmDeleteDatabase( cardNo, dbID );
|
||||||
|
XP_ASSERT( err == errNone );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue