6565#include < csignal>
6666#include < cstdarg>
6767#include < cstdio>
68+ #include < optional>
6869#include < signal.h>
6970#include < atomic>
7071
@@ -153,6 +154,24 @@ void signal_handler_init(void)
153154
154155#endif
155156
157+ /*
158+ Environment variables
159+ */
160+
161+ static std::optional<std::string> getUserPathEnvVar ()
162+ {
163+ if (const char *user_path = getenv (" LUANTI_USER_PATH" );
164+ user_path && *user_path) {
165+ return user_path;
166+ }
167+ if (const char *user_path = getenv (" MINETEST_USER_PATH" );
168+ user_path && *user_path) {
169+ warningstream << " MINETEST_USER_PATH is deprecated, "
170+ << " use LUANTI_USER_PATH instead." << std::endl;
171+ return user_path;
172+ }
173+ return std::nullopt ;
174+ }
156175
157176/*
158177 Path mangler
@@ -464,9 +483,17 @@ bool setSystemPaths()
464483 path_share += DIR_DELIM " .." ;
465484 }
466485
467- // Use %MINETEST_USER_PATH%
468- DWORD len = GetEnvironmentVariable (" MINETEST_USER_PATH" , buf, sizeof (buf));
469- FATAL_ERROR_IF (len > sizeof (buf), " Failed to get MINETEST_USER_PATH (too large for buffer)" );
486+ // Use %LUANTI_USER_PATH%
487+ DWORD len = GetEnvironmentVariable (" LUANTI_USER_PATH" , buf, sizeof (buf));
488+ if (!len) {
489+ len = GetEnvironmentVariable (" MINETEST_USER_PATH" , buf, sizeof (buf));
490+ if (len) {
491+ warningstream << " MINETEST_USER_PATH is deprecated, "
492+ << " use LUANTI_USER_PATH instead." << std::endl;
493+ }
494+ }
495+
496+ FATAL_ERROR_IF (len >= sizeof (buf), " Failed to get LUANTI_USER_PATH (too large for buffer)" );
470497 if (len == 0 ) {
471498 // Use "C:\Users\<user>\AppData\Roaming\<PROJECT_NAME_C>"
472499 len = GetEnvironmentVariable (" APPDATA" , buf, sizeof (buf));
@@ -532,9 +559,9 @@ bool setSystemPaths()
532559 break ;
533560 }
534561
535- const char * const env_user_path = getenv ( " MINETEST_USER_PATH " );
536- if (env_user_path && env_user_path[ 0 ] != ' \0 ' ) {
537- path_user = std::string (env_user_path );
562+ auto user_path_env = getUserPathEnvVar ( );
563+ if (user_path_env ) {
564+ path_user = std::move (user_path_env. value () );
538565 } else {
539566 // TODO: luanti with migration
540567 path_user = std::string (getHomeOrFail ()) + DIR_DELIM " ." " minetest" ;
@@ -552,6 +579,7 @@ bool setSystemPaths()
552579 CFBundleRef main_bundle = CFBundleGetMainBundle ();
553580 CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL (main_bundle);
554581 char path[PATH_MAX];
582+
555583 if (CFURLGetFileSystemRepresentation (resources_url,
556584 TRUE , (UInt8 *)path, PATH_MAX)) {
557585 path_share = std::string (path);
@@ -560,9 +588,9 @@ bool setSystemPaths()
560588 }
561589 CFRelease (resources_url);
562590
563- const char * const env_user_path = getenv ( " MINETEST_USER_PATH " );
564- if (env_user_path && env_user_path[ 0 ] != ' \0 ' ) {
565- path_user = std::string (env_user_path );
591+ auto user_path_env = getUserPathEnvVar ( );
592+ if (user_path_env ) {
593+ path_user = std::move (user_path_env. value () );
566594 } else {
567595 // TODO: luanti with migration
568596 path_user = std::string (getHomeOrFail ())
@@ -577,9 +605,10 @@ bool setSystemPaths()
577605bool setSystemPaths ()
578606{
579607 path_share = STATIC_SHAREDIR;
580- const char *const env_user_path = getenv (" MINETEST_USER_PATH" );
581- if (env_user_path && env_user_path[0 ] != ' \0 ' ) {
582- path_user = std::string (env_user_path);
608+
609+ auto user_path_env = getUserPathEnvVar ();
610+ if (user_path_env) {
611+ path_user = std::move (user_path_env.value ());
583612 } else {
584613 // TODO: luanti with migration
585614 path_user = std::string (getHomeOrFail ()) + DIR_DELIM " ." " minetest" ;
0 commit comments