Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-05-10 08:46:31 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-05-10 11:27:02 +0300
commitb607d1629251dcf1f1964cfddbc9d121863d5ca1 (patch)
tree84bb52547104cf1f594aa3d2481ed3e518e24b95 /source/blender
parent44ecea1ccbc06680cfc12a89799badbf0cc43ac9 (diff)
Cleanup: move preference saving logic into blendfile.c
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_appdir.h1
-rw-r--r--source/blender/blenkernel/BKE_blendfile.h2
-rw-r--r--source/blender/blenkernel/intern/appdir.c20
-rw-r--r--source/blender/blenkernel/intern/blendfile.c54
-rw-r--r--source/blender/windowmanager/intern/wm_files.c74
5 files changed, 81 insertions, 70 deletions
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index 7ff8514f675..e956aeb769a 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -36,6 +36,7 @@ const char *BKE_appdir_folder_id_version(const int folder_id, const int ver, con
bool BKE_appdir_app_is_portable_install(void);
bool BKE_appdir_app_template_any(void);
bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_len);
+bool BKE_appdir_app_template_has_userpref(const char *app_template);
void BKE_appdir_app_templates(struct ListBase *templates);
/* Initialize path to program executable */
diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 216bef0d1e3..76c05b0411a 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -62,6 +62,8 @@ struct UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
bool BKE_blendfile_userdef_write_app_template(const char *filepath, struct ReportList *reports);
+bool BKE_blendfile_userdef_write_all(struct ReportList *reports);
+
struct WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath,
const void *filebuf,
int filelength,
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 2b4123c74e2..c1ea57c5fcc 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -838,6 +838,26 @@ bool BKE_appdir_app_template_id_search(const char *app_template, char *path, siz
return false;
}
+bool BKE_appdir_app_template_has_userpref(const char *app_template)
+{
+ /* Test if app template provides a userpref.blend.
+ * If not, we will share user preferences with the rest of Blender. */
+ if (!app_template && app_template[0]) {
+ return false;
+ }
+
+ char app_template_path[FILE_MAX];
+ if (!BKE_appdir_app_template_id_search(
+ app_template, app_template_path, sizeof(app_template_path))) {
+ return false;
+ }
+
+ char userpref_path[FILE_MAX];
+ BLI_path_join(
+ userpref_path, sizeof(userpref_path), app_template_path, BLENDER_USERPREF_FILE, NULL);
+ return BLI_exists(userpref_path);
+}
+
void BKE_appdir_app_templates(ListBase *templates)
{
BLI_listbase_clear(templates);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index d1a3045a829..f54d938c0ca 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -566,6 +566,60 @@ bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *
return ok;
}
+bool BKE_blendfile_userdef_write_all(ReportList *reports)
+{
+ char filepath[FILE_MAX];
+ const char *cfgdir;
+ bool ok = true;
+ const bool use_template_userpref = BKE_appdir_app_template_has_userpref(U.app_template);
+
+ if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) {
+ bool ok_write;
+ BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
+
+ printf("Writing userprefs: '%s' ", filepath);
+ if (use_template_userpref) {
+ ok_write = BKE_blendfile_userdef_write_app_template(filepath, reports);
+ }
+ else {
+ ok_write = BKE_blendfile_userdef_write(filepath, reports);
+ }
+
+ if (ok_write) {
+ printf("ok\n");
+ }
+ else {
+ printf("fail\n");
+ ok = false;
+ }
+ }
+ else {
+ BKE_report(reports, RPT_ERROR, "Unable to create userpref path");
+ }
+
+ if (use_template_userpref) {
+ if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) {
+ /* Also save app-template prefs */
+ BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
+
+ printf("Writing userprefs app-template: '%s' ", filepath);
+ if (BKE_blendfile_userdef_write(filepath, reports) != 0) {
+ printf("ok\n");
+ }
+ else {
+ printf("fail\n");
+ ok = false;
+ }
+ }
+ else {
+ BKE_report(reports, RPT_ERROR, "Unable to create app-template userpref path");
+ ok = false;
+ }
+ }
+
+ return ok;
+}
+
WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath,
const void *filebuf,
int filelength,
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 6d90d4745a6..1308af2659a 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -716,26 +716,6 @@ const char *WM_init_state_app_template_get(void)
return wm_init_state_app_template.override ? wm_init_state_app_template.app_template : NULL;
}
-static bool wm_app_template_has_userpref(const char *app_template)
-{
- /* Test if app template provides a userpref.blend. If not, we will
- * share user preferences with the rest of Blender. */
- if (!app_template && app_template[0]) {
- return false;
- }
-
- char app_template_path[FILE_MAX];
- if (!BKE_appdir_app_template_id_search(
- app_template, app_template_path, sizeof(app_template_path))) {
- return false;
- }
-
- char userpref_path[FILE_MAX];
- BLI_path_join(
- userpref_path, sizeof(userpref_path), app_template_path, BLENDER_USERPREF_FILE, NULL);
- return BLI_exists(userpref_path);
-}
-
/**
* Called on startup, (context entirely filled with NULLs)
* or called for 'New File' both startup.blend and userpref.blend are checked.
@@ -1694,57 +1674,11 @@ void WM_OT_userpref_autoexec_path_remove(wmOperatorType *ot)
static int wm_userpref_write_exec(bContext *C, wmOperator *op)
{
wmWindowManager *wm = CTX_wm_manager(C);
- char filepath[FILE_MAX];
- const char *cfgdir;
- bool ok = true;
- bool use_template_userpref = wm_app_template_has_userpref(U.app_template);
- /* update keymaps in user preferences */
+ /* Update keymaps in user preferences. */
WM_keyconfig_update(wm);
- if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) {
- bool ok_write;
- BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
-
- printf("Writing userprefs: '%s' ", filepath);
- if (use_template_userpref) {
- ok_write = BKE_blendfile_userdef_write_app_template(filepath, op->reports);
- }
- else {
- ok_write = BKE_blendfile_userdef_write(filepath, op->reports);
- }
-
- if (ok_write) {
- printf("ok\n");
- }
- else {
- printf("fail\n");
- ok = false;
- }
- }
- else {
- BKE_report(op->reports, RPT_ERROR, "Unable to create userpref path");
- }
-
- if (use_template_userpref) {
- if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) {
- /* Also save app-template prefs */
- BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
-
- printf("Writing userprefs app-template: '%s' ", filepath);
- if (BKE_blendfile_userdef_write(filepath, op->reports) != 0) {
- printf("ok\n");
- }
- else {
- printf("fail\n");
- ok = false;
- }
- }
- else {
- BKE_report(op->reports, RPT_ERROR, "Unable to create app-template userpref path");
- ok = false;
- }
- }
+ const bool ok = BKE_blendfile_userdef_write_all(op->reports);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@@ -1822,8 +1756,8 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
app_template = app_template_buf;
/* Always load preferences when switching templates with own preferences. */
- use_userdef = wm_app_template_has_userpref(app_template) ||
- wm_app_template_has_userpref(U.app_template);
+ use_userdef = BKE_appdir_app_template_has_userpref(app_template) ||
+ BKE_appdir_app_template_has_userpref(U.app_template);
/* Turn override off, since we're explicitly loading a different app-template. */
WM_init_state_app_template_set(NULL);