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

📄 magictrainappui.cpp

📁 SYMBIAN S60 2ND列车时刻表软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				updateurl.Copy(KUpdateD);
				updateurl.Append(iDataVersion8);
				updateurl.Append(KUpdateDExt8);
				
				TFileName downloadfile;
				downloadfile.Copy(iDataPath);
				downloadfile.Append(iDataVersion);
				downloadfile.Append(KUpdateDExt);
				iDownloadEntity->Initialize(updateurl,downloadfile);
				iUpdateStatus = EUSDV;
			}		
		}else{
			HBufC* r_nosoft_update = StringLoader::LoadLC( R_NOSOFT_UPDATE);
    		HBufC* r_update_title = StringLoader::LoadLC( R_UPDATE_TITLE);        		
    		CEikonEnv::InfoWinL(r_update_title->Des(),r_nosoft_update->Des());
    		CleanupStack::PopAndDestroy(2);
    		
			if (!iDownloadEntity)
				iDownloadEntity = CDownloadEntity::NewL(iFs,*this);
			TBuf8<256> updateurl;
			updateurl.Copy(KUpdateD);
			updateurl.Append(iDataVersion8);
			updateurl.Append(KUpdateDExt);
			
			TFileName downloadfile;
			downloadfile.Copy(iDataPath);
			downloadfile.Append(iDataVersion);
			downloadfile.Append(KUpdateDExt);
			iDownloadEntity->Initialize(updateurl,downloadfile);
			iUpdateStatus = EUSDV;
		}
		rs.Close();
	}else if (aStatus == EDownloaded && iUpdateStatus == EUSDV) {
		RFileReadStream rs;
	    TInt err;
	    TFileName downloadfile;
		downloadfile.Copy(iDataPath);
		downloadfile.Append(iDataVersion);
		downloadfile.Append(KUpdateDExt);
		err = rs.Open(iFs,downloadfile,EFileRead);
		if (err == KErrNone) {
			TBuf<1000> words;
			TRAP(err,rs.ReadL(words,1000););
			iLastDataVersion.Copy(GetLastVersion(words));
			if (iLastDataVersion.Compare(iDataVersion) >0) {
				CAknMessageQueryDialog* updateDlg = CAknMessageQueryDialog::NewL( words );
			    updateDlg->PrepareLC(R_AVKON_MESSAGE_QUERY_DIALOG);        		
			    HBufC* updatedata = iEikonEnv->AllocReadResourceLC(R_UPDATE_DATA);               				
				updateDlg->QueryHeading()->SetTextL(*updatedata);
				CleanupStack::PopAndDestroy(updatedata);		
				if(	updateDlg->RunLD() )
				{
					if (!iDownloadEntity)
						iDownloadEntity = CDownloadEntity::NewL(iFs,*this);
					TBuf8<256> updateurl;
					updateurl.Copy(KUpdateD);
					updateurl.Append(iDataVersion8);
					updateurl.Append(KUpdateDataExt);
					
					TFileName downloadfile;
					downloadfile.Copy(iDataPath);
					downloadfile.Append(iDataVersion);
					downloadfile.Append(KUpdateDataExt);
					iDownloadEntity->Initialize(updateurl,downloadfile);
					iUpdateStatus = EUSData;
				}
			}else{
				HBufC* r_nosoft_update = StringLoader::LoadLC( R_NODATA_UPDATE);
        		HBufC* r_update_title = StringLoader::LoadLC( R_UPDATE_TITLE);        		
        		CEikonEnv::InfoWinL(r_update_title->Des(),r_nosoft_update->Des());
        		CleanupStack::PopAndDestroy(2);
			}	
		}else{
			HBufC* r_nosoft_update = StringLoader::LoadLC( R_NODATA_UPDATE);
    		HBufC* r_update_title = StringLoader::LoadLC( R_UPDATE_TITLE);        		
    		CEikonEnv::InfoWinL(r_update_title->Des(),r_nosoft_update->Des());
    		CleanupStack::PopAndDestroy(2);
		}
		rs.Close();
	}else if (aStatus == EDownloaded && iUpdateStatus == EUSData) {
		ParseUpdateData();
		HBufC* r_nosoft_update = StringLoader::LoadLC( R_FINALDATA_UPDATE);
		HBufC* r_update_title = StringLoader::LoadLC( R_UPDATE_TITLE);        		
		CEikonEnv::InfoWinL(r_update_title->Des(),r_nosoft_update->Des());
		CleanupStack::PopAndDestroy(2);
	}
}
void CMagicTrainAppUi::DownloadPercent(TInt aPercent)
{
	
}

void CMagicTrainAppUi::CompleteProgressNote()
{
	
}
void CMagicTrainAppUi::StepProgressNote(TInt aPercent)
{
	
}
void CMagicTrainAppUi::CancelProgressNote()
{
	
}
TBuf<10> CMagicTrainAppUi::GetLastVersion(const TDesC& words)
{
	TInt pos1 = words.Find(_L("["));
	TInt pos2 = words.Find(_L("]"));
	TInt len = pos2 - pos1 -1;
	TBuf<10> ret;
	ret=words.Mid(pos1+1,len);
	return ret;
}

void CMagicTrainAppUi::ParseUpdateData()
{
	TFileName downloadfile;
	downloadfile.Copy(iDataPath);
	downloadfile.Append(iDataVersion);
	downloadfile.Append(KUpdateDataExt);
	
	DecodeBase64Code(downloadfile);
	
	RFileReadStream rs;
	RFile file;
	
	TBuf8<5000> inputstr;	
		
	TInt size;
	TInt id;
	TInt len;
	TInt i;	
	TInt count;
	//update station
	rs.Open(iFs,downloadfile,EFileRead);
	
	TInt cmd = rs.ReadInt8L();
	file.Open(iFs,iStationFilePath,EFileRead|EFileWrite);
	file.Read(inputstr,2);
	count = inputstr[1]*256 + inputstr[0];
	while (cmd==1 || cmd ==2) {
		switch(cmd) {
			case 1:
			{
				file.Size(size);						
				rs.ReadL(inputstr,12);
				file.Write(size,inputstr,12);
				file.Flush();
				count += 1;
			}
				break;
			case 2:
			{
				file.Size(size);
				id  = rs.ReadInt16L();
				i=0;	
				do {
					file.Read((id+1)*12+2+i*5000,inputstr,5000);
					len = inputstr.Length();
					file.Write((id)*12+2+i*5000,inputstr,len);
					file.Flush();
					i += 1;
				}while (len!=0 );
				count -= 1;
			}
				break;
		}
		cmd = rs.ReadInt8L();
	}
	inputstr.SetLength(2);
	inputstr[0] = count % 256;
	inputstr[1] = count / 256;
	file.Write(0,inputstr,2);
	size  = 2+ count * 12;
	file.SetSize(size);
	file.Close();
	
	//update train
	file.Open(iFs,iTrainFilePath,EFileRead|EFileWrite);
	file.Read(inputstr,2);
	count = inputstr[1]*256 + inputstr[0];
	while (cmd==3 || cmd==4) {
		switch(cmd) {
			case 3:
			{
				file.Size(size);						
				rs.ReadL(inputstr,41);
				file.Write(size,inputstr,41);
				file.Flush();
				count += 1;
			}
				break;
			case 4:
			{
				id  = rs.ReadInt16L();
				i=0;	
				do {
					file.Read((id+1)*41+2+i*5000,inputstr,5000);
					len = inputstr.Length();
					file.Write((id)*41+2+i*5000,inputstr,len);
					file.Flush();
					i += 1;
				}while (len!=0 );
				
				count -= 1;
			}
				break;
		}
		cmd = rs.ReadInt8L();
	}
	inputstr.SetLength(2);
	inputstr[0] = count % 256;
	inputstr[1] = count / 256;
	file.Write(0,inputstr,2);
	size  = 2+ count * 41;
	file.SetSize(size);
	file.Close();
	
	//update train line
	file.Open(iFs,iTrainLineFilePath,EFileRead|EFileWrite);
	file.Read(inputstr,3);
	count = inputstr[2]*65536 + inputstr[1]*256 + inputstr[0];
	while (cmd==5 || cmd==6) {
		switch(cmd) {
			case 5:
			{
				file.Size(size);						
				rs.ReadL(inputstr,23);
				file.Write(size,inputstr,23);
				file.Flush();
				count += 1;
			}
				break;
			case 6:
			{
				id  = rs.ReadUint8L();
				id  = id + 256 * rs.ReadUint8L();
				id  = id + 65536 * rs.ReadUint8L();
				i=0;	
				do {
					file.Read((id+1)*23+3+i*5000,inputstr,5000);
					len = inputstr.Length();
					file.Write((id)*23+3+i*5000,inputstr,len);
					file.Flush();
					i += 1;
				}while (len!=0 );
				
				count -= 1;
			}
				break;
		}
		cmd = rs.ReadInt8L();
	}
	inputstr.SetLength(3);
	inputstr[2] = count / 65536;
	inputstr[1] = (count % 65536) / 256;
	inputstr[0] = count % 256;
	
	file.Write(0,inputstr,3);
	size  = 3+ count * 23;
	file.SetSize(size);
	file.Close();
	rs.Close();
	
	iDataVersion.Copy(iLastDataVersion);
	iDataVersion8.Copy(iLastDataVersion);
	SaveVersionL(iDataVersion8);	
	
	if (iEngine)
		delete iEngine;
	iEngine = Engine::NewL(this);
	
	
}
void CMagicTrainAppUi::ConstructFilePathSubL(RFs& fs,RFileReadStream& rs,TFileName& aFilePath,TFileName& aSubFilePath)
{
#ifdef _DEBUG
	aFilePath.Append(_L("C:\\"));
#else
	aFilePath.Append(_L("C:\\"));
#endif
    aFilePath.Append(aSubFilePath);
    TInt err;
	err = rs.Open(fs,aFilePath,EFileRead);
	if (err != KErrNone) {
    	aFilePath.SetLength(0);
    	aFilePath.Append(PathInfo::MemoryCardRootPath());
    	aFilePath.Append(aSubFilePath);
    	rs.Close();
    	if ( rs.Open(fs,aFilePath,EFileRead) != KErrNone) {
    		CleanupStack::PopAndDestroy(2);
    		Panic(ELoadTrainDLL);
    	}	
	}
    rs.Close();
}
void CMagicTrainAppUi::ConstructFilePathL()
{
	RFs fs;
	RFileReadStream rs;
	CleanupClosePushL(fs);
	CleanupClosePushL(rs);
	User::LeaveIfError(fs.Connect());
	
	TFileName SubStationFilePath(KStationFilePath);
	TFileName SubTrainFilePath(KTrainFilePath);
	TFileName SubTrainLineFilePath(KTrainLineFilePath);
	
	ConstructFilePathSubL(fs,rs,iStationFilePath,SubStationFilePath);
	ConstructFilePathSubL(fs,rs,iTrainFilePath,SubTrainFilePath);
	ConstructFilePathSubL(fs,rs,iTrainLineFilePath,SubTrainLineFilePath);
   
    CleanupStack::Pop();
    CleanupStack::PopAndDestroy();
}
void CMagicTrainAppUi::DecodeBase64Code(TFileName aFileName)
{
	RFile file;
	CleanupClosePushL(file);
	file.Open(iFs,aFileName,EFileRead|EFileWrite);
	
	TBuf8<5000> inputstr;	
	file.Read(inputstr,5000);
	
	//Decode base64 encoding with clean stack
	HBufC8* decodeBuf = StringUtil::Base64DecodeLC(inputstr);
	file.SetSize(0);
	file.Write(0,decodeBuf->Des(),decodeBuf->Length());
	file.Close();
	delete decodeBuf;
////Change to TDesC16
//HBufC *buff16 = HBufC::NewLC(ptr.Length());
//buff16->Des().Copy(ptr);
////Do something 
//...
////clean buffer
//CleanupStack::PopAndDestroy(2);
//
//	
//	RFile file;
//	CleanupClosePushL(file);
//	file.Open(iFs,aFileName,EFileRead|EFileWrite);
//	
//	TBuf8<5000> inputstr;	
//	inputstr.Zero();
//	file.Read(inputstr,5000);
//	inputstr.ZeroTerminate();
//	char* src = new char [5000];
//	src[0] = 0;
//	unsigned char* des= new unsigned char[5000];
//	des[0] = 0;
//	strcpy(src, (const char*)inputstr.Ptr());
//	TInt len = DecodeBase64((const char*)src, (unsigned char*)des, (int)strlen(src));
//	
//	char* pfilename=new char[256];
//	pfilename[0] = 0;
//	TBuf8<256> filename;
//	filename.Copy(aFileName);
//	filename.ZeroTerminate();
//	strcpy(pfilename, (const char*)filename.Ptr());
//	FILE * fpw;
//	fpw=fopen(pfilename,"wb");
//	fwrite(des,1,len,fpw);
//	fclose(fpw);
	
//	inputstr.Zero();
//	inputstr.Append((const unsigned char*)des,len);
//	file.SetSize(0);
//	file.Write(inputstr,inputstr.Length());
//	
//	CleanupStack::PopAndDestroy(1);
	
//	char* pfilename=new char[256];
//	pfilename[0] = 0;
//	TBuf8<256> filename;
//	filename.Copy(aFileName);
//	filename.ZeroTerminate();
//	strcpy(pfilename, (const char*)filename.Ptr());
//	DecodeFile(pfilename);
}
// End of File

⌨️ 快捷键说明

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