[Bf-blender-cvs] [5de109cc2d2] master: Remove G.relbase_valid

Campbell Barton noreply at git.blender.org
Thu Dec 16 01:42:37 CET 2021


Commit: 5de109cc2d220ca3bd731216b9cd521269ad663e
Author: Campbell Barton
Date:   Thu Dec 16 11:38:10 2021 +1100
Branches: master
https://developer.blender.org/rB5de109cc2d220ca3bd731216b9cd521269ad663e

Remove G.relbase_valid

In almost all cases there is no difference between `G.relbase_valid`
and checking `G.main->filepath` isn't an empty string.

In many places a non-empty string is already being used instead of
`G.relbase_valid`.

The only situation where this was needed was when saving from
`wm_file_write` where they temporarily became out of sync.
This has been replaced by adding a new member to `BlendFileWriteParams`
to account for saving an unsaved file for the first time.

Reviewed By: brecht

Ref D13564

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

M	source/blender/blenkernel/BKE_global.h
M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenloader/BLO_writefile.h
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/screen/screendump.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_info/info_ops.c
M	source/blender/editors/util/ed_util.c
M	source/blender/makesrna/intern/rna_main.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_files_link.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/creator/creator.c
M	source/creator/creator_args.c

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

diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index 184ebb8e934..ecf2e1f32a0 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -50,9 +50,6 @@ typedef struct Global {
   /** Last used location for library link/append. */
   char lib[1024];
 
-  /** When set: `G_MAIN->filepath` contains valid relative base path. */
-  bool relbase_valid;
-
   /**
    * Strings of recently opened files to show in the file menu.
    * A list of #RecentFile read from #BLENDER_HISTORY_FILE.
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 953c29f797a..41ef5e3f5ba 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -116,6 +116,7 @@ enum {
 
 typedef struct Main {
   struct Main *next, *prev;
+  /** The file-path of this blend file, an empty string indicates an unsaved file. */
   char filepath[1024];               /* 1024 = FILE_MAX */
   short versionfile, subversionfile; /* see BLENDER_FILE_VERSION, BLENDER_FILE_SUBVERSION */
   short minversionfile, minsubversionfile;
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index cc6854d2f2e..f43cf00a310 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -2062,9 +2062,10 @@ static void stampdata(
   time_t t;
 
   if (scene->r.stamp & R_STAMP_FILENAME) {
+    const char *blendfile_path = BKE_main_blendfile_path_from_global();
     SNPRINTF(stamp_data->file,
              do_prefix ? "File %s" : "%s",
-             G.relbase_valid ? BKE_main_blendfile_path_from_global() : "<untitled>");
+             (blendfile_path[0] != '\0') ? blendfile_path : "<untitled>");
   }
   else {
     stamp_data->file[0] = '\0';
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 5ad8f143b2b..e1d201d7806 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -933,7 +933,7 @@ const char *BKE_modifier_path_relbase(Main *bmain, Object *ob)
    * - Else if the file has been saved return the blend file path.
    * - Else if the file isn't saved and the ID isn't from a library, return the temp dir.
    */
-  if (G.relbase_valid || ID_IS_LINKED(ob)) {
+  if ((bmain->filepath[0] != '\0') || ID_IS_LINKED(ob)) {
     return ID_BLEND_PATH(bmain, &ob->id);
   }
 
@@ -948,7 +948,8 @@ const char *BKE_modifier_path_relbase_from_global(Object *ob)
 
 void BKE_modifier_path_init(char *path, int path_maxlen, const char *name)
 {
-  BLI_join_dirfile(path, path_maxlen, G.relbase_valid ? "//" : BKE_tempdir_session(), name);
+  const char *blendfile_path = BKE_main_blendfile_path_from_global();
+  BLI_join_dirfile(path, path_maxlen, blendfile_path[0] ? "//" : BKE_tempdir_session(), name);
 }
 
 /**
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 094181afca9..df76f003498 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1322,10 +1322,11 @@ static int ptcache_frame_from_filename(const char *filename, const char *ext)
 
 static int ptcache_path(PTCacheID *pid, char *filename)
 {
+  const char *blendfile_path = BKE_main_blendfile_path_from_global();
   Library *lib = (pid->owner_id) ? pid->owner_id->lib : NULL;
   const char *blendfilename = (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH) == 0) ?
                                   lib->filepath_abs :
-                                  BKE_main_blendfile_path_from_global();
+                                  blendfile_path;
   size_t i;
 
   if (pid->cache->flag & PTCACHE_EXTERNAL) {
@@ -1337,7 +1338,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
 
     return BLI_path_slash_ensure(filename); /* new strlen() */
   }
-  if (G.relbase_valid || lib) {
+  if ((blendfile_path[0] != '\0') || lib) {
     char file[MAX_PTCACHE_PATH]; /* we don't want the dir, only the file */
 
     BLI_split_file_part(blendfilename, file, sizeof(file));
@@ -1422,8 +1423,11 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p
   filename[0] = '\0';
   newname = filename;
 
-  if (!G.relbase_valid && (pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
-    return 0; /* save blend file before using disk pointcache */
+  if ((pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
+    const char *blendfile_path = BKE_main_blendfile_path_from_global();
+    if (blendfile_path[0] == '\0') {
+      return 0; /* save blend file before using disk pointcache */
+    }
   }
 
   /* start with temp dir */
@@ -1469,8 +1473,11 @@ static PTCacheFile *ptcache_file_open(PTCacheID *pid, int mode, int cfra)
     return NULL;
   }
 #endif
-  if (!G.relbase_valid && (pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
-    return NULL; /* save blend file before using disk pointcache */
+  if ((pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
+    const char *blendfile_path = BKE_main_blendfile_path_from_global();
+    if (blendfile_path[0] == '\0') {
+      return NULL; /* save blend file before using disk pointcache */
+    }
   }
 
   ptcache_filename(pid, filename, cfra, 1, 1);
@@ -3444,8 +3451,9 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid)
 {
   PointCache *cache = pid->cache;
   int last_exact = cache->last_exact;
+  const char *blendfile_path = BKE_main_blendfile_path_from_global();
 
-  if (!G.relbase_valid) {
+  if (blendfile_path[0] == '\0') {
     cache->flag &= ~PTCACHE_DISK_CACHE;
     if (G.debug & G_DEBUG) {
       printf("File must be saved before using disk cache!\n");
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h
index 9bc3714ff38..57b1199a870 100644
--- a/source/blender/blenloader/BLO_writefile.h
+++ b/source/blender/blenloader/BLO_writefile.h
@@ -60,6 +60,11 @@ struct BlendFileWriteParams {
   uint use_save_versions : 1;
   /** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */
   uint use_save_as_copy : 1;
+  /**
+   * Saving from the UI writes into the #Main.filepath, so a check for the `filepath`
+   * not having been set is needed.
+   */
+  uint use_save_first_time : 1;
   uint use_userdef : 1;
   const struct BlendThumbnail *thumb;
 };
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 45258a50961..3709ff4db5f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1326,6 +1326,8 @@ bool BLO_write_file(Main *mainvar,
   const bool use_save_as_copy = params->use_save_as_copy;
   const bool use_userdef = params->use_userdef;
   const BlendThumbnail *thumb = params->thumb;
+  const bool relbase_valid = (mainvar->filepath[0] != '\0') &&
+                             (params->use_save_first_time == false);
 
   /* path backup/restore */
   void *path_list_backup = NULL;
@@ -1353,9 +1355,8 @@ bool BLO_write_file(Main *mainvar,
   if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) {
 
     if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) {
-      /* Make all relative as none of the existing paths can be relative in an unsaved document.
-       */
-      if (G.relbase_valid == false) {
+      /* Make all relative as none of the existing paths can be relative in an unsaved document. */
+      if (relbase_valid == false) {
         remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE_ALL;
       }
     }
@@ -1371,13 +1372,13 @@ bool BLO_write_file(Main *mainvar,
 
     /* Only for relative, not relative-all, as this means making existing paths relative. */
     if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) {
-      if (G.relbase_valid && (BLI_path_cmp(dir_dst, dir_src) == 0)) {
+      if (relbase_valid && (BLI_path_cmp(dir_dst, dir_src) == 0)) {
         /* Saved to same path. Nothing to do. */
         remap_mode = BLO_WRITE_PATH_REMAP_NONE;
       }
     }
     else if (remap_mode == BLO_WRITE_PATH_REMAP_ABSOLUTE) {
-      if (G.relbase_valid == false) {
+      if (relbase_valid == false) {
         /* Unsaved, all paths are absolute.Even if the user manages to set a relative path,
          * there is no base-path that can be used to make it absolute. */
         remap_mode = BLO_WRITE_PATH_REMAP_NONE;
diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c
index 5c4ba67d72a..b26291c4d1b 100644
--- a/source/blender/editors/screen/screendump.c
+++ b/source/blender/editors/screen/screendump.c
@@ -180,8 +180,9 @@ static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
     /* extension is added by 'screenshot_check' after */
     char filepath[FILE_MAX] = "//screen";
-    if (G.relbase_valid) {
-      BLI_strncpy(filepath, BKE_main_blendfile_path_from_global(), sizeof(filepath));
+    const char *blendfile_path = BKE_main_blendfile_path_from_global();
+    if (blendfile_path[0] != '\0') {
+      BLI_strncpy(filepath, blendfile_path, sizeof(filepath));
       BLI_path_extension_replace(filepath, sizeof(filepath), ""); /* strip '.blend' */
     }
     RNA_string_set(op->ptr, "filepath", filepath);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 76a0e4f42e7..8178e54e023 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2463,9 +2463,10 @@ static void file_expand_directory(bContext *C)
   if (params) {
     if (BLI_path_is_rel(params->dir)) {
       /* Use of 'default' folder here is just to avoid an error message on '//' prefix. */
+      const char *blendfile_path = BKE_main_blendfile_path(bmain);
       BLI_path_abs(params->dir,
-                   G.relbase_valid ? BKE_main_blendfile_path(bmain) :
-                                     BKE_appdir_folder_default_or_root());
+                   (blendfile_path[0] != '\0') ? blendfile_path :
+                                                 BKE_appdir_folder_default_or_root());
     }
     else if (params->dir[0] == '~') {
       char tmpstr[sizeof(params->dir) - 1];
diff --g

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list