✔️ FIXED BUG: Wrong Default Data Path for Extensions

Eggheads talking about bytes and stuff.
Post Reply
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by Krishty »

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.
mikew
Data Genius
Posts: 601
Joined: 2022-Jan-09, 20:21

Re: 🔴 OPEN BUG: Wrong Default Data Path for Extensions

Post by mikew »

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.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: 🔴 OPEN BUG: Wrong Default Data Path for Extensions

Post by Krishty »

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.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by Krishty »

Fix has landed.
mikew
Data Genius
Posts: 601
Joined: 2022-Jan-09, 20:21

Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by mikew »

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?
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by Krishty »

mikew wrote: 2024-Feb-11, 12:57It would be good if dataDirPath__LEGACY_REMOVE could be set as the 'DataPath' registry entry for the extension.
That should definitely be the case now:
image.png
image.png (90.77 KiB) Viewed 239 times
mikew wrote: 2024-Feb-11, 12:57...but failing that, how do I set it so D:\WHATEVER is treated as the path for data?
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 🤷
mikew
Data Genius
Posts: 601
Joined: 2022-Jan-09, 20:21

Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by mikew »

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.
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.
It doesn't crash, just a 'Cannot start the game' on the 'Loading' page, so no Windbg log.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: ✔️ FIXED BUG: Wrong Default Data Path for Extensions

Post by Krishty »

mikew wrote: 2024-Feb-11, 14:28How 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.
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);
Now dataPath holds that path. Not sure about non-ASCII characters – haven’t worked with the C++ I/O functions for too long …
Post Reply