[Project64] Fix release build in common

This commit is contained in:
zilmar 2016-01-13 06:48:07 +11:00
parent 0939d70ef3
commit 1b2ca46906
3 changed files with 39 additions and 33 deletions

View File

@ -2,6 +2,7 @@
#ifdef _WIN32
#include <io.h>
#define USE_WINDOWS_API
#include <Windows.h>
#else
#include <unistd.h>
#endif
@ -20,17 +21,17 @@
CFile::CFile() :
#ifdef USE_WINDOWS_API
m_hFile(INVALID_HANDLE_VALUE),
m_hFile(INVALID_HANDLE_VALUE),
#else
m_hFile(NULL),
m_hFile(NULL),
#endif
m_bCloseOnDelete(false)
m_bCloseOnDelete(false)
{
}
CFile::CFile(void * hFile) :
m_hFile(hFile),
m_bCloseOnDelete(true)
m_hFile(hFile),
m_bCloseOnDelete(true)
{
if (hFile == 0)
{
@ -40,11 +41,11 @@ CFile::CFile(void * hFile) :
CFile::CFile(const char * lpszFileName, uint32_t nOpenFlags) :
#ifdef USE_WINDOWS_API
m_hFile(INVALID_HANDLE_VALUE),
m_hFile(INVALID_HANDLE_VALUE),
#else
m_hFile(NULL),
m_hFile(NULL),
#endif
m_bCloseOnDelete(true)
m_bCloseOnDelete(true)
{
Open(lpszFileName, nOpenFlags);
}
@ -58,7 +59,7 @@ CFile::~CFile()
#endif
{
Close();
}
}
}
bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
@ -87,7 +88,7 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
dwAccess = GENERIC_WRITE;
break;
case modeReadWrite:
dwAccess = GENERIC_READ|GENERIC_WRITE;
dwAccess = GENERIC_READ | GENERIC_WRITE;
break;
default:
_ASSERTE(false);
@ -126,10 +127,10 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
if ((nOpenFlags & CFileBase::modeCreate) != CFileBase::modeCreate)
{
printf("Checking if %s exists\n",lpszFileName);
if (!CPath(lpszFileName).Exists())
printf("Checking if %s exists\n",lpszFileName);
if (!CPath(lpszFileName).Exists())
{
printf("%s does not exists\n",lpszFileName);
printf("%s does not exists\n",lpszFileName);
return false;
}
}
@ -154,7 +155,7 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
if ((nOpenFlags & CFileBase::modeWrite) == CFileBase::modeWrite ||
(nOpenFlags & CFileBase::modeReadWrite) == CFileBase::modeReadWrite)
{
printf("tryinng to open %s (rb+)\n",lpszFileName);
printf("tryinng to open %s (rb+)\n",lpszFileName);
m_hFile = fopen(lpszFileName, "rb+");
if (m_hFile != NULL)
{
@ -163,7 +164,7 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
}
else if ((nOpenFlags & CFileBase::modeRead) == CFileBase::modeRead)
{
printf("tryinng to open %s (rb)\n",lpszFileName);
printf("tryinng to open %s (rb)\n",lpszFileName);
m_hFile = fopen(lpszFileName, "rb");
if (m_hFile != NULL)
{
@ -199,17 +200,17 @@ bool CFile::Close()
return bError;
}
uint32_t CFile::SeekToEnd ( void )
uint32_t CFile::SeekToEnd(void)
{
return Seek(0, CFile::end);
}
void CFile::SeekToBegin ( void )
void CFile::SeekToBegin(void)
{
Seek(0, CFile::begin);
}
bool CFile::IsOpen( void ) const
bool CFile::IsOpen(void) const
{
#ifdef USE_WINDOWS_API
return m_hFile != INVALID_HANDLE_VALUE;
@ -284,7 +285,7 @@ int32_t CFile::Seek(int32_t lOff, SeekPosition nFrom)
{
#ifdef USE_WINDOWS_API
ULONG dwNew = ::SetFilePointer(m_hFile, lOff, NULL, (ULONG)nFrom);
if (dwNew == (ULONG)-1)
if (dwNew == (ULONG)-1)
{
return -1;
}
@ -331,9 +332,9 @@ uint32_t CFile::GetLength() const
#ifdef USE_WINDOWS_API
return GetFileSize(m_hFile, 0);
#else
uint32_t pos = GetPosition();
uint32_t pos = GetPosition();
fseek((FILE *)m_hFile, 0, SEEK_END);
uint32_t FileSize = GetPosition();
uint32_t FileSize = GetPosition();
fseek((FILE *)m_hFile, (int32_t)pos, SEEK_SET);
return FileSize;
#endif
@ -351,4 +352,4 @@ bool CFile::SetEndOfFile()
return ftruncate(fileno((FILE *)m_hFile),GetPosition()) == 0;
#endif
#endif
}
}

View File

@ -1,7 +1,9 @@
#include "stdafx.h"
#include <malloc.h>
#include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#endif
stdstr::stdstr()
{
}
@ -259,14 +261,14 @@ stdstr_f::stdstr_f(const char * strFormat, ...)
#ifdef _WIN32
stdwstr_f::stdwstr_f(const wchar_t * strFormat, ...)
{
va_list args;
va_start(args, strFormat);
va_list args;
va_start(args, strFormat);
wchar_t Msg[1000];
_vsnwprintf(Msg, sizeof(Msg) - 1, strFormat, args);
wchar_t Msg[1000];
_vsnwprintf(Msg, sizeof(Msg) - 1, strFormat, args);
va_end(args);
va_end(args);
this->assign(Msg);
this->assign(Msg);
}
#endif
#endif

View File

@ -1,4 +1,7 @@
#include "stdafx.h"
#ifdef _WIN32
#include <Windows.h>
#endif
typedef std::map<uint32_t, stdstr> ModuleNameMap;
@ -192,17 +195,17 @@ void CTraceFileLog::Write(uint32_t module, uint8_t severity, const char * /*file
if (!m_hLogFile.IsOpen()) { return; }
#ifdef _WIN32
SYSTEMTIME sysTime;
SYSTEMTIME sysTime;
::GetLocalTime(&sysTime);
stdstr_f timestamp("%04d/%02d/%02d %02d:%02d:%02d.%03d %05d,", sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds, GetCurrentThreadId());
#else
time_t ltime;
ltime=time(&ltime);
struct tm result={0};
struct tm result={0};
localtime_r(&ltime, &result);
struct timeval curTime;
struct timeval curTime;
gettimeofday(&curTime, NULL);
int milliseconds = curTime.tv_usec / 1000;