use system APIs to find stuff in app directory rather than hard coding

path.  Use system apis to find uniquie file names for games.
This commit is contained in:
ehouse 2005-03-26 03:25:44 +00:00
parent 663b3cc1a7
commit 3e476b3771
8 changed files with 64 additions and 77 deletions

View file

@ -30,8 +30,8 @@ extern "C" {
#include "mempool.h" #include "mempool.h"
} }
DictionaryCtxt* sym_dictionary_makeL( MPFORMAL TFileName* path,
DictionaryCtxt* sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName ); const XP_UCHAR* aDictName );
#endif #endif

View file

@ -42,6 +42,6 @@ extern "C" {
#define CUR_PREFS_VERS 0x0405 #define CUR_PREFS_VERS 0x0405
DrawCtx* sym_drawctxt_make( MPFORMAL CWindowGc* gc, CCoeEnv* aCoeEnv, DrawCtx* sym_drawctxt_make( MPFORMAL CWindowGc* gc, CCoeEnv* aCoeEnv,
CEikonEnv* aEikonEnv ); CEikonEnv* aEikonEnv, CEikApplication* aApp );
#endif #endif

View file

@ -59,7 +59,7 @@ class CXWordsAppView : public CCoeControl
@param aRect the rectangle this view will be drawn to @param aRect the rectangle this view will be drawn to
@result a pointer to the created instance of CXWordsAppView @result a pointer to the created instance of CXWordsAppView
*/ */
static CXWordsAppView* NewL(const TRect& aRect); static CXWordsAppView* NewL(const TRect& aRect, CEikApplication* aApp );
/*! /*!
@function NewLC @function NewLC
@ -68,7 +68,7 @@ class CXWordsAppView : public CCoeControl
@param aRect the rectangle this view will be drawn to @param aRect the rectangle this view will be drawn to
@result a pointer to the created instance of CXWordsAppView @result a pointer to the created instance of CXWordsAppView
*/ */
static CXWordsAppView* NewLC(const TRect& aRect); static CXWordsAppView* NewLC(const TRect& aRect, CEikApplication* aApp );
/*! /*!
@ -103,7 +103,7 @@ class CXWordsAppView : public CCoeControl
@discussion Perform the first phase of two phase construction @discussion Perform the first phase of two phase construction
*/ */
CXWordsAppView(); CXWordsAppView( CEikApplication* aApp );
/* Added by eeh */ /* Added by eeh */
public: public:
@ -178,6 +178,8 @@ class CXWordsAppView : public CCoeControl
static TInt TimerCallback( TAny* aThis ); static TInt TimerCallback( TAny* aThis );
CEikApplication* iApp; /* remove if there's some way to get from
env */
CurGameInfo iGi; CurGameInfo iGi;
CommonPrefs iCp; CommonPrefs iCp;
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY

View file

@ -119,7 +119,7 @@ symMakeBitmap( SymDictCtxt* /*ctxt*/, RFile* file )
XP_U8 nRows = readXP_U8( file ); XP_U8 nRows = readXP_U8( file );
XP_U8 srcByte = 0; XP_U8 srcByte = 0;
XP_U8 nBits; XP_U16 nBits;
bitmap = new (ELeave) CFbsBitmap(); bitmap = new (ELeave) CFbsBitmap();
bitmap->Create( TSize(nCols, nRows), dispMode ); bitmap->Create( TSize(nCols, nRows), dispMode );
@ -213,7 +213,7 @@ readFileToBuf( XP_UCHAR* dictBuf, const RFile* file )
} // readFileToBuf } // readFileToBuf
DictionaryCtxt* DictionaryCtxt*
sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName ) sym_dictionary_makeL( MPFORMAL TFileName* base, const XP_UCHAR* aDictName )
{ {
if ( !aDictName ) { if ( !aDictName ) {
SymDictCtxt* ctxt = (SymDictCtxt*)XP_MALLOC( mpool, sizeof( *ctxt ) ); SymDictCtxt* ctxt = (SymDictCtxt*)XP_MALLOC( mpool, sizeof( *ctxt ) );
@ -222,29 +222,10 @@ sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName )
return &ctxt->super; return &ctxt->super;
} else { } else {
#ifdef XWORDS_DIR
# if defined __WINS__
_LIT( dir,"z:\\system\\apps\\" XWORDS_DIR "\\" );
# elif defined __MARM__
_LIT( dir,"c:\\system\\apps\\" XWORDS_DIR "\\" );
# endif
#else
/* Symbian's broken compiler won't let me concatenate XWORDS_DIR with
strings nor pass it in defined, so hack here. If you're using the
broken ABLD.BAT system, you get to deal with it. :-) */
# if defined __WINS__
_LIT( dir,"z:\\system\\apps\\xwords_80\\" );
# elif defined __MARM__
_LIT( dir,"c:\\system\\apps\\XWORDS_80\\" );
# endif
#endif
TFileName nameD; /* need the full path to name in this */
nameD.Copy( dir );
TBuf16<32> dname16; TBuf16<32> dname16;
dname16.Copy( TPtrC8(aDictName) ); dname16.Copy( TPtrC8(aDictName) );
nameD.Append( dname16 ); base->Append( dname16 );
nameD.Append( _L(".xwd") ); base->Append( _L(".xwd") );
SymDictCtxt* ctxt = NULL; SymDictCtxt* ctxt = NULL;
RFs fileSession; RFs fileSession;
@ -252,9 +233,9 @@ sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName )
CleanupClosePushL(fileSession); CleanupClosePushL(fileSession);
RFile file; RFile file;
TInt err = file.Open( fileSession, nameD, EFileRead ); TInt err = file.Open( fileSession, *base, EFileRead );
if ( err != KErrNone ) { if ( err != KErrNone ) {
XP_LOGDESC16( &nameD ); XP_LOGDESC16( base );
XP_LOGF( "file.Open => %d", err ); XP_LOGF( "file.Open => %d", err );
} }
User::LeaveIfError( err ); User::LeaveIfError( err );

View file

@ -26,6 +26,8 @@ extern "C" {
} // extern "C" } // extern "C"
#include <eikapp.h>
#if defined SERIES_60 #if defined SERIES_60
# include <w32std.h> # include <w32std.h>
@ -35,6 +37,7 @@ extern "C" {
# define BMNAME( file, bm ) file ## _60 ## bm # define BMNAME( file, bm ) file ## _60 ## bm
#elif defined SERIES_80 #elif defined SERIES_80
# include <eikappui.h>
# include <cknenv.h> # include <cknenv.h>
# include <coemain.h> # include <coemain.h>
# include "xwords_80.mbg" # include "xwords_80.mbg"
@ -751,7 +754,7 @@ figureFonts( SymDrawCtxt* sctx )
DrawCtx* DrawCtx*
sym_drawctxt_make( MPFORMAL CWindowGc* aGC, CCoeEnv* aCoeEnv, sym_drawctxt_make( MPFORMAL CWindowGc* aGC, CCoeEnv* aCoeEnv,
CEikonEnv* aEikonEnv ) CEikonEnv* aEikonEnv, CEikApplication* aApp )
{ {
XP_LOGF( "in sym_drawctxt_make" ); XP_LOGF( "in sym_drawctxt_make" );
SymDrawCtxt* sctx = (SymDrawCtxt*)XP_MALLOC( mpool, sizeof( *sctx ) ); SymDrawCtxt* sctx = (SymDrawCtxt*)XP_MALLOC( mpool, sizeof( *sctx ) );
@ -819,15 +822,7 @@ sym_drawctxt_make( MPFORMAL CWindowGc* aGC, CCoeEnv* aCoeEnv,
figureFonts( sctx ); figureFonts( sctx );
/* this path will change for other platforms/devices!!! */ TFileName bitmapFile = aApp->BitmapStoreName();
#if defined __WINS__
_LIT( kBitmapsPath, "z:\\system\\apps\\" XWORDS_DIR
"\\" XWORDS_DIR ".mbm" );
#elif defined __MARM__
_LIT( kBitmapsPath, "c:\\system\\apps\\" XWORDS_DIR
"\\" XWORDS_DIR ".mbm" );
#endif
TFileName bitmapFile( kBitmapsPath );
XP_LOGF( "loading bitmaps0" ); XP_LOGF( "loading bitmaps0" );
sctx->iDownArrow = new (ELeave) CFbsBitmap(); sctx->iDownArrow = new (ELeave) CFbsBitmap();

View file

@ -27,6 +27,7 @@ extern "C" {
#if defined SERIES_60 #if defined SERIES_60
# include <eikenv.h> # include <eikenv.h>
#endif #endif
#include <apparc.h>
_LIT( kGameTypeExt, ".xwg" ); _LIT( kGameTypeExt, ".xwg" );
@ -145,16 +146,18 @@ CXWGamesMgr::GameNameToPath( TFileName* aPath, const TDesC16* aName )
void void
CXWGamesMgr::MakeDefaultName( TGameName* aName ) CXWGamesMgr::MakeDefaultName( TGameName* aName )
{ {
/* return a unique new name */ RFs fs = iCoeEnv->FsSession();
for ( ; ; ) { TFileName nameD;
aName->Delete( 0, 256 ); TGameName tmpName( _L("game") );
aName->Append( _L("game") ); GameNameToPath( &nameD, &tmpName );
aName->AppendNum( ++iGameCount );
if ( !Exists( aName ) ) { TInt err = CApaApplication::GenerateFileName( fs, nameD );
break; User::LeaveIfError( err );
}
} TParse nameParser;
nameParser.Set( nameD, NULL, NULL );
aName->Copy( nameParser.Name() );
} // MakeDefaultName } // MakeDefaultName
void void

View file

@ -25,19 +25,22 @@
# include <eikinfo.h> # include <eikinfo.h>
#elif defined SERIES_80 #elif defined SERIES_80
# include <ckninfo.h> # include <ckninfo.h>
# include <eikappui.h>
# include <eikapp.h>
#endif #endif
#include "xwords.pan" #include "xwords.pan"
#include "xwappui.h" #include "xwappui.h"
#include "xwappview.h" #include "xwappview.h"
#include "xwords.hrh" #include "xwords.hrh"
#include "symutil.h"
// ConstructL is called by the application framework // ConstructL is called by the application framework
void CXWordsAppUi::ConstructL() void CXWordsAppUi::ConstructL()
{ {
BaseConstructL(); BaseConstructL();
iAppView = CXWordsAppView::NewL(ClientRect()); iAppView = CXWordsAppView::NewL( ClientRect(), Application() );
AddToStackL(iAppView); AddToStackL(iAppView);
} }

View file

@ -34,6 +34,7 @@
#include <stringloader.h> #include <stringloader.h>
#include <stdlib.h> // for srand #include <stdlib.h> // for srand
#include <s32file.h> #include <s32file.h>
#include <eikapp.h>
#include "xwappview.h" #include "xwappview.h"
#include "xwappui.h" #include "xwappui.h"
@ -51,22 +52,23 @@
#include "LocalizedStrIncludes.h" #include "LocalizedStrIncludes.h"
// Standard construction sequence // Standard construction sequence
CXWordsAppView* CXWordsAppView::NewL(const TRect& aRect) CXWordsAppView* CXWordsAppView::NewL(const TRect& aRect, CEikApplication* aApp )
{ {
CXWordsAppView* self = CXWordsAppView::NewLC(aRect); CXWordsAppView* self = CXWordsAppView::NewLC( aRect, aApp );
CleanupStack::Pop(self); CleanupStack::Pop(self);
return self; return self;
} }
CXWordsAppView* CXWordsAppView::NewLC(const TRect& aRect) CXWordsAppView* CXWordsAppView::NewLC(const TRect& aRect, CEikApplication* aApp )
{ {
CXWordsAppView* self = new (ELeave) CXWordsAppView; CXWordsAppView* self = new (ELeave) CXWordsAppView( aApp );
CleanupStack::PushL(self); CleanupStack::PushL(self);
self->ConstructL(aRect); self->ConstructL(aRect);
return self; return self;
} }
CXWordsAppView::CXWordsAppView() CXWordsAppView::CXWordsAppView( CEikApplication* aApp )
: iApp( aApp )
{ {
#ifdef DEBUG #ifdef DEBUG
TInt processHandleCount, threadHandleCount; TInt processHandleCount, threadHandleCount;
@ -178,7 +180,8 @@ void CXWordsAppView::ConstructL(const TRect& aRect)
GetXwordsRWDir( &basePath, EGamesLoc ); GetXwordsRWDir( &basePath, EGamesLoc );
iGamesMgr = CXWGamesMgr::NewL( MPPARM(mpool) iCoeEnv, &basePath ); iGamesMgr = CXWGamesMgr::NewL( MPPARM(mpool) iCoeEnv, &basePath );
iDraw = sym_drawctxt_make( MPPARM(mpool) &SystemGc(), iCoeEnv, iEikonEnv ); iDraw = sym_drawctxt_make( MPPARM(mpool) &SystemGc(), iCoeEnv,
iEikonEnv, iApp );
User::LeaveIfNull( iDraw ); User::LeaveIfNull( iDraw );
if ( !FindAllDicts() ) { if ( !FindAllDicts() ) {
@ -412,7 +415,7 @@ CXWordsAppView::sym_util_makeEmptyDict( XW_UtilCtxt* uc )
CXWordsAppView* self = (CXWordsAppView*)uc->closure; CXWordsAppView* self = (CXWordsAppView*)uc->closure;
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(self->mpool) DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(self->mpool)
NULL ); NULL, NULL );
return dict; return dict;
} }
@ -598,8 +601,10 @@ CXWordsAppView::MakeOrLoadGameL()
#endif #endif
); );
TFileName path;
GetXwordsRWDir( &path, EDictsLoc );
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool) DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool)
iGi.dictName ); &path, iGi.dictName );
User::LeaveIfNull( dict ); User::LeaveIfNull( dict );
XP_U16 newGameID = SC( XP_U16, sym_util_getCurSeconds( &iUtil ) ); XP_U16 newGameID = SC( XP_U16, sym_util_getCurSeconds( &iUtil ) );
@ -1000,29 +1005,21 @@ CXWordsAppView::NotImpl()
void void
CXWordsAppView::GetXwordsRWDir( TFileName* aPathRef, TDriveReason aWhy ) CXWordsAppView::GetXwordsRWDir( TFileName* aPathRef, TDriveReason aWhy )
{ {
aPathRef->Delete( 0, aPathRef->Length() ); TFileName fn = iApp->BitmapStoreName(); /* isn't the a method to just get
the path? */
TParse nameParser;
nameParser.Set( fn, NULL, NULL );
TPtrC path = nameParser.DriveAndPath();
switch( aWhy ) { switch( aWhy ) {
case EGamesLoc: case EGamesLoc:
aPathRef->Append( _L("C:") ); /* read-write: must be on C */
break;
case EDictsLoc: case EDictsLoc:
#if defined __WINS__ aPathRef->Copy( nameParser.DriveAndPath() );
aPathRef->Append( _L("Z:") );
#elif defined __MARM__
aPathRef->Append( _L("C:") );
#endif
break; break;
case EPrefsLoc: case EPrefsLoc:
aPathRef->Copy( nameParser.Path() );
break; /* don't want a drive */ break; /* don't want a drive */
} }
#ifdef XWORDS_DIR
_LIT( dir,"\\system\\apps\\" XWORDS_DIR "\\" );
#else
_LIT( dir,"\\system\\apps\\xwords_80\\" );
#endif
aPathRef->Append( dir );
} /* GetXwordsRWDir */ } /* GetXwordsRWDir */
_LIT(filename,"xwdata.dat"); _LIT(filename,"xwdata.dat");
@ -1127,8 +1124,11 @@ CXWordsAppView::DoNewGame()
DictionaryCtxt* prevDict = model_getDictionary( iGame.model ); DictionaryCtxt* prevDict = model_getDictionary( iGame.model );
if ( 0 != XP_STRCMP( dict_getName(prevDict), iGi.dictName ) ) { if ( 0 != XP_STRCMP( dict_getName(prevDict), iGi.dictName ) ) {
dict_destroy( prevDict ); dict_destroy( prevDict );
TFileName path;
GetXwordsRWDir( &path, EDictsLoc );
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool) DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool)
iGi.dictName ); &path, iGi.dictName );
model_setDictionary( iGame.model, dict ); model_setDictionary( iGame.model, dict );
} }
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
@ -1180,6 +1180,7 @@ void
CXWordsAppView::LoadOneGameL( TGameName* aGameName ) CXWordsAppView::LoadOneGameL( TGameName* aGameName )
{ {
XWStreamCtxt* stream = MakeSimpleStream( NULL ); XWStreamCtxt* stream = MakeSimpleStream( NULL );
DictionaryCtxt* dict;
iGamesMgr->LoadGameL( aGameName, stream ); iGamesMgr->LoadGameL( aGameName, stream );
@ -1188,7 +1189,9 @@ CXWordsAppView::LoadOneGameL( TGameName* aGameName )
stream_getBytes( stream, dictName, len ); stream_getBytes( stream, dictName, len );
dictName[len] = '\0'; dictName[len] = '\0';
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool) dictName ); TFileName path;
GetXwordsRWDir( &path, EDictsLoc );
dict = sym_dictionary_makeL( MPPARM(mpool) &path, dictName );
XP_ASSERT( !!dict ); XP_ASSERT( !!dict );
game_makeFromStream( MPPARM(mpool) stream, &iGame, game_makeFromStream( MPPARM(mpool) stream, &iGame,