void Log_AutoLogging_SaveMatch(void) { int error, num; FILE *f; char *dir, *tempname, savedname[2 * MAX_OSPATH], *fullsavedname, *exts[] = {"log", NULL}; if (!temp_log_ready) return; temp_log_ready = false; dir = Log_LogDirectory(); tempname = va("%s/%s", MT_TempDirectory(), TEMP_LOG_NAME); fullsavedname = va("%s/%s", dir, auto_matchname); if ((num = Util_Extend_Filename(fullsavedname, exts)) == -1) { Com_Printf("Error: no available filenames\n"); return; } snprintf (savedname, sizeof(savedname), "%s_%03i.log", auto_matchname, num); fullsavedname = va("%s/%s", dir, savedname); if (!(f = fopen(tempname, "rb"))) return; fclose(f); if ((error = rename(tempname, fullsavedname))) { FS_CreatePath(fullsavedname); error = rename(tempname, fullsavedname); } if (!error) Com_Printf("Match console log saved to %s\n", savedname); }
void Log_AutoLogging_SaveMatch(qbool allow_upload) { int error, num; FILE *f; char *dir, *tempname, savedname[2 * MAX_OSPATH], *fullsavedname, *exts[] = {"log", NULL}; if (!temp_log_ready) return; if (temp_log_upload_pending) { Com_Printf("Error: Can't save the log. Log upload is still pending.\n"); return; } temp_log_ready = false; dir = Log_LogDirectory(); tempname = va("%s/%s", MT_TempDirectory(), TEMP_LOG_NAME); fullsavedname = va("%s/%s", dir, auto_matchname); if ((num = Util_Extend_Filename(fullsavedname, exts)) == -1) { Com_Printf("Error: no available filenames\n"); return; } snprintf (savedname, sizeof(savedname), "%s_%03i.log", auto_matchname, num); fullsavedname = va("%s/%s", dir, savedname); if (!(f = fopen(tempname, "rb"))) return; fclose(f); if ((error = rename(tempname, fullsavedname))) { FS_CreatePath(fullsavedname); error = rename(tempname, fullsavedname); } if (!error) { Com_Printf("Match console log saved to %s\n", savedname); if (allow_upload && Log_IsUploadAllowed()) { // note: we allow the client to be a spectator, so that spectators // can submit logs for matches they spec in case players don't do it Log_AutoLogging_Upload(fullsavedname); } } }
static void Log_log_f(void) { char *fulllogname; FILE *templog; switch (Cmd_Argc()) { case 1: if (autologging) Com_Printf("Auto console logging is in progress\n"); else if (Log_IsLogging()) Com_Printf("Logging to %s\n", logfilename); else Com_Printf("Not logging\n"); return; case 2: if (!strcasecmp(Cmd_Argv(1), "stop")) { if (autologging) { Log_AutoLogging_StopMatch(); } else { if (Log_IsLogging()) { Log_Stop(); Com_Printf("Stopped logging to %s\n", logfilename); } else { Com_Printf("Not logging\n"); } } return; } if (autologging) { Com_Printf("Auto console logging must be stopped first!\n"); return; } if (Log_IsLogging()) { Log_Stop(); Com_Printf("Stopped logging to %s\n", logfilename); } strlcpy(logfilename, Cmd_Argv(1), sizeof(logfilename) - 4); Util_Process_Filename(logfilename); if (!Util_Is_Valid_Filename(logfilename)) { Com_Printf(Util_Invalid_Filename_Msg("filename")); return; } COM_ForceExtensionEx (logfilename, ".log", sizeof (logfilename)); fulllogname = va("%s/%s", Log_LogDirectory(), logfilename); if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) { FS_CreatePath(fulllogname); if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) { Com_Printf("Error: Couldn't open %s\n", logfilename); return; } } Com_Printf("Logging to %s\n", logfilename); logfile = templog; break; default: Com_Printf("Usage: %s [filename | stop]\n", Cmd_Argv(0)); return; } }