void Persons2::UpdateLog(ItemPtr eventitem,int credits,EventLog::Stage stage) { if (!TargLog) { TargLog=new EventLog(eventloglist); UpdateLog(TargLog,0,stage,eventitem); TargLog->encsize=1; } else { UpdateLog(TargLog,0,stage); } }
void Persons2::UpdateLog(MobileItemPtr eventitem,int credits,EventLog::Stage stage) { if (!TruckLog) { TruckLog=new EventLog(eventloglist); UpdateLog(TruckLog,credits,stage,eventitem); TruckLog->encounteredtype=PT_VEHICLES; TruckLog->encsize=10; } else { UpdateLog(TruckLog,credits,stage); } }
int freadError(FILE * file, string texFilePath) { if(GLubyte error = ferror(file) != 0) { stringstream sstm; sstm << "TGA file read error. Code: " << error << " File: " << texFilePath; UpdateLog(sstm.str(), true); } if(GLubyte error = feof(file) != 0) { stringstream sstm; sstm << "TGA file end-of-file error. Code: " << error << " File: " << texFilePath; UpdateLog(sstm.str(), true); } return -1; }
void ShowMessageInfo(tMessage *pMsg) { if (MsgInfo[pMsg->Type].Log) PrintF("%s x%02X", MsgInfo[pMsg->Type].MsgStr, pMsg->Options); UpdateLog(pMsg->Type, pMsg->Options); UpdateQueueInfo(); }
void CTaskQueue::DealResult(CTaskInfo* pTaskInfo,int nRes) { Lock; CString strLog; strLog.Format(_T("result taskid=%d,res=%d,TaskListCount=%d"),pTaskInfo->m_Index,nRes,m_TaskList.size()); UpdateLog(strLog.GetBuffer()); g_Logger.Debug(__FILE__,__LINE__,strLog); // if (pTaskInfo->m_nFileType == FILETYPE_PNG || // pTaskInfo->m_nFileType == FILETYPE_BMP || // pTaskInfo->m_nFileType == FILETYPE_TIF || // pTaskInfo->m_nFileType == FILETYPE_TIFF || // pTaskInfo->m_nFileType == FILETYPE_JPEG || // pTaskInfo->m_nFileType == FILETYPE_JPG ) // { // if ( nRes == FALSE ) // { // g_dealCount++; // strLog.Format(_T("处理个数 %ld"),g_dealCount); // UpdateDealCount(strLog.GetBuffer()); // } // } // else if ( nRes != FALSE ) // { // g_dealCount++; // strLog.Format(_T("处理个数 %ld"),g_dealCount); // UpdateDealCount(strLog.GetBuffer()); // } //g_Logger.Debug_Trace(__FILE__,__LINE__,_T("result taskid=%d,res=%d,TaskListCount=%d"),pTaskInfo->m_Index,nRes,m_TaskList.size()); UnLock; }
LRESULT DlgBfLog::QryBfLogMsg(WPARAM wParam,LPARAM lParam) { UpdateLog(); return 0; }
bool User::Create() { NoErrorConnection conn; user.id = conn.InsertAutoIncrement("users", user, "uid"); if (user.id == -1) return false; UpdateLog(); return true; }
int fseekError(GLubyte error, string texFilePath) { stringstream sstm; sstm << "TGA file seek error. Code: " << error << " File: " << texFilePath; UpdateLog(sstm.str(), true); return -1; }
void Persons2::UpdatePlayerLog(AirStrucPtr eventitem,EventLog::Stage stage) { if (!PlayerLog) { PlayerLog=new EventLog(eventloglist); UpdateLog(PlayerLog,0,stage,eventitem); PlayerLog->homebase=eventitem->ai.eventlog->homebase; PlayerLog->encounteredtype=eventitem->ai.eventlog->encounteredtype; PlayerLog->escorttype=eventitem->ai.eventlog->escorttype; PlayerLog->encsize=1; } else { UpdateLog(PlayerLog,0,stage); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); client = new ClientModel; connect(client, SIGNAL(SendMessageToMainForm(QString)), this, SLOT(UpdateLog(QString))); connect(ui->startButton, SIGNAL(clicked()), this, SLOT(StartClient())); }
Indicadores::Indicadores(QWidget *parent ) :QDialog(parent) { setupUi(this); //return; QDateTime dateTime = QDateTime::currentDateTime(); QString Fecha = dateTime.toString("dd-MM-yy"); UpdateLog(Fecha + ".txt"); }
void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) { if (!m_LogAccess) return; if (m_ignoreLogTimer) return; UpdateLog(); // Scroll to the last line if (!msgQueue.empty()) { m_Log->ScrollLines(1); m_Log->ShowPosition( m_Log->GetLastPosition() ); } }
void ControlCenter::Run() { Initialize(); bool need_refresh = false; for (bool done = false; !done;) { if (need_refresh) { // refresh the window since we call endwin before invoking bbs code. RefreshAll(); need_refresh = false; } wtimeout(commands_->window(), 500); int key = commands_->GetChar(); if (key == ERR) { // we have a timeout. process other events need_refresh = false; UpdateLog(); UpdateStatus(status_.get()); CleanNetIfNeeded(); RunEventsIfNeeded(); continue; } need_refresh = true; session()->SetWfcStatus(2); // Call endwin since we'll be out of curses IO endwin(); switch (toupper(key)) { case 'B': wfc_command(INST_LOC_BOARDEDIT, boardedit, cleanup_net); log_->Put("Ran BoardEdit"); break; case 'C': wfc_command(INST_LOC_CHAINEDIT, chainedit); log_->Put("Ran ChainEdit"); break; case 'D': wfc_command(INST_LOC_DIREDIT, dlboardedit); log_->Put("Ran DirEdit"); break; case 'E': wfc_command(INST_LOC_EMAIL, send_email_f, cleanup_net); break; case 'G': wfc_command(INST_LOC_GFILEEDIT, gfileedit); break; case 'H': wfc_command(INST_LOC_EVENTEDIT, eventedit); break; case 'I': wfc_command(INST_LOC_VOTEEDIT, ivotes); break; case 'J': wfc_command(INST_LOC_CONFEDIT, edit_confs); break; case 'L': wfc_command(INST_LOC_WFC, view_sysop_log_f); break; case 'M': wfc_command(INST_LOC_EMAIL, read_mail_f, cleanup_net); break; case 'N': wfc_command(INST_LOC_WFC, []() { print_local_file("net.log"); }); break; case 'P': wfc_command(INST_LOC_WFC, print_pending_list); break; case 'R': wfc_command(INST_LOC_MAILR, mailr); break; case 'S': wfc_command(INST_LOC_WFC, prstatus, getkey_f); break; case 'U': wfc_command(INST_LOC_UEDIT, []() { uedit(1, UEDIT_NONE); } ); break; case 'Y': wfc_command(INST_LOC_WFC, view_yesterday_sysop_log_f); break; case 'Z': wfc_command(INST_LOC_WFC, zlog, getkey_f); break; case 'Q': done=true; break; // ansicallout doesn't work due to arrow keys and other drawing problems with it under curses. // case '/': wfc_command(INST_LOC_NET, []() { force_callout(0); }); log_->Put("Ran Network Callout"); break; case ' ': log_->Put("Not Implemented Yet"); break; } TouchAll(); } }
bool User::SaveName() { try { SafeConnection conn; conn.SetField("users", QUERY("uid" << user.id), user, "name" ); UpdateLog(); return true; } catch (const DBError&) { return false; } }
int LoadHSPToPalette(HSPalette * hsPal) { if(hsPal == NULL) { UpdateLog("HSPalette object is null.", true); return -1; //given palette is null } FILE * file; //MAC CHANGE - Arsen //Changed from fopen_s to fopen. This means no more error codes so I just decided to return -1. //So long as file isn't null, then there should be no problem, but this could probably be safer file = fopen(hsPal->paletteFilePath.data(), "rb"); if(!file) { GLuint error = -1; UpdateLog("Could not open palette file: " + hsPal->paletteFilePath, true); return error; //couldn't open the file } GLubyte * paletteData = (GLubyte*)malloc(1024 * sizeof(GLubyte)); for(int i = 0; i < 256; i++) { if(fread((void *)(paletteData + i*4), 3, 1, file) != 1) {return freadError(file, hsPal->paletteFilePath);} *(paletteData + i*4 + 3) = 0x00; } fclose(file); return StorePaletteData(hsPal, paletteData); }
int StorePaletteData(HSPalette * hsPal, GLubyte * paletteData) { GLuint textureID; glActiveTexture(GL_TEXTURE1); glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, paletteData); delete(paletteData); glBindTexture(GL_TEXTURE_2D, 0); ////allocate space //unsigned int * paletteData = (unsigned int*)malloc(PALETTE_LENGTH * PALETTE_COLOR_LENGTH * sizeof(unsigned int)); ////have to turn each byte into an unsigned int. THANKS SHADERS //for(int i = 0; i < PALETTE_LENGTH * PALETTE_COLOR_LENGTH; i++) //{ // //get each color byte // GLubyte byte; // unsigned int intColor; // if(fread(&byte, 1, 1, file) != 1) {return freadError(file, hsPal->paletteFilePath);} // intColor = (unsigned int)byte; // memcpy(paletteData + i, &intColor, sizeof(unsigned int)); //} //save the palette data //hsPal->paletteData = paletteData; hsPal->textureID = textureID; GLenum glError = glGetError(); if(glError != GL_NO_ERROR) { string glErrorString = "OpenGL error in StorePaletteData()."; UpdateLog(glErrorString, true); } return 0; }
CTaskInfo* CTaskQueue::PopTask() { g_Logger.Debug_Trace(__FILE__,__LINE__,_T("Taking a product ... ")); CTaskInfo* pTaskInfo = NULL; if (m_TaskListlist.size()>0) { pTaskInfo = m_TaskListlist.front(); m_TaskListlist.pop_front(); //g_Logger.Debug_Trace(__FILE__,__LINE__,_T("Succeed")); //g_Logger.Debug_Trace(__FILE__,__LINE__,_T("----ConsumeID---------------%d"),pTaskInfo->m_Index); CString strLog; strLog.Format(_T("file count =%d"),m_TaskListlist.size()); UpdateLog(strLog.GetBuffer()); } return pTaskInfo; }
VOID ShowProcess(ULONG pEProcess) { PLARGE_INTEGER ExitTime; ULONG PID; PUCHAR pFileName; TCHAR pMessage[256]; ExitTime = (PLARGE_INTEGER)(pEProcess + EXIT_TIME_OFFSET); if(ExitTime->QuadPart != 0) //已经结束的进程的ExitTime为非零 return ; PID = *(PULONG)(pEProcess + PROCESS_ID_OFFSET); pFileName = (PUCHAR)(pEProcess + FILE_NAME_OFFSET); DbgPrint("0x%08X %04d %s",pEProcess,PID,pFileName); sprintf(pMessage,"%d\t%s\t%0x", PID,pFileName,pEProcess); UpdateLog((PTSTR)pMessage); }
void Log::LogE(const char *formatString, ...) { va_list argptr; va_start(argptr, formatString); vsprintf(dstBuf, formatString, argptr); va_end(argptr); UpdateTime(); UpdateLog(); if (logToConsole) printf("%s", logSStream.str().c_str()); if (logToFile) { fileStream << logSStream.str(); fileStream.flush(); } }
void Persons2::UpdateLog(AirStrucPtr eventitem,int credits,EventLog::Stage stage) { UpdateLog(eventitem->ai.eventlog,credits,stage,eventitem); }
void EosTcpClientThread::run() { QString msg = QString("tcp client %1:%2 thread started").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); const size_t ReconnectDelay = 5000; EosTimer reconnectTimer; // outer loop for auto-reconnect while( m_Run ) { EosTcp *tcp = EosTcp::Create(); if( tcp->Initialize(m_PrivateLog,m_Ip.toUtf8().constData(),m_Port) ) { OSCParser parser; parser.SetRoot(new OSCHandler(*this)); std::string inPrefix = QString("TCPIN [%1:%2] ").arg(m_Ip).arg(m_Port).toUtf8().constData(); std::string outPrefix = QString("TCPOUT [%1:%2] ").arg(m_Ip).arg(m_Port).toUtf8().constData(); sPacket packet; // connect while(m_Run && tcp->GetConnectState()==EosTcp::CONNECT_IN_PROGRESS) { tcp->Tick(m_PrivateLog); UpdateLog(); msleep(10); } UpdateLog(); // send/recv while connected if(m_Run && tcp->GetConnectState()==EosTcp::CONNECT_CONNECTED) { m_Mutex.lock(); m_NetEventQ.push_back(NET_EVENT_CONNECTED); m_Mutex.unlock(); PACKET_Q sendQ; OSCStream oscStream(m_FrameMode); do { size_t len = 0; const char *data = tcp->Recv(m_PrivateLog, 100, len); oscStream.Add(data, len); while( m_Run ) { packet.data = oscStream.GetNextFrame(packet.size); if(packet.data && packet.size!=0) { m_Prefix = inPrefix; m_LogMsgType = EosLog::LOG_MSG_TYPE_RECV; parser.PrintPacket(*this, packet.data, packet.size); parser.ProcessPacket(*this, packet.data, packet.size); delete[] packet.data; } else break; } msleep(1); m_Mutex.lock(); m_SendQ.swap(sendQ); m_Mutex.unlock(); sPacket framedPacket; for(PACKET_Q::iterator i=sendQ.begin(); m_Run && i!=sendQ.end(); i++) { framedPacket.size = i->size; framedPacket.data = OSCStream::CreateFrame(m_FrameMode, i->data, framedPacket.size); if(framedPacket.data && framedPacket.size!=0) { if( tcp->Send(m_PrivateLog,framedPacket.data,framedPacket.size) ) { m_Prefix = outPrefix; m_LogMsgType = EosLog::LOG_MSG_TYPE_SEND; parser.PrintPacket(*this, i->data, i->size); } delete[] framedPacket.data; } delete[] i->data; } sendQ.clear(); UpdateLog(); msleep(1); } while(m_Run && tcp->GetConnectState()==EosTcp::CONNECT_CONNECTED); m_Mutex.lock(); m_NetEventQ.push_back(NET_EVENT_DISCONNECTED); m_Mutex.unlock(); } } delete tcp; if( m_Run ) { msg = QString("tcp client %1:%2 reconnecting in %3...").arg(m_Ip).arg(m_Port).arg(ReconnectDelay/1000); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); } reconnectTimer.Start(); while(m_Run && !reconnectTimer.GetExpired(ReconnectDelay)) msleep(10); } msg = QString("tcp client %1:%2 thread ended").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); }
void EosUdpInThread::run() { QString msg = QString("udp input %1:%2 thread started").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); const size_t ReconnectDelay = 5000; EosTimer reconnectTimer; // outer loop for auto-reconnect while( m_Run ) { EosUdpIn *udpIn = EosUdpIn::Create(); if( udpIn->Initialize(m_PrivateLog,m_Ip.toUtf8().constData(),m_Port) ) { sockaddr_in addr; OSCParser parser; parser.SetRoot(new OSCHandler(*this)); char *scratch = 0; size_t scratchSize = 0; // run while( m_Run ) { int len = 0; int addrSize = static_cast<int>( sizeof(addr) ); const char *data = udpIn->RecvPacket(m_PrivateLog, 100, 0, len, &addr, &addrSize); if(data && len>0) { QHostAddress host( reinterpret_cast<const sockaddr*>(&addr) ); m_Prefix = QString("IN [%1:%2] ").arg( host.toString() ).arg(m_Port).toUtf8().constData(); parser.PrintPacket(*this, data, static_cast<size_t>(len)); if(scratch!=0 && scratchSize<static_cast<size_t>(len)) { delete[] scratch; scratch = 0; } if(scratch == 0) { scratchSize = static_cast<size_t>(len); scratch = new char[scratchSize]; } memcpy(scratch, data, static_cast<size_t>(len)); parser.ProcessPacket(*this, scratch, static_cast<size_t>(len)); } UpdateLog(); msleep(1); } if(scratch != 0) delete[] scratch; } delete udpIn; if( m_Run ) { msg = QString("udp input %1:%2 reconnecting in %3...").arg(m_Ip).arg(m_Port).arg(ReconnectDelay/1000); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); } reconnectTimer.Start(); while(m_Run && !reconnectTimer.GetExpired(ReconnectDelay)) msleep(10); } msg = QString("udp input %1:%2 thread ended").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); }
void EosUdpOutThread::run() { QString msg = QString("udp output %1:%2 thread started").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); const unsigned int ReconnectDelay = 5000; EosTimer reconnectTimer; m_Prefix = QString("OUT [%1:%2] ").arg(m_Ip).arg(m_Port).toUtf8().constData(); // outer loop for auto-reconnect while( m_Run ) { EosUdpOut *udpOut = EosUdpOut::Create(); if( udpOut->Initialize(m_PrivateLog,m_Ip.toUtf8().constData(),m_Port) ) { m_Mutex.lock(); m_NetEventQ.push_back(NET_EVENT_CONNECTED); m_Mutex.unlock(); OSCParser logParser; logParser.SetRoot(new OSCMethod()); // run PACKET_Q q; while( m_Run ) { m_Mutex.lock(); m_Q.swap(q); m_Mutex.unlock(); for(PACKET_Q::const_iterator i=q.begin(); i!=q.end(); i++) { if( udpOut->SendPacket(m_PrivateLog,i->data,static_cast<int>(i->size)) ) logParser.PrintPacket(*this, i->data, i->size); delete[] i->data; } q.clear(); UpdateLog(); msleep(1); } m_Mutex.lock(); m_NetEventQ.push_back(NET_EVENT_DISCONNECTED); m_Mutex.unlock(); } delete udpOut; if( m_Run ) { msg = QString("udp output %1:%2 reconnecting in %3...").arg(m_Ip).arg(m_Port).arg(ReconnectDelay/1000); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); } reconnectTimer.Start(); while(m_Run && !reconnectTimer.GetExpired(ReconnectDelay)) msleep(10); } msg = QString("udp output %1:%2 thread ended").arg(m_Ip).arg(m_Port); m_PrivateLog.AddInfo( msg.toUtf8().constData() ); UpdateLog(); }
void User::SaveField(const std::string& field, bool updateLog) const { NoErrorConnection conn; conn.SetField("users", QUERY("uid" << user.id), user, field); if (updateLog) UpdateLog(); }
void User::Purge() const { NoErrorConnection conn; conn.Remove("users", QUERY("uid" << user.id)); UpdateLog(); }
void User::SaveGIDs() { NoErrorConnection conn; conn.SetFields("users", QUERY("uid" << user.id), user, { "primary gid", "secondary gids", "gadmin gids" }); UpdateLog(); }
BOOL LoggingProc ( IN LPLOG_THREAD_DATA pArg ) { HQUERY hQuery; HCOUNTER hThisCounter; DWORD dwDelay; DWORD dwSampleInterval, dwSampleTime; PDH_STATUS pdhStatus; DWORD dwNumCounters; LONG lStatus; TCHAR szDefaultDir[MAX_PATH]; TCHAR szBaseName[MAX_PATH]; LPTSTR szThisPath; DWORD dwLogType = OPD_CSV_FILE; BOOL bRun = FALSE; DWORD dwSamplesUntilNewFile; TCHAR szCurrentLogFile[MAX_PATH]; LONG lWaitStatus; LPTSTR szStringArray[4]; DWORD dwFileSizeLimit; LONGLONG llFileSizeLimit; LONGLONG llFileSize; PLOG_COUNTER_INFO pCtrInfo; // read registry values if (!LoadDataFromRegistry (pArg, szDefaultDir, szBaseName, szCurrentLogFile)) { // unable to initialize the query from the registry return FALSE; } // convert to milliseconds for use in timeouts dwSampleInterval = pArg->dwTimeInterval * 1000L; // open query and add counters from info file pdhStatus = PdhOpenQuery (NULL, 0, &hQuery); // from current activity if (pdhStatus == ERROR_SUCCESS) { dwNumCounters = 0; for (szThisPath = pArg->mszCounterList; *szThisPath != 0; szThisPath += lstrlen(szThisPath) + 1) { pdhStatus = PdhAddCounter (hQuery, (LPTSTR)szThisPath, dwNumCounters++, &hThisCounter); if (pdhStatus == ERROR_SUCCESS) { // then add this handle to the list pCtrInfo = G_ALLOC (sizeof (LOG_COUNTER_INFO)); if (pCtrInfo != NULL) { // insert at front of list since the order isn't // important and this is simpler than walking the // list each time. pCtrInfo->hCounter = hThisCounter; pCtrInfo->next = pFirstCounter; pFirstCounter = pCtrInfo; } } } // to make sure we get to log the data SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_HIGHEST); bRun = TRUE; while (bRun) { // Get the current Log filename if (pArg->dwRenameIntervalCount != 0) { // then this is an autonamed file // so make current name BuildCurrentLogFileName ( szBaseName, szDefaultDir, szCurrentLogFile, &pArg->dwCurrentSerialNumber, pArg->dwAutoNameFormat, pArg->dwLogType); // reset loop counter switch (pArg->dwRenameIntervalUnits) { case OPD_RENAME_KBYTES: dwFileSizeLimit = pArg->dwRenameIntervalCount * 1024; dwSamplesUntilNewFile = 0; break; case OPD_RENAME_MBYTES: dwFileSizeLimit = pArg->dwRenameIntervalCount * 1024 * 1024; dwSamplesUntilNewFile = 0; break; case OPD_RENAME_HOURS: case OPD_RENAME_DAYS: case OPD_RENAME_MONTHS: default: dwSamplesUntilNewFile = GetSamplesInRenameInterval( pArg->dwTimeInterval, pArg->dwRenameIntervalCount, pArg->dwRenameIntervalUnits); dwFileSizeLimit = 0; break; } } else { // filename is left as read from the registry dwSamplesUntilNewFile = 0; dwFileSizeLimit = 0; } llFileSizeLimit = dwFileSizeLimit; // open log file using this query dwLogType = pArg->dwLogType; pdhStatus = OpenLogW ( szCurrentLogFile, LOG_WRITE_ACCESS | LOG_CREATE_ALWAYS, &dwLogType, hQuery, 0); if (pdhStatus == ERROR_SUCCESS) { szStringArray[0] = pArg->szQueryName; szStringArray[1] = szCurrentLogFile; ReportEvent (hEventLog, EVENTLOG_INFORMATION_TYPE, 0, PERFLOG_LOGGING_QUERY, NULL, 2, 0, szStringArray, NULL); // start sampling immediately dwDelay = 0; while ((lWaitStatus = WaitForSingleObject (pArg->hExitEvent, dwDelay)) == WAIT_TIMEOUT) { // the event flag will be set when the sampling should exit. if // the wait times out, then that means it's time to collect and // log another sample of data. // the argument received the time it took to take the // sample so the delay can be adjusted accordingly dwSampleTime = 0; pdhStatus = UpdateLog (&dwSampleTime); if (pdhStatus == ERROR_SUCCESS) { // see if it's time to rename the file if (dwSamplesUntilNewFile) { if (!--dwSamplesUntilNewFile) break; } else if (llFileSizeLimit) { // see if the file is too big pdhStatus = GetLogFileSize (&llFileSize); if (pdhStatus == ERROR_SUCCESS) { if (llFileSizeLimit <= llFileSize) break; } } // compute new timeout value if (dwSampleTime < dwSampleInterval) { dwDelay = dwSampleInterval - dwSampleTime; } else { dwDelay = 0; } } else { // unable to update the log so log event and exit ReportEvent (hEventLog, EVENTLOG_ERROR_TYPE, 0, PERFLOG_UNABLE_UPDATE_LOG, NULL, 0, sizeof(DWORD), NULL, (LPVOID)&pdhStatus); bRun = FALSE; break; } } // end while wait keeps timing out if (lWaitStatus == WAIT_OBJECT_0) { // then the loop was terminated by the Exit event // so clear the "run" flag to exit the loop & thread bRun = FALSE; } CloseLog (0); } else { // unable to open log file so log event log message bRun = FALSE; // exit now } } // end while (bRun) PdhCloseQuery (hQuery); // update log serial number if necssary if (pArg->dwAutoNameFormat == OPD_NAME_NNNNNN) { lStatus = RegSetValueEx ( pArg->hKeyQuery, TEXT("Log File Serial Number"), 0L, REG_DWORD, (LPBYTE)&pArg->dwCurrentSerialNumber, sizeof(DWORD)); } } else { // unable to open query so write event log message } return bRun; }
int LoadTGAToTexture(HSTexture * hsTex, bool openGL3, bool useTGAPalette) { if(hsTex == NULL) { UpdateLog("HSTexture object is null.", true); return -1; //given texture is null } //the data that OpenGL ultimately needs GLushort imageWidth = 0; GLushort imageHeight = 0; GLubyte * imageData; GLuint textureID; GLuint bufferID; //variables to help us get the above data FILE * file; bool opaque = true; GLubyte imageIDLength; GLubyte colorMapType; GLubyte imageType; GLushort colorMapLength; GLubyte colorMapEntrySize; GLubyte pixelDepth; GLubyte bytesPerPixel; GLubyte colorBytesPerPixel = 3; //BGR GLubyte bytesPerColorMapEntry; GLubyte GLbytesPerPixel; GLubyte imageDescriptor; bool topAlign = true; bool rightAlign = true; //open the file string texFilePath = hsTex->textureFilePath; //MAC CHANGE - Arsen //Changed from fopen_s to fopen. This means no more error codes so I just decided to return -1. //So long as file isn't null, then there should be no problem, but this could probably be safer. file = fopen(texFilePath.data(), "rb"); if(!file) { GLuint error = -1; UpdateLog("Could not open texture file: " + texFilePath, true); return error; //couldn't open the file } //gather all the general info about the TGA file if(GLubyte error = fseek(file, 0L, SEEK_SET) != 0) {return fseekError(error, texFilePath);} //move to the beginning of the file if(fread(&imageIDLength, 1, 1, file) != 1) {return freadError(file, texFilePath);} //get the length of the image id field if(fread(&colorMapType, 1, 1, file) != 1) {return freadError(file, texFilePath);} //see if the file has a color map in it or not if(fread(&imageType, 1, 1, file) != 1) {return freadError(file, texFilePath);} //find out what kind of image file this is if(imageType != 9 && imageType != 10) { UpdateLog("TGA file is not run-lengh encoded: " + texFilePath, true); return -1; //this needs to be RLE, either indexed or truecolor } if(GLubyte error = fseek(file, 2L, SEEK_CUR) != 0) {return fseekError(error, texFilePath);} //skip the first two bytes of the color map specification if(fread(&colorMapLength, 2, 1, file) != 1) {return freadError(file, texFilePath);} //get the length of the color map if(fread(&colorMapEntrySize, 1, 1, file) != 1) {return freadError(file, texFilePath);} //get the size of each color map entry if(colorMapEntrySize == 15) { colorMapEntrySize = 16; //make sure it's a multiple of 8 } bytesPerColorMapEntry = colorMapEntrySize/8; //get the size of each color map entry in bytes if(GLubyte error = fseek(file, 4L, SEEK_CUR) != 0) {return fseekError(error, texFilePath);} //skip the first four bytes of the image specification if(fread((void *)&imageWidth, 2, 1, file) != 1) {return freadError(file, texFilePath);} //get the image width if(fread((void *)&imageHeight, 2, 1, file) != 1) {return freadError(file, texFilePath);} //get the image height if(fread(&pixelDepth, 1, 1, file) != 1) {return freadError(file, texFilePath);} //get the size of each pixel in bits bytesPerPixel = pixelDepth/8; //get the size of each pixel in bytes if((imageType == 9 && pixelDepth != 8) || (imageType == 10 && pixelDepth != 24)) { UpdateLog("TGA must be indexed 8-bit or truecolor 24-bit: " + texFilePath, true); return -1; //only allowed configurations are: indexed with 8-bit, or truecolor with 24 bit } if(fread(&imageDescriptor, 1, 1, file) != 1) {return freadError(file, texFilePath);} //get the image descriptor, and pull some data from it if((imageDescriptor & ATTRIBUTE_BITS) > 0) { UpdateLog("TGA must not have any attributes defined: " + texFilePath, true); return -1; //no attributes should be defined } if((imageDescriptor & TOP_ALIGN) == 0) { topAlign = false; //the pixels are bottom-aligned } if((imageDescriptor & RIGHT_ALIGN) == 0) { rightAlign = false; //the pixels are left-aligned } if(GLubyte error = fseek(file, (long)imageIDLength, SEEK_CUR) != 0) {return fseekError(error, texFilePath);} //skip the imageID if(useTGAPalette && colorMapType != 0) { //save the palette data if(hsTex->ownPalette == NULL) { hsTex->ownPalette = new HSPalette(); } if(bytesPerColorMapEntry != 3 || colorMapLength != 256) { UpdateLog("Malformed palette data in indexed TGA file: " + texFilePath, true); return -1; } GLubyte * paletteData = (GLubyte*)malloc(1024 * sizeof(GLubyte)); for(int i = 0; i < 256; i++) { if(fread((void *)(paletteData + i*4), bytesPerColorMapEntry, 1, file) != 1) {return freadError(file, texFilePath);} *(paletteData + i*4 + 3) = 0x00; } if(StorePaletteData(hsTex->ownPalette, paletteData) != 0) { UpdateLog("Error reading palette data from indexed TGA file: " + texFilePath, true); return -1; } } else { if(GLubyte error = fseek(file, (long)(colorMapLength * bytesPerColorMapEntry), SEEK_CUR) != 0) {return fseekError(error, texFilePath);} //skip the color map } //okay, time for the fun part: picking through the image data. //it's ALWAYS going to be in RLE format so we can't just grab the raw data. //we need to take the compressed data and turn it into a 32bit BGRA format to pass to opengl GLuint maxPixels = imageWidth * imageHeight; //we need this so we know when to stop GLuint curPixels = 0; //keeps track of how far we've gone through the actual output buffer GLubyte * color; if(imageType == 9) { GLbytesPerPixel = 1; colorBytesPerPixel = 1; } else if(imageType == 10) { GLbytesPerPixel = 4; } imageData = (GLubyte*)malloc(maxPixels * GLbytesPerPixel); //set up our image data buffer color = (GLubyte*)malloc(colorBytesPerPixel); //create a buffer to hold color data before it gets passed to the imageData GLubyte repCount; //this'll hold each repetition count field //if(imageType == 9) //{ // //open the palette file, if this is an indexed image // if(GLuint error = fopen_s(&palFile, palFilePath.data(), "rb") != 0) // { // UpdateLog("Could not open palette file: " + texFilePath, true); // return error; //couldn't open the file // } //} while(curPixels < maxPixels) { if(fread(&repCount, 1, 1, file) != 1) { return freadError(file, texFilePath);} //get the repetition count field if((repCount & RL_PACKET) == 0) { //this is a raw packet. //Just shove the pixel data into the image data buffer repCount = repCount & REP_COUNT_BITS; //get the actual number of following pixels //put the pixels into the image data buffer for(int i = 0; i <= repCount; i++) { //get the color data for this pixel if(imageType == 9) { //the data in the file represents indicies, so just pull it directly into the buffer if(fread(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel), bytesPerPixel, 1, file) != 1) {return freadError(file, texFilePath);} } else if(imageType == 10) { //the data in the file represents the actual color, so just pull it directly into the buffer if(fread(color, bytesPerPixel, 1, file) != 1) {return freadError(file, texFilePath);} memcpy(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel), color, colorBytesPerPixel); //if the color is the transparent color then make the pixel transparent if(*color == 255 && *(color + 1) == 0 && *(color + 2) == 255) { opaque = false; } else { opaque = true; } //add the alpha channel if(opaque) { *(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel) + 3) = 0xFF; } else { *(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel) + 3) = 0x00; } } //for(int j = bytesPerPixel - 1; j >= 0; j--) //{ // //gotta read each individual pixel in backwards since TGA stores color backwards // if(fread(imageData + (curPixels * (bytesPerPixel + alphaBytes)) + (i * (bytesPerPixel + alphaBytes)) + j, 1, 1, file) != 1) { return -1; } //} } } else { //this is a run-length packet. //Put the specificed number of pixels of the specified color into the image data buffer repCount = repCount & REP_COUNT_BITS; //get the actual number of following pixels //get the color of this run if(imageType == 9) { //the data in the file represents indicies, so just pull it directly into the buffer if(fread(color, bytesPerPixel, 1, file) != 1) {return freadError(file, texFilePath);} } else if(imageType == 10) { //the data in the file represents the actual color, so just pull it directly into the buffer if(fread(color, bytesPerPixel, 1, file) != 1) {return freadError(file, texFilePath);} //if the color is the transparent color then make the pixel transparent if(*color == 255 && *(color + 1) == 0 && *(color + 2) == 255) { opaque = false; } else { opaque = true; } } //for(int i = bytesPerPixel - 1; i >= 0; i--) //{ // //since TGA stores colors as BGR, we need to read it backwards to get RGB // if(fread(runColor + i, 1, 1, file) != 1) { return -1; } //} for(int i = 0; i <= repCount; i++) { //put a pixel of the specified packet color into the image data buffer memcpy(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel), color, colorBytesPerPixel); if(imageType == 10) { //add the alpha channel if(opaque) { *(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel) + colorBytesPerPixel) = 0xFF; } else { *(imageData + (curPixels * GLbytesPerPixel) + (i * GLbytesPerPixel) + colorBytesPerPixel) = 0x00; } } } } curPixels += repCount + 1; //update how far we've moved through the actual pixels } fclose(file); delete(color); //create and bind the texture glActiveTexture(GL_TEXTURE0); glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); //set some options //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); GLint internalFormat; GLint format; if(imageType == 9) { if(openGL3) { internalFormat = GL_R8; format = GL_RED; } else { internalFormat = GL_ALPHA8; format = GL_ALPHA; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } else if(imageType == 10) { internalFormat = GL_RGBA8; format = GL_BGRA; glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } //just... just jam it in! glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, imageWidth, imageHeight, 0, format, GL_UNSIGNED_BYTE, imageData); delete(imageData); glBindTexture(GL_TEXTURE_2D, 0); //save whether or not this is indexed if(imageType == 9) { hsTex->indexed = true; } else if(imageType == 10) { hsTex->indexed = false; } //make a buffer object if(hsTex->bufferID == 0) { //make an array of coordinates based on the texture dimensions GLfloat * dim = new GLfloat[12]; dim[0] = 0.0f; dim[1] = 0.0f; dim[2] = 0.0f; dim[3] = (GLfloat)imageWidth; dim[4] = 0.0f; dim[5] = 0.0f; dim[6] = (GLfloat)imageWidth; dim[7] = (GLfloat)imageHeight; dim[8] = 0.0f; dim[9] = 0.0f; dim[10] = (GLfloat)imageHeight; dim[11] = 0.0f; //make and save the coordinates to a buffer glGenBuffers(1, &bufferID); glBindBuffer(GL_ARRAY_BUFFER, bufferID); glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), dim, GL_STATIC_DRAW); delete[] dim; if(openGL3) { //get the position and texCoordIn positions GLenum positionLoc; GLenum texCoordInLoc; if(hsTex->indexed) { positionLoc = positionLocIndexed; texCoordInLoc = texCoordInLocIndexed; } else { positionLoc = positionLocNonIndexed; texCoordInLoc = texCoordInLocNonIndexed; } //make a vertex array object, and put stuff in it GLuint vaoID; glGenVertexArraysAPPLE(1, &vaoID); glBindVertexArrayAPPLE(vaoID); glEnableVertexAttribArray(positionLoc); glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); //the buffer object we just made goes here, representing the actual coordinates/dimensions glBindBuffer(GL_ARRAY_BUFFER, texCoordBufferID); glEnableVertexAttribArray(texCoordInLoc); glVertexAttribPointer(texCoordInLoc, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); //put the texture coordinates here glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBufferID); //put in the element array //unbind and save the array object glBindVertexArrayAPPLE(0); hsTex->vaoID = vaoID; } //unbind and save the buffer glBindBuffer(GL_ARRAY_BUFFER, 0); hsTex->bufferID = bufferID; } //now, put all the results in the texture struct hsTex->textureID = textureID; hsTex->rightAlign = rightAlign; hsTex->topAlign = topAlign; GLenum glError = glGetError(); if(glError != GL_NO_ERROR) { string glErrorString = "OpenGL error in LoadTGAToTexture()."; UpdateLog(glErrorString, true); } return 0; }
void User::SavePassword() { NoErrorConnection conn; conn.SetFields("users", QUERY("uid" << user.id), user, { "password", "salt" }); UpdateLog(); }