mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
Use SHGetSpecialFolderPath to locate dicts in /Document Files/Crosswords; reserve 1-pixel space around Rem: text
This commit is contained in:
parent
91b20350f7
commit
cbdf8edcf5
8 changed files with 69 additions and 50 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "cedict.h"
|
#include "cedict.h"
|
||||||
#include "debhacks.h"
|
#include "debhacks.h"
|
||||||
#include "cedebug.h"
|
#include "cedebug.h"
|
||||||
|
#include "ceutil.h"
|
||||||
|
|
||||||
typedef struct CEDictionaryCtxt {
|
typedef struct CEDictionaryCtxt {
|
||||||
DictionaryCtxt super;
|
DictionaryCtxt super;
|
||||||
|
@ -651,13 +652,19 @@ getDictDir( wchar_t* buf, XP_U16 bufLen )
|
||||||
} /* getDictDir */
|
} /* getDictDir */
|
||||||
|
|
||||||
XP_U16
|
XP_U16
|
||||||
ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt )
|
ceLocateNDicts( CEAppGlobals* globals, XP_U16 nSought, OnePathCB cb,
|
||||||
|
void* ctxt )
|
||||||
{
|
{
|
||||||
XP_U16 nFound = 0;
|
XP_U16 nFound = 0;
|
||||||
wchar_t path[CE_MAX_PATH_LEN+1];
|
wchar_t path[CE_MAX_PATH_LEN+1];
|
||||||
|
|
||||||
if ( getDictDir( path, VSIZE(path) ) ) {
|
if ( getDictDir( path, VSIZE(path) ) ) {
|
||||||
locateOneDir( MPPARM(mpool) path, cb, ctxt, nSought, &nFound );
|
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt, nSought, &nFound );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( nFound < nSought ) {
|
||||||
|
ceGetPath( globals, PROGFILES_PATH, path, VSIZE(path) );
|
||||||
|
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt, nSought, &nFound );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nFound < nSought ) {
|
if ( nFound < nSought ) {
|
||||||
|
@ -673,7 +680,8 @@ ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt )
|
||||||
wsprintf( path, L"\\%s\\Crosswords", data.cFileName );
|
wsprintf( path, L"\\%s\\Crosswords", data.cFileName );
|
||||||
|
|
||||||
XP_LOGW( "looking in:", path );
|
XP_LOGW( "looking in:", path );
|
||||||
locateOneDir( MPPARM(mpool) path, cb, ctxt, nSought, &nFound );
|
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt,
|
||||||
|
nSought, &nFound );
|
||||||
}
|
}
|
||||||
if ( nFound >= nSought ) {
|
if ( nFound >= nSought ) {
|
||||||
break;
|
break;
|
||||||
|
@ -725,7 +733,7 @@ findAlternateDict( CEAppGlobals* XP_UNUSED_DBG(globals), wchar_t* path )
|
||||||
data.sought = wbname( shortPath, sizeof(shortPath), path );
|
data.sought = wbname( shortPath, sizeof(shortPath), path );
|
||||||
data.result = path;
|
data.result = path;
|
||||||
|
|
||||||
(void)ceLocateNDicts( MPPARM(globals->mpool) CE_MAXDICTS, matchShortName,
|
(void)ceLocateNDicts( globals, CE_MAXDICTS, matchShortName,
|
||||||
&data );
|
&data );
|
||||||
return data.found;
|
return data.found;
|
||||||
} /* findAlternateDict */
|
} /* findAlternateDict */
|
||||||
|
|
|
@ -40,7 +40,8 @@ typedef XP_Bool (*OnePathCB)( const wchar_t* wPath, XP_U16 index, void* ctxt );
|
||||||
* dict files. Return the number actually found. Caller is responsible for
|
* dict files. Return the number actually found. Caller is responsible for
|
||||||
* making sure bufs contains nSought slots.
|
* making sure bufs contains nSought slots.
|
||||||
*/
|
*/
|
||||||
XP_U16 ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt );
|
XP_U16 ceLocateNDicts( CEAppGlobals* globals, XP_U16 nSought,
|
||||||
|
OnePathCB cb, void* ctxt );
|
||||||
|
|
||||||
/* return just the name, no extension, of dict, written to buf, pointed to by
|
/* return just the name, no extension, of dict, written to buf, pointed to by
|
||||||
return value (which is into buf, but not necessarily the first char.) */
|
return value (which is into buf, but not necessarily the first char.) */
|
||||||
|
|
|
@ -1171,7 +1171,7 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
|
|
||||||
formatRemText( nTilesLeft, dctx->scoreIsVertical, buf );
|
formatRemText( nTilesLeft, dctx->scoreIsVertical, buf );
|
||||||
|
|
||||||
height = xprect->height-2;
|
height = xprect->height - 2; /* space for border */
|
||||||
if ( height > globals->cellHt - CELL_BORDER ) {
|
if ( height > globals->cellHt - CELL_BORDER ) {
|
||||||
height = globals->cellHt - CELL_BORDER;
|
height = globals->cellHt - CELL_BORDER;
|
||||||
}
|
}
|
||||||
|
@ -1180,6 +1180,10 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
ceMeasureText( dctx, hdc, fce, buf, 0, widthP, heightP );
|
ceMeasureText( dctx, hdc, fce, buf, 0, widthP, heightP );
|
||||||
|
|
||||||
(void)SelectObject( hdc, oldFont );
|
(void)SelectObject( hdc, oldFont );
|
||||||
|
|
||||||
|
/* Put back the 2 we took above */
|
||||||
|
*heightP += 2;
|
||||||
|
*widthP += 2;
|
||||||
} else {
|
} else {
|
||||||
*widthP = *heightP = 0;
|
*widthP = *heightP = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,8 +186,7 @@ loadFromGameInfo( GameInfoState* giState )
|
||||||
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
||||||
}
|
}
|
||||||
if ( giState->isNewGame ) {
|
if ( giState->isNewGame ) {
|
||||||
(void)ceLocateNDicts( MPPARM(giState->dlgHdr.globals->mpool)
|
(void)ceLocateNDicts( globals, CE_MAXDICTS, addDictToState, giState );
|
||||||
CE_MAXDICTS, addDictToState, giState );
|
|
||||||
} else {
|
} else {
|
||||||
wchar_t wPath[CE_MAX_PATH_LEN+1];
|
wchar_t wPath[CE_MAX_PATH_LEN+1];
|
||||||
XP_ASSERT( gi->dictName[0] != '\0' );
|
XP_ASSERT( gi->dictName[0] != '\0' );
|
||||||
|
|
|
@ -1349,7 +1349,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||||
|
|
||||||
/* choose one. If none found it's an error. */
|
/* choose one. If none found it's an error. */
|
||||||
#ifndef STUBBED_DICT
|
#ifndef STUBBED_DICT
|
||||||
result = 1 == ceLocateNDicts( MPPARM(mpool) 1, ceSetDictName,
|
result = 1 == ceLocateNDicts( globals, 1, ceSetDictName,
|
||||||
globals );
|
globals );
|
||||||
if ( !result ) {
|
if ( !result ) {
|
||||||
wchar_t buf[512];
|
wchar_t buf[512];
|
||||||
|
@ -1866,6 +1866,7 @@ closeGame( CEAppGlobals* globals )
|
||||||
static void
|
static void
|
||||||
freeGlobals( CEAppGlobals* globals )
|
freeGlobals( CEAppGlobals* globals )
|
||||||
{
|
{
|
||||||
|
XP_U16 ii;
|
||||||
MPSLOT;
|
MPSLOT;
|
||||||
|
|
||||||
MPASSIGN( mpool, globals->mpool );
|
MPASSIGN( mpool, globals->mpool );
|
||||||
|
@ -1880,8 +1881,10 @@ freeGlobals( CEAppGlobals* globals )
|
||||||
if ( !!globals->util.vtable ) {
|
if ( !!globals->util.vtable ) {
|
||||||
XP_FREE( mpool, globals->util.vtable );
|
XP_FREE( mpool, globals->util.vtable );
|
||||||
}
|
}
|
||||||
if ( !!globals->specialDir ) {
|
for ( ii = 0; ii < N_CACHED_PATHS; ++ii ) {
|
||||||
XP_FREE( mpool, globals->specialDir );
|
if ( !!globals->specialDirs[ii] ) {
|
||||||
|
XP_FREE( mpool, globals->specialDirs[ii] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_FREE( globals->mpool, globals );
|
XP_FREE( globals->mpool, globals );
|
||||||
|
|
|
@ -29,13 +29,14 @@
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "cesockwr.h"
|
#include "cesockwr.h"
|
||||||
|
|
||||||
|
#define LCROSSWORDS_DIR_NODBG L"Crosswords"
|
||||||
#define CE_GAMEFILE_VERSION 0x01 /* means draw gets to save/restore */
|
#define CE_GAMEFILE_VERSION 0x01 /* means draw gets to save/restore */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define CROSSWORDS_DIR "Cross_dbg"
|
# define CROSSWORDS_DIR "Cross_dbg"
|
||||||
# define LCROSSWORDS_DIR L"Cross_dbg"
|
# define LCROSSWORDS_DIR L"Cross_dbg"
|
||||||
#else
|
#else
|
||||||
# define CROSSWORDS_DIR "Crosswords"
|
# define CROSSWORDS_DIR "Crosswords"
|
||||||
# define LCROSSWORDS_DIR L"Crosswords"
|
# define LCROSSWORDS_DIR LCROSSWORDS_DIR_NODBG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
|
@ -101,6 +102,12 @@ enum { OWNED_RECT_LEFT
|
||||||
,N_OWNED_RECTS
|
,N_OWNED_RECTS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MY_DOCS_CACHE,
|
||||||
|
PROGFILES_CACHE,
|
||||||
|
N_CACHED_PATHS
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct CEAppGlobals {
|
typedef struct CEAppGlobals {
|
||||||
HINSTANCE hInst;
|
HINSTANCE hInst;
|
||||||
HDC hdc; /* to pass drawing ctxt to draw code */
|
HDC hdc; /* to pass drawing ctxt to draw code */
|
||||||
|
@ -160,7 +167,7 @@ typedef struct CEAppGlobals {
|
||||||
int dbWidth, dbHeight;
|
int dbWidth, dbHeight;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wchar_t* specialDir; /* reserved for ceGetPath() */
|
wchar_t* specialDirs[N_CACHED_PATHS]; /* reserved for ceGetPath() */
|
||||||
|
|
||||||
#ifdef XWFEATURE_SEARCHLIMIT
|
#ifdef XWFEATURE_SEARCHLIMIT
|
||||||
XP_Bool askTrayLimits;
|
XP_Bool askTrayLimits;
|
||||||
|
|
|
@ -747,47 +747,38 @@ trapBackspaceKey( HWND hDlg )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* cegcc headers define this to SHGetSpecialFolderPathW, but that's not
|
/* Bugs in mingw32ce headers force defining _WIN32_IE, which causes
|
||||||
* what's in the library... */
|
* SHGetSpecialFolderPath to be defined as SHGetSpecialFolderPathW which
|
||||||
#ifdef SHGetSpecialFolderPath
|
* is not on Wince. Once I turn off _WIN32_IE this can go away. */
|
||||||
|
#ifdef _WIN32_IE
|
||||||
|
# ifdef SHGetSpecialFolderPath
|
||||||
# undef SHGetSpecialFolderPath
|
# undef SHGetSpecialFolderPath
|
||||||
#endif
|
# endif
|
||||||
BOOL SHGetSpecialFolderPath( HWND hwndOwner,
|
BOOL SHGetSpecialFolderPath( HWND hwndOwner,
|
||||||
LPTSTR lpszPath,
|
LPTSTR lpszPath,
|
||||||
int nFolder,
|
int nFolder,
|
||||||
BOOL fCreate );
|
BOOL fCreate );
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lookupSpecialDir( wchar_t* bufW )
|
lookupSpecialDir( wchar_t* bufW, XP_U16 indx )
|
||||||
{
|
{
|
||||||
bufW[0] = 0;
|
bufW[0] = 0;
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
#if 0
|
SHGetSpecialFolderPath( NULL, bufW,
|
||||||
BOOL (*mySHGetSpecialFolderPath)( HWND hwndOwner,
|
(indx == MY_DOCS_CACHE)?
|
||||||
LPTSTR lpszPath,
|
CSIDL_PERSONAL : CSIDL_PROGRAM_FILES,
|
||||||
int nFolder,
|
TRUE );
|
||||||
BOOL fCreate );
|
|
||||||
HMODULE module;
|
|
||||||
|
|
||||||
module = LoadLibrary( L"coredll" );
|
|
||||||
if ( !!module ) {
|
|
||||||
mySHGetSpecialFolderPath = GetProcAddress( module,
|
|
||||||
L"SHGetSpecialFolderPath" );
|
|
||||||
if ( !!mySHGetSpecialFolderPath ) {
|
|
||||||
HRESULT res = (*mySHGetSpecialFolderPath)( NULL, bufW,
|
|
||||||
CSIDL_PERSONAL, TRUE );
|
|
||||||
}
|
|
||||||
FreeLibrary( module );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
SHGetSpecialFolderPath( NULL, bufW, CSIDL_PERSONAL, TRUE );
|
|
||||||
#endif
|
|
||||||
if ( 0 == bufW[0] ) {
|
if ( 0 == bufW[0] ) {
|
||||||
XP_WARNF( "SHGetSpecialFolderPath hack failed" );
|
XP_WARNF( "SHGetSpecialFolderPath failed" );
|
||||||
wcscpy( bufW, L"\\My Documents" );
|
wcscpy( bufW, L"\\My Documents" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if ( indx == PROGFILES_CACHE ) {
|
||||||
|
wcscat( bufW, L"\\" LCROSSWORDS_DIR_NODBG );
|
||||||
|
} else {
|
||||||
wcscat( bufW, L"\\" LCROSSWORDS_DIR L"\\" );
|
wcscat( bufW, L"\\" LCROSSWORDS_DIR L"\\" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_U16
|
XP_U16
|
||||||
|
@ -796,17 +787,18 @@ ceGetPath( CEAppGlobals* globals, CePathType typ,
|
||||||
{
|
{
|
||||||
XP_U16 len;
|
XP_U16 len;
|
||||||
wchar_t bufW[CE_MAX_PATH_LEN];
|
wchar_t bufW[CE_MAX_PATH_LEN];
|
||||||
wchar_t* specialDir = globals->specialDir;
|
XP_U16 cacheIndx = typ == PROGFILES_PATH ? PROGFILES_CACHE : MY_DOCS_CACHE;
|
||||||
|
wchar_t* specialDir = globals->specialDirs[cacheIndx];
|
||||||
XP_Bool asAscii = XP_FALSE;
|
XP_Bool asAscii = XP_FALSE;
|
||||||
|
|
||||||
if ( !specialDir ) {
|
if ( !specialDir ) {
|
||||||
wchar_t buf[128];
|
wchar_t buf[128];
|
||||||
XP_U16 len;
|
XP_U16 len;
|
||||||
lookupSpecialDir( buf );
|
lookupSpecialDir( buf, cacheIndx );
|
||||||
len = 1 + wcslen( buf );
|
len = 1 + wcslen( buf );
|
||||||
specialDir = XP_MALLOC( globals->mpool, len * sizeof(specialDir[0]) );
|
specialDir = XP_MALLOC( globals->mpool, len * sizeof(specialDir[0]) );
|
||||||
wcscpy( specialDir, buf );
|
wcscpy( specialDir, buf );
|
||||||
globals->specialDir = specialDir;
|
globals->specialDirs[cacheIndx] = specialDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy( bufW, specialDir );
|
wcscpy( bufW, specialDir );
|
||||||
|
@ -822,11 +814,15 @@ ceGetPath( CEAppGlobals* globals, CePathType typ,
|
||||||
asAscii = XP_TRUE;
|
asAscii = XP_TRUE;
|
||||||
wcscat( bufW, L"_newgame" );
|
wcscat( bufW, L"_newgame" );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROGFILES_PATH:
|
||||||
|
/* nothing to do */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = wcslen( bufW );
|
len = wcslen( bufW );
|
||||||
if ( asAscii ) {
|
if ( asAscii ) {
|
||||||
(void)WideCharToMultiByte( CP_ACP, 0, bufW, len,
|
(void)WideCharToMultiByte( CP_ACP, 0, bufW, len + 1,
|
||||||
(char*)bufOut, bufLen, NULL, NULL );
|
(char*)bufOut, bufLen, NULL, NULL );
|
||||||
} else {
|
} else {
|
||||||
wcscpy( (wchar_t*)bufOut, bufW );
|
wcscpy( (wchar_t*)bufOut, bufW );
|
||||||
|
|
|
@ -47,6 +47,7 @@ typedef enum {
|
||||||
PREFS_FILE_PATH_L
|
PREFS_FILE_PATH_L
|
||||||
,DEFAULT_DIR_PATH_L
|
,DEFAULT_DIR_PATH_L
|
||||||
,DEFAULT_GAME_PATH
|
,DEFAULT_GAME_PATH
|
||||||
|
,PROGFILES_PATH
|
||||||
} CePathType;
|
} CePathType;
|
||||||
XP_U16 ceGetPath( CEAppGlobals* globals, CePathType typ,
|
XP_U16 ceGetPath( CEAppGlobals* globals, CePathType typ,
|
||||||
void* buf, XP_U16 bufLen );
|
void* buf, XP_U16 bufLen );
|
||||||
|
|
Loading…
Add table
Reference in a new issue