File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ Template for new versions:
6969
7070## Documentation
7171- Dreamfort: add link to Dreamfort tutorial youtube series: https://www.youtube.com/playlist?list=PLzXx9JcB9oXxmrtkO1y8ZXzBCFEZrKxve
72+ - The error message that comes up if there is a version mismatch between DF and the installed DFHack now informs you which DF versions are supported by the installed version of DFHack
7273
7374## API
7475
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ using namespace DFHack;
9393using namespace df ::enums;
9494using df::global::init;
9595using df::global::world;
96+ using std::string;
9697
9798// FIXME: A lot of code in one file, all doing different things... there's something fishy about it.
9899
@@ -1611,7 +1612,26 @@ bool Core::InitMainThread() {
16111612 }
16121613 else
16131614 {
1614- fatal (" Not a known DF version.\n " );
1615+ std::stringstream msg;
1616+ msg << " Not a known DF version.\n "
1617+ " \n "
1618+ " Please make sure that you have a version\n "
1619+ " of DFHack installed that matches the version\n "
1620+ " of Dwarf Fortress.\n "
1621+ " \n " ;
1622+ auto supported_versions = vif->getVersionInfosForCurOs ();
1623+ if (supported_versions.size ()) {
1624+ msg << " DF releases supported by this version of DFHack:\n\n " ;
1625+ for (auto & sv : supported_versions) {
1626+ string ver = sv->getVersion ();
1627+ if (ver.starts_with (" v0." )) { // translate "v0.50" to the standard format: "v50"
1628+ ver = " v" + ver.substr (3 );
1629+ }
1630+ msg << " " << ver << " \n " ;
1631+ }
1632+ msg << " \n " ;
1633+ }
1634+ fatal (msg.str ());
16151635 }
16161636 errorstate = true ;
16171637 return false ;
Original file line number Diff line number Diff line change @@ -29,18 +29,22 @@ distribution.
2929#include < algorithm>
3030#include < map>
3131#include < iostream>
32- using namespace std ;
3332
3433#include " VersionInfoFactory.h"
3534#include " VersionInfo.h"
3635#include " Error.h"
3736#include " Memory.h"
3837#include " MemAccess.h"
3938#include " PluginManager.h"
40- using namespace DFHack ;
4139
4240#include < tinyxml.h>
4341
42+ using namespace DFHack ;
43+ using std::cerr;
44+ using std::endl;
45+ using std::string;
46+ using std::vector;
47+
4448VersionInfoFactory::VersionInfoFactory ()
4549{
4650 error = false ;
@@ -77,6 +81,19 @@ std::shared_ptr<const VersionInfo> VersionInfoFactory::getVersionInfoByPETimesta
7781 return nullptr ;
7882}
7983
84+ std::vector<std::shared_ptr<const VersionInfo>> VersionInfoFactory::getVersionInfosForCurOs () const {
85+ static const OSType expected = VersionInfo::getCurOS ();
86+
87+ std::vector<std::shared_ptr<const VersionInfo>> ret;
88+
89+ for (const auto & version : versions) {
90+ if (version->getOS () == expected && version->getVersion ().find (" LOCAL" ) == std::string::npos)
91+ ret.emplace_back (version);
92+ }
93+
94+ return ret;
95+ }
96+
8097static uintptr_t to_addr (const char * cstr) {
8198 if (sizeof (uintptr_t ) == sizeof (unsigned long ))
8299 return strtoul (cstr, 0 , 0 );
Original file line number Diff line number Diff line change @@ -75,6 +75,17 @@ namespace DFHack
7575 OS = rhs.OS ;
7676 };
7777
78+ static OSType getCurOS () {
79+ #if defined(_WIN32)
80+ const OSType expected = OS_WINDOWS;
81+ #elif defined(_DARWIN)
82+ const OSType expected = OS_APPLE;
83+ #else
84+ const OSType expected = OS_LINUX;
85+ #endif
86+ return expected;
87+ }
88+
7889 uintptr_t getBase () const { return base; };
7990 intptr_t getRebaseDelta () const { return rebase_delta; }
8091 void setBase (const uintptr_t _base) { base = _base; };
@@ -171,13 +182,8 @@ namespace DFHack
171182 };
172183
173184 void ValidateOS () {
174- #if defined(_WIN32)
175- const OSType expected = OS_WINDOWS;
176- #elif defined(_DARWIN)
177- const OSType expected = OS_APPLE;
178- #else
179- const OSType expected = OS_LINUX;
180- #endif
185+ static const OSType expected = getCurOS ();
186+
181187 if (expected != getOS ()) {
182188 std::cerr << " OS mismatch; resetting to " << int (expected) << std::endl;
183189 setOS (expected);
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ namespace DFHack
4242 bool isInErrorState () const {return error;};
4343 std::shared_ptr<const VersionInfo> getVersionInfoByMD5 (std::string md5string) const ;
4444 std::shared_ptr<const VersionInfo> getVersionInfoByPETimestamp (uintptr_t timestamp) const ;
45+ std::vector<std::shared_ptr<const VersionInfo>> getVersionInfosForCurOs () const ;
4546 // trash existing list
4647 void clear ();
4748 private:
You can’t perform that action at this time.
0 commit comments