Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified AgentSvc/AgentSvc.h
100755 → 100644
Empty file.
40 changes: 29 additions & 11 deletions Underlight/cOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "Utils.h"
#include "resource.h"
#include <time.h>
#include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
#include "shlobj.h"
#include "tchar.h"

// define the following to enable buffering on debug output
#define BUFFER_DEBUG_OUT
Expand All @@ -23,15 +27,21 @@ extern HINSTANCE hInstance;

cOutput::cOutput(TCHAR *fn, bool append_to_file, bool fForceFlush /*= false */)
{

append = append_to_file;
m_fForceFlush = fForceFlush;
_tcscpy(filename, fn);
_tcscat(filename, _T(".out"));

if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath)))
{
PathAppend(szPath, _T("\\Underlight\\"));
CreateDirectory(szPath, NULL);
PathAppend(szPath, filename);
}
// check file size; rename if necessary
HANDLE hFile;
BY_HANDLE_FILE_INFORMATION info;
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFile = CreateFile(szPath, GENERIC_READ , FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

if (INVALID_HANDLE_VALUE == hFile)
{
Expand All @@ -48,12 +58,20 @@ cOutput::cOutput(TCHAR *fn, bool append_to_file, bool fForceFlush /*= false */)
SYSTEMTIME dsttime;
GetDSTTime(&dsttime);
TCHAR backup_filename[_MAX_DIR];

if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath_backup)))
{
PathAppend(szPath, _T("\\Underlight\\"));
CreateDirectory(szPath, NULL);
PathAppend(szPath, backup_filename);
}
LoadString(hInstance, IDS_BACKUP_LOG, message, sizeof(message));
_stprintf(backup_filename, message, fn, dsttime.wMonth, dsttime.wDay, dsttime.wYear);
int result = rename(filename, backup_filename);
_stprintf(szPath_backup, message, fn, dsttime.wMonth, dsttime.wDay, dsttime.wYear);
int result = rename(szPath, szPath_backup);
int qqq=0;
}



// insure a directory component exists. if not, create it
// mket 11/02/01
TCHAR dir[_MAX_DIR];
Expand All @@ -74,14 +92,14 @@ cOutput::cOutput(TCHAR *fn, bool append_to_file, bool fForceFlush /*= false */)

if (append)
if (fForceFlush)
fh =_tfopen(filename,_T("a+c"));
fh =_tfopen(szPath,_T("a+c"));
else
fh =_tfopen(filename,_T("a+"));
fh =_tfopen(szPath,_T("a+"));
else
if (fForceFlush)
fh =_tfopen(filename,_T("wc"));
fh =_tfopen(szPath,_T("wc"));
else
fh =_tfopen(filename,_T("w"));
fh =_tfopen(szPath,_T("w"));

if (fh == NULL )
{
Expand Down Expand Up @@ -139,9 +157,9 @@ void cOutput::ReInit(void)
fclose(fh);

if (append)
fh =_tfopen(filename,_T("a+"));
fh =_tfopen(szPath,_T("a+"));
else
fh =_tfopen(filename,_T("w"));
fh =_tfopen(szPath,_T("w"));

if (fh == NULL )
{
Expand Down
15 changes: 9 additions & 6 deletions Underlight/cOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
class cOutput
{

public:
public:

private:
FILE *fh;
FILE* fh;
TCHAR filename[DEFAULT_MESSAGE_SIZE];
TCHAR szPath[MAX_PATH];
TCHAR szPath_backup[MAX_PATH];;
bool append;
bool m_fForceFlush; // true = flush after each write. Use with care.

public:
cOutput(TCHAR *fn, bool append_to_file, bool fForceFlush = false);
cOutput(TCHAR* fn, bool append_to_file, bool fForceFlush = false);
void ReInit(void); // close & reopen
void Write(TCHAR *data, bool long_date = false);
void Write(TCHAR* data, bool long_date = false);
void WriteStamp(bool long_date = false);
~cOutput(void);
~cOutput(void);


inline FILE *FileHandle(void) { return fh; };

Expand Down