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"
}
DictionaryCtxt* sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName );
DictionaryCtxt* sym_dictionary_makeL( MPFORMAL TFileName* path,
const XP_UCHAR* aDictName );
#endif

View file

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

View file

@ -59,7 +59,7 @@ class CXWordsAppView : public CCoeControl
@param aRect the rectangle this view will be drawn to
@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
@ -68,7 +68,7 @@ class CXWordsAppView : public CCoeControl
@param aRect the rectangle this view will be drawn to
@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
*/
CXWordsAppView();
CXWordsAppView( CEikApplication* aApp );
/* Added by eeh */
public:
@ -178,6 +178,8 @@ class CXWordsAppView : public CCoeControl
static TInt TimerCallback( TAny* aThis );
CEikApplication* iApp; /* remove if there's some way to get from
env */
CurGameInfo iGi;
CommonPrefs iCp;
#ifndef XWFEATURE_STANDALONE_ONLY

View file

@ -119,7 +119,7 @@ symMakeBitmap( SymDictCtxt* /*ctxt*/, RFile* file )
XP_U8 nRows = readXP_U8( file );
XP_U8 srcByte = 0;
XP_U8 nBits;
XP_U16 nBits;
bitmap = new (ELeave) CFbsBitmap();
bitmap->Create( TSize(nCols, nRows), dispMode );
@ -213,7 +213,7 @@ readFileToBuf( XP_UCHAR* dictBuf, const RFile* file )
} // readFileToBuf
DictionaryCtxt*
sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName )
sym_dictionary_makeL( MPFORMAL TFileName* base, const XP_UCHAR* aDictName )
{
if ( !aDictName ) {
SymDictCtxt* ctxt = (SymDictCtxt*)XP_MALLOC( mpool, sizeof( *ctxt ) );
@ -222,29 +222,10 @@ sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName )
return &ctxt->super;
} 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;
dname16.Copy( TPtrC8(aDictName) );
nameD.Append( dname16 );
nameD.Append( _L(".xwd") );
base->Append( dname16 );
base->Append( _L(".xwd") );
SymDictCtxt* ctxt = NULL;
RFs fileSession;
@ -252,9 +233,9 @@ sym_dictionary_makeL( MPFORMAL const XP_UCHAR* aDictName )
CleanupClosePushL(fileSession);
RFile file;
TInt err = file.Open( fileSession, nameD, EFileRead );
TInt err = file.Open( fileSession, *base, EFileRead );
if ( err != KErrNone ) {
XP_LOGDESC16( &nameD );
XP_LOGDESC16( base );
XP_LOGF( "file.Open => %d", err );
}
User::LeaveIfError( err );

View file

@ -26,6 +26,8 @@ extern "C" {
} // extern "C"
#include <eikapp.h>
#if defined SERIES_60
# include <w32std.h>
@ -35,6 +37,7 @@ extern "C" {
# define BMNAME( file, bm ) file ## _60 ## bm
#elif defined SERIES_80
# include <eikappui.h>
# include <cknenv.h>
# include <coemain.h>
# include "xwords_80.mbg"
@ -751,7 +754,7 @@ figureFonts( SymDrawCtxt* sctx )
DrawCtx*
sym_drawctxt_make( MPFORMAL CWindowGc* aGC, CCoeEnv* aCoeEnv,
CEikonEnv* aEikonEnv )
CEikonEnv* aEikonEnv, CEikApplication* aApp )
{
XP_LOGF( "in sym_drawctxt_make" );
SymDrawCtxt* sctx = (SymDrawCtxt*)XP_MALLOC( mpool, sizeof( *sctx ) );
@ -818,16 +821,8 @@ sym_drawctxt_make( MPFORMAL CWindowGc* aGC, CCoeEnv* aCoeEnv,
sctx->colors[COLOR_TRPL_WORD] = KRgbCyan;
figureFonts( sctx );
/* this path will change for other platforms/devices!!! */
#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 );
TFileName bitmapFile = aApp->BitmapStoreName();
XP_LOGF( "loading bitmaps0" );
sctx->iDownArrow = new (ELeave) CFbsBitmap();

View file

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

View file

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

View file

@ -34,6 +34,7 @@
#include <stringloader.h>
#include <stdlib.h> // for srand
#include <s32file.h>
#include <eikapp.h>
#include "xwappview.h"
#include "xwappui.h"
@ -51,22 +52,23 @@
#include "LocalizedStrIncludes.h"
// 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);
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);
self->ConstructL(aRect);
return self;
}
CXWordsAppView::CXWordsAppView()
CXWordsAppView::CXWordsAppView( CEikApplication* aApp )
: iApp( aApp )
{
#ifdef DEBUG
TInt processHandleCount, threadHandleCount;
@ -178,7 +180,8 @@ void CXWordsAppView::ConstructL(const TRect& aRect)
GetXwordsRWDir( &basePath, EGamesLoc );
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 );
if ( !FindAllDicts() ) {
@ -412,7 +415,7 @@ CXWordsAppView::sym_util_makeEmptyDict( XW_UtilCtxt* uc )
CXWordsAppView* self = (CXWordsAppView*)uc->closure;
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(self->mpool)
NULL );
NULL, NULL );
return dict;
}
@ -598,8 +601,10 @@ CXWordsAppView::MakeOrLoadGameL()
#endif
);
TFileName path;
GetXwordsRWDir( &path, EDictsLoc );
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool)
iGi.dictName );
&path, iGi.dictName );
User::LeaveIfNull( dict );
XP_U16 newGameID = SC( XP_U16, sym_util_getCurSeconds( &iUtil ) );
@ -1000,29 +1005,21 @@ CXWordsAppView::NotImpl()
void
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 ) {
case EGamesLoc:
aPathRef->Append( _L("C:") ); /* read-write: must be on C */
break;
case EDictsLoc:
#if defined __WINS__
aPathRef->Append( _L("Z:") );
#elif defined __MARM__
aPathRef->Append( _L("C:") );
#endif
aPathRef->Copy( nameParser.DriveAndPath() );
break;
case EPrefsLoc:
aPathRef->Copy( nameParser.Path() );
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 */
_LIT(filename,"xwdata.dat");
@ -1127,8 +1124,11 @@ CXWordsAppView::DoNewGame()
DictionaryCtxt* prevDict = model_getDictionary( iGame.model );
if ( 0 != XP_STRCMP( dict_getName(prevDict), iGi.dictName ) ) {
dict_destroy( prevDict );
TFileName path;
GetXwordsRWDir( &path, EDictsLoc );
DictionaryCtxt* dict = sym_dictionary_makeL( MPPARM(mpool)
iGi.dictName );
&path, iGi.dictName );
model_setDictionary( iGame.model, dict );
}
#ifndef XWFEATURE_STANDALONE_ONLY
@ -1180,6 +1180,7 @@ void
CXWordsAppView::LoadOneGameL( TGameName* aGameName )
{
XWStreamCtxt* stream = MakeSimpleStream( NULL );
DictionaryCtxt* dict;
iGamesMgr->LoadGameL( aGameName, stream );
@ -1188,7 +1189,9 @@ CXWordsAppView::LoadOneGameL( TGameName* aGameName )
stream_getBytes( stream, dictName, len );
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 );
game_makeFromStream( MPPARM(mpool) stream, &iGame,