forked from oreo639/LimePlayer3DS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.cpp
51 lines (43 loc) · 1.17 KB
/
debug.cpp
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
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#if !NODEBUG
#include "debug.hpp"
#include "file.hpp"
static FILE* logFP = NULL;
static bool is_init = false;
static bool log_file = false;
void debug_init(bool use_file) {
if (!is_init && use_file) {
File::Move("/3ds/limeplayer3ds/2.log", "/3ds/limeplayer3ds/3.log");
File::Move("/3ds/limeplayer3ds/1.log", "/3ds/limeplayer3ds/2.log");
File::Move("/3ds/limeplayer3ds/0.log", "/3ds/limeplayer3ds/1.log");
File::Move("/3ds/limeplayer3ds/recent.log", "/3ds/limeplayer3ds/0.log");
logFP = fopen("/3ds/limeplayer3ds/recent.log", "w+");
if (logFP) {
is_init = true;
log_file = use_file;
debug_perform("Debug output for LimePlayer3DS version %s\nTHIS FILE IS AUTOMATICALY GENERATED PLEASE DO NOT MODIFY!\n", LIMEPLAYER_VERSION);
}
}
}
void debug_exit(void) {
if (is_init) {
if (log_file)
fclose(logFP);
is_init = false;
}
}
void debug_perform(const char* fmt, ...) {
if (is_init) {
va_list args;
va_start(args, fmt);
if (log_file)
vfprintf(logFP, fmt, args);
vfprintf(stderr, fmt, args);
va_end(args);
// Make sure data is written to file NOW.
fflush(logFP);
}
}
#endif // if !NODEBUG