diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-10 07:09:42 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-10 07:13:07 +0300 |
commit | ef3c49de8186278d57d0319ab4bf4fe923b7016d (patch) | |
tree | 0ab65b060c37704e067c4a2eb7bf4489e9d8792d /source/blender/windowmanager | |
parent | 099ae99589bf21e03bbf380613438114953dd8ea (diff) |
Cleanup: early return when directories can't be found
Also reduce variable scope and assert when an invalid argument
is passed to BKE_appdir_folder_id_create.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 16 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_platform_support.c | 44 |
2 files changed, 29 insertions, 31 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 186edfe68d6..6d2248ba354 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1397,29 +1397,27 @@ void wm_homefile_read_post(struct bContext *C, void wm_history_file_read(void) { - char name[FILE_MAX]; - LinkNode *l, *lines; - struct RecentFile *recent; - const char *line; - int num; const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); - if (!cfgdir) { return; } + char name[FILE_MAX]; + LinkNode *l; + int num; + BLI_join_dirfile(name, sizeof(name), cfgdir, BLENDER_HISTORY_FILE); - lines = BLI_file_read_as_lines(name); + LinkNode *lines = BLI_file_read_as_lines(name); wm_history_files_free(); /* read list of recent opened files from recent-files.txt to memory */ for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) { - line = l->link; + const char *line = l->link; /* don't check if files exist, causes slow startup for remote/external drives */ if (line[0]) { - recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); + struct RecentFile *recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); BLI_addtail(&(G.recent_files), recent); recent->filepath = BLI_strdup(line); num++; diff --git a/source/blender/windowmanager/intern/wm_platform_support.c b/source/blender/windowmanager/intern/wm_platform_support.c index becc2d896d0..a0519506d29 100644 --- a/source/blender/windowmanager/intern/wm_platform_support.c +++ b/source/blender/windowmanager/intern/wm_platform_support.c @@ -32,35 +32,35 @@ */ static bool wm_platform_support_check_approval(const char *platform_support_key, bool update) { - const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); - bool result = false; - if (G.factory_startup) { - return result; + return false; + } + const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); + if (!cfgdir) { + return false; } - if (cfgdir) { - char filepath[FILE_MAX]; - BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE); - LinkNode *lines = BLI_file_read_as_lines(filepath); - for (LinkNode *line_node = lines; line_node; line_node = line_node->next) { - char *line = line_node->link; - if (STREQ(line, platform_support_key)) { - result = true; - break; - } + bool result = false; + char filepath[FILE_MAX]; + BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE); + LinkNode *lines = BLI_file_read_as_lines(filepath); + for (LinkNode *line_node = lines; line_node; line_node = line_node->next) { + char *line = line_node->link; + if (STREQ(line, platform_support_key)) { + result = true; + break; } + } - if (!result && update) { - FILE *fp = BLI_fopen(filepath, "a"); - if (fp) { - fprintf(fp, "%s\n", platform_support_key); - fclose(fp); - } + if (!result && update) { + FILE *fp = BLI_fopen(filepath, "a"); + if (fp) { + fprintf(fp, "%s\n", platform_support_key); + fclose(fp); } - - BLI_file_free_lines(lines); } + + BLI_file_free_lines(lines); return result; } |