⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 model.cpp

📁 symbian AutoStart,symbian 开机自动运行
💻 CPP
字号:
#include <e32std.h>
#include <eikenv.h>
#include <coeutils.h>
#include <s32file.h>

#include "Model.h"
#include "AutoStartDocument.h"

CModel::CModel( CAutoStartDocument* aDocument ) : iDocument( aDocument )	
    {
    }

void CModel::ConstructL()
    {
    }

CModel::~CModel()
    {
    }

CModel* CModel::NewL( CAutoStartDocument* aDocument )
    {
    CModel* self = new (ELeave) CModel( aDocument );
    
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop();

    return self;
    }


void CModel::Reset()
	{
	iAutoStartEnable= ETrue;
	}

void CModel::ExternalizeL() const
	{
	TFileName fileName;

	TParse parse;
	parse.SetNoWild( iDocument->Application()->AppFullName(), NULL, NULL );

	TBuf<50> privatePath;
	CEikonEnv::Static()->FsSession().PrivatePath( privatePath );

	#if defined(__WINS__) || defined (_WINSCW__)
		_LIT( KDriveLetter, "C:" );
		fileName.Copy( KDriveLetter );
		fileName.Append( privatePath );
	#else
		fileName.Copy( parse.Drive() );
		fileName.Append( privatePath );	
	#endif

	fileName.Append( KSettingFileName );

	RFs fileSession;
    User::LeaveIfError( fileSession.Connect() );
    CleanupClosePushL( fileSession );

	RFileWriteStream outputFileStream;
    if ( KErrNone != outputFileStream.Replace( fileSession,
                                 fileName, EFileShareExclusive) )
		{
		// Cleanup the file session
		CleanupStack::PopAndDestroy( ); // fileSession
		return;
		}

    CleanupClosePushL( outputFileStream );
	outputFileStream.WriteInt8L( iAutoStartEnable );
 
    CleanupStack::PopAndDestroy( );  // outputFileStream
	CleanupStack::PopAndDestroy( );  // fileSession

	}

void CModel::InternalizeL()
	{
	TFileName fileName;

	TParse parse;
	parse.SetNoWild( iDocument->Application()->AppFullName(), NULL, NULL );

	TBuf<50> privatePath;
	CEikonEnv::Static()->FsSession().PrivatePath( privatePath );

	#if defined(__WINS__) || defined (_WINSCW__)
		_LIT( KDriveLetter, "C:" );
		fileName.Copy( KDriveLetter );
		fileName.Append( privatePath );
	#else
		fileName.Copy( parse.Drive() );
		fileName.Append( privatePath );	
	#endif

	fileName.Append( KSettingFileName );

	if ( !ConeUtils::FileExists( fileName ) )
		{
		ConeUtils::EnsurePathExistsL( fileName );
		
		// We need to create the file name here
		RFileWriteStream fileWStream;
		CleanupClosePushL( fileWStream );
		User::LeaveIfError( fileWStream.Create( CEikonEnv::Static()->FsSession(),
                                    fileName, EFileShareExclusive) );
		
		fileWStream.CommitL();
		CleanupStack::PopAndDestroy();  // fileWStream
		
		Reset();

		// If the file does not exist, then create it!!!
		ExternalizeL();
		}

	RFs fileSession;
    User::LeaveIfError( fileSession.Connect() );
    CleanupClosePushL( fileSession );

    RFileReadStream inputFileStream;
    User::LeaveIfError( inputFileStream.Open( fileSession,
                                fileName, EFileShareReadersOnly ) );
    CleanupClosePushL( inputFileStream );
	
	// Read autostart flag
	iAutoStartEnable = inputFileStream.ReadInt8L();

    CleanupStack::PopAndDestroy( );  // inputFileStream
	CleanupStack::PopAndDestroy( );  // fileSession
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -