Add --wipe-cache

This commit is contained in:
TheBrokenRail 2022-09-23 00:31:42 -04:00
parent 5739c5f999
commit 5aae95fd37
4 changed files with 83 additions and 50 deletions

View File

@ -5,8 +5,10 @@
### ``--version`` (Or ``-v``) ### ``--version`` (Or ``-v``)
If you run MCPI-Reborn with ``--version`` it will print its version to ``stdout``. If you run MCPI-Reborn with ``--version`` it will print its version to ``stdout``.
### ``--print-available-feature-flags`` (Client Mode Only) ### Client Mode Only
If you run MCPI-Reborn with ``--print-available-feature-flags``, it will print the available feature flags to ``stdout`` and then immediately exit.
#### ``--print-available-feature-flags``
This print the available feature flags (and their default values) to ``stdout`` and then immediately exit.
The feature flags are printed in the following format: The feature flags are printed in the following format:
``` ```
@ -14,19 +16,24 @@ TRUE This Flag Is On By Default
FALSE This Flag Is Off By Default FALSE This Flag Is Off By Default
``` ```
### ``--default`` (Client Mode Only) #### ``--default``
If you run MCPI-Reborn with ``--default``, it will skip the startup configuration dialogs and just use the default values. This will skip the startup configuration dialogs and just use the default values. This will use the cached configuration unless ``--no-cache`` is used.
### ``--only-generate`` (Server Mode Only) #### ``--benchmark``
If you run MCPI-Reborn with ``--only-generate``, it will immediately exit once world generation has completed. This is mainly used for automatically testing MCPI-Reborn. This will make MCPI-Reborn enter a simple benchmark mode. This means automatically loading a newly generated world, then rotating the camera for a period of time. When it has finished, it will then exit and print the average FPS while the world was loaded. In this mode, all user input is blocked. However you can still modify rendering settings by changing feature flags.
### ``--benchmark`` (Client Mode Only)
If you run MCPI-Reborn with ``--benchmark``, it will enter a simple benchmark mode. This means automatically loading a newly generated world, then rotating the camera for a period of time. When it has finished, it will then exit and print the average FPS while the world was loaded. In this mode, all user input is blocked. However you can still modify rendering settings by changing feature flags.
The world used will always be re-created on start and uses a hard-coded seed. The world used will always be re-created on start and uses a hard-coded seed.
### ``--no-cache`` (Client Mode Only) #### ``--no-cache``
If you run MCPI-Reborn with ``--no-cache``, it will skip loading and saving the cached launcher configuration. This will skip loading and saving the cached launcher configuration.
#### ``--wipe-cache``
This will wipe the cached launcher configuration.
### Server Mode Only
#### ``--only-generate``
This will make MCPI-Reborn immediately exit once world generation has completed. This is mainly used for automatically testing MCPI-Reborn.
## Environmental Variables ## Environmental Variables

View File

@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <sstream> #include <sstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
@ -139,3 +140,14 @@ void save_cache() {
WARN("Failure While Saving Launcher Cache"); WARN("Failure While Saving Launcher Cache");
} }
} }
// Wipe Cache
void wipe_cache() {
// Log
INFO("Wiping Launcher Cache...");
// Unlink File
if (unlink(get_cache_path().c_str()) != 0) {
WARN("Failure While Wiping Cache: %s", strerror(errno));
}
}

View File

@ -17,3 +17,6 @@ launcher_cache load_cache();
// Save Cache // Save Cache
void save_cache(); void save_cache();
// Wipe Cache
void wipe_cache();

View File

@ -149,9 +149,6 @@ int main(int argc, char *argv[]) {
ERR("$HOME Isn't Set"); ERR("$HOME Isn't Set");
} }
// Pre-Bootstrap
pre_bootstrap(argc, argv);
// Print Features // Print Features
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--print-available-feature-flags") == 0) { if (strcmp(argv[i], "--print-available-feature-flags") == 0) {
@ -164,33 +161,22 @@ int main(int argc, char *argv[]) {
} }
} }
// --default // Pre-Bootstrap
pre_bootstrap(argc, argv);
// Create ~/.minecraft-pi If Needed
{
char *minecraft_folder = NULL;
safe_asprintf(&minecraft_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
const char *const command[] = {"mkdir", "-p", minecraft_folder, NULL};
run_simple_command(command, "Unable To Create Data Directory");
free(minecraft_folder);
}
// --wipe-cache
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--default") == 0) { if (strcmp(argv[i], "--wipe-cache") == 0) {
// Use Default Feature Flags wipe_cache();
set_env_if_unset("MCPI_FEATURE_FLAGS", []() {
std::string feature_flags = "";
load_available_feature_flags([&feature_flags](std::string flag) {
bool default_value;
// Strip Default Value
std::string stripped_flag = strip_feature_flag_default(flag, &default_value);
// Specify Default Value
if (default_value) {
// Enabled By Default
feature_flags += stripped_flag + '|';
}
});
if (feature_flags.length() > 0 && feature_flags[feature_flags.length() - 1] == '|') {
feature_flags.pop_back();
}
return feature_flags;
});
set_env_if_unset("MCPI_RENDER_DISTANCE", []() {
return DEFAULT_RENDER_DISTANCE;
});
set_env_if_unset("MCPI_USERNAME", []() {
return DEFAULT_USERNAME;
});
break; break;
} }
} }
@ -203,19 +189,44 @@ int main(int argc, char *argv[]) {
break; break;
} }
} }
// Create ~/.minecraft-pi If Needed
{
char *minecraft_folder = NULL;
safe_asprintf(&minecraft_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
const char *const command[] = {"mkdir", "-p", minecraft_folder, NULL};
run_simple_command(command, "Unable To Create Data Directory");
free(minecraft_folder);
}
// Load Cache // Load Cache
launcher_cache cache = no_cache ? empty_cache : load_cache(); launcher_cache cache = no_cache ? empty_cache : load_cache();
// --default
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--default") == 0) {
// Use Default Feature Flags
set_env_if_unset("MCPI_FEATURE_FLAGS", [&cache]() {
std::string feature_flags = "";
load_available_feature_flags([&feature_flags, &cache](std::string flag) {
bool value;
// Strip Default Value
std::string stripped_flag = strip_feature_flag_default(flag, &value);
// Use Cache
if (cache.feature_flags.count(stripped_flag) > 0) {
value = cache.feature_flags[stripped_flag];
}
// Specify Default Value
if (value) {
// Enabled By Default
feature_flags += stripped_flag + '|';
}
});
if (feature_flags.length() > 0 && feature_flags[feature_flags.length() - 1] == '|') {
feature_flags.pop_back();
}
return feature_flags;
});
set_env_if_unset("MCPI_RENDER_DISTANCE", [&cache]() {
return cache.render_distance;
});
set_env_if_unset("MCPI_USERNAME", [&cache]() {
return cache.username;
});
break;
}
}
// Setup MCPI_FEATURE_FLAGS // Setup MCPI_FEATURE_FLAGS
{ {
std::vector<std::string> command; std::vector<std::string> command;