Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-29 09:34:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-29 09:34:58 +0400
commitbd2f6c590707f6677da5ad84d29c10029936f2cf (patch)
treeb54ea59a8252afca5436bbc68993fe44c619f253
parentdea537fd68e0b8c3b3e2fb377a9f4ee0ab897ece (diff)
default blend file name setting (untitled.blend) length check wasn't correct, move to generic function BLI_ensure_filename().
-rw-r--r--source/blender/blenlib/BLI_path_util.h1
-rw-r--r--source/blender/blenlib/intern/path_util.c10
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c20
3 files changed, 19 insertions, 12 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index cb812fe8595..113c511a4f7 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -122,6 +122,7 @@ bool BLI_testextensie_array(const char *str, const char **ext_array);
bool BLI_testextensie_glob(const char *str, const char *ext_fnmatch);
bool BLI_replace_extension(char *path, size_t maxlen, const char *ext);
bool BLI_ensure_extension(char *path, size_t maxlen, const char *ext);
+bool BLI_ensure_filename(char *filepath, size_t maxlen, const char *filename);
void BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, short name_offs, short len);
bool BLI_uniquename_cb(bool (*unique_check)(void *arg, const char *name),
void *arg, const char * defname, char delim, char *name, short name_len);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 4d6c9797ed1..bcdc226a2a7 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1641,6 +1641,16 @@ bool BLI_ensure_extension(char *path, size_t maxlen, const char *ext)
return true;
}
+bool BLI_ensure_filename(char *filepath, size_t maxlen, const char *filename)
+{
+ char *c = (char *)BLI_last_slash(filepath);
+ if (!c || ((c - filepath) < maxlen - (strlen(filename) + 1))) {
+ strcpy(c ? &c[1] : filepath, filename);
+ return true;
+ }
+ return false;
+}
+
/* Converts "/foo/bar.txt" to "/foo/" and "bar.txt"
* - wont change 'string'
* - wont create any directories
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index a68d6daa96f..fbb51702844 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2419,15 +2419,10 @@ static void WM_OT_recover_auto_save(wmOperatorType *ot)
/* *************** save file as **************** */
-static void untitled(char *filepath)
+static void wm_filepath_default(char *filepath)
{
- if (G.save_over == 0 && strlen(filepath) < FILE_MAX - 16) {
- char *c = (char *)BLI_last_slash(filepath);
-
- if (c)
- strcpy(&c[1], "untitled.blend");
- else
- strcpy(filepath, "untitled.blend");
+ if (G.save_over == false) {
+ BLI_ensure_filename(filepath, FILE_MAX, "untitled.blend");
}
}
@@ -2455,7 +2450,7 @@ static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent
else
BLI_strncpy(name, G.main->name, FILE_MAX);
- untitled(name);
+ wm_filepath_default(name);
RNA_string_set(op->ptr, "filepath", name);
WM_event_add_fileselect(C, op);
@@ -2471,11 +2466,12 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
save_set_compress(op);
- if (RNA_struct_property_is_set(op->ptr, "filepath"))
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
RNA_string_get(op->ptr, "filepath", path);
+ }
else {
BLI_strncpy(path, G.main->name, FILE_MAX);
- untitled(path);
+ wm_filepath_default(path);
}
fileflags = G.fileflags & ~G_FILE_USERPREFS;
@@ -2566,7 +2562,7 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U
else
BLI_strncpy(name, G.main->name, FILE_MAX);
- untitled(name);
+ wm_filepath_default(name);
RNA_string_set(op->ptr, "filepath", name);