MCPcopy Create free account
hub / github.com/DFHack/dfhack / InitMainThread

Method InitMainThread

library/Core.cpp:1096–1263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1094}
1095
1096bool Core::InitMainThread(std::filesystem::path path) {
1097 // this hook is always called from DF's main (render) thread, so capture this thread id
1098 df_render_thread = std::this_thread::get_id();
1099 hack_path = path;
1100
1101 Filesystem::init();
1102
1103 #ifdef LINUX_BUILD
1104 extern void dfhack_crashlog_init();
1105 dfhack_crashlog_init();
1106 #endif
1107
1108 // Re-route stdout and stderr again - DF seems to set up stdout and
1109 // stderr.txt on Windows as of 0.43.05. Also, log before switching files to
1110 // make it obvious what's going on if someone checks the *.txt files.
1111 #ifndef LINUX_BUILD
1112 // Don't do this on Linux because it will break PRINT_MODE:TEXT
1113 // this is handled as appropriate in Console-posix.cpp
1114 fprintf(stdout, "dfhack: redirecting stdout to stdout.log (again)\n");
1115 if (!freopen("stdout.log", "w", stdout))
1116 std::cerr << "Could not redirect stdout to stdout.log" << std::endl;
1117 #endif
1118 fprintf(stderr, "dfhack: redirecting stderr to stderr.log\n");
1119 if (!freopen("stderr.log", "w", stderr))
1120 std::cerr << "Could not redirect stderr to stderr.log" << std::endl;
1121
1122 std::cerr << "DFHack build: " << Version::git_description() << std::endl;
1123 if (strlen(Version::dfhack_run_url())) {
1124 std::cerr << "Build url: " << Version::dfhack_run_url() << std::endl;
1125 }
1126 std::cerr << "Starting with working directory: " << Filesystem::getcwd() << std::endl;
1127 std::cerr << "Hack path: " << getHackPath() << std::endl;
1128
1129 std::cerr << "Binding to SDL.\n";
1130 if (!DFSDL::init(con)) {
1131 fatal("cannot bind SDL libraries");
1132 return false;
1133 }
1134
1135 // find out what we are...
1136 std::filesystem::path symbols_path = getHackPath() / "symbols.xml";
1137 auto local_vif = std::make_unique<DFHack::VersionInfoFactory>();
1138 std::cerr << "Identifying DF version.\n";
1139 try
1140 {
1141 local_vif->loadFile(symbols_path);
1142 }
1143 catch(Error::All & err)
1144 {
1145 std::stringstream out;
1146 out << "Error while reading symbols.xml:\n";
1147 out << err.what() << std::endl;
1148 errorstate = true;
1149 fatal(out.str());
1150 return false;
1151 }
1152 vif = std::move(local_vif);
1153 auto local_p = std::make_unique<DFHack::Process>(*vif);

Callers 1

dfhooks_initFunction · 0.80

Calls 15

dfhack_crashlog_initFunction · 0.85
git_descriptionFunction · 0.85
dfhack_run_urlFunction · 0.85
getHackPathFunction · 0.85
fatalFunction · 0.85
git_xml_matchFunction · 0.85
dfhack_versionFunction · 0.85
loadFileMethod · 0.80
containsMethod · 0.80
initFunction · 0.50
whatMethod · 0.45

Tested by

no test coverage detected