[Bf-blender-cvs] [05f821b094b] master: Cleanup: remove unnecessary use of BLI_make_file_string

Campbell Barton noreply at git.blender.org
Fri Sep 9 14:48:38 CEST 2022


Commit: 05f821b094b44ef588d4c678193f76ae2ee1797d
Author: Campbell Barton
Date:   Fri Sep 9 22:38:57 2022 +1000
Branches: master
https://developer.blender.org/rB05f821b094b44ef588d4c678193f76ae2ee1797d

Cleanup: remove unnecessary use of BLI_make_file_string

Use BLI_join_dirfile instead, also reduce right-shift.

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

M	source/blender/editors/render/render_preview.cc
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc
index 7d1ac079d08..aa05b2ff198 100644
--- a/source/blender/editors/render/render_preview.cc
+++ b/source/blender/editors/render/render_preview.cc
@@ -1304,41 +1304,33 @@ static void shader_preview_free(void *customdata)
 
 static ImBuf *icon_preview_imbuf_from_brush(Brush *brush)
 {
-  static const int flags = IB_rect | IB_multilayer | IB_metadata;
+  if (!brush->icon_imbuf && (brush->flag & BRUSH_CUSTOM_ICON) && brush->icon_filepath[0]) {
+    const int flags = IB_rect | IB_multilayer | IB_metadata;
 
-  char filepath[FILE_MAX];
-  const char *folder;
+    /* First use the path directly to try and load the file. */
+    char filepath[FILE_MAX];
 
-  if (!(brush->icon_imbuf)) {
-    if (brush->flag & BRUSH_CUSTOM_ICON) {
+    BLI_strncpy(filepath, brush->icon_filepath, sizeof(brush->icon_filepath));
+    BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&brush->id));
 
-      if (brush->icon_filepath[0]) {
-        /* First use the path directly to try and load the file. */
+    /* Use default color-spaces for brushes. */
+    brush->icon_imbuf = IMB_loadiffname(filepath, flags, nullptr);
 
-        BLI_strncpy(filepath, brush->icon_filepath, sizeof(brush->icon_filepath));
-        BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&brush->id));
+    /* Otherwise lets try to find it in other directories. */
+    if (!(brush->icon_imbuf)) {
+      const char *brushicons_dir = BKE_appdir_folder_id(BLENDER_DATAFILES, "brushicons");
+      /* Expected to be found, but don't crash if it's not. */
+      if (brushicons_dir) {
+        BLI_join_dirfile(filepath, sizeof(filepath), brushicons_dir, brush->icon_filepath);
 
-        /* Use default color-spaces for brushes. */
+        /* Use default color spaces. */
         brush->icon_imbuf = IMB_loadiffname(filepath, flags, nullptr);
-
-        /* otherwise lets try to find it in other directories */
-        if (!(brush->icon_imbuf)) {
-          folder = BKE_appdir_folder_id(BLENDER_DATAFILES, "brushicons");
-
-          BLI_make_file_string(
-              BKE_main_blendfile_path_from_global(), filepath, folder, brush->icon_filepath);
-
-          if (filepath[0]) {
-            /* Use default color spaces. */
-            brush->icon_imbuf = IMB_loadiffname(filepath, flags, nullptr);
-          }
-        }
-
-        if (brush->icon_imbuf) {
-          BKE_icon_changed(BKE_icon_id_ensure(&brush->id));
-        }
       }
     }
+
+    if (brush->icon_imbuf) {
+      BKE_icon_changed(BKE_icon_id_ensure(&brush->id));
+    }
   }
 
   if (!(brush->icon_imbuf)) {
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 13c1579d24b..38747bd706c 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1899,7 +1899,7 @@ static bool wm_file_write(bContext *C,
 /** \name Auto-Save API
  * \{ */
 
-static void wm_autosave_location(char *filepath)
+static void wm_autosave_location(char filepath[FILE_MAX])
 {
   const int pid = abs(getpid());
   char path[1024];
@@ -1918,23 +1918,23 @@ static void wm_autosave_location(char *filepath)
     BLI_snprintf(path, sizeof(path), "%d_autosave.blend", pid);
   }
 
+  const char *tempdir_base = BKE_tempdir_base();
 #ifdef WIN32
-  /* XXX Need to investigate how to handle default location of '/tmp/'
-   * This is a relative directory on Windows, and it may be
-   * found. Example:
-   * Blender installed on D:\ drive, D:\ drive has D:\tmp\
-   * Now, BLI_exists() will find '/tmp/' exists, but
-   * BLI_make_file_string will create string that has it most likely on C:\
-   * through BLI_windows_get_default_root_dir().
-   * If there is no C:\tmp autosave fails. */
-  if (!BLI_exists(BKE_tempdir_base())) {
+  /* XXX Need to investigate how to handle default location of `/tmp/`
+   * This is a relative directory on Windows, and it may be found. Example:
+   * Blender installed on `D:\` drive, `D:\` drive has `D:\tmp\` Now, `BLI_exists()`
+   * will find `/tmp/` exists, but #BLI_make_file_string will create string
+   * that has it most likely on `C:\` through #BLI_windows_get_default_root_dir.
+   * If there is no `C:\tmp` autosave fails. */
+  if (!BLI_exists(tempdir_base)) {
     const char *savedir = BKE_appdir_folder_id_create(BLENDER_USER_AUTOSAVE, NULL);
-    BLI_make_file_string("/", filepath, savedir, path);
-    return;
+    if (savedir) {
+      tempdir_base = savedir;
+    }
   }
 #endif
 
-  BLI_join_dirfile(filepath, FILE_MAX, BKE_tempdir_base(), path);
+  BLI_join_dirfile(filepath, FILE_MAX, tempdir_base, path);
 }
 
 static void wm_autosave_write(Main *bmain, wmWindowManager *wm)



More information about the Bf-blender-cvs mailing list