Cleanup: use parameters struct for wm_homefile_read

Also add wm_homefile_read_ex which is only needed for the first
execution at startup.
This commit is contained in:
Campbell Barton 2021-08-12 14:24:27 +10:00
parent c741558509
commit 216414c65a
3 changed files with 85 additions and 61 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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);