Repository navigation
Expand file tree
/
Copy pathOutputConsole.cpp
More file actions
108 lines (94 loc) · 2.42 KB
/
Copy pathOutputConsole.cpp
File metadata and controls
108 lines (94 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
FILE : OutputConsole.cpp
PROJECT : xstore
PROGRAMMER : 951261
DESCRIPTION : Writes text to the screen. Also writes to debug file
*/
#include "AtgConsole.h"
#include "AtgUtil.h"
#include "OutputConsole.h"
#include <stdio.h>
#define TEXTBUFFER_SIZE (1024 * 10) // 2KB buffer
static bool shouldClearScreen = false;
ATG::Console g_console;// console for output
#ifdef USE_UNICODE
WCHAR buf[TEXTBUFFER_SIZE]; // Text buffer
void __cdecl dprintf(const wchar_t* strFormat, ...)
#else
char buf[TEXTBUFFER_SIZE]; // Text buffer
void __cdecl dprintf(const char* strFormat, ...)
#endif
{
FILE* flog;
va_list pArglist;
va_start(pArglist, strFormat);
#ifdef USE_UNICODE
_vsnwprintf_s(buf, TEXTBUFFER_SIZE, strFormat, pArglist);
#else
vsnprintf_s(buf, TEXTBUFFER_SIZE, strFormat, pArglist);
#endif
va_end(pArglist);
if (shouldClearScreen)
g_console.ClearNoRender();
g_console.Display(buf);
shouldClearScreen = false;
// g_console.Format("%s", buf);
#ifdef USE_UNICODE
if (!fexists("game:\\Simple 360 NAND Flasher.log"))
{
fopen_s(&flog, "game:\\Simple 360 NAND Flasher.log", "wb");
char* cStart = "\xfe\xff";
fwrite(cStart, strlen(cStart), 1, flog);
fclose(flog);
}
if (wcsncmp(strFormat, MSG_PROCESSING_START, wcslen(MSG_PROCESSING_START)) != 0 && wcsncmp(strFormat, MSG_PROCESSED_START, wcslen(MSG_PROCESSED_START)) != 0)
{
fopen_s(&flog, "game:\\Simple 360 NAND Flasher.log", "ab");
if (flog != NULL)
{
fwrite(buf, wcslen(buf) * sizeof(wchar_t), 1, flog);
fclose(flog);
}
}
#else
printf("%s", buf);
FILE* fp = NULL;
errno_t err = fopen_s(&fp, LOG_FILE_PATH, "a+");
if(fp) {
fprintf(fp, "%s", buf);
fclose(fp);
} else {
printf("Failed to open log file\n");
}
#endif
}
void MakeConsole(const char* font, unsigned long BackgroundColor, unsigned long TextColor)
{
g_console.Create(font, BackgroundColor, TextColor);
g_console.SendOutputToDebugChannel(TRUE);
}
void ClearConsole()
{
g_console.Clear();
}
void ClearConsoleOnNextPrint()
{
shouldClearScreen = true;
}
void __cdecl log_printf(const char* strFormat, ...) {
va_list pArglist;
va_start(pArglist, strFormat);
#ifdef USE_UNICODE
_vsnwprintf_s(buf, TEXTBUFFER_SIZE, strFormat, pArglist);
#else
vsnprintf_s(buf, TEXTBUFFER_SIZE, strFormat, pArglist);
#endif
va_end(pArglist);
printf("%s", buf);
FILE* fp = NULL;
errno_t err = fopen_s(&fp, LOG_FILE_PATH, "a+");
if(fp) {
fprintf(fp, "%s", buf);
fclose(fp);
}
}