From 9ee8319cd589bd7605f45293b17a682c4daf5ec0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 19 Oct 2017 23:57:03 +1100 Subject: Exit with invalid command line arguments Loading blender with an unknown name would interpret it as a blend file. This meant passing `--arg` arguments would end up creating new blend files which could be confusing if you made a typo on a command line argument. Now check the string has a blend file extension, exiting if it doesn't. --- source/creator/creator_args.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'source/creator') diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 21d03cc8265..322b93f4f42 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -44,6 +44,8 @@ #include "BLI_fileops.h" #include "BLI_mempool.h" +#include "BLO_readfile.h" /* only for BLO_has_bfile_extension */ + #include "BKE_blender_version.h" #include "BKE_context.h" @@ -1764,11 +1766,17 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data) return -1; } - /* Just pretend a file was loaded, so the user can press Save and it'll save at the filename from the CLI. */ - BLI_strncpy(G.main->name, filename, FILE_MAX); - G.relbase_valid = true; - G.save_over = true; - printf("... opened default scene instead; saving will write to %s\n", filename); + if (BLO_has_bfile_extension(filename)) { + /* Just pretend a file was loaded, so the user can press Save and it'll save at the filename from the CLI. */ + BLI_strncpy(G.main->name, filename, FILE_MAX); + G.relbase_valid = true; + G.save_over = true; + printf("... opened default scene instead; saving will write to: %s\n", filename); + } + else { + printf("Error: argument has no '.blend' file extension, not using as new file, exiting! %s\n", filename); + exit(1); + } } G.file_loaded = 1; -- cgit v1.2.3 From 465b6333ccb5b56ced54ca342c60086c60ab21db Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 20 Oct 2017 00:19:58 +1100 Subject: Correct last commit, use WM_exit Without this temp directory isn't removed. --- source/creator/creator_args.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/creator') diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 322b93f4f42..19f30584f89 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -1775,7 +1775,8 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data) } else { printf("Error: argument has no '.blend' file extension, not using as new file, exiting! %s\n", filename); - exit(1); + G.is_break = true; + WM_exit(C); } } -- cgit v1.2.3