Example #1
0
static bool window_changelog_read_file()
{
	window_changelog_dispose_file();
	utf8 path[MAX_PATH];
	sprintf(path, "%s%cchangelog.txt", gExePath, platform_get_path_separator());
	if (!readentirefile(path, (void**)&_changelogText, (int*)&_changelogTextSize)) {
		log_error("Unable to read changelog.txt");
		return false;
	}
	_changelogText = realloc(_changelogText, _changelogTextSize + 1);
	_changelogText[_changelogTextSize++] = 0;

	char *start = _changelogText;
	if (_changelogTextSize >= 3 && utf8_is_bom(_changelogText))
		start += 3;

	int changelogLinesCapacity = 8;
	_changelogLines = malloc(changelogLinesCapacity * sizeof(char*));
	_changelogLines[0] = start;
	_changelogNumLines = 1;

	char *ch = start;
	while (*ch != 0) {
		unsigned char c = *ch;
		if (c == '\n') {
			*ch++ = 0;
			_changelogNumLines++;
			if (_changelogNumLines > changelogLinesCapacity) {
				changelogLinesCapacity *= 2;
				_changelogLines = realloc(_changelogLines, changelogLinesCapacity * sizeof(char*));
			}
			_changelogLines[_changelogNumLines - 1] = ch;
		} else if (c < 32 || c > 122) {
			// A character that won't be drawn or change state.
			*ch++ = FORMAT_OUTLINE_OFF;
		} else {
			ch++;
		}
	}

	_changelogLines = realloc(_changelogLines, _changelogNumLines * sizeof(char*));

	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
	_changelogLongestLineWidth = 0;
	for (int i = 0; i < _changelogNumLines; i++) {
		int width = gfx_get_string_width(_changelogLines[i]);
		_changelogLongestLineWidth = max(width, _changelogLongestLineWidth);
	}
	return true;
}
Example #2
0
static bool window_changelog_read_file()
{
	window_changelog_dispose_file();
	utf8 path[MAX_PATH];
	safe_strcpy(path, gExePath, MAX_PATH);
	safe_strcat_path(path, "changelog.txt", MAX_PATH);
	if (!readentirefile(path, (void**)&_changelogText, &_changelogTextSize)) {
		log_error("Unable to read changelog.txt");
		return false;
	}
	void* new_memory = realloc(_changelogText, _changelogTextSize + 1);
	if (new_memory == NULL) {
		log_error("Failed to reallocate memory for changelog text");
		return false;
	}
	_changelogText = (char*)new_memory;
	_changelogText[_changelogTextSize++] = 0;

	char *start = _changelogText;
	if (_changelogTextSize >= 3 && utf8_is_bom(_changelogText))
		start += 3;

	sint32 changelogLinesCapacity = 8;
	_changelogLines = malloc(changelogLinesCapacity * sizeof(char*));
	_changelogLines[0] = start;
	_changelogNumLines = 1;

	char *ch = start;
	while (*ch != 0) {
		uint8 c = *ch;
		if (c == '\n') {
			*ch++ = 0;
			_changelogNumLines++;
			if (_changelogNumLines > changelogLinesCapacity) {
				changelogLinesCapacity *= 2;
				new_memory = realloc(_changelogLines, changelogLinesCapacity * sizeof(char*));
				if (new_memory == NULL) {
					log_error("Failed to reallocate memory for change log lines");
					return false;
				}
				_changelogLines = (char**)new_memory;
			}
			_changelogLines[_changelogNumLines - 1] = ch;
		} else if (c < 32 || c > 122) {
			// A character that won't be drawn or change state.
			*ch++ = FORMAT_OUTLINE_OFF;
		} else {
			ch++;
		}
	}

	new_memory = realloc(_changelogLines, _changelogNumLines * sizeof(char*));
	if (new_memory == NULL) {
		log_error("Failed to reallocate memory for change log lines");
		return false;
	}
	_changelogLines = (char**)new_memory;

	gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
	_changelogLongestLineWidth = 0;
	for (sint32 i = 0; i < _changelogNumLines; i++) {
		sint32 width = gfx_get_string_width(_changelogLines[i]);
		_changelogLongestLineWidth = max(width, _changelogLongestLineWidth);
	}
	return true;
}