mirror of
https://github.com/esuo1198/TaikoArcadeLoader.git
synced 2026-10-01 19:27:55 +03:00
Change clang-format settings and format all codes
This commit is contained in:
+60
-60
@@ -5,107 +5,107 @@ void *consoleHandle = 0;
|
||||
|
||||
static void
|
||||
toml_myfree (void *p) {
|
||||
if (p) {
|
||||
char *pp = (char *)p;
|
||||
delete[] pp;
|
||||
}
|
||||
if (p) {
|
||||
char *pp = (char *)p;
|
||||
delete[] pp;
|
||||
}
|
||||
}
|
||||
|
||||
toml_table_t *
|
||||
openConfig (std::filesystem::path path) {
|
||||
if (!std::filesystem::exists (path) || !path.has_filename ()) {
|
||||
printWarning ("%s (%s): file does not exist\n", __func__, path.string ().c_str ());
|
||||
return 0;
|
||||
}
|
||||
if (!std::filesystem::exists (path) || !path.has_filename ()) {
|
||||
printWarning ("%s (%s): file does not exist\n", __func__, path.string ().c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::ifstream stream (path);
|
||||
if (!stream.is_open ()) {
|
||||
printWarning ("%s (%s): could not open\n", __func__, path.string ().c_str ());
|
||||
return 0;
|
||||
}
|
||||
std::ifstream stream (path);
|
||||
if (!stream.is_open ()) {
|
||||
printWarning ("%s (%s): could not open\n", __func__, path.string ().c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
stream.seekg (0, stream.end);
|
||||
size_t length = stream.tellg ();
|
||||
stream.seekg (0, stream.beg);
|
||||
stream.seekg (0, stream.end);
|
||||
size_t length = stream.tellg ();
|
||||
stream.seekg (0, stream.beg);
|
||||
|
||||
char *buf = (char *)calloc (length + 1, sizeof (char));
|
||||
stream.read (buf, length);
|
||||
char *buf = (char *)calloc (length + 1, sizeof (char));
|
||||
stream.read (buf, length);
|
||||
|
||||
char errorbuf[200];
|
||||
toml_table_t *config = toml_parse (buf, errorbuf, 200);
|
||||
stream.close ();
|
||||
free (buf);
|
||||
char errorbuf[200];
|
||||
toml_table_t *config = toml_parse (buf, errorbuf, 200);
|
||||
stream.close ();
|
||||
free (buf);
|
||||
|
||||
if (!config) {
|
||||
printWarning ("%s (%s): %s\n", __func__, path.string ().c_str (), errorbuf);
|
||||
return 0;
|
||||
}
|
||||
if (!config) {
|
||||
printWarning ("%s (%s): %s\n", __func__, path.string ().c_str (), errorbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return config;
|
||||
return config;
|
||||
}
|
||||
|
||||
toml_table_t *
|
||||
openConfigSection (toml_table_t *config, const std::string §ionName) {
|
||||
toml_table_t *section = toml_table_in (config, sectionName.c_str ());
|
||||
if (!section) {
|
||||
printWarning ("%s (%s): cannot find section\n", __func__, sectionName.c_str ());
|
||||
return 0;
|
||||
}
|
||||
toml_table_t *section = toml_table_in (config, sectionName.c_str ());
|
||||
if (!section) {
|
||||
printWarning ("%s (%s): cannot find section\n", __func__, sectionName.c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
return section;
|
||||
return section;
|
||||
}
|
||||
|
||||
bool
|
||||
readConfigBool (toml_table_t *table, const std::string &key, bool notFoundValue) {
|
||||
toml_datum_t data = toml_bool_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
toml_datum_t data = toml_bool_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
|
||||
return (bool)data.u.b;
|
||||
return (bool)data.u.b;
|
||||
}
|
||||
|
||||
int64_t
|
||||
readConfigInt (toml_table_t *table, const std::string &key, int64_t notFoundValue) {
|
||||
toml_datum_t data = toml_int_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
toml_datum_t data = toml_int_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
|
||||
return data.u.i;
|
||||
return data.u.i;
|
||||
}
|
||||
|
||||
const std::string
|
||||
readConfigString (toml_table_t *table, const std::string &key, const std::string ¬FoundValue) {
|
||||
toml_datum_t data = toml_string_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
std::string str = data.u.s;
|
||||
toml_myfree (data.u.s);
|
||||
toml_datum_t data = toml_string_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
std::string str = data.u.s;
|
||||
toml_myfree (data.u.s);
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::vector<int64_t>
|
||||
readConfigIntArray (toml_table_t *table, const std::string &key, std::vector<int64_t> notFoundValue) {
|
||||
toml_array_t *array = toml_array_in (table, key.c_str ());
|
||||
if (!array) return notFoundValue;
|
||||
toml_array_t *array = toml_array_in (table, key.c_str ());
|
||||
if (!array) return notFoundValue;
|
||||
|
||||
std::vector<int64_t> datas;
|
||||
for (int i = 0;; i++) {
|
||||
toml_datum_t data = toml_int_at (array, i);
|
||||
if (!data.ok) break;
|
||||
datas.push_back (data.u.i);
|
||||
}
|
||||
std::vector<int64_t> datas;
|
||||
for (int i = 0;; i++) {
|
||||
toml_datum_t data = toml_int_at (array, i);
|
||||
if (!data.ok) break;
|
||||
datas.push_back (data.u.i);
|
||||
}
|
||||
|
||||
return datas;
|
||||
return datas;
|
||||
}
|
||||
|
||||
void
|
||||
printColour (int colour, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
|
||||
if (consoleHandle == 0) consoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
if (consoleHandle == 0) consoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
|
||||
SetConsoleTextAttribute (consoleHandle, colour);
|
||||
vprintf (format, args);
|
||||
SetConsoleTextAttribute (consoleHandle, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
|
||||
SetConsoleTextAttribute (consoleHandle, colour);
|
||||
vprintf (format, args);
|
||||
SetConsoleTextAttribute (consoleHandle, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
|
||||
|
||||
va_end (args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user