[Bf-blender-cvs] [fbb66d81b7] app-templates: Simplify path calculation
Campbell Barton
noreply at git.blender.org
Thu Mar 23 04:49:18 CET 2017
Commit: fbb66d81b7e1616779b85e8b022401343cc99249
Author: Campbell Barton
Date: Thu Mar 23 14:40:15 2017 +1100
Branches: app-templates
https://developer.blender.org/rBfbb66d81b7e1616779b85e8b022401343cc99249
Simplify path calculation
===================================================================
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index da167f7ffc..4e8ed8d61e 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -647,6 +647,8 @@ int wm_homefile_read(
ListBase wmbase;
char filepath_startup[FILE_MAX];
char filepath_userdef[FILE_MAX];
+ /* When 'app_template' is set: '{BLENDER_DATAFILES}/app_templates/{app_template}' */
+ char template_directory[FILE_MAX];
bool success = false;
/* Indicates whether user preferences were really load from memory.
@@ -679,6 +681,7 @@ int wm_homefile_read(
filepath_startup[0] = '\0';
filepath_userdef[0] = '\0';
+ template_directory[0] = '\0';
if (!use_factory_settings) {
const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
@@ -708,32 +711,39 @@ int wm_homefile_read(
}
}
- /* insert template name into startup file */
- if (!filepath_startup_override) {
- const char *app_template = NULL;
+ const char *app_template = NULL;
- if (app_template_override) {
- app_template = app_template_override;
- }
- else if (!use_factory_settings && U.app_template[0]) {
- app_template = U.app_template;
+ if (filepath_startup_override != NULL) {
+ /* pass */
+ }
+ else if (app_template_override) {
+ app_template = app_template_override;
+ }
+ else if (!use_factory_settings && U.app_template[0]) {
+ app_template = U.app_template;
+ }
+
+ if (app_template != NULL) {
+ char temp_path[FILE_MAX];
+ BLI_join_dirfile(temp_path, sizeof(temp_path), "app_templates", app_template);
+ const char *filepath_startup_template = BKE_appdir_folder_id(BLENDER_DATAFILES, temp_path);
+ if (filepath_startup_template) {
+ BLI_strncpy(template_directory, filepath_startup_template, sizeof(template_directory));
}
+ }
- if (app_template != NULL) {
- if (!use_factory_settings) {
- BLI_path_suffix(filepath_startup, sizeof(filepath_startup), app_template, "_");
- }
+ /* insert template name into startup file */
+ if (app_template != NULL) {
+ if (!use_factory_settings) {
+ BLI_path_suffix(filepath_startup, sizeof(filepath_startup), app_template, "_");
+ }
- if (use_factory_settings || BLI_access(filepath_startup, R_OK)) {
- char temp_path[FILE_MAX];
- BLI_join_dirfile(temp_path, sizeof(temp_path), "app_templates", U.app_template);
- const char *filepath_startup_template = BKE_appdir_folder_id(BLENDER_DATAFILES, temp_path);
- if (filepath_startup_template) {
- /* note that the path is being set even when 'use_factory_settings == true' */
- BLI_join_dirfile(
- filepath_startup, sizeof(filepath_startup),
- filepath_startup_template, BLENDER_STARTUP_FILE);
- }
+ if (use_factory_settings || BLI_access(filepath_startup, R_OK) != 0) {
+ if (template_directory[0] != '\0') {
+ /* note that the path is being set even when 'use_factory_settings == true' */
+ BLI_join_dirfile(
+ filepath_startup, sizeof(filepath_startup),
+ template_directory, BLENDER_STARTUP_FILE);
}
}
}
@@ -769,36 +779,30 @@ int wm_homefile_read(
U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
#endif
}
-
- /* Load a file but keep the splash open */
- if (app_template_override) {
- BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template));
- }
/* load template preferences */
- if (U.app_template[0] != '\0') {
+ if (template_directory[0] != '\0') {
char temp_path[FILE_MAX];
- BLI_join_dirfile(temp_path, sizeof(temp_path), "app_templates", U.app_template);
- const char *filepath_userdef_template = BKE_appdir_folder_id(BLENDER_DATAFILES, temp_path);
-
- if (filepath_userdef_template) {
- BLI_join_dirfile(temp_path, sizeof(temp_path), filepath_userdef_template, BLENDER_USERPREF_FILE);
- UserDef *userdef_template = NULL;
- /* just avoids missing file warning */
- if (BLI_exists(temp_path)) {
- userdef_template = BKE_blendfile_userdef_read(temp_path, NULL);
- }
- if (userdef_template == NULL) {
- /* we need to have preferences load to overwrite preferences from previous template */
- userdef_template = BKE_blendfile_userdef_read_from_memory(
- datatoc_startup_blend, datatoc_startup_blend_size, NULL);
- }
- if (userdef_template) {
- BKE_blender_userdef_set_template(userdef_template);
- BKE_blender_userdef_free_data(userdef_template);
- MEM_freeN(userdef_template);
- }
+ BLI_join_dirfile(temp_path, sizeof(temp_path), template_directory, BLENDER_USERPREF_FILE);
+ UserDef *userdef_template = NULL;
+ /* just avoids missing file warning */
+ if (BLI_exists(temp_path)) {
+ userdef_template = BKE_blendfile_userdef_read(temp_path, NULL);
}
+ if (userdef_template == NULL) {
+ /* we need to have preferences load to overwrite preferences from previous template */
+ userdef_template = BKE_blendfile_userdef_read_from_memory(
+ datatoc_startup_blend, datatoc_startup_blend_size, NULL);
+ }
+ if (userdef_template) {
+ BKE_blender_userdef_set_template(userdef_template);
+ BKE_blender_userdef_free_data(userdef_template);
+ MEM_freeN(userdef_template);
+ }
+ }
+
+ if (app_template_override) {
+ BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template));
}
/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
More information about the Bf-blender-cvs
mailing list