[Bf-blender-cvs] [216414c65a6] master: Cleanup: use parameters struct for wm_homefile_read

Campbell Barton noreply at git.blender.org
Thu Aug 12 06:40:42 CEST 2021


Commit: 216414c65a6b3690aba75caf74d1dbf6dd8247a1
Author: Campbell Barton
Date:   Thu Aug 12 14:24:27 2021 +1000
Branches: master
https://developer.blender.org/rB216414c65a6b3690aba75caf74d1dbf6dd8247a1

Cleanup: use parameters struct for wm_homefile_read

Also add wm_homefile_read_ex which is only needed for the first
execution at startup.

===================================================================

M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/wm_files.h

===================================================================

diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index abf957a6396..65659dd7ab7 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -993,31 +993,12 @@ const char *WM_init_state_app_template_get(void)
 
 /**
  * Called on startup, (context entirely filled with NULLs)
- * or called for 'New File' both startup.blend and userpref.blend are checked.
- *
- * \param use_factory_settings:
- * Ignore on-disk startup file, use bundled `datatoc_startup_blend` instead.
- * Used for "Restore Factory Settings".
- *
- * \param use_userdef: Load factory settings as well as startup file.
- * Disabled for "File New" we don't want to reload preferences.
- *
- * \param filepath_startup_override:
- * Optional path pointing to an alternative blend file (may be NULL).
- *
- * \param app_template_override:
- * Template to use instead of the template defined in user-preferences.
- * When not-null, this is written into the user preferences.
+ * or called for 'New File' both `startup.blend` and `userpref.blend` are checked.
  */
-void wm_homefile_read(bContext *C,
-                      ReportList *reports,
-                      bool use_factory_settings,
-                      bool use_empty_data,
-                      bool use_data,
-                      bool use_userdef,
-                      const char *filepath_startup_override,
-                      const char *app_template_override,
-                      bool *r_is_factory_startup)
+void wm_homefile_read_ex(bContext *C,
+                         const struct wmHomeFileRead_Params *params_homefile,
+                         ReportList *reports,
+                         bool *r_is_factory_startup)
 {
 #if 0 /* UNUSED, keep as this may be needed later & the comment below isn't self evident. */
   /* Context does not always have valid main pointer here. */
@@ -1026,6 +1007,14 @@ void wm_homefile_read(bContext *C,
   ListBase wmbase;
   bool success = false;
 
+  /* May be enabled, when the user configuration doesn't exist. */
+  const bool use_data = params_homefile->use_data;
+  const bool use_userdef = params_homefile->use_userdef;
+  bool use_factory_settings = params_homefile->use_factory_settings;
+  const bool use_empty_data = params_homefile->use_empty_data;
+  const char *filepath_startup_override = params_homefile->filepath_startup_override;
+  const char *app_template_override = params_homefile->app_template_override;
+
   bool filepath_startup_is_factory = true;
   char filepath_startup[FILE_MAX];
   char filepath_userdef[FILE_MAX];
@@ -1320,6 +1309,13 @@ void wm_homefile_read(bContext *C,
   }
 }
 
+void wm_homefile_read(bContext *C,
+                      const struct wmHomeFileRead_Params *params_homefile,
+                      ReportList *reports)
+{
+  wm_homefile_read_ex(C, params_homefile, reports, NULL);
+}
+
 /* -------------------------------------------------------------------- */
 /** \name Blend-File History API
  * \{ */
@@ -2087,14 +2083,15 @@ static int wm_userpref_read_exec(bContext *C, wmOperator *op)
   UserDef U_backup = U;
 
   wm_homefile_read(C,
-                   op->reports,
-                   use_factory_settings,
-                   false,
-                   use_data,
-                   use_userdef,
-                   NULL,
-                   WM_init_state_app_template_get(),
-                   NULL);
+                   &(const struct wmHomeFileRead_Params){
+                       .use_data = use_data,
+                       .use_userdef = use_userdef,
+                       .use_factory_settings = use_factory_settings,
+                       .use_empty_data = false,
+                       .filepath_startup_override = NULL,
+                       .app_template_override = WM_init_state_app_template_get(),
+                   },
+                   op->reports);
 
   wm_userpref_read_exceptions(&U, &U_backup);
   SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
@@ -2233,16 +2230,17 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
     app_template = WM_init_state_app_template_get();
   }
 
-  bool use_data = true;
   wm_homefile_read(C,
-                   op->reports,
-                   use_factory_settings,
-                   use_empty_data,
-                   use_data,
-                   use_userdef,
-                   filepath,
-                   app_template,
-                   NULL);
+                   &(const struct wmHomeFileRead_Params){
+                       .use_data = true,
+                       .use_userdef = use_userdef,
+                       .use_factory_settings = use_factory_settings,
+                       .use_empty_data = use_empty_data,
+                       .filepath_startup_override = filepath,
+                       .app_template_override = app_template,
+                   },
+                   op->reports);
+
   if (use_splash) {
     WM_init_splash(C);
   }
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index d7ea47fc625..953aa683441 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -279,10 +279,7 @@ void WM_init(bContext *C, int argc, const char **argv)
 
   WM_msgbus_types_init();
 
-  /* get the default database, plus a wm */
   bool is_factory_startup = true;
-  const bool use_data = true;
-  const bool use_userdef = true;
 
   /* Studio-lights needs to be init before we read the home-file,
    * otherwise the versioning cannot find the default studio-light. */
@@ -290,15 +287,17 @@ void WM_init(bContext *C, int argc, const char **argv)
 
   BLI_assert((G.fileflags & G_FILE_NO_UI) == 0);
 
-  wm_homefile_read(C,
-                   NULL,
-                   G.factory_startup,
-                   false,
-                   use_data,
-                   use_userdef,
-                   NULL,
-                   WM_init_state_app_template_get(),
-                   &is_factory_startup);
+  wm_homefile_read_ex(C,
+                      &(const struct wmHomeFileRead_Params){
+                          .use_data = true,
+                          .use_userdef = true,
+                          .use_factory_settings = G.factory_startup,
+                          .use_empty_data = false,
+                          .filepath_startup_override = NULL,
+                          .app_template_override = WM_init_state_app_template_get(),
+                      },
+                      NULL,
+                      &is_factory_startup);
 
   /* Call again to set from userpreferences... */
   BLT_lang_set(NULL);
diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h
index c7fe07cad7f..7009885495b 100644
--- a/source/blender/windowmanager/wm_files.h
+++ b/source/blender/windowmanager/wm_files.h
@@ -33,15 +33,42 @@ extern "C" {
 
 /* wm_files.c */
 void wm_history_file_read(void);
+
+struct wmHomeFileRead_Params {
+  /** Load data, disable when only loading user preferences. */
+  unsigned int use_data : 1;
+  /** Load factory settings as well as startup file (disabled for "File New"). */
+  unsigned int use_userdef : 1;
+
+  /**
+   * Ignore on-disk startup file, use bundled `datatoc_startup_blend` instead.
+   * Used for "Restore Factory Settings".
+   */
+  unsigned int use_factory_settings : 1;
+  /**
+   * Load the startup file without any data-blocks.
+   * Useful for automated content generation, so the file starts without data.
+   */
+  unsigned int use_empty_data : 1;
+  /**
+   * Optional path pointing to an alternative blend file (may be NULL).
+   */
+  const char *filepath_startup_override;
+  /**
+   * Template to use instead of the template defined in user-preferences.
+   * When not-null, this is written into the user preferences.
+   */
+  const char *app_template_override;
+};
+
+void wm_homefile_read_ex(struct bContext *C,
+                         const struct wmHomeFileRead_Params *params_homefile,
+                         struct ReportList *reports,
+                         bool *r_is_factory_startup);
 void wm_homefile_read(struct bContext *C,
-                      struct ReportList *reports,
-                      bool use_factory_settings,
-                      bool use_empty_data,
-                      bool use_data,
-                      bool use_userdef,
-                      const char *filepath_startup_override,
-                      const char *app_template_override,
-                      bool *r_is_factory_startup);
+                      const struct wmHomeFileRead_Params *params_homefile,
+                      struct ReportList *reports);
+
 void wm_file_read_report(bContext *C, struct Main *bmain);
 
 void wm_close_file_dialog(bContext *C, struct wmGenericCallback *post_action);



More information about the Bf-blender-cvs mailing list