-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLogFile.cpp
More file actions
237 lines (206 loc) · 6.02 KB
/
LogFile.cpp
File metadata and controls
237 lines (206 loc) · 6.02 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "stdafx.h"
#include "LogFile.h"
#if defined(_PS3)
#include <cell/sysmodule.h>
#include <sys/paths.h>
#include <cell/cell_fs.h>
#include <sys/timer.h>
#include <sys/time.h>
// define the file system you want to dump log:
//#define USE_HOSTFS_HOME
#ifdef USE_CFS
#define MOUNT_POINT SYS_DEV_HDD0"/game"
#endif
#ifdef USE_FAT
#define MOUNT_POINT SYS_DEV_MS
#endif
#ifdef USE_HOSTFS_HOME
#define MOUNT_POINT SYS_APP_HOME
#endif
#ifdef USE_HOSTFS_ROOT
#define MOUNT_POINT SYS_HOST_ROOT"/tmp"
#endif
#ifdef USE_DISCFS
#define MOUNT_POINT SYS_DEV_BDVD"/PS3_GAME/USRDIR"
#endif
#ifndef MOUNT_POINT
#define MOUNT_POINT SYS_APP_HOME
#endif
#endif // PS3
namespace GameService
{
#if defined(_XBOX) || defined(_XENON)
GS_CHAR LogFile::G_FileName[GS_EFileIndex_MAX][64] =
{
"game:\\GameServiceLog.txt",
"game:\\Data\\GFxAssets\\GS_TmpDLCImgFile.png",
};
#elif defined(_PS3)
GS_CHAR LogFile::G_FileName[GS_EFileIndex_MAX][64] =
{
MOUNT_POINT"/GameServiceLog.txt",
MOUNT_POINT"/Data/GFxAssets/GS_TmpDLCImgFile.png",
};
#else
GS_CHAR LogFile::G_FileName[GS_EFileIndex_MAX][64] =
{
"D:\\GameServiceLog.txt",
"D:\\GS_TmpDLCImgFile.png"
};
#endif
const GS_CHAR* LogFile::GetFileName(GS_INT fileIndex)
{
if (fileIndex < GS_EFileIndex_Log || fileIndex >= GS_EFileIndex_MAX)
return NULL;
return G_FileName[fileIndex];
}
LogFile::LogFile(GS_BOOL isDumpLog)
{
#if defined(_XBOX) || defined(_XENON)
for (GS_UINT i=0; i<GS_EFileIndex_MAX; i++)
{
if (GS_EFileIndex_Log == i && !isDumpLog)
{
m_hFile[i] = INVALID_HANDLE_VALUE;
continue;
}
if (GS_EFileIndex_TmpImg == i)
continue;
m_hFile[i] = CreateFile( G_FileName[i], GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
}
#elif defined(_PS3)
// initialize
for (GS_UINT i=0; i<GS_EFileIndex_MAX; i++)
{
m_iFile[i] = -1;
}
int ret = -1;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
if (ret < 0) {
// DebugOutput("cellSysmoduleLoadModule(CELL_SYSMODULE_FS) failed (0x%x)\n", ret);
return;
}
// make sure path mount finished
CellFsStat status;
for (int i = 0; i < 15; i++) {
ret = cellFsStat(MOUNT_POINT, &status);
if (ret == CELL_FS_SUCCEEDED) {
break;
}
sys_timer_sleep(1);
}
for (GS_UINT i=0; i<GS_EFileIndex_MAX; i++)
{
if (GS_EFileIndex_Log == i && !isDumpLog)
{
m_iFile[i] = -1;
continue;
}
ret = cellFsOpen(G_FileName[i], CELL_FS_O_RDWR|CELL_FS_O_CREAT|CELL_FS_O_TRUNC, &m_iFile[i], NULL, 0);
if (ret != CELL_FS_SUCCEEDED)
{
// DebugOutput("cellSysmoduleLoadModule(CELL_SYSMODULE_FS) failed (0x%x)\n", ret);
m_iFile[i] = -1;
return;
}
}
#endif
}
LogFile::~LogFile()
{
#if defined(_XBOX) || defined(_XENON)
for (GS_UINT i=0; i<GS_EFileIndex_MAX; i++)
{
if( m_hFile[i] != INVALID_HANDLE_VALUE )
{
CloseHandle( m_hFile[i] );
}
}
#elif defined(_PS3)
int ret = -1;
ret = cellSysmoduleUnloadModule(CELL_SYSMODULE_FS);
if (ret < 0) {
// DebugOutput("cellSysmoduleUnloadModule(CELL_SYSMODULE_FS) failed (0x%x)\n", ret);
}
#endif
}
GS_BOOL LogFile::DumpLog(const GS_CHAR* log)
{
GS_CHAR final_log[1024];
#if defined(_XBOX) || defined(_XENON)
if( INVALID_HANDLE_VALUE == m_hFile[GS_EFileIndex_Log] )
return FALSE;
// add time stamp into all logs
SYSTEMTIME local_time;
GetLocalTime( &local_time );
sprintf_s(final_log, 1024, "%d.%d.%d-%d:%d:%d\t%s\n",
local_time.wYear,local_time.wMonth,local_time.wDay,local_time.wHour,local_time.wMinute,local_time.wSecond,
log);
// Write to the file
DWORD dwWritten;
if( WriteFile( m_hFile[GS_EFileIndex_Log], ( VOID* )final_log, strlen( final_log ), &dwWritten, NULL ) == 0 )
{
// DebugOutput( "WriteSaveGame: WriteFile failed. Error = %08x\n", GetLastError() );
return FALSE;
}
#elif defined(_PS3)
if (-1 == m_iFile[GS_EFileIndex_Log])
return FALSE;
// add time stamp into all logs
struct tm *date;
time_t now;
time( &now );
date = localtime( &now );
sprintf(final_log, "%d.%d.%d-%d:%d:%d\t%s\n",
date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,
log);
// Write to the file
int ret = -1;
uint64_t sw;
ret = cellFsWrite(m_iFile[GS_EFileIndex_Log], (const void *)final_log, strlen(final_log), &sw);
if (ret != CELL_FS_SUCCEEDED)
{
// DebugOutput("[GameService] - LogFile::Write failed (0x%x)\n", ret);
return FALSE;
}
#endif
return TRUE;
}
GS_BOOL LogFile::WriteLocalFile(GS_INT fileIndex, GS_BYTE* data, GS_DWORD size)
{
if (fileIndex < GS_EFileIndex_Log || fileIndex >= GS_EFileIndex_MAX)
return FALSE;
// Write to the file
#if defined(_XBOX)
if (GS_EFileIndex_TmpImg == fileIndex)
{
m_hFile[fileIndex] = CreateFile( G_FileName[fileIndex], GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
}
DWORD dwWritten;
if( WriteFile( m_hFile[fileIndex], ( VOID* )data, size, &dwWritten, NULL ) == 0 )
{
// DebugOutput( "WriteSaveGame: WriteFile failed. Error = %08x\n", GetLastError() );
return FALSE;
}
if (GS_EFileIndex_TmpImg == fileIndex)
{
if (0 == FlushFileBuffers(m_hFile[fileIndex]))
return FALSE;
CloseHandle( m_hFile[fileIndex] );
m_hFile[fileIndex] = INVALID_HANDLE_VALUE;
}
#elif defined(_PS3)
int ret = -1;
uint64_t sw;
ret = cellFsWrite(m_iFile[fileIndex], (const void *)data, size, &sw);
if (ret != CELL_FS_SUCCEEDED)
{
// DebugOutput("[GameService] - LogFile::Write failed (0x%x)\n", ret);
return FALSE;
}
#endif
return TRUE;
}
} // namespace