The mechanism that helps extensions find their files is hacky and flawed. Extensions do have access to the path in their DataPath registry key, but the DIDtoF22 extensions do crazy stuff with it (like changing the current working directory).
This is legacy from a time when TFXplorer was installed by copying it to the TAW directory.
The case where the user does not explicitly set data paths (and who does!) is even worse.
Extensions need an easy way to locate the directory they were installed to. And an easy way to open files there.
✔️ FIXED BUG: Wrong Default Data Path for Extensions
Re: 🔴 OPEN BUG: Wrong Default Data Path for Extensions
Yeah, while this is the least of my worries right now, it seems that if I try to use a filename without any path, my file need to be where the TFXplorer exe is. The DataPath registry entry is ignored.
Re: 🔴 OPEN BUG: Wrong Default Data Path for Extensions
This won’t work magically – both Linux and Win32 use the current directory to search for relative files, but on both the current directory is a per-process property. It is impossible for two threads to use different current directories. That’s bad because TFXplorer’s extension initialization is multi-threaded (and it must be, as this is where 90 % of startup time passes).
There is a variable dataDirPath__LEGACY_REMOVE in the API for the extension initialization routine. Extensions should use that path to build absolute file names.
That intimidating postfix stems from me planning to replace it with API functions that open files for you. This is, however, a prime candidate for feature creep – start doing that and next thing you know you’re writing your own OS and runtime libraries in TFXplorer …
For now, we are stuck with that variable. If you have trouble using it, I can guide you.
With the next commit, that variable will have valid content.
There is a variable dataDirPath__LEGACY_REMOVE in the API for the extension initialization routine. Extensions should use that path to build absolute file names.
That intimidating postfix stems from me planning to replace it with API functions that open files for you. This is, however, a prime candidate for feature creep – start doing that and next thing you know you’re writing your own OS and runtime libraries in TFXplorer …
For now, we are stuck with that variable. If you have trouble using it, I can guide you.
With the next commit, that variable will have valid content.
Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions
Fix has landed.
Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions
It would be good if dataDirPath__LEGACY_REMOVE could be set as the 'DataPath' registry entry for the extension.
...but failing that, how do I set it so D:\WHATEVER is treated as the path for data?
...but failing that, how do I set it so D:\WHATEVER is treated as the path for data?
Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions
That should definitely be the case now:
Before the first function create a global string variable with the base path:
#include <string>
std::string dataPath = "D:\\WHATEVER"; // mind double backslashes due to escaping!
Then, in loadTerrain() (or wherever you need to load something) replace
std::ifstream colpal{ "C:\\Users\\Krishty\\Desktop\\tfx_e\\colpal.dat", std::ios::binary };
with
std::ifstream colpal{ dataPath + "\\colpal.dat", std::ios::binary };
Normally, you should be able to assign dataDirPath__LEGACY_REMOVE to your global dataPath in UAW_EXTENSION_CREATE() and it should take on the value from the registry. As mentioned above, it works for me and I don’t see how it wouldn’t work for you 🤷
Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions
How would I do that?...or is this the default behaviour if I don't do anything specific? If so, it's not working for me.Normally, you should be able to assign dataDirPath__LEGACY_REMOVE to your global dataPath in UAW_EXTENSION_CREATE() and it should take on the value from the registry.
It doesn't crash, just a 'Cannot start the game' on the 'Loading' page, so no Windbg log.
Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions
Yes, I can’t / won’t change the language’s default behavior, which is addressing all paths relative to the current directory.
To assign dataDirPath__LEGACY_REMOVE to your global dataPath in UAW_EXTENSION_CREATE(), do:
Code: Select all
// Before AW_EXTENSION_CREATE:
#include <locale>
#include <codecvt>
static std::string utf8From(UAW_Char const * uawString) {
return std::wstring_convert<std::codecvt_utf8_utf16<UAW_Char>, UAW_Char>{ }.to_bytes(utf16String);
}
// …
extern "C" __declspec(dllexport) int UAW_CALL UAW_EXTENSION_CREATE(
UAW_API_Extension * uaw,
UAW_Extension_Callbacks * result,
void * legacyPleaseIgnore
) {
dataPath = utf8From(uaw->dataDirPath__LEGACY_REMOVE);