コード例 #1
0
ファイル: ZipArchive.cpp プロジェクト: F5000/spree
bool CZipArchive::AddNewFile(LPCTSTR lpszBasePath, LPCTSTR lpszFilePath, int iLevel, unsigned long nBufSize)
{
	if (!nBufSize)
		return false;
		
	CFileHeader header;

	if( lpszBasePath )
	{
		header.m_szFileName = GetFileDirAndName(lpszFilePath);
		CString basepath = GetFileDirAndName(lpszBasePath);
		header.m_szFileName.Replace( basepath, _T("") );
	}
	else
	{
		header.m_szFileName = GetFileDirAndName(lpszFilePath);
	}

	if (header.m_szFileName.IsEmpty())
		return false;
	if (!OpenNewFile(header, iLevel, lpszFilePath))
		return false;
	
	if (!IsDirectory(header.m_uExternalAttr))
	{
		CFile f;
		CFileException* e = new CFileException;
		BOOL bRet = f.Open(lpszFilePath, CFile::modeRead | CFile::shareDenyWrite, e);
		e->Delete();
		if (!bRet)
			return false;
		
		DWORD iRead;
		CAutoBuffer buf(nBufSize);
		do
		{
			iRead = f.Read(buf, nBufSize);
			if (iRead)
				WriteNewFile(buf, iRead);
		}
		while (iRead == buf.GetSize());
	}
	CloseNewFile();
	return true;
}
コード例 #2
0
ファイル: modencrypt.cpp プロジェクト: uesoft/AutoPHS
void ModEncrypt::CheckInstallDate()
{

	COleDateTime InsDate, Today;
    long i , iNum;
	CFile f,f1;
	long st;
	CFileException e;
	try{
		//下面是安装日期记录文件
		f.Open(user::gstrWinDir + FileIns,CFile::modeRead);
		iNum=f.GetLength()/sizeof(time_t) - 1;
		if(Qsort.sortarray !=NULL)
		{
			delete [] Qsort.sortarray;
			Qsort.sortarray=NULL;
		}
		if(Qsort.sortindex!=NULL)
		{
			delete [] Qsort.sortindex;
			Qsort.sortindex=NULL;
		}
		Qsort.sortarray=new DATE [iNum];
		Qsort.sortindex=new int [iNum];
		f.Seek(sizeof(DATE),CFile::begin);
		for(i=0;i<iNum;i++)
		{
			f.Read(&InsDate,sizeof(DATE));
			//移动4个字节
			Qsort.sortarray[i] = InsDate;
			Qsort.sortindex[i] = i;
		}
		Qsort.QuickSort(0, iNum-1);
		//最早的安装日期
		//MsgBox Qsort.sortarray[1)
		//最晚的安装日期
		//MsgBox Qsort.sortarray[iNum)
		InsDate=COleDateTime::GetCurrentTime();
		f.Close();
		SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileIns);
		DATE tmpD;
		f.Open(user::gstrWinDir + FileIns,CFile::modeWrite);
		f.Seek(8,CFile::begin);
		if( ! FileExists(user::gstrWinDir + FileOutDate) )
		{
			if( UEGetSettingInstallNumber("1", 0) >= INSTALL_NUM )
			{
				//如果安装次数超过
				glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1;
			}
			else
			{
				//如果时间超过,则演示版功能受到限制
				if( glngLimitedDemoVersionDays > RUN_DAYS_NUM )
					glngLimitedDemoVersionDays = RUN_DAYS_NUM;
				else if( glngLimitedDemoVersionDays <= 0 )
					glngLimitedDemoVersionDays = RUN_DAYS_NUM;
				else
					glngLimitedDemoVersionDays = RUN_DAYS_NUM;
				
				COleDateTime Date=COleDateTime::GetCurrentTime();
				COleDateTime dateTmp = Qsort.sortarray[iNum-1];
				if(Date >= dateTmp )
				{
					dateTmp=Qsort.sortarray[0];
					if( Date >= dateTmp)
					{
						glngUseDemoVersionDays = Date - COleDateTime(Qsort.sortarray[1]);
					}
					else
					{
						glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1;//因为用户自已调整了时间所以让演示版到期
						tmpD=(DATE)InsDate;
						f.Write(&tmpD,sizeof(DATE));
					}
				}
				else
				{
					glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1;//因为用户自已调整了时间所以让演示版到期
					tmpD=(DATE)InsDate;
					f.Write(&tmpD,sizeof(DATE));
				}
			}
			
			if( glngUseDemoVersionDays >= glngLimitedDemoVersionDays )
			{
				f1.Open(user::gstrWinDir + FileOutDate,CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
				Today=COleDateTime::GetCurrentTime();
				tmpD=(DATE)Today;
				f1.Write(&tmpD,sizeof(DATE));
				f1.Close();
				tmpD=0;
				st=f.GetLength();
				if(st>=16)
				{	
					st=8;
					f.Seek(st,CFile::begin);
					f.Write(&tmpD,sizeof(DATE));
				}
				SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileOutDate);
				gbLegalUser = FALSE;
				if( FileExists(user::gstrWinDir + FileFlag) )
					DeleteFile(user::gstrWinDir + FileFlag);
			}
			else
			{
				if( UEGetSettingInstallNumber( "2", 0) >= RUN_NUM )
				{
					//如果运行次数超过
					SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileOutDate);
					gbLegalUser = FALSE;
					if( FileExists(user::gstrWinDir + FileFlag) )
						DeleteFile( user::gstrWinDir + FileFlag);
				}	
				else 
				{
					if( UEGetSettingInstallNumber( "2", 0) < 0 )
					{
						UESaveSettingInstallNumber( "2", RUN_NUM);
						gbLegalUser = FALSE;
					}
					else
					{
						CopyFile( user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag,TRUE);
						SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag);
						gbLegalUser = TRUE;
					}
				}
			}
		}
		else
		{
			gbLegalUser = FALSE;
			if( FileExists(user::gstrWinDir + FileFlag) ) 
				DeleteFile( user::gstrWinDir + FileFlag);
		}
		f.Close();
	}
	catch(CFileException *e)
	{
		e->ReportError();
		e->Delete();
	}
}