From b74b8b6a6cacf1b09dba850b727b2d7279c4f753 Mon Sep 17 00:00:00 2001
From: twinaphex <libretro@gmail.com>
Date: Sat, 13 Jun 2020 08:19:49 +0200
Subject: [PATCH] Move launched_from_cli to global state

---
 content.h            |  3 ---
 retroarch.c          |  2 +-
 retroarch.h          |  1 +
 tasks/task_content.c | 29 ++++++++++++-----------------
 4 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/content.h b/content.h
index e642e4bdeb..e2b8ee6ed9 100644
--- a/content.h
+++ b/content.h
@@ -85,9 +85,6 @@ bool content_reset_savestate_backups(void);
 bool content_undo_load_buf_is_empty(void);
 bool content_undo_save_buf_is_empty(void);
 
-/* Checks if launched from the commandline */
-bool content_launched_from_cli(void);
-
 /* Clears the pending subsystem rom buffer */
 bool content_is_subsystem_pending_load(void);
 
diff --git a/retroarch.c b/retroarch.c
index 1facf66b05..d72dec5606 100644
--- a/retroarch.c
+++ b/retroarch.c
@@ -34690,7 +34690,7 @@ bool retroarch_main_init(int argc, char *argv[])
    if (init_failed)
    {
       /* Check if menu was active prior to core initialization */
-      if (!content_launched_from_cli()
+      if (!global->launched_from_cli
 #ifdef HAVE_MENU
           || p_rarch->menu_driver_alive
 #endif
diff --git a/retroarch.h b/retroarch.h
index f249934a69..c355981c0b 100644
--- a/retroarch.h
+++ b/retroarch.h
@@ -224,6 +224,7 @@ typedef struct rarch_resolution
 
 typedef struct global
 {
+   bool launched_from_cli;
    struct
    {
       char savefile[8192];
diff --git a/tasks/task_content.c b/tasks/task_content.c
index ba6ec48869..0ba605d900 100644
--- a/tasks/task_content.c
+++ b/tasks/task_content.c
@@ -204,8 +204,6 @@ typedef struct content_state
    struct string_list *temporary_content;
 } content_state_t;
 
-/* TODO/FIXME - global state - perhaps move outside this file */
-static bool _launched_from_cli = true;
 static content_state_t content_st;
 
 #ifdef HAVE_CDROM
@@ -1951,8 +1949,11 @@ end:
 }
 #endif
 
-static bool task_load_content_callback(content_ctx_info_t *content_info,
-      bool loading_from_menu, bool loading_from_cli, bool loading_from_companion_ui)
+static bool task_load_content_internal(
+      content_ctx_info_t *content_info,
+      bool loading_from_menu,
+      bool loading_from_cli,
+      bool loading_from_companion_ui)
 {
    content_information_ctx_t content_ctx;
 
@@ -2102,7 +2103,7 @@ bool task_push_load_content_with_new_core_from_companion_ui(
    command_event(CMD_EVENT_LOAD_CORE, NULL);
 #endif
 
-   _launched_from_cli = false;
+   global->launched_from_cli = false;
 
    if (global)
    {
@@ -2113,7 +2114,7 @@ bool task_push_load_content_with_new_core_from_companion_ui(
    }
 
    /* Load content */
-   if (!task_load_content_callback(content_info, true, false, true))
+   if (!task_load_content_internal(content_info, true, false, true))
       return false;
 
 #ifdef HAVE_MENU
@@ -2133,7 +2134,7 @@ bool task_push_load_content_from_cli(
       void *user_data)
 {
    /* Load content */
-   if (!task_load_content_callback(content_info, true, true, false))
+   if (!task_load_content_internal(content_info, true, true, false))
       return false;
 
    return true;
@@ -2153,7 +2154,7 @@ bool task_push_start_builtin_core(
    retroarch_set_current_core_type(type, true);
 
    /* Load content */
-   if (!task_load_content_callback(content_info, true, false, false))
+   if (!task_load_content_internal(content_info, true, false, false))
    {
       retroarch_menu_running();
       return false;
@@ -2187,7 +2188,7 @@ bool task_push_load_content_with_current_core_from_companion_ui(
     * > TODO/FIXME: Set loading_from_companion_ui 'false' for
     *   now, until someone can implement the required higher
     *   level functionality in 'win32_common.c' and 'ui_cocoa.m' */
-   if (!task_load_content_callback(content_info, true, false, false))
+   if (!task_load_content_internal(content_info, true, false, false))
       return false;
 
    /* Push quick menu onto menu stack */
@@ -2209,7 +2210,7 @@ bool task_push_load_content_with_core_from_menu(
    path_set(RARCH_PATH_CONTENT, fullpath);
 
    /* Load content */
-   if (!task_load_content_callback(content_info, true, false, false))
+   if (!task_load_content_internal(content_info, true, false, false))
    {
       retroarch_menu_running();
       return false;
@@ -2236,7 +2237,7 @@ bool task_push_load_subsystem_with_core_from_menu(
    p_content->pending_subsystem_init = true;
 
    /* Load content */
-   if (!task_load_content_callback(content_info, true, false, false))
+   if (!task_load_content_internal(content_info, true, false, false))
    {
       retroarch_menu_running();
       return false;
@@ -2280,12 +2281,6 @@ void content_clear_subsystem(void)
    }
 }
 
-/* Checks if launched from the commandline */
-bool content_launched_from_cli(void)
-{
-   return _launched_from_cli;
-}
-
 /* Get the current subsystem */
 int content_get_subsystem(void)
 {