IOS7: Add check of size for log file to make sure it does not grow too much

This commit is contained in:
Thierry Crozat 2023-04-27 01:23:06 +01:00
parent e3b643d9a6
commit 50c315e316
2 changed files with 26 additions and 13 deletions

View file

@ -374,19 +374,31 @@ void iOS7_buildSharedOSystemInstance() {
void iOS7_main(int argc, char **argv) { void iOS7_main(int argc, char **argv) {
//OSystem_iOS7::migrateApp(); //OSystem_iOS7::migrateApp();
Common::String logFilePath = iOS7_getDocumentsDir() + "/scummvm.log";
FILE *newfp = fopen(logFilePath.c_str(), "a"); Common::String logFilePath = iOS7_getDocumentsDir() + "/scummvm.log";
if (newfp != NULL) { FILE *logFile = fopen(logFilePath.c_str(), "a");
if (logFile != nullptr) {
// We check for log file size; if it's too big, we rewrite it.
// This happens only upon app launch
// NOTE: We don't check for file size each time we write a log message.
long sz = ftell(logFile);
if (sz > MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
fclose(logFile);
fprintf(stdout, "Default log file is bigger than %dKB. It will be overwritten!", MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES / 1024);
// Create the log file from scratch overwriting the previous one
logFile = fopen(logFilePath.c_str(), "w");
if (logFile == nullptr)
fprintf(stdout, "Could not open default log file for rewrite!");
}
if (logFile != NULL) {
fclose(stdout); fclose(stdout);
fclose(stderr); fclose(stderr);
*stdout = *newfp; *stdout = *logFile;
*stderr = *newfp; *stderr = *logFile;
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, NULL); setbuf(stderr, NULL);
}
//extern int gDebugLevel;
//gDebugLevel = 10;
} }
chdir(iOS7_getDocumentsDir().c_str()); chdir(iOS7_getDocumentsDir().c_str());
@ -398,9 +410,9 @@ void iOS7_main(int argc, char **argv) {
scummvm_main(argc, (const char *const *) argv); scummvm_main(argc, (const char *const *) argv);
g_system->quit(); // TODO: Consider removing / replacing this! g_system->quit(); // TODO: Consider removing / replacing this!
if (newfp != NULL) { if (logFile != NULL) {
//*stdout = NULL; //*stdout = NULL;
//*stderr = NULL; //*stderr = NULL;
fclose(newfp); fclose(logFile);
} }
} }

View file

@ -38,6 +38,7 @@
#define AUDIO_BUFFERS 3 #define AUDIO_BUFFERS 3
#define WAVE_BUFFER_SIZE 2048 #define WAVE_BUFFER_SIZE 2048
#define AUDIO_SAMPLE_RATE 44100 #define AUDIO_SAMPLE_RATE 44100
#define MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES (100*1024)
typedef void (*SoundProc)(void *param, byte *buf, int len); typedef void (*SoundProc)(void *param, byte *buf, int len);
typedef int (*TimerProc)(int interval); typedef int (*TimerProc)(int interval);