Changeset - r22793:0c646694741d
[Not reviewed]
master
0 4 0
Charles Pigott - 7 years ago 2018-04-12 20:31:35
charlespigott@googlemail.com
Add: List recent news messages in crashlog output
4 files changed with 32 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/crashlog.cpp
Show inline comments
 
@@ -18,24 +18,25 @@
 
#include "strings_func.h"
 
#include "blitter/factory.hpp"
 
#include "base_media_base.h"
 
#include "music/music_driver.hpp"
 
#include "sound/sound_driver.hpp"
 
#include "video/video_driver.hpp"
 
#include "saveload/saveload.h"
 
#include "screenshot.h"
 
#include "gfx_func.h"
 
#include "network/network.h"
 
#include "language.h"
 
#include "fontcache.h"
 
#include "news_gui.h"
 

	
 
#include "ai/ai_info.hpp"
 
#include "game/game.hpp"
 
#include "game/game_info.hpp"
 
#include "company_base.h"
 
#include "company_func.h"
 

	
 
#include <time.h>
 

	
 
#ifdef WITH_ALLEGRO
 
#	include <allegro.h>
 
#endif /* WITH_ALLEGRO */
 
@@ -300,24 +301,45 @@ char *CrashLog::LogLibraries(char *buffe
 
 * @param last   The last position in the buffer to write to.
 
 * @return the position of the \c '\0' character after the buffer.
 
 */
 
char *CrashLog::LogGamelog(char *buffer, const char *last) const
 
{
 
	CrashLog::gamelog_buffer = buffer;
 
	CrashLog::gamelog_last = last;
 
	GamelogPrint(&CrashLog::GamelogFillCrashLog);
 
	return CrashLog::gamelog_buffer + seprintf(CrashLog::gamelog_buffer, last, "\n");
 
}
 

	
 
/**
 
 * Writes any recent news messages to the buffer.
 
 * @param buffer The begin where to write at.
 
 * @param last   The last position in the buffer to write to.
 
 * @return the position of the \c '\0' character after the buffer.
 
 */
 
char *CrashLog::LogRecentNews(char *buffer, const char *last) const
 
{
 
	buffer += seprintf(buffer, last, "Recent news messages:\n");
 

	
 
	for (NewsItem *news = _oldest_news; news != NULL; news = news->next) {
 
		YearMonthDay ymd;
 
		ConvertDateToYMD(news->date, &ymd);
 
		buffer += seprintf(buffer, last, "(%i-%02i-%02i) StringID: %u, Type: %u, Ref1: %u, %u, Ref2: %u, %u\n",
 
		                   ymd.year, ymd.month + 1, ymd.day, news->string_id, news->type,
 
		                   news->reftype1, news->ref1, news->reftype2, news->ref2);
 
	}
 
	buffer += seprintf(buffer, last, "\n");
 
	return buffer;
 
}
 

	
 
/**
 
 * Fill the crash log buffer with all data of a crash log.
 
 * @param buffer The begin where to write at.
 
 * @param last   The last position in the buffer to write to.
 
 * @return the position of the \c '\0' character after the buffer.
 
 */
 
char *CrashLog::FillCrashLog(char *buffer, const char *last) const
 
{
 
	time_t cur_time = time(NULL);
 
	buffer += seprintf(buffer, last, "*** OpenTTD Crash Report ***\n\n");
 
	buffer += seprintf(buffer, last, "Crash at: %s", asctime(gmtime(&cur_time)));
 

	
 
	YearMonthDay ymd;
 
@@ -325,24 +347,25 @@ char *CrashLog::FillCrashLog(char *buffe
 
	buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i)\n\n", ymd.year, ymd.month + 1, ymd.day, _date_fract);
 

	
 
	buffer = this->LogError(buffer, last, CrashLog::message);
 
	buffer = this->LogOpenTTDVersion(buffer, last);
 
	buffer = this->LogRegisters(buffer, last);
 
	buffer = this->LogStacktrace(buffer, last);
 
	buffer = this->LogOSVersion(buffer, last);
 
	buffer = this->LogCompiler(buffer, last);
 
	buffer = this->LogConfiguration(buffer, last);
 
	buffer = this->LogLibraries(buffer, last);
 
	buffer = this->LogModules(buffer, last);
 
	buffer = this->LogGamelog(buffer, last);
 
	buffer = this->LogRecentNews(buffer, last);
 

	
 
	buffer += seprintf(buffer, last, "*** End of OpenTTD Crash Report ***\n");
 
	return buffer;
 
}
 

	
 
/**
 
 * Write the crash log to a file.
 
 * @note On success the filename will be filled with the full path of the
 
 *       crash log file. Make sure filename is at least \c MAX_PATH big.
 
 * @param buffer The begin of the buffer to write to the disk.
 
 * @param filename      Output for the filename of the written file.
 
 * @param filename_last The last position in the filename buffer.
src/crashlog.h
Show inline comments
 
@@ -76,24 +76,25 @@ protected:
 
	 * is information about it available.
 
	 * @param buffer The begin where to write at.
 
	 * @param last   The last position in the buffer to write to.
 
	 * @return the position of the \c '\0' character after the buffer.
 
	 */
 
	virtual char *LogModules(char *buffer, const char *last) const;
 

	
 

	
 
	char *LogOpenTTDVersion(char *buffer, const char *last) const;
 
	char *LogConfiguration(char *buffer, const char *last) const;
 
	char *LogLibraries(char *buffer, const char *last) const;
 
	char *LogGamelog(char *buffer, const char *last) const;
 
	char *LogRecentNews(char *buffer, const char *list) const;
 

	
 
public:
 
	/** Stub destructor to silence some compilers. */
 
	virtual ~CrashLog() {}
 

	
 
	char *FillCrashLog(char *buffer, const char *last) const;
 
	bool WriteCrashLog(const char *buffer, char *filename, const char *filename_last) const;
 

	
 
	/**
 
	 * Write the (crash) dump to a file.
 
	 * @note On success the filename will be filled with the full path of the
 
	 *       crash dump file. Make sure filename is at least \c MAX_PATH big.
src/news_gui.cpp
Show inline comments
 
@@ -33,28 +33,28 @@
 
#include "command_func.h"
 
#include "company_base.h"
 
#include "settings_internal.h"
 

	
 
#include "widgets/news_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
const NewsItem *_statusbar_news_item = NULL;
 

	
 
static uint MIN_NEWS_AMOUNT = 30;           ///< preferred minimum amount of news messages
 
static uint _total_news = 0;                ///< current number of news items
 
static NewsItem *_oldest_news = NULL;       ///< head of news items queue
 
static NewsItem *_latest_news = NULL;       ///< tail of news items queue
 
static uint MIN_NEWS_AMOUNT = 30;      ///< preferred minimum amount of news messages
 
static uint _total_news = 0;           ///< current number of news items
 
NewsItem *_oldest_news = NULL;         ///< head of news items queue
 
static NewsItem *_latest_news = NULL;  ///< tail of news items queue
 

	
 
/**
 
 * Forced news item.
 
 * Users can force an item by accessing the history or "last message".
 
 * If the message being shown was forced by the user, a pointer is stored
 
 * in _forced_news. Otherwise, \a _forced_news variable is NULL.
 
 */
 
static const NewsItem *_forced_news = NULL;       ///< item the user has asked for
 

	
 
/** Current news item (last item shown regularly). */
 
static const NewsItem *_current_news = NULL;
 

	
src/news_gui.h
Show inline comments
 
@@ -3,16 +3,20 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file news_gui.h GUI functions related to the news. */
 

	
 
#ifndef NEWS_GUI_H
 
#define NEWS_GUI_H
 

	
 
#include "news_type.h"
 

	
 
void ShowLastNewsMessage();
 
void ShowMessageHistory();
 

	
 
extern NewsItem *_oldest_news;
 

	
 
#endif /* NEWS_GUI_H */
0 comments (0 inline, 0 general)