From 3b0e7a8527f4c57294c1334f6540d2dcc0ffb4b9 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 18 Nov 2018 11:36:02 +1030 Subject: [PATCH] [Project64] Clean up some code and warnings in Common code --- Source/Common/IniFileClass.cpp | 20 +++++++++++++++---- Source/Common/IniFileClass.h | 5 +++-- Source/Common/LogClass.cpp | 5 +---- Source/Common/MemoryManagement.cpp | 1 + Source/Common/StdString.h | 4 ++-- Source/Common/Thread.cpp | 4 ++++ Source/Common/Thread.h | 1 + Source/Common/Trace.cpp | 12 ++++++++--- Source/Common/path.h | 9 ++++----- .../Settings/SettingsPage-Game-Status.cpp | 4 ++-- 10 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Source/Common/IniFileClass.cpp b/Source/Common/IniFileClass.cpp index 7f8d43e9d..9c1afda72 100644 --- a/Source/Common/IniFileClass.cpp +++ b/Source/Common/IniFileClass.cpp @@ -55,7 +55,7 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces) if (NoOfSpaces < 0) { int ReadPos = Pos + (NoOfSpaces * -1); - int WritePos = Pos; + WritePos = Pos; do { @@ -338,6 +338,18 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change } while (result >= 0); } + if (!bFoundSection && strcmp(lpSectionName, "default") == 0) + { + m_SectionsPos.insert(FILELOC::value_type(lpSectionName, 0)); + if (ChangeCurrentSection) + { + m_CurrentSection = lpSectionName; + m_CurrentSectionFilePos = 0; + } + m_File.Seek(m_lastSectionSearch, CFileBase::begin); + bFoundSection = true; + } + if (bFoundSection && ChangeCurrentSection) { m_CurrentSectionData.clear(); @@ -482,7 +494,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) { return false; } - uint32_t dwRet = m_File.Read(pData.get(), dwSize); + uint32_t dwRet = m_File.Read(pData.get(), (uint32_t)dwSize); if (dwRet == 0 || dwRet < dwSize) { return false; @@ -502,11 +514,11 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) char *pEndSection = pSection + strlen(strSection.c_str()), *Data = pData.get(); char *pNextSection = NULL; - int result, ReadPos = pEndSection - pData.get(); + int result, ReadPos = (int)(pEndSection - pData.get()); do { char * Input = NULL; - int MaxDataSize = dwSize + 1; + int MaxDataSize = (int)(dwSize + 1); result = -1; for (int count = ReadPos; count < MaxDataSize; count++) { diff --git a/Source/Common/IniFileClass.h b/Source/Common/IniFileClass.h index f68c29da6..6d8b90e88 100644 --- a/Source/Common/IniFileClass.h +++ b/Source/Common/IniFileClass.h @@ -27,8 +27,9 @@ class CIniFileBase typedef std::map KeyValueList; public: - typedef std::map KeyValueData; - typedef std::vector SectionList; + typedef std::map KeyValueData; + typedef std::vector SectionList; + typedef std::list strlist; protected: CFileBase & m_File; diff --git a/Source/Common/LogClass.cpp b/Source/Common/LogClass.cpp index 972e6e8c4..2a899486e 100644 --- a/Source/Common/LogClass.cpp +++ b/Source/Common/LogClass.cpp @@ -82,7 +82,7 @@ void CLog::LogArgs(const char * Message, va_list & args ) void CLog::Log( const char * Message ) { if (!m_hLogFile.IsOpen()) { return; } - uint32_t message_len = strlen(Message); + uint32_t message_len = (uint32_t)strlen(Message); m_hLogFile.Write(Message, message_len); if (m_FlushOnWrite) { @@ -113,8 +113,6 @@ void CLog::Log( const char * Message ) do { uint8_t Data[300]; - uint32_t dwRead; - dwRead = m_hLogFile.Read(Data,sizeof(Data)); if (dwRead == 0) { @@ -146,7 +144,6 @@ void CLog::Log( const char * Message ) m_hLogFile.Seek(ReadPos,CFile::begin); - uint32_t dwRead; dwRead = m_hLogFile.Read(Data,SizeToRead); m_hLogFile.Seek(WritePos,CFile::begin); diff --git a/Source/Common/MemoryManagement.cpp b/Source/Common/MemoryManagement.cpp index c2342ea5d..be8a54ef5 100644 --- a/Source/Common/MemoryManagement.cpp +++ b/Source/Common/MemoryManagement.cpp @@ -66,6 +66,7 @@ void* AllocateAddressSpace(size_t size, void * base_address) bool FreeAddressSpace(void* addr, size_t size) { #ifdef _WIN32 + size = 0; //unused return VirtualFree(addr, 0, MEM_RELEASE) != 0; #else msync(addr, size, MS_SYNC); diff --git a/Source/Common/StdString.h b/Source/Common/StdString.h index 411fbdd4a..f6bcc4df9 100644 --- a/Source/Common/StdString.h +++ b/Source/Common/StdString.h @@ -60,5 +60,5 @@ public: }; #endif -typedef std::list strlist; -typedef strlist::iterator strlist_iter; +typedef std::list strlist; +typedef strlist::iterator strlist_iter; diff --git a/Source/Common/Thread.cpp b/Source/Common/Thread.cpp index a8cc74f82..1dcc10565 100644 --- a/Source/Common/Thread.cpp +++ b/Source/Common/Thread.cpp @@ -66,7 +66,11 @@ void * CThread::ThreadWrapper (CThread * _this) void * res = NULL; try { +#if defined(__i386__) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM) res = (void *)_this->m_StartAddress(_this->m_lpThreadParameter); +#else + res = (void *)((uint64_t)_this->m_StartAddress(_this->m_lpThreadParameter)); +#endif } catch (...) { diff --git a/Source/Common/Thread.h b/Source/Common/Thread.h index 38bc03559..ab89fd113 100644 --- a/Source/Common/Thread.h +++ b/Source/Common/Thread.h @@ -1,4 +1,5 @@ #pragma once +#include class CThread { diff --git a/Source/Common/Trace.cpp b/Source/Common/Trace.cpp index 4a0a1730a..03bd9e721 100644 --- a/Source/Common/Trace.cpp +++ b/Source/Common/Trace.cpp @@ -122,12 +122,18 @@ void CTraceLog::CloseTrace(void) { CGuard Guard(m_CS); m_Modules.clear(); + + if (g_ModuleLogLevel) + { + delete g_ModuleLogLevel; + g_ModuleLogLevel = NULL; + } } void CTraceLog::FlushTrace(void) { CGuard Guard(m_CS); - for (uint32_t i = 0, n = m_Modules.size(); i < n; i++) + for (size_t i = 0, n = m_Modules.size(); i < n; i++) { m_Modules[i]->FlushTrace(); } @@ -138,7 +144,7 @@ void CTraceLog::TraceMessage(uint32_t module, uint8_t severity, const char * fil { CGuard Guard(m_CS); - for (uint32_t i = 0, n = m_Modules.size(); i < n; i++) + for (size_t i = 0, n = m_Modules.size(); i < n; i++) { m_Modules[i]->Write(module, severity, file, line, function, Message); } @@ -200,7 +206,7 @@ CTraceFileLog::CTraceFileLog(const char * FileName, bool FlushFile, CLog::LOG_OP { /* Clamp file size to 5 MB if it exceeds 2047 or falls short of 3. */ dwMaxFileSize = 5; } - m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB); + m_hLogFile.SetMaxFileSize((uint32_t)(dwMaxFileSize * MB)); m_hLogFile.Open(FileName, eMode); } diff --git a/Source/Common/path.h b/Source/Common/path.h index 1ac02be49..3fd6eef7c 100644 --- a/Source/Common/path.h +++ b/Source/Common/path.h @@ -7,7 +7,7 @@ class CPath //Enums public: - enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 }; + enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 }; #ifdef _WIN32 enum DIR_MODULE_DIRECTORY { MODULE_DIRECTORY = 2 }; enum DIR_MODULE_FILE { MODULE_FILE = 3 }; @@ -22,7 +22,6 @@ public: //Attributes private: - std::string m_strPath; #ifdef _WIN32 void * m_hFindFile; @@ -119,10 +118,10 @@ public: bool DirectoryExists() const; //File Information - bool IsFile() const { return !IsDirectory(); } - bool Exists() const; + bool IsFile() const { return !IsDirectory(); } + bool Exists() const; #ifdef _WIN32 - bool SelectFile(void * hwndOwner, const char * InitialDir, const char * FileFilter, bool FileMustExist); + bool SelectFile(void * hwndOwner, const char * InitialDir, const char * FileFilter, bool FileMustExist); #endif //Directory operations diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Game-Status.cpp b/Source/Project64/UserInterface/Settings/SettingsPage-Game-Status.cpp index 446fb1ab1..f1a0e6b09 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Game-Status.cpp +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Game-Status.cpp @@ -21,7 +21,7 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay) } CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); - strlist Keys; + CIniFile::strlist Keys; RomIniFile.GetKeyList("Rom Status", Keys); stdstr Status = UISettingsLoadStringVal(Rdb_Status); @@ -29,7 +29,7 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay) ComboBox = AddModComboBoxTxt(GetDlgItem(IDC_STATUS_TYPE), Rdb_Status); if (ComboBox) { - for (strlist::iterator item = Keys.begin(); item != Keys.end(); item++) + for (CIniFile::strlist::iterator item = Keys.begin(); item != Keys.end(); item++) { if (strstr(item->c_str(), ".Sel") != NULL) { continue; } if (strstr(item->c_str(), ".Auto") != NULL) { continue; }