forked from bartvdbraak/blender
default blend file name setting (untitled.blend) length check wasn't correct, move to generic function BLI_ensure_filename().
This commit is contained in:
parent
dea537fd68
commit
bd2f6c5907
@ -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_testextensie_glob(const char *str, const char *ext_fnmatch);
|
||||||
bool BLI_replace_extension(char *path, size_t maxlen, const char *ext);
|
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_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);
|
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),
|
bool BLI_uniquename_cb(bool (*unique_check)(void *arg, const char *name),
|
||||||
void *arg, const char * defname, char delim, char *name, short name_len);
|
void *arg, const char * defname, char delim, char *name, short name_len);
|
||||||
|
@ -1641,6 +1641,16 @@ bool BLI_ensure_extension(char *path, size_t maxlen, const char *ext)
|
|||||||
return true;
|
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"
|
/* Converts "/foo/bar.txt" to "/foo/" and "bar.txt"
|
||||||
* - wont change 'string'
|
* - wont change 'string'
|
||||||
* - wont create any directories
|
* - wont create any directories
|
||||||
|
@ -2419,15 +2419,10 @@ static void WM_OT_recover_auto_save(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* *************** save file as **************** */
|
/* *************** 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) {
|
if (G.save_over == false) {
|
||||||
char *c = (char *)BLI_last_slash(filepath);
|
BLI_ensure_filename(filepath, FILE_MAX, "untitled.blend");
|
||||||
|
|
||||||
if (c)
|
|
||||||
strcpy(&c[1], "untitled.blend");
|
|
||||||
else
|
|
||||||
strcpy(filepath, "untitled.blend");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2455,7 +2450,7 @@ static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent
|
|||||||
else
|
else
|
||||||
BLI_strncpy(name, G.main->name, FILE_MAX);
|
BLI_strncpy(name, G.main->name, FILE_MAX);
|
||||||
|
|
||||||
untitled(name);
|
wm_filepath_default(name);
|
||||||
RNA_string_set(op->ptr, "filepath", name);
|
RNA_string_set(op->ptr, "filepath", name);
|
||||||
|
|
||||||
WM_event_add_fileselect(C, op);
|
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);
|
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);
|
RNA_string_get(op->ptr, "filepath", path);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
BLI_strncpy(path, G.main->name, FILE_MAX);
|
BLI_strncpy(path, G.main->name, FILE_MAX);
|
||||||
untitled(path);
|
wm_filepath_default(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileflags = G.fileflags & ~G_FILE_USERPREFS;
|
fileflags = G.fileflags & ~G_FILE_USERPREFS;
|
||||||
@ -2566,7 +2562,7 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U
|
|||||||
else
|
else
|
||||||
BLI_strncpy(name, G.main->name, FILE_MAX);
|
BLI_strncpy(name, G.main->name, FILE_MAX);
|
||||||
|
|
||||||
untitled(name);
|
wm_filepath_default(name);
|
||||||
|
|
||||||
RNA_string_set(op->ptr, "filepath", name);
|
RNA_string_set(op->ptr, "filepath", name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user