//删除一个区域 void CIniFile::DelSection(const char* sSectionName) { int i = GetSectionIndex(0,sSectionName); struct LINE_ITEM *pItem; if(i >= 0) { pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i); m_arrayOfLine.RemoveAt(i); if(pItem) delete pItem; for(; i < m_arrayOfLine.GetSize(); i) { pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i); if(pItem && pItem->nType == LINE_TYPE_SECTION ) break; else { if(pItem) delete pItem; m_arrayOfLine.RemoveAt(i); } } m_bModified = true; if(m_bAutoFlush) FlushToFile(); } }
//设置配置项的值(字符串) void CIniFile::SetString(const char* sSectionName, const char* sKeyName, const char* sKeyValue) { int i = GetSectionIndex(0,sSectionName); int j; if(i < 0) i = AddSection(sSectionName); if(i >= 0) j = GetKeyIndex(i, sKeyName); else return; struct LINE_ITEM *pItem; if(j >= 0) { pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(j); pItem->sValue = sKeyValue; } else { pItem = new struct LINE_ITEM; pItem->nType = LINE_TYPE_KEY; pItem->sName = sKeyName; pItem->sValue = sKeyValue; m_arrayOfLine.InsertAt(i + 1, pItem); j = i+1; } if(j >= 0) m_bModified = true; if(m_bAutoFlush) FlushToFile(); }
void GCMemcardDirectory::FlushThread() { if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableMemcardSaving) { return; } Common::SetCurrentThreadName( StringFromFormat("Memcard%x-Flush", card_index).c_str()); while (true) { // no-op until signalled m_flush_trigger.Wait(); if (m_exiting) { m_exiting = false; return; } // no-op as long as signalled within flush_interval while (m_flush_trigger.WaitFor(flush_interval)) { if (m_exiting) { m_exiting = false; return; } } FlushToFile(); } }
void GCMemcardDirectory::FlushThread() { if (!SConfig::GetInstance().bEnableMemcardSdWriting) { return; } Common::SetCurrentThreadName(StringFromFormat("Memcard %d flushing thread", card_index).c_str()); while (true) { // no-op until signalled m_flush_trigger.Wait(); if (m_exiting.TestAndClear()) return; // no-op as long as signalled within flush_interval while (m_flush_trigger.WaitFor(flush_interval)) { if (m_exiting.TestAndClear()) return; } FlushToFile(); } }
GCMemcardDirectory::~GCMemcardDirectory() { m_exiting = true; m_flush_trigger.Set(); m_flush_thread.join(); FlushToFile(); }
xLogger::~xLogger(void) { ::TerminateThread(hDebugViewThread, 0); //DeleteCriticalSection( &g_cs ); FlushToFile(); delete[] m_data; fclose(stdout); fclose(stdin); FreeConsole(); }
void xLogger::Log( const char* line ) { uint32 length = strlen(line); // 缓存装不下了,写入文件 if (m_size + length + 2 > LOG_FILE_SZIE) { FlushToFile(); } // 装入缓存 { SYSTEMTIME time; GetSystemTime(&time); char* buffer = new char[length + 100]; int infoType = 0; static HANDLE consolehwnd; consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE); switch(line[1]) { case '0': SetConsoleTextAttribute(consolehwnd, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); break; case '1': SetConsoleTextAttribute(consolehwnd, FOREGROUND_BLUE | FOREGROUND_GREEN ); break; case '2': SetConsoleTextAttribute(consolehwnd, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY ); break; case '3': SetConsoleTextAttribute(consolehwnd, FOREGROUND_RED | FOREGROUND_INTENSITY ); break; } sprintf(buffer, "[%d/%d/%d %d:%d(+8)] %s \r\n", time.wYear, time.wMonth, time.wDay, (time.wHour + 8) % 24, time.wMinute, line + 2); memcpy( m_data + m_size, buffer, strlen(buffer) ); m_size += strlen(buffer); freopen("CONOUT$","w+t",stdout); freopen("CONIN$","r+t",stdin); std::cout << buffer; delete[] buffer; } }
//增加一个区域,返回索引值,失败返回小于0的值 int CIniFile::AddSection(const char* sSectionName) { int i = GetSectionIndex(0,sSectionName); if(i >= 0) return i; else { struct LINE_ITEM *pItem = new struct LINE_ITEM; pItem->nType = LINE_TYPE_SECTION; pItem->sName = sSectionName; i = m_arrayOfLine.Add(pItem); m_bModified = true; if(m_bAutoFlush) FlushToFile(); return i; } }
xLogger::xLogger(void) { // 1mb m_data = new char[LOG_FILE_SZIE]; m_size = 0; Terminated = false; AllocConsole(); freopen("CONOUT$","w+t",stdout); freopen("CONIN$","r+t",stdin); //InitializeCriticalSection( &g_cs ); hDebugViewThread = (HANDLE)::_beginthreadex(0, 0, DebugViewThreadProc, (void*)this, 0, &m_nThreadId); //Log( GetCommandLine()); FlushToFile(); }
//重新初始化本对象 void CIniFile::Reset(void) { //首先存盘 if(m_bAutoFlush) FlushToFile(); //删除所有对象 struct LINE_ITEM *pItem; for(int i = m_arrayOfLine.GetSize() - 1; i >= 0; i --) { pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i); if(pItem) delete pItem; } m_arrayOfLine.RemoveAll(); m_sFileName = ""; m_nTotalSection = 0; m_bAutoFlush = true; }
//删除一个配置项 int CIniFile::DelKey(const char* sSectionName, const char* sKeyName) { int nSectionIndex = GetSectionIndex(-1, sSectionName); if(nSectionIndex >= 0) { int nKeyIndex = this->GetKeyIndex(nSectionIndex, sKeyName); if(nKeyIndex >= 0) { struct LINE_ITEM *pItem; pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(nKeyIndex); m_arrayOfLine.RemoveAt(nKeyIndex); if(pItem) delete pItem; m_bModified = true; if(m_bAutoFlush) FlushToFile(); } return nKeyIndex; } return -1; }
GCMemcardDirectory::~GCMemcardDirectory() { FlushToFile(); }