Skip to content

Commit 294461d

Browse files
committed
Show last 10 lines of log.txt on crash
1 parent dd2be39 commit 294461d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/windows/launcher.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,44 @@ namespace Launcher {
529529
return true;
530530
}
531531

532+
533+
534+
std::string GetLastLinesOLog(const fs::path& filePath, int lineCount)
535+
{
536+
std::ifstream file(filePath, std::ios::binary);
537+
if (!file)
538+
return {};
539+
540+
file.seekg(0, std::ios::end);
541+
std::streamoff fileSize = file.tellg();
542+
543+
if (fileSize <= 0)
544+
return {};
545+
546+
std::string buffer;
547+
int linesFound = 0;
548+
549+
for (std::streamoff pos = fileSize - 1; pos >= 0; --pos)
550+
{
551+
file.seekg(pos);
552+
char c;
553+
file.get(c);
554+
555+
if (c == '\n')
556+
{
557+
if (++linesFound > lineCount)
558+
break;
559+
}
560+
561+
buffer.push_back(c);
562+
563+
if (pos == 0)
564+
break;
565+
}
566+
std::reverse(buffer.begin(), buffer.end());
567+
return buffer;
568+
}
569+
532570
void LauncherMainWindow::OnIsaacCompleted(DWORD exitCode) {
533571
if (_exePath) {
534572
delete[] _exePath;
@@ -551,6 +589,11 @@ namespace Launcher {
551589
exitCode != STATUS_CONTROL_C_EXIT) {
552590
if (exitCode != 0xFFFFFFFF) {
553591
_logWindow.LogWarn("Game exited with error code %#lx (%s)\n", exitCode, desc.c_str());
592+
_logWindow.LogWarn("Last few lines of the log.txt: \n");
593+
_logWindow.LogWarn("-- START -- \n");
594+
_logWindow.LogWarn(GetLastLinesOLog(fs::absolute(_configuration->GetConfigurationPath()).parent_path().string() + "/Binding of Isaac Repentance+/log.txt", 10).c_str());
595+
_logWindow.LogWarn("-- END -- \n");
596+
_logWindow.LogWarn("Check log.txt and launcher.log for more details! \n");
554597
}
555598
if (exitCode == 0xc0000135) { //missing dll, the lua5.3.3r will be missing in older versions of rgon with potentially fucked exes by the old launcher practices
556599
wxMessageBox(

0 commit comments

Comments
 (0)