//--------------------------------------------------------------------------- int Table::ConsistencyCheck(int in) { char path_lock[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( Name, drive, dir, fname, ext ); _makepath( path_lock, drive, dir, fname, ".lck"); if (access(path_lock, 0)) // file does not exist { SetConsistencyInfo(CONSISTENCY_DONTKNOW); return 1; // no consistency check available, assume ok } FILE *lock = fopen(path_lock, "rb"); if (!lock) { SetConsistencyInfo(CONSISTENCY_DONTKNOW); return 1; // failed to open lock, assume ok } unsigned int lockcrctable, lockcrcidx; fread(&lockcrctable, 4, 1, lock); fread(&lockcrcidx, 4, 1, lock); fclose(lock); unsigned int thiscrctable = crc32file(Name); unsigned int thiscrcidx = crc32file(IdxName); if (lockcrctable != thiscrctable || lockcrcidx != thiscrcidx) { if (in) { SetConsistencyInfo(CONSISTENCY_BACKUPCORRUPTED); return 0; // corrupted } if (!RestoreBackup()) { SetConsistencyInfo(CONSISTENCY_CORRUPTED); return 0; // corrupted } if (!ConsistencyCheck(1)) return 0; else SetConsistencyInfo(CONSISTENCY_RESTORED); } else { SetConsistencyInfo(CONSISTENCY_OK); // Data is valid, let's backup it if we need // #ifdef DBBACKUP MakeBackup(); // #endif } return 1; // data is valid }
TDL_WEBUPDATE_RESULT CTDLWebUpdater::DoUpdate(const CString& sAppFolder, const CString& sPrevCmdLine) { if (WebMisc::IsOnline()) { // reset result m_nResUpdate = TDLWUR_SUCCESS; if (SetAppFolder(sAppFolder) && InitialiseTemporaries()) { if (!DoProgressDialog(sPrevCmdLine)) RestoreBackup(); m_dlgProgress.DestroyWindow(); CleanupTemporaries(); } } else m_nResUpdate = TDLWUR_ERR_CONNECTED; return LogError(sAppFolder); }
void CCodeProcessor::ProcessModule( bool forcequiet, int depth, int& maxdepth, int& numheaders, int& skippedfiles, const char *baseroot, const char *root, const char *module ) { char filename[ 256 ]; bool checkroot = false; if ( depth > maxdepth ) { maxdepth = depth; } // Load the base module sprintf( filename, "%s\\%s", root, module ); strlwr( filename ); bool firstheader = true; retry: // Check module list for ( int i = 0; i < m_nModuleCount; i++ ) { if ( !stricmp( m_Modules[ i ].name, filename ) ) { if ( forcequiet ) { m_nHeadersProcessed++; numheaders++; if ( m_Modules[ i ].skipped ) { skippedfiles++; } } AddHeader( depth, filename, m_szCurrentCPP ); return; } } int filelength; char *buffer = (char *)COM_LoadFile( filename, &filelength ); if ( !buffer ) { if ( !checkroot ) { checkroot = true; // Load the base module sprintf( filename, "%s\\%s", baseroot, module ); goto retry; } m_Modules[ m_nModuleCount ].skipped = true; strcpy( m_Modules[ m_nModuleCount++ ].name, filename ); skippedfiles++; return; } m_nBytesProcessed += filelength; m_Modules[ m_nModuleCount ].skipped = false; strcpy( m_Modules[ m_nModuleCount++ ].name, filename ); bool readonly = false; bool madechanges = false; CreateBackup( filename, readonly ); if ( !forcequiet ) { strcpy( m_szCurrentCPP, filename ); vprint( 0, "- %s\n", (char *)&filename[ m_nOffset ] ); } // Parse tokens looking for #include directives or class starts char *current = buffer; char *startofline; current = CC_ParseToken( current ); while ( current ) { // No more tokens if ( strlen( com_token ) <= 0 ) break; if ( !stricmp( com_token, "#include" ) ) { startofline = current - strlen( "#include" ); current = CC_ParseToken( current ); if ( strlen( com_token ) > 0) { vprint( 1, "#include %s", com_token ); m_nHeadersProcessed++; numheaders++; AddHeader( depth, filename, m_szCurrentCPP ); bool dobuild = true; if ( firstheader ) { if ( !stricmp( com_token, "cbase.h" ) ) { dobuild = false; } if ( !TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) ) { // build is broken, stop assert( 0 ); } } firstheader = false; if ( dobuild ) { // Try removing the header and compiling char saveinfo[2]; memcpy( saveinfo, startofline, 2 ); startofline[ 0 ] = '/'; startofline[ 1 ] = '/'; if ( TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) ) { vprint( 0, ", unnecessary\n" ); madechanges = true; } else { // Restore line memcpy( startofline, saveinfo, 2 ); vprint( 0, "\n" ); } } else { vprint( 0, "\n" ); } } } current = CC_ParseToken( current ); } // Save out last set of changes { FILE *fp; fp = fopen( filename, "wb" ); if ( fp ) { fwrite( buffer, filelength, 1, fp ); fclose( fp ); } } COM_FreeFile( (unsigned char *)buffer ); if ( !madechanges ) { RestoreBackup( filename, readonly ); } if ( !forcequiet && !GetQuiet() ) { vprint( 0, " %s: headers (%i)", (char *)&filename[ m_nOffset ], numheaders ); if ( maxdepth > 1 ) { vprint( 0, ", depth %i", maxdepth ); } vprint( 0, "\n" ); } m_nLinesOfCode += linesprocessed; linesprocessed = 0; }