[Project64] Clean up some code and warnings in Common code

This commit is contained in:
zilmar 2018-11-18 11:36:02 +10:30
parent e7f93f2def
commit 3b0e7a8527
10 changed files with 43 additions and 22 deletions

View File

@ -55,7 +55,7 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
if (NoOfSpaces < 0) if (NoOfSpaces < 0)
{ {
int ReadPos = Pos + (NoOfSpaces * -1); int ReadPos = Pos + (NoOfSpaces * -1);
int WritePos = Pos; WritePos = Pos;
do do
{ {
@ -338,6 +338,18 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change
} while (result >= 0); } 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) if (bFoundSection && ChangeCurrentSection)
{ {
m_CurrentSectionData.clear(); m_CurrentSectionData.clear();
@ -482,7 +494,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
{ {
return false; 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) if (dwRet == 0 || dwRet < dwSize)
{ {
return false; return false;
@ -502,11 +514,11 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
char *pEndSection = pSection + strlen(strSection.c_str()), *Data = pData.get(); char *pEndSection = pSection + strlen(strSection.c_str()), *Data = pData.get();
char *pNextSection = NULL; char *pNextSection = NULL;
int result, ReadPos = pEndSection - pData.get(); int result, ReadPos = (int)(pEndSection - pData.get());
do do
{ {
char * Input = NULL; char * Input = NULL;
int MaxDataSize = dwSize + 1; int MaxDataSize = (int)(dwSize + 1);
result = -1; result = -1;
for (int count = ReadPos; count < MaxDataSize; count++) for (int count = ReadPos; count < MaxDataSize; count++)
{ {

View File

@ -27,8 +27,9 @@ class CIniFileBase
typedef std::map<std::string, std::string, insensitive_compare> KeyValueList; typedef std::map<std::string, std::string, insensitive_compare> KeyValueList;
public: public:
typedef std::map<std::string, std::string> KeyValueData; typedef std::map<std::string, std::string> KeyValueData;
typedef std::vector<std::string> SectionList; typedef std::vector<std::string> SectionList;
typedef std::list<std::string> strlist;
protected: protected:
CFileBase & m_File; CFileBase & m_File;

View File

@ -82,7 +82,7 @@ void CLog::LogArgs(const char * Message, va_list & args )
void CLog::Log( const char * Message ) void CLog::Log( const char * Message )
{ {
if (!m_hLogFile.IsOpen()) { return; } 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); m_hLogFile.Write(Message, message_len);
if (m_FlushOnWrite) if (m_FlushOnWrite)
{ {
@ -113,8 +113,6 @@ void CLog::Log( const char * Message )
do do
{ {
uint8_t Data[300]; uint8_t Data[300];
uint32_t dwRead;
dwRead = m_hLogFile.Read(Data,sizeof(Data)); dwRead = m_hLogFile.Read(Data,sizeof(Data));
if (dwRead == 0) if (dwRead == 0)
{ {
@ -146,7 +144,6 @@ void CLog::Log( const char * Message )
m_hLogFile.Seek(ReadPos,CFile::begin); m_hLogFile.Seek(ReadPos,CFile::begin);
uint32_t dwRead;
dwRead = m_hLogFile.Read(Data,SizeToRead); dwRead = m_hLogFile.Read(Data,SizeToRead);
m_hLogFile.Seek(WritePos,CFile::begin); m_hLogFile.Seek(WritePos,CFile::begin);

View File

@ -66,6 +66,7 @@ void* AllocateAddressSpace(size_t size, void * base_address)
bool FreeAddressSpace(void* addr, size_t size) bool FreeAddressSpace(void* addr, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
size = 0; //unused
return VirtualFree(addr, 0, MEM_RELEASE) != 0; return VirtualFree(addr, 0, MEM_RELEASE) != 0;
#else #else
msync(addr, size, MS_SYNC); msync(addr, size, MS_SYNC);

View File

@ -60,5 +60,5 @@ public:
}; };
#endif #endif
typedef std::list<stdstr> strlist; typedef std::list<stdstr> strlist;
typedef strlist::iterator strlist_iter; typedef strlist::iterator strlist_iter;

View File

@ -66,7 +66,11 @@ void * CThread::ThreadWrapper (CThread * _this)
void * res = NULL; void * res = NULL;
try try
{ {
#if defined(__i386__) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM)
res = (void *)_this->m_StartAddress(_this->m_lpThreadParameter); res = (void *)_this->m_StartAddress(_this->m_lpThreadParameter);
#else
res = (void *)((uint64_t)_this->m_StartAddress(_this->m_lpThreadParameter));
#endif
} }
catch (...) catch (...)
{ {

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <Common\stdtypes.h>
class CThread class CThread
{ {

View File

@ -122,12 +122,18 @@ void CTraceLog::CloseTrace(void)
{ {
CGuard Guard(m_CS); CGuard Guard(m_CS);
m_Modules.clear(); m_Modules.clear();
if (g_ModuleLogLevel)
{
delete g_ModuleLogLevel;
g_ModuleLogLevel = NULL;
}
} }
void CTraceLog::FlushTrace(void) void CTraceLog::FlushTrace(void)
{ {
CGuard Guard(m_CS); 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(); m_Modules[i]->FlushTrace();
} }
@ -138,7 +144,7 @@ void CTraceLog::TraceMessage(uint32_t module, uint8_t severity, const char * fil
{ {
CGuard Guard(m_CS); 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); 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. */ { /* Clamp file size to 5 MB if it exceeds 2047 or falls short of 3. */
dwMaxFileSize = 5; dwMaxFileSize = 5;
} }
m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB); m_hLogFile.SetMaxFileSize((uint32_t)(dwMaxFileSize * MB));
m_hLogFile.Open(FileName, eMode); m_hLogFile.Open(FileName, eMode);
} }

View File

@ -7,7 +7,7 @@ class CPath
//Enums //Enums
public: public:
enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 }; enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 };
#ifdef _WIN32 #ifdef _WIN32
enum DIR_MODULE_DIRECTORY { MODULE_DIRECTORY = 2 }; enum DIR_MODULE_DIRECTORY { MODULE_DIRECTORY = 2 };
enum DIR_MODULE_FILE { MODULE_FILE = 3 }; enum DIR_MODULE_FILE { MODULE_FILE = 3 };
@ -22,7 +22,6 @@ public:
//Attributes //Attributes
private: private:
std::string m_strPath; std::string m_strPath;
#ifdef _WIN32 #ifdef _WIN32
void * m_hFindFile; void * m_hFindFile;
@ -119,10 +118,10 @@ public:
bool DirectoryExists() const; bool DirectoryExists() const;
//File Information //File Information
bool IsFile() const { return !IsDirectory(); } bool IsFile() const { return !IsDirectory(); }
bool Exists() const; bool Exists() const;
#ifdef _WIN32 #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 #endif
//Directory operations //Directory operations

View File

@ -21,7 +21,7 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay)
} }
CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str());
strlist Keys; CIniFile::strlist Keys;
RomIniFile.GetKeyList("Rom Status", Keys); RomIniFile.GetKeyList("Rom Status", Keys);
stdstr Status = UISettingsLoadStringVal(Rdb_Status); stdstr Status = UISettingsLoadStringVal(Rdb_Status);
@ -29,7 +29,7 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay)
ComboBox = AddModComboBoxTxt(GetDlgItem(IDC_STATUS_TYPE), Rdb_Status); ComboBox = AddModComboBoxTxt(GetDlgItem(IDC_STATUS_TYPE), Rdb_Status);
if (ComboBox) 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(), ".Sel") != NULL) { continue; }
if (strstr(item->c_str(), ".Auto") != NULL) { continue; } if (strstr(item->c_str(), ".Auto") != NULL) { continue; }