📄 netdb.cpp.svn-base
字号:
if( bOK )
nCount ++;
}
}
return nCount;
}
BOOL CNetDatabase::GetLatestTimeNet( CSPTime &tm, int packagetype )
{
return m_packages.GetLatestTime( tm, packagetype );
}
CServers & CNetDatabase::GetServers( )
{
return m_servers;
}
CPackages & CNetDatabase::GetPackages( )
{
return m_packages;
}
int CNetDatabase::GetMaxStockNumber( )
{
return CStDatabase::GetMaxStockNumber();
}
int CNetDatabase::LoadCodetable( CStockContainer & container )
{
return CStDatabase::LoadCodetable( container );
}
int CNetDatabase::LoadBaseText( CStock *pstock )
{
return CStDatabase::LoadBaseText( pstock );
}
int CNetDatabase::LoadKData( CStock *pstock, int period )
{
return CStDatabase::LoadKData( pstock, period );
}
int CNetDatabase::LoadDRData( CStock *pstock )
{
return CStDatabase::LoadDRData( pstock );
}
BOOL CNetDatabase::EmptyTempDirectory( LPCTSTR lpszPath )
{
CString strFinder;
if( NULL == lpszPath )
{
char szTempPath[MAX_PATH+1];
memset( szTempPath, 0, sizeof(szTempPath) );
if( GetSelfTempPath( szTempPath, MAX_PATH ) <= 0 )
return FALSE;
strFinder = szTempPath;
}
else
strFinder = lpszPath;
strFinder += "*";
CFileFind finder;
BOOL bWorking = finder.FindFile( strFinder );
while( bWorking )
{
bWorking = finder.FindNextFile();
DWORD attr = GetFileAttributes( finder.GetFilePath() );
if( 0xFFFFFFFF != attr && (attr & FILE_ATTRIBUTE_DIRECTORY) )
{
CString strName = finder.GetFileName();
if( 0 != strName.CompareNoCase(".") && 0 != strName.CompareNoCase("..") )
{
EmptyTempDirectory( finder.GetFilePath() + STRING_DIRSEP );
RemoveDirectory( finder.GetFilePath() );
}
}
else
{
DeleteFile( finder.GetFilePath() );
}
}
finder.Close();
return TRUE;
}
// protected method
BOOL CNetDatabase::GetTempFile( CString &rString )
{
char szTempPath[MAX_PATH+1];
memset( szTempPath, 0, sizeof(szTempPath) );
GetSelfTempPath( szTempPath, MAX_PATH );
if( 0 == strlen(szTempPath) )
GetTempPath( MAX_PATH, szTempPath );
if( 0 == strlen(szTempPath) )
return FALSE;
char szFile[MAX_PATH+1];
memset( szFile, 0, sizeof(szFile) );
if( 0!=GetTempFileName( szTempPath, "net", 0, szFile ) )
{
rString = szFile;
return TRUE;
}
return FALSE;
}
BOOL CNetDatabase::RemoveTempFile( CString sFileName )
{
return DeleteFile( sFileName );
}
BOOL CNetDatabase::OpenTempFile( CFile &file )
{
CString strFileName;
GetTempFile( strFileName );
BOOL bOpen = file.Open( strFileName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive );
if( !bOpen )
DeleteFile(strFileName);
return bOpen;
}
BOOL CNetDatabase::CloseAndRemoveTempFile( CFile &file )
{
if( CFile::hFileNull != file.m_hFile )
{
CString strFileName = file.GetFilePath( );
try{
file.Close();
}catch( CException * e ) { e->Delete(); }
return DeleteFile( strFileName );
}
return FALSE;
}
BOOL CNetDatabase::GetTempNewDirectory( CString &sTempNewDir )
{
char szTempPath[MAX_PATH+1];
memset( szTempPath, 0, sizeof(szTempPath) );
GetSelfTempPath( szTempPath, MAX_PATH );
if( 0 == strlen(szTempPath) )
GetTempPath( MAX_PATH, szTempPath );
if( 0 == strlen(szTempPath) )
return FALSE;
CString sDir = szTempPath;
sDir += "NFO";
srand( time(NULL) );
DWORD dw = rand() % 10000;
sTempNewDir.Format( "%s%.4d\\", sDir, dw );
int nCount = 0;
while( 0 == access(sDir,0) )
{
nCount ++;
if( nCount > 1000 )
return FALSE;
dw ++;
sTempNewDir.Format( "%s%.4d\\", sDir, dw );
}
return CreateDirectory( sTempNewDir, NULL );
}
BOOL CNetDatabase::RemoveTempNewDirectory( CString sTempNewDir )
{
CFileFind finder;
BOOL bWorking = finder.FindFile( sTempNewDir + "*.*" );
while( bWorking )
{
bWorking = finder.FindNextFile();
DeleteFile( finder.GetFilePath() );
}
finder.Close();
return RemoveDirectory(sTempNewDir);
}
int CNetDatabase::GetFileCount( const char * path, BOOL bRecurse )
{
if( NULL == path || strlen(path) == 0 )
return FALSE;
int nCount = 0;
CString strFinder = path;
if( strFinder.GetLength() > 0 &&
strFinder[strFinder.GetLength()-1] != '\\' && strFinder[strFinder.GetLength()-1] != '/' )
strFinder += STRING_DIRSEP;
strFinder += "*";
CFileFind finder;
BOOL bWorking = finder.FindFile( strFinder );
while( bWorking )
{
bWorking = finder.FindNextFile();
DWORD attr = GetFileAttributes( finder.GetFilePath() );
if( 0xFFFFFFFF != attr && (attr & FILE_ATTRIBUTE_DIRECTORY) && bRecurse )
{
CString strName = finder.GetFileName();
if( 0 != strName.CompareNoCase(".") && 0 != strName.CompareNoCase("..") )
nCount += GetFileCount( finder.GetFilePath() + STRING_DIRSEP, bRecurse );
}
if( 0xFFFFFFFF != attr && !(attr & FILE_ATTRIBUTE_DIRECTORY) )
nCount ++;
}
finder.Close();
return nCount;
}
BOOL CNetDatabase::InstallPackageEx( CPackage &pac, const char *zipfilename,
PROGRESS_CALLBACK fnCallback, void *cookie )
{
if( !pac.m_bIsZipped )
{
if( fnCallback )
fnCallback( PROG_INSTALLPACKAGE, 0, NULL, cookie );
return InstallPackage( pac, zipfilename, fnCallback, cookie );
}
if( NULL == zipfilename || strlen(zipfilename) == 0 )
return FALSE;
CInfoZip InfoZip;
if (!InfoZip.InitializeUnzip())
{
SetLastError( ERR_NETDB_ZIPDLL );
return FALSE;
}
CString sTempNewDir;
if( !GetTempNewDirectory( sTempNewDir ) )
{
InfoZip.FinalizeUnzip();
return FALSE;
}
if( fnCallback )
fnCallback( PROG_EXTRACTZIPFILES, 0, NULL, cookie );
if (!InfoZip.ExtractFiles(zipfilename, sTempNewDir))
{
SetLastError( ERR_NETDB_ZIP );
InfoZip.FinalizeUnzip();
return FALSE;
}
if (!InfoZip.FinalizeUnzip())
{
SetLastError( ERR_NETDB_ZIPDLL );
}
if( fnCallback )
fnCallback( PROG_INSTALLPACKAGE, 0, NULL, cookie );
int nTotalCount = GetFileCount( sTempNewDir );
BOOL bRet = InstallPackagePath( pac, sTempNewDir, fnCallback, cookie, nTotalCount, 0 );
RemoveTempNewDirectory( sTempNewDir );
return bRet;
}
BOOL CNetDatabase::InstallPackagePath( CPackage &pac, const char *path,
PROGRESS_CALLBACK fnCallback, void *cookie,
int nTotalCount, int nFinishCount, BOOL bDeleteAfterInstall )
{
if( NULL == path || strlen(path) == 0 )
return FALSE;
CString strFinder = path;
if( strFinder[strFinder.GetLength()-1] != '\\' && strFinder[strFinder.GetLength()-1] != '/' )
strFinder += STRING_DIRSEP;
strFinder += "*";
BOOL bRet = TRUE;
CFileFind finder;
BOOL bWorking = finder.FindFile( strFinder );
while( bWorking )
{
bWorking = finder.FindNextFile();
DWORD attr = GetFileAttributes( finder.GetFilePath() );
if( 0xFFFFFFFF != attr && (attr & FILE_ATTRIBUTE_DIRECTORY) )
{
CString strName = finder.GetFileName();
if( 0 != strName.CompareNoCase(".") && 0 != strName.CompareNoCase("..") )
{
bRet &= InstallPackagePath( pac, finder.GetFilePath() + STRING_DIRSEP,
fnCallback, cookie, nTotalCount, nFinishCount );
if( bDeleteAfterInstall )
RemoveDirectory( finder.GetFilePath() );
}
}
if( 0xFFFFFFFF != attr && !(attr & FILE_ATTRIBUTE_DIRECTORY) )
{
if( 1 == nTotalCount )
bRet &= InstallPackage( pac, finder.GetFilePath(), fnCallback, cookie );
else
bRet &= InstallPackage( pac, finder.GetFilePath(), fnCallback, cookie );
if( bDeleteAfterInstall )
DeleteFile( finder.GetFilePath() );
nFinishCount ++;
if( fnCallback && nTotalCount > 1 )
fnCallback( PROG_PROGRESS, DWORD(STKLIB_MAXF_PROGRESS*nFinishCount/nTotalCount), NULL, cookie );
}
}
finder.Close();
if( fnCallback )
fnCallback( PROG_PROGRESS, STKLIB_MAX_PROGRESS, NULL, cookie );
return bRet;
}
BOOL CNetDatabase::InstallPackage( CPackage &pac, const char *pacfile,
PROGRESS_CALLBACK fnCallback, void *cookie )
{
CString strFilenameOrg;
if( pac.m_bIsZipped )
strFilenameOrg = pacfile;
else if( !pac.m_strURL.IsEmpty() )
strFilenameOrg = pac.m_strURL;
else
strFilenameOrg = pacfile;
int nIndex = strFilenameOrg.ReverseFind( '/' );
if( -1 != nIndex )
strFilenameOrg = strFilenameOrg.Mid( nIndex + 1 );
nIndex = strFilenameOrg.ReverseFind( '\\' );
if( -1 != nIndex )
strFilenameOrg = strFilenameOrg.Mid( nIndex + 1 );
BOOL bOK = strFilenameOrg.GetLength() > 4;
if( bOK && CPackage::packageCode == pac.m_nType )
{
CString strDomainFile = AfxGetProfile().GetDomainFile();
int nIndex = strDomainFile.ReverseFind( '/' );
if( -1 != nIndex )
strDomainFile = strDomainFile.Mid( nIndex + 1 );
nIndex = strDomainFile.ReverseFind( '\\' );
if( -1 != nIndex )
strDomainFile = strDomainFile.Mid( nIndex + 1 );
if( 0 == strFilenameOrg.CompareNoCase( strDomainFile ) ) // 板块数据
bOK = (InstallCodetblBlock( pacfile, strFilenameOrg ) >= 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".blk" ) ) // 分析家板块
bOK = (InstallCodetblFxjBlock( pacfile, strFilenameOrg ) >= 0 );
else
bOK = (InstallCodetbl( pacfile, strFilenameOrg ) > 0 );
}
else if( bOK && CPackage::packageDay == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".stk" ) ) // 通用格式
bOK = ( InstallKDataTy( pacfile, CKData::ktypeDay, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dad" ) ) // 分析家格式
bOK = ( InstallKDataFxj( pacfile, CKData::ktypeDay, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 说明文件
bOK = TRUE;
else
bOK = FALSE;
}
else if( bOK && CPackage::packageMin5 == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".stk" ) ) // 通用格式
bOK = ( InstallKDataTy( pacfile, CKData::ktypeMin5, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dad" ) ) // 分析家格式
bOK = ( InstallKDataFxj( pacfile, CKData::ktypeMin5, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 说明文件
bOK = TRUE;
else
bOK = FALSE;
}
else if( bOK && CPackage::packageDR == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dat" ) ) // 普通格式
bOK = ( InstallDRDataClk( pacfile, strFilenameOrg ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".pwr" ) ) // 分析家除权格式
bOK = ( InstallDRDataFxj( pacfile ) > 0 );
else
bOK = FALSE;
}
else if( bOK && CPackage::packageBasetext == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 文本资料
bOK = ( InstallBaseText( pacfile, strFilenameOrg ) > 0 );
else
bOK = FALSE;
}
else if( bOK && CPackage::packageBasetable == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".bst" ) ) // 财务格式
bOK = ( InstallBasetable( pacfile, strFilenameOrg ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dbf" ) ) // 通达信财务格式
bOK = ( InstallBasetableTdx( pacfile ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".fin" ) ) // 分析家财务格式
bOK = ( InstallBasetableFxj( pacfile ) > 0 );
else
bOK = FALSE;
}
else
bOK = FALSE;
if( !bOK )
{
CFileStatus rStatus;
if( ! (CFile::GetStatus( pacfile, rStatus ) && rStatus.m_size > 0) )
bOK = TRUE;
}
if( !bOK && fnCallback )
{
CString string = pac.m_strDescript;
fnCallback( PROG_ERRORPAC, 0, string.GetBuffer(string.GetLength()+1), cookie );
string.ReleaseBuffer();
}
return bOK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -