Skip to content

Commit

Permalink
Replace shared_str with xr_string for log and fs.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Feb 13, 2018
1 parent 80433fa commit 3d2060b
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/utils/xrLCUtil/LevelCompilerLoggerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ void LevelCompilerLoggerWindow::LogThreadProc()
BOOL bWasChanges = FALSE;
char tbuf[256];
csLog.Enter();
if (LogSize != LogFile->size())
if (LogSize != LogFile.size())
{
bWasChanges = TRUE;
for (; LogSize < LogFile->size(); LogSize++)
for (; LogSize < LogFile.size(); LogSize++)
{
const char* S = *(*LogFile)[LogSize];
const char* S = LogFile[LogSize].c_str();
if (!S)
S = "";
SendMessage(hwLog, LB_ADDSTRING, 0, (LPARAM)S);
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class XRCORE_API IWriter
xr_stack<u32> chunk_pos;

public:
shared_str fName;
xr_string fName;

public:
IWriter() {}
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", *fName); }
virtual ~IWriter() { R_ASSERT3(chunk_pos.empty(), "Opened chunk not closed.", fName.c_str()); }
// kernel
virtual void seek(u32 pos) = 0;
virtual u32 tell() = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/xrCore/FS_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class CFileWriter : public IWriter
{
R_ASSERT(name && name[0]);
fName = name;
VerifyPath(*fName);
VerifyPath(fName.c_str());
if (exclusive)
{
int handle = _sopen(*fName, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
int handle = _sopen(fName.c_str(), _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY, SH_DENYWR);
#ifdef _EDITOR
if (handle == -1)
Msg("!Can't create file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
Expand All @@ -34,9 +34,9 @@ class CFileWriter : public IWriter
}
else
{
hf = fopen(*fName, "wb");
hf = fopen(fName.c_str(), "wb");
if (hf == 0)
Msg("!Can't write file: '%s'. Error: '%s'.", *fName, _sys_errlist[errno]);
Msg("!Can't write file: '%s'. Error: '%s'.", fName.c_str(), _sys_errlist[errno]);
}
}

Expand All @@ -46,11 +46,11 @@ class CFileWriter : public IWriter
{
fclose(hf);
// release RO attrib
DWORD dwAttr = GetFileAttributes(*fName);
DWORD dwAttr = GetFileAttributes(fName.c_str());
if ((dwAttr != u32(-1)) && (dwAttr & FILE_ATTRIBUTE_READONLY))
{
dwAttr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(*fName, dwAttr);
SetFileAttributes(fName.c_str(), dwAttr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ void CLocatorAPI::w_close(IWriter*& S)
{
R_ASSERT(S->fName.size());
string_path fname;
xr_strcpy(fname, sizeof fname, *S->fName);
xr_strcpy(fname, sizeof fname, S->fName.c_str());
bool bReg = S->valid();
xr_delete(S);

Expand Down
21 changes: 6 additions & 15 deletions src/xrCore/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static Lock logCS(MUTEX_PROFILE_ID(log));
#else // CONFIG_PROFILE_LOCKS
static Lock logCS;
#endif // CONFIG_PROFILE_LOCKS
xr_vector<shared_str>* LogFile = NULL;
xr_vector<xr_string> LogFile;
static LogCallback LogCB = 0;

void FlushLog()
Expand All @@ -29,9 +29,9 @@ void FlushLog()
IWriter* f = FS.w_open(logFName);
if (f)
{
for (u32 it = 0; it < LogFile->size(); it++)
for (const auto &i : LogFile)
{
LPCSTR s = *((*LogFile)[it]);
LPCSTR s = i.c_str();
f->w_string(s ? s : "");
}
FS.w_close(f);
Expand All @@ -42,20 +42,14 @@ void FlushLog()

void AddOne(const char* split)
{
if (!LogFile)
return;

logCS.Enter();

#ifdef DEBUG
OutputDebugString(split);
OutputDebugString("\n");
#endif

{
shared_str temp = shared_str(split);
LogFile->push_back(temp);
}
LogFile.push_back(split);

// exec CallBack
if (LogExecCB && LogCB)
Expand Down Expand Up @@ -191,9 +185,7 @@ LogCallback SetLogCB(const LogCallback& cb)
LPCSTR log_name() { return (log_file_name); }
void InitLog()
{
R_ASSERT(LogFile == NULL);
LogFile = new xr_vector<shared_str>();
LogFile->reserve(1000);
LogFile.reserve(1000);
}

void CreateLog(BOOL nl)
Expand All @@ -217,6 +209,5 @@ void CreateLog(BOOL nl)
void CloseLog(void)
{
FlushLog();
LogFile->clear();
xr_delete(LogFile);
LogFile.clear();
}
2 changes: 1 addition & 1 deletion src/xrCore/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void InitLog();
void CloseLog();
void XRCORE_API FlushLog();

extern XRCORE_API xr_vector<shared_str>* LogFile;
extern XRCORE_API xr_vector<xr_string> LogFile;
extern XRCORE_API BOOL LogExecCB;

#endif
6 changes: 3 additions & 3 deletions src/xrEngine/Text_Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void CTextConsole::DrawLog(HDC hDC, RECT* pRect)
TextOut(hDC, xb, Height - tm.tmHeight - 3, s_edt, xr_strlen(s_edt));

SetTextColor(hDC, RGB(205, 205, 225));
u32 log_line = LogFile->size() - 1;
u32 log_line = LogFile.size() - 1;
string16 q, q2;
xr_itoa(log_line, q, 10);
xr_strcpy(q2, sizeof(q2), "[");
Expand All @@ -260,14 +260,14 @@ void CTextConsole::DrawLog(HDC hDC, RECT* pRect)
TextOut(hDC, Width - 8 * qn, Height - tm.tmHeight - tm.tmHeight, q2, qn);

int ypos = Height - tm.tmHeight - tm.tmHeight;
for (int i = LogFile->size() - 1 - scroll_delta; i >= 0; --i)
for (int i = LogFile.size() - 1 - scroll_delta; i >= 0; --i)
{
ypos -= tm.tmHeight;
if (ypos < y_top_max)
{
break;
}
LPCSTR ls = ((*LogFile)[i]).c_str();
LPCSTR ls = LogFile[i].c_str();

if (!ls)
{
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/XR_IOConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void CConsole::OnRender()
}

// ---------------------
u32 log_line = LogFile->size() - 1;
u32 log_line = LogFile.size() - 1;
ypos -= LDIST;
for (int i = log_line - scroll_delta; i >= 0; --i)
{
Expand All @@ -338,7 +338,7 @@ void CConsole::OnRender()
{
break;
}
LPCSTR ls = ((*LogFile)[i]).c_str();
LPCSTR ls = LogFile[i].c_str();

if (!ls)
{
Expand Down
6 changes: 3 additions & 3 deletions src/xrEngine/XR_IOConsole_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void CConsole::Register_callbacks()
void CConsole::Prev_log() // DIK_PRIOR=PAGE_UP
{
scroll_delta++;
if (scroll_delta > int(LogFile->size()) - 1)
if (scroll_delta > int(LogFile.size()) - 1)
{
scroll_delta = LogFile->size() - 1;
scroll_delta = LogFile.size() - 1;
}
}

Expand All @@ -60,7 +60,7 @@ void CConsole::Next_log() // DIK_NEXT=PAGE_DOWN

void CConsole::Begin_log() // PAGE_UP+Ctrl
{
scroll_delta = LogFile->size() - 1;
scroll_delta = LogFile.size() - 1;
}

void CConsole::End_log() // PAGE_DOWN+Ctrl
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class CCC_ClearLog : public IConsole_Command
CCC_ClearLog(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = true; };
virtual void Execute(LPCSTR)
{
LogFile->clear();
LogFile.clear();
FlushLog();
Msg("* Log file has been cleaned successfully!");
}
Expand Down

0 comments on commit 3d2060b

Please sign in to comment.