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.
This commit is contained in:
@@ -734,6 +734,7 @@ const char *BKE_appdir_folder_id_create(const int folder_id, const char *subfold
|
||||
BLENDER_USER_CONFIG,
|
||||
BLENDER_USER_SCRIPTS,
|
||||
BLENDER_USER_AUTOSAVE)) {
|
||||
BLI_assert_unreachable();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1166,19 +1166,21 @@ static void studiolight_add_files_from_datafolder(const int folder_id,
|
||||
const char *subfolder,
|
||||
int flag)
|
||||
{
|
||||
struct direntry *dirs;
|
||||
const char *folder = BKE_appdir_folder_id(folder_id, subfolder);
|
||||
if (folder) {
|
||||
const uint dirs_num = BLI_filelist_dir_contents(folder, &dirs);
|
||||
int i;
|
||||
for (i = 0; i < dirs_num; i++) {
|
||||
if (dirs[i].type & S_IFREG) {
|
||||
studiolight_add_file(dirs[i].path, flag);
|
||||
}
|
||||
}
|
||||
BLI_filelist_free(dirs, dirs_num);
|
||||
dirs = NULL;
|
||||
if (!folder) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct direntry *dirs;
|
||||
const uint dirs_num = BLI_filelist_dir_contents(folder, &dirs);
|
||||
int i;
|
||||
for (i = 0; i < dirs_num; i++) {
|
||||
if (dirs[i].type & S_IFREG) {
|
||||
studiolight_add_file(dirs[i].path, flag);
|
||||
}
|
||||
}
|
||||
BLI_filelist_free(dirs, dirs_num);
|
||||
dirs = NULL;
|
||||
}
|
||||
|
||||
static int studiolight_flag_cmp_order(const StudioLight *sl)
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_file_free_lines(lines);
|
||||
}
|
||||
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user