コード例 #1
0
ファイル: njamfont.cpp プロジェクト: blchinezu/EZX-Projects
//---------------------------------------------------------------------------
NjamFont::NjamFont(const char *Filename, int CharWidth, int CharHeight)
{
    m_Surface = NULL;


    printf("Loading font: %s ... ", Filename);
    SDL_Surface *temp = IMG_Load(Filename);
    if (!temp)
    {
        LogFile("FAILED.\n");
        LogFile((const char *)SDL_GetError());
        return;
    }
    LogFile("OK.\n");

    // setting color key for font: black is transparent
    /* 	Uint32 black = SDL_MapRGB(temp->format, 0, 0, 0);
     	SDL_SetColorKey(temp, SDL_SRCCOLORKEY, black);/

    	/* Convert image to video format */
    m_Surface = SDL_DisplayFormatAlpha(temp);
    SDL_FreeSurface(temp);
    if ( m_Surface == NULL )
        fprintf(stderr, "Couldn't convert font image: %s\n", SDL_GetError());

    m_CharWidth = CharWidth;
    m_CharHeight = CharHeight;
}
コード例 #2
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static int TRACE_fputc(KonohaContext *kctx, kFile *file, int ch, KTraceInfo *trace)
{
	if(fputc(ch, file->fp) == EOF) {
		KTraceErrorPoint(trace, SystemFault, "fputc", LogFile(file), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), SystemFault, NULL, trace->baseStack);
	}
	else if(!kFile_is(ChangeLessStream, file)) {
		KTraceChangeSystemPoint(trace, "fputc", LogFile(file), LogWrittenByte(1));
	}
	return ch;
}
コード例 #3
0
ファイル: njamfont.cpp プロジェクト: blchinezu/EZX-Projects
//---------------------------------------------------------------------------
// Outputs Text into Destionation surface at coordinate (x, y)
bool NjamFont::WriteTextXY(SDL_Surface *Destination, int x, int y, const char *Text)
{
    const char FontMap[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;:!@*()%/abcdefghijklmnopqrstuvwxyz";
    if (!m_Surface || !Destination)
        return false;

    x/=2.5;
    y/=2.5;

    SDL_Rect src, dest;
    src.y = 0;
    src.w = m_CharWidth;
    src.h = m_CharHeight;

    if (y < -m_CharHeight || y > Destination->h)	// out of screen
        return true;

    for (int i=0; Text[i]; i++)
    {
        dest.y = y;
        dest.x = x + i * m_CharWidth;

        if (dest.x < -m_CharWidth)			// not yet in screen
            continue;

        if (dest.x > Destination->w)		// outside
            break;

        if (Text[i] == ' ' || Text[i] == 10 || Text[i] == 13)			// SPACE, NL, CR
            continue;

        bool Found = false;
        for (int j=0; j < (sizeof(FontMap)/sizeof(char)); j++)
        {
            if (Text[i] == FontMap[j])
            {
                Found = true;
                src.x = j * m_CharWidth;

                if (0 != SDL_BlitSurface(m_Surface, &src, Destination, &dest))
                {
                    LogFile("Failed to blit font character image.\n");
                    LogFile((const char *)SDL_GetError());
                    return false;
                }
                break;
            }
        }

        if (!Found)
            printf("TEXT OUTPUT WARNING: Character: %c (code: %d) was not found. (Text=\"%s\")\n", Text[i], Text[i], Text);
    }
    return true;
}
コード例 #4
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static size_t TRACE_fwrite(KonohaContext *kctx, kFile *file, const char *buf, size_t bufsiz, KTraceInfo *trace)
{
	size_t size = fwrite(buf, 1, bufsiz, file->fp);
	if(ferror(file->fp) != 0){
		KTraceErrorPoint(trace, SystemFault, "fwrite", LogFile(file), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), SystemFault, NULL, trace->baseStack);
	}
	if(size > 0 && !kFile_is(ChangeLessStream, file)) {
		KTraceChangeSystemPoint(trace, "fwrite", LogFile(file), LogWrittenByte(size));
	}
	return size;
}
コード例 #5
0
ファイル: main.c プロジェクト: c-ber/cber
fm_code_t parse_xml_msg(char * sdata, int len)
{
    fm_code_t result = FM_OK;

    if(sdata == NULL)
        return FM_ERR;

    char * pdata = NULL;
    pdata = strstr_cb(sdata+0x22b0, len-0x22b0);

    unsigned long int ltime =  atoll(pdata);
    Time  time = {};
    msecond_to_time(ltime, 0, &time);
    printf("beijing time: %s\n",time.str_tm);
    char cmd[64] = {0};
    sprintf(cmd, "date -s \"%s\"",time.str_tm);

    if( 0 != pox_system(cmd) )
    {
        LogFile(FMPROCLOG,"设置系统时间出错");
        return -4;
    }

    return result;

}
コード例 #6
0
ファイル: dllmain.cpp プロジェクト: FantomKnight/nucleuscoop
VOID InitInstance()
{
	IniFile ini;
	std::string inipath("x360ce.ini");
	if (!ini.Load(inipath))
		CheckCommonDirectory(&inipath, "x360ce");
	if (!ini.Load(inipath)) return;

	bool filelog;
	bool systemlog;

	ini.Get("Options", "FileLog", &filelog);
	ini.Get("Options", "SystemLog", &systemlog);

	if (systemlog)
		LogSystem();

	if (filelog)
	{
		SYSTEMTIME systime;
		GetLocalTime(&systime);
		std::string processName;
		ModuleFileName(&processName);

		std::string logfile = StringFormat("x360ce_%s_%02u-%02u-%02u_%08u.log", processName.c_str(), systime.wYear,
			systime.wMonth, systime.wDay, GetTickCount());

		LogFile(logfile);
	}

	// Get will initalize static InputHookManager object and we want to initialize it ASAP
	InputHookManager::Get();
}
コード例 #7
0
ファイル: log_smod.c プロジェクト: Ceiu/hyperspace-asss
void ReopenLog(void)
{
	const char *ln;
	char fname[256];

	pthread_mutex_lock(&logmtx);

	if (logfile)
		fclose(logfile);

	/* cfghelp: Log:LogFile, global, string, def: asss.log
	 * The name of the log file. */
	ln = cfg->GetStr(GLOBAL, "Log", "SmodLogFile");
	if (!ln) ln = "smod.log";

	/* if it has a /, treat it as an absolute path. otherwise, prepend
	 * 'log/' */
	if (strchr(ln, '/'))
		astrncpy(fname, ln, sizeof(fname));
	else
		snprintf(fname, sizeof(fname), "log/%s", ln);

	logfile = fopen(fname, "a");

	pthread_mutex_unlock(&logmtx);

	LogFile("I <log_smod> opening log file ==================================");
}
コード例 #8
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static void TRACE_fflush(KonohaContext *kctx, kFile *file, KTraceInfo *trace)
{
	fflush(file->fp);
	if(ferror(file->fp) != 0){
		KTraceErrorPoint(trace, SystemFault, "fflush", LogFile(file), LogErrno);
	}
}
コード例 #9
0
void TestLogFileRead(void)
{
	CLogFile*		pcLogFile;
	CMemoryFile*	pcMemoryFile;
	CFileBasic		cFile;
	BOOL			bResult;
	int				iLength;
	char			sz[200];
	filePos			iRead;

	pcMemoryFile = MemoryFile();
	cFile.Init(pcMemoryFile);
	cFile.Open(EFM_Write_Create);
	cFile.WriteString("The suspense is killing me!");
	cFile.Close();

	pcLogFile = LogFile(pcMemoryFile);
	cFile.Init(pcLogFile);

	bResult = cFile.Open(EFM_Read);
	AssertTrue(bResult);

	pcLogFile->Begin();

	bResult = cFile.ReadStringLength(&iLength);
	AssertTrue(bResult);
	AssertInt(28, iLength);
	AssertFalse(cFile.IsEndOfFile());
	bResult = cFile.ReadStringChars(sz, iLength);
	AssertString("The suspense is killing me!", sz);
	AssertTrue(cFile.IsEndOfFile());

	memset(sz, 0, 200);
	bResult = cFile.Seek(20);
	AssertTrue(bResult);
	bResult = cFile.ReadStringChars(sz, 8);
	AssertString("killing ", sz);
	AssertLongLongInt(28, cFile.GetFilePos());
	AssertFalse(cFile.IsEndOfFile());

	memset(sz, 0, 200);
	bResult = cFile.ReadStringChars(sz, 4);
	AssertString("me!", sz);
	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	iRead = cFile.Read(sz, 1, 1);
	AssertLongLongInt(0, iRead);
	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	bResult = cFile.Close();
	AssertTrue(bResult);

	cFile.Kill();
}
コード例 #10
0
ファイル: LogPrintf.c プロジェクト: spxiwh/lalsuite
/**
 * Verbatim output of the given log-message if LogLevel() >= level
 */
void
LogPrintfVerbatim (LogLevel_t level, const char* format, ...)
{

  if ( LogLevel() < level )
    return;

  va_list va;
  va_start(va, format);

  /* simply print this to output  */
  vfprintf (LogFile(), format, va );
  fflush(LogFile());

  va_end(va);

} /* LogPrintfVerbatim() */
コード例 #11
0
ファイル: LogPrintf.c プロジェクト: spxiwh/lalsuite
/**
 * Output the given log-message, prefixed by a timestamp and level, if LogLevel() >= level
 */
void
LogPrintf (LogLevel_t level, const char* format, ...)
{

  if ( LogLevel() < level )
    return;

  va_list va;
  va_start(va, format);

  fprintf(LogFile(), "%s (%d) [%s]: ", LogGetTimestamp(), getpid(), LogFormatLevel(level) );
  vfprintf(LogFile(), format, va);
  fflush(LogFile());

  va_end(va);

} /* LogPrintf() */
コード例 #12
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static int TRACE_fgetc(KonohaContext *kctx, kFile *file, KTraceInfo *trace)
{
	int ch = fgetc(file->fp);
	if(ferror(file->fp) != 0) {
		KTraceErrorPoint(trace, SystemFault, "fgetc", LogFile(file), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), SystemFault, NULL, trace->baseStack);
	}
	return ch;
}
コード例 #13
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static size_t TRACE_fread(KonohaContext *kctx, kFile *file, char *buf, size_t bufsiz, KTraceInfo *trace)
{
	size_t size = fread(buf, 1, bufsiz, file->fp);
	if(ferror(file->fp) != 0){
		KTraceErrorPoint(trace, SystemFault, "fread", LogFile(file), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), SystemFault, NULL, trace->baseStack);
	}
	kFile_CheckEOF(kctx, file, trace);
	return size;
}
コード例 #14
0
void TestLogFileCommandsComplex(void)
{
	CLogFile*		pcLogFile;
	CMemoryFile*	pcMemoryFile;
	CFileBasic		cFile;
	BOOL			bResult;
	int				iWritten;
	char			szABC[] = {"ABCDEFGHIJK"};
	char			sz123[] = {"123"};
	char			sz4[] = {"4"};
	char			szExclamation[] = {"!?"};
	char			szQWE[] = {"_QWE_"};
	char			szResult[12];

	pcMemoryFile = MemoryFile();
	pcMemoryFile->Open(EFM_ReadWrite_Create);
	pcMemoryFile->Write(szABC, 1, 12);
	pcMemoryFile->Close();

	pcLogFile = LogFile(pcMemoryFile);
	cFile.Init(pcLogFile);

	pcLogFile->Begin();

	cFile.Open(EFM_ReadWrite_Create);
	AssertInt(12, (int)cFile.GetFileLength());

	iWritten = (int)cFile.Write(sz123, 1, 3);
	AssertInt(3, iWritten);
	iWritten = (int)cFile.Write(sz4, 1, 1);
	AssertInt(1, iWritten);
	cFile.Close();

	cFile.Open(EFM_ReadWrite_Create);
	cFile.Write(szExclamation, 1, 2);
	cFile.Seek(3, EFSO_CURRENT);
	cFile.Write(szQWE, 5, 1);
	cFile.Close();

	cFile.Open(EFM_Read);
	AssertInt(12, (int)cFile.GetFileLength());
	memset(szResult, 0, 12);
	cFile.Read(szResult, 12, 1);
	AssertString("!?34E_QWE_K", szResult);
	cFile.Close();
	
	bResult = pcLogFile->Commit();
	AssertTrue(bResult);
	AssertFalse(pcMemoryFile->IsOpen());
	AssertInt(12, pcMemoryFile->GetBufferSize());
	AssertString("!?34E_QWE_K", (char*)pcMemoryFile->GetBufferPointer());

	pcLogFile->Kill();
}
コード例 #15
0
ファイル: ditool.cpp プロジェクト: FantomKnight/nucleuscoop
int _tmain(int argc, _TCHAR* argv[])
{
	LogFile("ditool.txt");

	setlocale(LC_ALL, "");
	hInst = GetModuleHandle(NULL);
	HRESULT hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL);

	if (SUCCEEDED(hr)) g_pDI->EnumDevices(DI8DEVCLASS_ALL, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY);

	_getch();

	return 0;
}
コード例 #16
0
void TestLogFileCommandsSimple(void)
{
	CLogFile*		pcLogFile;
	CMemoryFile*	pcMemoryFile;
	CFileBasic		cFile;
	BOOL			bResult;
	int				iInt;
	int				iWritten;
	int				iResult;
	int				iRead;

	pcMemoryFile = MemoryFile();
	pcLogFile = LogFile(pcMemoryFile);
	cFile.Init(pcLogFile);

	pcLogFile->Begin();

	bResult = cFile.Open(EFM_ReadWrite_Create);
	AssertTrue(bResult);
	AssertTrue(cFile.IsOpen());

	iInt = 872349342;
	iWritten = (int)cFile.Write(&iInt, sizeof(int), 1);
	AssertInt(1, iWritten);
	AssertInt(0, pcMemoryFile->GetBufferSize());

	bResult = cFile.Close();
	AssertTrue(bResult);
	AssertInt(3, pcLogFile->GetNumCommands());

	bResult = cFile.Open(EFM_ReadWrite_Create);
	AssertTrue(bResult);
	AssertTrue(cFile.IsOpen());
	AssertInt(sizeof(int), (int)cFile.GetFileLength());
	iRead = (int)cFile.Read(&iResult, sizeof(int), 1);
	AssertInt(1, iRead);
	AssertInt(iInt, iResult);
	bResult = cFile.Close();
	AssertTrue(bResult);
	AssertInt(5, pcLogFile->GetNumCommands());

	bResult = pcLogFile->Commit();
	AssertTrue(bResult);
	AssertFalse(pcMemoryFile->IsOpen());
	AssertInt(sizeof(int), pcMemoryFile->GetBufferSize());
	AssertInt(iInt, *((int*)pcMemoryFile->GetBufferPointer()));

	pcLogFile->Kill();
}
コード例 #17
0
ファイル: Logging.cpp プロジェクト: Anonymous2/project64
void StartLog (void) 
{
	if (!LogOptions.GenerateLog) { 
		StopLog();
		return; 
	}
	if (hLogFile) { return; }

	CPath LogFile(CPath::MODULE_DIRECTORY);
	LogFile.AppendDirectory(_T("Logs"));
	LogFile.SetNameExtension(_T("cpudebug.log"));
		
	hLogFile = CreateFile(LogFile,GENERIC_WRITE, FILE_SHARE_READ,NULL,CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
	SetFilePointer(hLogFile,0,NULL,FILE_BEGIN);
}
コード例 #18
0
ファイル: adminlog.cpp プロジェクト: jpnurmi/znc
	void SetLogFilePath(CString sPath) {
		if (sPath.empty()) {
			sPath = GetSavePath() + "/znc.log";
		}

		CFile LogFile(sPath);
		CString sLogDir = LogFile.GetDir();
		struct stat ModDirInfo;
		CFile::GetInfo(GetSavePath(), ModDirInfo);
		if (!CFile::Exists(sLogDir)) {
			CDir::MakeDir(sLogDir, ModDirInfo.st_mode);
		}

		m_sLogFile = sPath;
		SetNV("path", sPath);
	}
コード例 #19
0
ViewLogFileWindow::ViewLogFileWindow(const std::string& PathToLogFile)
{
  set_default_size(500, 350);
  set_position(Gtk::WIN_POS_CENTER_ON_PARENT);

  set_title(_("Install log"));

  m_CloseButton.set_label(_("Close"));

  m_RefLogTextBuffer = Gtk::TextBuffer::create();
  m_RefLogTextBuffer->set_text("");

  m_LogTextView.set_editable(false);
  m_LogTextView.set_buffer(m_RefLogTextBuffer);
  m_LogTextView.set_wrap_mode(Gtk::WRAP_WORD);

  m_LogSWindow.add(m_LogTextView);
  m_LogSWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);


  m_VBox.set_border_width(12);
  m_VBox.pack_start(m_LogSWindow,Gtk::PACK_EXPAND_WIDGET,12);
  m_VBox.pack_start(m_CloseButton,Gtk::PACK_SHRINK,12);

  add(m_VBox);

  m_CloseButton.signal_clicked().connect(
      sigc::mem_fun(*this, &ViewLogFileWindow::onCloseClicked)
    );

  std::ifstream LogFile(PathToLogFile.c_str());
  std::string Line, FullContent;

  while(getline(LogFile,Line))
  {
    FullContent += Line + "\n";
  }
  LogFile.close();

  m_RefLogTextBuffer->set_text(FullContent);

  show_all_children();

  set_modal(true);
}
コード例 #20
0
ファイル: log.cpp プロジェクト: sorbits/znc
void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/)
{
	CString sPath;
	time_t curtime;
	tm* timeinfo;
	char buffer[1024];

	time(&curtime);
	// Don't forget the user's timezone offset
	setenv("TZ", m_pUser->GetTimezone().c_str(), 1);
	timeinfo = localtime(&curtime);

	// Generate file name
	if (!strftime(buffer, sizeof(buffer), m_sLogPath.c_str(), timeinfo))
	{
		DEBUG("Could not format log path [" << sPath << "]");
		return;
	}
	sPath = buffer;

	// $WINDOW has to be handled last, since it can contain %
	sPath.Replace("$NETWORK", (m_pNetwork ? m_pNetwork->GetName() : "znc"));
	sPath.Replace("$WINDOW", sWindow.Replace_n("/", "?"));
	sPath.Replace("$USER", (m_pUser ? m_pUser->GetUserName() : "UNKNOWN"));

	// Check if it's allowed to write in this specific path
	sPath = CDir::CheckPathPrefix(GetSavePath(), sPath);
	if (sPath.empty())
	{
		DEBUG("Invalid log path ["<<m_sLogPath<<"].");
		return;
	}

	CFile LogFile(sPath);
	CString sLogDir = LogFile.GetDir();
	if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir);
	if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
	{
		snprintf(buffer, sizeof(buffer), "[%02d:%02d:%02d] ",
				timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

		LogFile.Write(buffer + sLine + "\n");
	} else
		DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}
コード例 #21
0
ファイル: Logging.cpp プロジェクト: DaMan69/project64
void CLogging::StartLog(void)
{
    if (!GenerateLog())
    {
        StopLog();
        return;
    }
    if (m_hLogFile != NULL)
    {
        return;
    }

    CPath LogFile(CPath::MODULE_DIRECTORY);
    LogFile.AppendDirectory("Logs");
    LogFile.SetNameExtension("cpudebug.log");

    m_hLogFile = new CFile(LogFile, CFileBase::modeCreate | CFileBase::modeWrite);
}
コード例 #22
0
ファイル: Logging.cpp プロジェクト: andrewservania/project64
void CLogging::StartLog(void)
{
    if (!GenerateLog())
    {
        StopLog();
        return;
    }
    if (m_hLogFile != NULL)
    {
        return;
    }

    CPath LogFile(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(),"");
    LogFile.AppendDirectory("Logs");
    LogFile.SetNameExtension("cpudebug.log");

    m_hLogFile = new CFile(LogFile, CFileBase::modeCreate | CFileBase::modeWrite);
}
コード例 #23
0
ファイル: adminlog.cpp プロジェクト: jpnurmi/znc
	void Log(CString sLine, int iPrio = LOG_INFO) {
		if (m_eLogMode & LOG_TO_SYSLOG)
			syslog(iPrio, "%s", sLine.c_str());

		if (m_eLogMode & LOG_TO_FILE) {
			time_t curtime;
			tm* timeinfo;
			char buf[23];

			time(&curtime);
			timeinfo = localtime(&curtime);
			strftime(buf,sizeof(buf),"[%Y-%m-%d %H:%M:%S] ",timeinfo);

			CFile LogFile(m_sLogFile);

			if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
				LogFile.Write(buf + sLine + "\n");
			else
				DEBUG("Failed to write to [" << m_sLogFile  << "]: " << strerror(errno));
		}
	}
コード例 #24
0
void TestLogFileOpen(void)
{
	CLogFile*		pcLogFile;
	CMemoryFile*	pcMemoryFile;
	CFileBasic		cFile;
	BOOL			bResult;

	pcMemoryFile = MemoryFile();
	pcLogFile = LogFile(pcMemoryFile);
	AssertNotNull(pcLogFile);

	cFile.Init(pcLogFile);

	bResult = cFile.Open(EFM_ReadWrite_Create);
	AssertTrue(bResult);

	bResult = cFile.Close();
	AssertTrue(bResult);

	cFile.Kill();
}
コード例 #25
0
ファイル: cLogMgr.cpp プロジェクト: tkc12000/HYKS
//로그 찍기
VOID cLogMgr::AddLog( char* strmsg, ... )
{

	char szBuff[4096];
	char szDate[128];		//날짜
	char szTime[128];		//시간

	_strdate_s( szDate, 128 );
	_strtime_s( szTime, 128 );
	vsprintf_s( szBuff, strmsg, (char*)(&strmsg+1) );

	//Console에 출력할 경우
	if( m_nTarget & LOG_CONSOLE )
	{
		printf( "(data[%s] time[%s] ) : %s\n", szDate, szTime, szBuff );
	}

	//FILE 에 출력 할경우
	if( m_nTarget & LOG_FILE )
	{
		LogFile( "(data[%s] time[%s] ) : %s\n", szDate, szTime, szBuff );
	}

	//LOG 윈도우에 출력할 경우 ( 디버그 모드에서만 지원
#ifdef _DEBUG

	if( m_nTarget & LOG_WINDOW )
	{
		//윈도우 리스트 박스에 로그 추가
		SendMessage( m_hWndListBox, LB_ADDSTRING, 0, (LPARAM)szBuff );

		//추가된 리스트 박스의 순번 얻기 (마지막을 선택하면 된다 )
		UINT32 n = SendMessage( m_hWndListBox, LB_GETCOUNT, 0, 0 ) - 1;

		//선택 커서 마지막으로
		SendMessage( m_hWndListBox, LB_SETCURSEL, (WPARAM)n, 0 );
	}

#endif //_DEBUG
}
コード例 #26
0
ファイル: log.cpp プロジェクト: BGCX261/znc-msvc-svn-to-git
void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/)
{
	CString sPath;
	time_t curtime;
	tm* timeinfo;
	char buffer[1024];

	time(&curtime);
	// Don't forget the user's timezone offset (which is in hours and we want seconds)
	curtime += (time_t) (m_pUser->GetTimezoneOffset() * 60 * 60);
	timeinfo = localtime(&curtime);

	/* Generate file name: ~/.znc/users/<user>/moddata/log/WINDOW_YYYYMMDD.log  */
	CString sWindowFixed(sWindow);
	sWindowFixed = sWindowFixed.Replace_n("/", "_");
	sWindowFixed = sWindowFixed.Replace_n("\\", "_");
	sWindowFixed = sWindowFixed.Replace_n(":", "_");
	sWindowFixed = sWindowFixed.Replace_n("*", "_");
	sWindowFixed = sWindowFixed.Replace_n("?", "_");
	sWindowFixed = sWindowFixed.Replace_n("\"", "_");
	sWindowFixed = sWindowFixed.Replace_n("<", "_");
	sWindowFixed = sWindowFixed.Replace_n(">", "_");
	sWindowFixed = sWindowFixed.Replace_n("|", "_");

	sPath = GetSavePath() + "/" + sWindowFixed + "_";
	snprintf(buffer, sizeof(buffer), "%04d%02d%02d.log", timeinfo->tm_year + 1900,
			timeinfo->tm_mon + 1, timeinfo->tm_mday);
	sPath += buffer;

	CFile LogFile(sPath);
	if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
	{
		snprintf(buffer, sizeof(buffer), "[%02d:%02d:%02d] ",
				timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

		LogFile.Write(buffer + sLine + "\n");
	} else
		DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}
コード例 #27
0
ファイル: Context.cpp プロジェクト: Nucleoprotein/OneTweakNG
MainContext::MainContext()
{
	LogFile("OneTweakNG.log");

	if(config.GetAutoFix()) EnableAutoFix();

	MH_Initialize();

	MH_CreateHook(D3D9DLL::Get().Direct3DCreate9, HookDirect3DCreate9, reinterpret_cast<void**>(&TrueDirect3DCreate9));
	MH_EnableHook(D3D9DLL::Get().Direct3DCreate9);

	MH_CreateHook(CreateWindowExA, HookCreateWindowExA, reinterpret_cast<void**>(&TrueCreateWindowExA));
	MH_EnableHook(CreateWindowExA);

	MH_CreateHook(CreateWindowExW, HookCreateWindowExW, reinterpret_cast<void**>(&TrueCreateWindowExW));
	MH_EnableHook(CreateWindowExW);

	MH_CreateHook(SetWindowLongA, HookSetWindowLongA, reinterpret_cast<void**>(&TrueSetWindowLongA));
	MH_EnableHook(SetWindowLongA);

	MH_CreateHook(SetWindowLongW, HookSetWindowLongW, reinterpret_cast<void**>(&TrueSetWindowLongW));
	MH_EnableHook(SetWindowLongW);
}
コード例 #28
0
ファイル: log.cpp プロジェクト: NeilHanlon/znc
void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/)
{
    CString sPath;
    time_t curtime;

    time(&curtime);
    // Generate file name
    sPath = CUtils::FormatTime(curtime, m_sLogPath, m_pUser->GetTimezone());
    if (sPath.empty())
    {
        DEBUG("Could not format log path [" << sPath << "]");
        return;
    }

    // $WINDOW has to be handled last, since it can contain %
    sPath.Replace("$NETWORK", (m_pNetwork ? m_pNetwork->GetName() : "znc"));
    sPath.Replace("$WINDOW", sWindow.Replace_n("/", "?"));
    sPath.Replace("$USER", (m_pUser ? m_pUser->GetUserName() : "UNKNOWN"));

    // Check if it's allowed to write in this specific path
    sPath = CDir::CheckPathPrefix(GetSavePath(), sPath);
    if (sPath.empty())
    {
        DEBUG("Invalid log path ["<<m_sLogPath<<"].");
        return;
    }

    CFile LogFile(sPath);
    CString sLogDir = LogFile.GetDir();
    if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir);
    if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT))
    {
        LogFile.Write(CUtils::FormatTime(curtime, "[%H:%M:%S] ", m_pUser->GetTimezone()) + sLine + "\n");
    } else
        DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}
コード例 #29
0
void TestLogFileMultipleReadsAfterOpens(void)
{
	CLogFile*		pcLogFile;
	CDiskFile*		pcDiskFile;
	CFileBasic		cFile;
	CFileUtil		cFileUtil;
	char			szSource[] = {"The Name of the Wise Man"};
	int				iSourcelen;
	char			szResult[50];
	char			szWrite[] = {"Cat Catt ct... "};
	int				iWriteLen;
	char			szA[] = {"A"};

	cFileUtil.RemoveDir("Output/LogFile2");
	cFileUtil.MakeDir("Output/LogFile2");
	pcDiskFile = DiskFile("Output/LogFile2/OpenClose.txt");
	pcDiskFile->Open(EFM_ReadWrite_Create);
	iSourcelen = (int)strlen(szSource);
	pcDiskFile->Write(szSource, iSourcelen + 1, 1);
	pcDiskFile->Close();
	AssertTrue(cFileUtil.Exists("Output/LogFile2/OpenClose.txt"));

	pcLogFile = LogFile(pcDiskFile);
	cFile.Init(pcLogFile);
	pcLogFile->Begin();

	AssertTrue(cFile.Open(EFM_Read));
	AssertInt(iSourcelen + 1, (int)cFile.GetFileSize());
	cFile.ReadData(szResult, iSourcelen + 1);
	AssertString(szSource, szResult);
	cFile.Close();

	cFile.Open(EFM_ReadWrite_Create);
	iWriteLen = (int)strlen(szWrite);
	cFile.WriteData(szWrite, iWriteLen);
	AssertInt(iSourcelen + 1, (int)cFile.GetFileSize());
	pcLogFile->Close();

	cFile.Delete();
	AssertTrue(cFileUtil.Exists("Output/LogFile2/OpenClose.txt"));
	AssertInt(0, (int)cFile.GetFileSize());

	cFile.Open(EFM_ReadWrite_Create);
	cFile.Write(szA, 2, 1);
	AssertInt(2, (int)cFile.GetFileSize());

	cFile.Close();

	pcLogFile->Commit();
	cFile.Kill();

	AssertTrue(cFileUtil.Exists("Output/LogFile2/OpenClose.txt"));
	AssertInt(2, cFileUtil.Size("Output/LogFile2/OpenClose.txt"));

	pcDiskFile = DiskFile("Output/LogFile2/OpenClose.txt");
	pcLogFile = LogFile(pcDiskFile);
	cFile.Init(pcLogFile);
	pcLogFile->Begin();

	AssertTrue(cFile.Open(EFM_Read));
	cFile.ReadData(szResult, 2);
	AssertString("A", szResult);

	cFile.Seek(0);
	cFile.ReadData(szResult, 2);
	AssertString("A", szResult);

	cFile.Close();

	cFile.Delete();
	pcLogFile->Commit();
	cFile.Kill();

	AssertFalse(cFileUtil.Exists("Output/LogFile2/OpenClose.txt"));
}
コード例 #30
0
void TestLogFileFindHoles(void)
{
	CLogFile*		pcLogFile;
	CFileBasic		cFile;
	BOOL			bResult;
	int				iInt1;
	int				iInt2;
	int				iInt3;
	CArrayPointer	apvOverlapping;
	int				i;
	int				iSize;

	pcLogFile = LogFile(NULL);
	cFile.Init(pcLogFile);

	pcLogFile->Begin();

	bResult = cFile.Open(EFM_ReadWrite_Create);
	AssertTrue(bResult);
	
	iInt1 = 872349342;
	iInt2 = 763421934;
	iInt3 = 158723346;
	iSize = sizeof(int);

	apvOverlapping.Init();
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 1);
	AssertTrue(bResult);
	AssertInt(0, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	cFile.Write(&iInt1, 4, 1);
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 4);
	AssertFalse(bResult);

	cFile.Write(&iInt2, 4, 1);
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 8);
	AssertFalse(bResult);

	for (i = 0; i < 8; i++)
	{
		bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, i);
		AssertFalse(bResult);
	}
	for (i = 0; i < 8; i++)
	{
		bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, i, 8 -i);
		AssertFalse(bResult);
	}
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 7, 2);
	AssertTrue(bResult);
	AssertInt(1, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	cFile.Seek(4, EFSO_CURRENT);
	cFile.Write(&iInt3, 4, 1);
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 16);
	AssertTrue(bResult);
	AssertInt(2, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 12, 4);
	AssertFalse(bResult);

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 11, 5);
	AssertTrue(bResult);
	AssertInt(1, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 8);
	AssertFalse(bResult);

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 9);
	AssertTrue(bResult);
	AssertInt(1, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 7, 2);
	AssertTrue(bResult);
	AssertInt(1, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	apvOverlapping.Init();
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 8, 1);
	AssertTrue(bResult);
	AssertInt(0, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	apvOverlapping.Init();
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 8, 4);
	AssertTrue(bResult);
	AssertInt(0, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 8, 5);
	AssertTrue(bResult);
	AssertInt(1, apvOverlapping.NumElements());
	apvOverlapping.Kill();

	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 0, 0);
	AssertFalse(bResult);
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 7, 0);
	AssertFalse(bResult);
	bResult = pcLogFile->TestFindHoles(1, &apvOverlapping, 8, 0);
	AssertFalse(bResult);

	//apvOverlapping.Kill();

	cFile.Close();
	pcLogFile->Kill();
}