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

View File

@ -1,7 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include <malloc.h> #include <malloc.h>
#include <algorithm> #include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#endif
stdstr::stdstr() stdstr::stdstr()
{ {
} }
@ -259,14 +261,14 @@ stdstr_f::stdstr_f(const char * strFormat, ...)
#ifdef _WIN32 #ifdef _WIN32
stdwstr_f::stdwstr_f(const wchar_t * strFormat, ...) stdwstr_f::stdwstr_f(const wchar_t * strFormat, ...)
{ {
va_list args; va_list args;
va_start(args, strFormat); va_start(args, strFormat);
wchar_t Msg[1000]; wchar_t Msg[1000];
_vsnwprintf(Msg, sizeof(Msg) - 1, strFormat, args); _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" #include "stdafx.h"
#ifdef _WIN32
#include <Windows.h>
#endif
typedef std::map<uint32_t, stdstr> ModuleNameMap; 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; } if (!m_hLogFile.IsOpen()) { return; }
#ifdef _WIN32 #ifdef _WIN32
SYSTEMTIME sysTime; SYSTEMTIME sysTime;
::GetLocalTime(&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()); 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 #else
time_t ltime; time_t ltime;
ltime=time(&ltime); ltime=time(&ltime);
struct tm result={0}; struct tm result={0};
localtime_r(&ltime, &result); localtime_r(&ltime, &result);
struct timeval curTime; struct timeval curTime;
gettimeofday(&curTime, NULL); gettimeofday(&curTime, NULL);
int milliseconds = curTime.tv_usec / 1000; int milliseconds = curTime.tv_usec / 1000;