mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
shell: do not create logs with --help
This commit is contained in:
parent
6911640dad
commit
8cfbd31040
4 changed files with 66 additions and 90 deletions
|
@ -6,24 +6,16 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static int m_ArgCount = 0;
|
|
||||||
static const char **m_ArgStrings = nullptr;
|
|
||||||
|
|
||||||
void Shell_GetCommandLine(int *arg_count, const char ***args)
|
|
||||||
{
|
|
||||||
*arg_count = m_ArgCount;
|
|
||||||
*args = m_ArgStrings;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
if (!Shell_ParseArgs(argc, (const char **)argv)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *log_path = File_GetFullPath(PROJECT_NAME ".log");
|
char *log_path = File_GetFullPath(PROJECT_NAME ".log");
|
||||||
Log_Init(log_path);
|
Log_Init(log_path);
|
||||||
Memory_FreePointer(&log_path);
|
Memory_FreePointer(&log_path);
|
||||||
|
|
||||||
m_ArgCount = argc;
|
|
||||||
m_ArgStrings = (const char **)argv;
|
|
||||||
|
|
||||||
Shell_Setup();
|
Shell_Setup();
|
||||||
int32_t exit_code = Shell_Main();
|
int32_t exit_code = Shell_Main();
|
||||||
Shell_Terminate(exit_code);
|
Shell_Terminate(exit_code);
|
||||||
|
|
|
@ -11,13 +11,13 @@ typedef struct {
|
||||||
extern void Shell_Shutdown(void);
|
extern void Shell_Shutdown(void);
|
||||||
extern SDL_Window *Shell_GetWindow(void);
|
extern SDL_Window *Shell_GetWindow(void);
|
||||||
|
|
||||||
|
extern bool Shell_ParseArgs(int32_t arg_count, const char **args);
|
||||||
void Shell_Setup(void);
|
void Shell_Setup(void);
|
||||||
extern int32_t Shell_Main(void);
|
extern int32_t Shell_Main(void);
|
||||||
void Shell_Terminate(int32_t exit_code);
|
void Shell_Terminate(int32_t exit_code);
|
||||||
void Shell_ExitSystem(const char *message);
|
void Shell_ExitSystem(const char *message);
|
||||||
void Shell_ExitSystemFmt(const char *fmt, ...);
|
void Shell_ExitSystemFmt(const char *fmt, ...);
|
||||||
|
|
||||||
void Shell_GetCommandLine(int *arg_count, const char ***args);
|
|
||||||
void Shell_ScheduleExit(void);
|
void Shell_ScheduleExit(void);
|
||||||
bool Shell_IsExiting(void);
|
bool Shell_IsExiting(void);
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@ static SHELL_ARGS m_Args = {
|
||||||
static const char *m_CurrentGameFlowPath;
|
static const char *m_CurrentGameFlowPath;
|
||||||
|
|
||||||
static void M_ShowHelp(void);
|
static void M_ShowHelp(void);
|
||||||
static bool M_ParseArgs(SHELL_ARGS *out_args);
|
|
||||||
static void M_LoadConfig(void);
|
static void M_LoadConfig(void);
|
||||||
static void M_HandleConfigChange(const EVENT *event, void *data);
|
static void M_HandleConfigChange(const EVENT *event, void *data);
|
||||||
|
|
||||||
|
@ -96,41 +95,6 @@ static void M_ShowHelp(void)
|
||||||
puts("-s/--save <NUM>: launch from a specific save slot (starts at 1).");
|
puts("-s/--save <NUM>: launch from a specific save slot (starts at 1).");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool M_ParseArgs(SHELL_ARGS *const out_args)
|
|
||||||
{
|
|
||||||
const char **args = nullptr;
|
|
||||||
int32_t arg_count = 0;
|
|
||||||
Shell_GetCommandLine(&arg_count, &args);
|
|
||||||
|
|
||||||
out_args->mod = M_MOD_OG;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < arg_count; i++) {
|
|
||||||
if (!strcmp(args[i], "-h") || !strcmp(args[i], "--help")) {
|
|
||||||
M_ShowHelp();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!strcmp(args[i], "-g") || !strcmp(args[i], "--gold")
|
|
||||||
|| !strcmp(args[i], "-gold")) {
|
|
||||||
out_args->mod = M_MOD_UB;
|
|
||||||
}
|
|
||||||
if (!strcmp(args[i], "--demo-pc") || !strcmp(args[i], "-demo_pc")) {
|
|
||||||
out_args->mod = M_MOD_DEMO_PC;
|
|
||||||
}
|
|
||||||
if ((!strcmp(args[i], "-l") || !strcmp(args[i], "--level"))
|
|
||||||
&& i + 1 < arg_count) {
|
|
||||||
out_args->level_to_play = args[i + 1];
|
|
||||||
out_args->mod = M_MOD_CUSTOM_LEVEL;
|
|
||||||
}
|
|
||||||
if ((!strcmp(args[i], "-s") || !strcmp(args[i], "--save"))
|
|
||||||
&& i + 1 < arg_count) {
|
|
||||||
if (String_ParseInteger(args[i + 1], &out_args->save_to_load)) {
|
|
||||||
out_args->save_to_load--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void M_HandleConfigChange(const EVENT *const event, void *const data)
|
static void M_HandleConfigChange(const EVENT *const event, void *const data)
|
||||||
{
|
{
|
||||||
const CONFIG *const old = &g_Config;
|
const CONFIG *const old = &g_Config;
|
||||||
|
@ -191,12 +155,40 @@ const char *Shell_GetGameFlowPath(void)
|
||||||
return m_ModPaths[m_Args.mod].game_flow_path;
|
return m_ModPaths[m_Args.mod].game_flow_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Shell_ParseArgs(const int32_t arg_count, const char **args)
|
||||||
|
{
|
||||||
|
SHELL_ARGS *const out_args = &m_Args;
|
||||||
|
out_args->mod = M_MOD_OG;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < arg_count; i++) {
|
||||||
|
if (!strcmp(args[i], "-h") || !strcmp(args[i], "--help")) {
|
||||||
|
M_ShowHelp();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!strcmp(args[i], "-g") || !strcmp(args[i], "--gold")
|
||||||
|
|| !strcmp(args[i], "-gold")) {
|
||||||
|
out_args->mod = M_MOD_UB;
|
||||||
|
}
|
||||||
|
if (!strcmp(args[i], "--demo-pc") || !strcmp(args[i], "-demo_pc")) {
|
||||||
|
out_args->mod = M_MOD_DEMO_PC;
|
||||||
|
}
|
||||||
|
if ((!strcmp(args[i], "-l") || !strcmp(args[i], "--level"))
|
||||||
|
&& i + 1 < arg_count) {
|
||||||
|
out_args->level_to_play = args[i + 1];
|
||||||
|
out_args->mod = M_MOD_CUSTOM_LEVEL;
|
||||||
|
}
|
||||||
|
if ((!strcmp(args[i], "-s") || !strcmp(args[i], "--save"))
|
||||||
|
&& i + 1 < arg_count) {
|
||||||
|
if (String_ParseInteger(args[i + 1], &out_args->save_to_load)) {
|
||||||
|
out_args->save_to_load--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t Shell_Main(void)
|
int32_t Shell_Main(void)
|
||||||
{
|
{
|
||||||
if (!M_ParseArgs(&m_Args)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameString_Init();
|
GameString_Init();
|
||||||
EnumMap_Init();
|
EnumMap_Init();
|
||||||
Config_Init();
|
Config_Init();
|
||||||
|
|
|
@ -100,7 +100,6 @@ static void M_ConfigureOpenGL(void);
|
||||||
static bool M_CreateGameWindow(void);
|
static bool M_CreateGameWindow(void);
|
||||||
|
|
||||||
static void M_ShowHelp(void);
|
static void M_ShowHelp(void);
|
||||||
static bool M_ParseArgs(SHELL_ARGS *out_args);
|
|
||||||
static void M_LoadConfig(void);
|
static void M_LoadConfig(void);
|
||||||
static void M_HandleConfigChange(const EVENT *event, void *data);
|
static void M_HandleConfigChange(const EVENT *event, void *data);
|
||||||
|
|
||||||
|
@ -352,38 +351,6 @@ static void M_ShowHelp(void)
|
||||||
puts("-s/--save <NUM>: launch from a specific save slot (starts at 1).");
|
puts("-s/--save <NUM>: launch from a specific save slot (starts at 1).");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool M_ParseArgs(SHELL_ARGS *const out_args)
|
|
||||||
{
|
|
||||||
const char **args = nullptr;
|
|
||||||
int32_t arg_count = 0;
|
|
||||||
Shell_GetCommandLine(&arg_count, &args);
|
|
||||||
|
|
||||||
out_args->mod = M_MOD_OG;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < arg_count; i++) {
|
|
||||||
if (!strcmp(args[i], "-h") || !strcmp(args[i], "--help")) {
|
|
||||||
M_ShowHelp();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!strcmp(args[i], "-g") || !strcmp(args[i], "--gold")
|
|
||||||
|| !strcmp(args[i], "-gold")) {
|
|
||||||
out_args->mod = M_MOD_GM;
|
|
||||||
}
|
|
||||||
if ((!strcmp(args[i], "-l") || !strcmp(args[i], "--level"))
|
|
||||||
&& i + 1 < arg_count) {
|
|
||||||
out_args->level_to_play = args[i + 1];
|
|
||||||
out_args->mod = M_MOD_CUSTOM_LEVEL;
|
|
||||||
}
|
|
||||||
if ((!strcmp(args[i], "-s") || !strcmp(args[i], "--save"))
|
|
||||||
&& i + 1 < arg_count) {
|
|
||||||
if (String_ParseInteger(args[i + 1], &out_args->save_to_load)) {
|
|
||||||
out_args->save_to_load--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void M_LoadConfig(void)
|
static void M_LoadConfig(void)
|
||||||
{
|
{
|
||||||
Config_Read();
|
Config_Read();
|
||||||
|
@ -449,13 +416,38 @@ static void M_HandleConfigChange(const EVENT *const event, void *const data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Shell_ParseArgs(const int32_t arg_count, const char **args)
|
||||||
|
{
|
||||||
|
SHELL_ARGS *const out_args = &m_Args;
|
||||||
|
out_args->mod = M_MOD_OG;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < arg_count; i++) {
|
||||||
|
if (!strcmp(args[i], "-h") || !strcmp(args[i], "--help")) {
|
||||||
|
M_ShowHelp();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!strcmp(args[i], "-g") || !strcmp(args[i], "--gold")
|
||||||
|
|| !strcmp(args[i], "-gold")) {
|
||||||
|
out_args->mod = M_MOD_GM;
|
||||||
|
}
|
||||||
|
if ((!strcmp(args[i], "-l") || !strcmp(args[i], "--level"))
|
||||||
|
&& i + 1 < arg_count) {
|
||||||
|
out_args->level_to_play = args[i + 1];
|
||||||
|
out_args->mod = M_MOD_CUSTOM_LEVEL;
|
||||||
|
}
|
||||||
|
if ((!strcmp(args[i], "-s") || !strcmp(args[i], "--save"))
|
||||||
|
&& i + 1 < arg_count) {
|
||||||
|
if (String_ParseInteger(args[i + 1], &out_args->save_to_load)) {
|
||||||
|
out_args->save_to_load--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: refactor the hell out of me
|
// TODO: refactor the hell out of me
|
||||||
int32_t Shell_Main(void)
|
int32_t Shell_Main(void)
|
||||||
{
|
{
|
||||||
if (!M_ParseArgs(&m_Args)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INFO("Game directory: %s", File_GetGameDirectory());
|
LOG_INFO("Game directory: %s", File_GetGameDirectory());
|
||||||
|
|
||||||
if (m_Args.mod == M_MOD_GM) {
|
if (m_Args.mod == M_MOD_GM) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue