Change to use unique_ptr

This commit is contained in:
esuo1198
2024-03-22 23:37:55 +09:00
parent b452adeaed
commit bde5d384b6
5 changed files with 19 additions and 20 deletions
+6 -7
View File
@@ -321,8 +321,9 @@ Init () {
INSTALL_HOOK (bngrw_attach);
INSTALL_HOOK (bngrw_reqWaitTouch);
auto configPath = std::filesystem::current_path () / "config.toml";
toml_table_t *config = openConfig (configPath);
auto configPath = std::filesystem::current_path () / "config.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
toml_table_t *config = config_ptr.get ();
if (config) {
auto drum = openConfigSection (config, "drum");
if (drum) drumWaitPeriod = readConfigInt (drum, "wait_period", drumWaitPeriod);
@@ -331,11 +332,11 @@ Init () {
useTaikoController = readConfigBool (taikoController, "analog", useTaikoController);
if (useTaikoController) printf ("Using analog input mode. All the keyboard drum inputs have been disabled.\n");
}
toml_free (config);
}
auto keyconfigPath = std::filesystem::current_path () / "keyconfig.toml";
toml_table_t *keyconfig = openConfig (keyconfigPath);
auto keyconfigPath = std::filesystem::current_path () / "keyconfig.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> keyconfig_ptr (openConfig (keyconfigPath), toml_free);
toml_table_t *keyconfig = keyconfig_ptr.get ();
if (keyconfig) {
SetConfigValue (keyconfig, "EXIT", &EXIT);
@@ -359,8 +360,6 @@ Init () {
SetConfigValue (keyconfig, "P2_LEFT_RED", &P2_LEFT_RED);
SetConfigValue (keyconfig, "P2_RIGHT_RED", &P2_RIGHT_RED);
SetConfigValue (keyconfig, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE);
toml_free (keyconfig);
}
}
} // namespace bnusio
+4 -4
View File
@@ -100,9 +100,10 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) {
// This is bad, dont do this
// I/O in DllMain can easily cause a deadlock
const char *version = "auto";
auto configPath = std::filesystem::current_path () / "config.toml";
toml_table_t *config = openConfig (configPath);
const char *version = "auto";
auto configPath = std::filesystem::current_path () / "config.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
toml_table_t *config = config_ptr.get ();
if (config) {
auto amauth = openConfigSection (config, "amauth");
if (amauth) {
@@ -122,7 +123,6 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) {
}
auto patches = openConfigSection (config, "patches");
if (patches) version = readConfigString (patches, "version", version);
toml_free (config);
}
if (!strcmp (version, "auto")) {
+3 -3
View File
@@ -124,8 +124,9 @@ Init () {
INSTALL_HOOK (HaspGetInfo);
INSTALL_HOOK (HaspRead);
auto configPath = std::filesystem::current_path () / "config.toml";
toml_table_t *config = openConfig (configPath);
auto configPath = std::filesystem::current_path () / "config.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
toml_table_t *config = config_ptr.get ();
if (config) {
auto patches = openConfigSection (config, "patches");
if (patches) {
@@ -145,7 +146,6 @@ Init () {
modeCollabo026 = readConfigBool (cn_jun_2023, "mode_collabo026", modeCollabo026);
}
}
toml_free (config);
}
// Apply common config patch
+3 -3
View File
@@ -48,8 +48,9 @@ Init () {
bool sharedAudio = true;
bool unlockSongs = true;
auto configPath = std::filesystem::current_path () / "config.toml";
toml_table_t *config = openConfig (configPath);
auto configPath = std::filesystem::current_path () / "config.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
toml_table_t *config = config_ptr.get ();
if (config) {
auto patches = openConfigSection (config, "patches");
if (patches) {
@@ -62,7 +63,6 @@ Init () {
sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio);
unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs);
}
toml_free (config);
}
// Apply common config patch
+3 -3
View File
@@ -52,8 +52,9 @@ Init () {
bool sharedAudio = true;
bool unlockSongs = true;
auto configPath = std::filesystem::current_path () / "config.toml";
toml_table_t *config = openConfig (configPath);
auto configPath = std::filesystem::current_path () / "config.toml";
std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
toml_table_t *config = config_ptr.get ();
if (config) {
auto patches = openConfigSection (config, "patches");
if (patches) {
@@ -66,7 +67,6 @@ Init () {
sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio);
unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs);
}
toml_free (config);
}
// Apply common config patch