Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Wed, 22 Nov 2017 16:26:00 +0000 (03:26 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 22 Nov 2017 16:26:00 +0000 (03:26 +1100)
1  2 
source/blender/blenkernel/BKE_blendfile.h
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/blendfile.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c

index 0a8eac7961a11a0f5939540aee1b801b688eb0e5,9ff164f60bea460019d3f2d86a9915393cd44b9e..a9a7e2045f01805d4a8332bbc8a7b5b455080b68
@@@ -59,11 -59,8 +59,12 @@@ struct UserDef *BKE_blendfile_userdef_r
          struct ReportList *reports);
  
  bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
+ bool BKE_blendfile_userdef_write_app_template(const char *filepath, struct ReportList *reports);
  
 +struct WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath, struct ReportList *reports);
 +bool BKE_blendfile_workspace_config_write(struct Main *bmain, const char *filepath, struct ReportList *reports);
 +void BKE_blendfile_workspace_config_data_free(struct WorkspaceConfigFileData *workspace_config);
 +
  /* partial blend file writing */
  void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);
  void BKE_blendfile_write_partial_begin(struct Main *bmain_src);
index 6df008e7ac9f8235386b72ed993302e2f1bc6341,cc992a4a520191dab33c9bea70c5d0f2041a086a..f6dfb7f922c36ff448912b0b730b9f7ae825f3be
@@@ -241,11 -226,9 +241,10 @@@ static void setup_app_data
        CTX_data_main_set(C, G.main);
  
        if (bfd->user) {
 +
                /* only here free userdef themes... */
-               BKE_blender_userdef_free_data(&U);
-               U = *bfd->user;
+               BKE_blender_userdef_data_set_and_free(bfd->user);
+               bfd->user = NULL;
  
                /* Security issue: any blend file could include a USER block.
                 *
@@@ -539,48 -511,29 +536,71 @@@ bool BKE_blendfile_userdef_write(const 
        return ok;
  }
  
+ /**
+  * Only write the userdef in a .blend, merging with the existing blend file.
+  * \return success
+  *
+  * \note In the future we should re-evaluate user preferences,
+  * possibly splitting out system/hardware specific prefs.
+  */
+ bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports)
+ {
+       /* if it fails, overwrite is OK. */
+       UserDef *userdef_default = BKE_blendfile_userdef_read(filepath, NULL);
+       if (userdef_default == NULL) {
+               return BKE_blendfile_userdef_write(filepath, reports);
+       }
+       BKE_blender_userdef_app_template_data_swap(&U, userdef_default);
+       bool ok = BKE_blendfile_userdef_write(filepath, reports);
+       BKE_blender_userdef_app_template_data_swap(&U, userdef_default);
+       BKE_blender_userdef_data_free(userdef_default, false);
+       MEM_freeN(userdef_default);
+       return ok;
+ }
 +WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath, ReportList *reports)
 +{
 +      BlendFileData *bfd;
 +      WorkspaceConfigFileData *workspace_config = NULL;
 +
 +      bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_USERDEF);
 +      if (bfd) {
 +              workspace_config = MEM_mallocN(sizeof(*workspace_config), __func__);
 +              workspace_config->main = bfd->main;
 +              workspace_config->workspaces = bfd->main->workspaces;
 +
 +              MEM_freeN(bfd);
 +      }
 +
 +      return workspace_config;
 +}
 +
 +bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, ReportList *reports)
 +{
 +      int fileflags = G.fileflags & ~(G_FILE_NO_UI | G_FILE_AUTOPLAY | G_FILE_HISTORY);
 +      bool retval = false;
 +
 +      BKE_blendfile_write_partial_begin(bmain);
 +
 +      for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
 +              BKE_blendfile_write_partial_tag_ID(&workspace->id, true);
 +      }
 +
 +      if (BKE_blendfile_write_partial(bmain, filepath, fileflags, reports)) {
 +              retval = true;
 +      }
 +
 +      BKE_blendfile_write_partial_end(bmain);
 +
 +      return retval;
 +}
 +
 +void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config)
 +{
 +      BKE_main_free(workspace_config->main);
 +      MEM_freeN(workspace_config);
 +}
  
  /** \} */