factory.c: remove static selected_file[] string buffer
This commit is contained in:
parent
05175292a6
commit
b5d61472e5
@ -2685,7 +2685,7 @@ void Reload_scripts_list(void)
|
|||||||
|
|
||||||
void Button_Brush_Factory(void)
|
void Button_Brush_Factory(void)
|
||||||
{
|
{
|
||||||
static char selected_file[MAX_PATH_CHARACTERS]="";
|
static char * selected_file = NULL; // currently selected file in factory file selector
|
||||||
|
|
||||||
short clicked_button;
|
short clicked_button;
|
||||||
T_List_button* scriptlist;
|
T_List_button* scriptlist;
|
||||||
@ -2728,11 +2728,12 @@ void Button_Brush_Factory(void)
|
|||||||
|
|
||||||
Window_redraw_list(scriptlist);
|
Window_redraw_list(scriptlist);
|
||||||
// Display current path:
|
// Display current path:
|
||||||
q = strlen(Config.Scripts_directory);
|
q = Config.Scripts_directory == NULL ? 0 : strlen(Config.Scripts_directory);
|
||||||
if (q<=DESC_WIDTH)
|
if (q<=DESC_WIDTH)
|
||||||
{
|
{
|
||||||
|
if (q > 0)
|
||||||
strcpy(displayed_path, Config.Scripts_directory);
|
strcpy(displayed_path, Config.Scripts_directory);
|
||||||
for (; q<DESC_WIDTH; q++)
|
for (; q < DESC_WIDTH; q++)
|
||||||
displayed_path[q]=' ';
|
displayed_path[q]=' ';
|
||||||
displayed_path[q]='\0';
|
displayed_path[q]='\0';
|
||||||
}
|
}
|
||||||
@ -2819,7 +2820,8 @@ void Button_Brush_Factory(void)
|
|||||||
|
|
||||||
if (item->Type == FSOBJECT_FILE)
|
if (item->Type == FSOBJECT_FILE)
|
||||||
{
|
{
|
||||||
strcpy(selected_file, item->Full_name);
|
free(selected_file);
|
||||||
|
selected_file = strdup(item->Full_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (item->Type == FSOBJECT_DIR || item->Type == FSOBJECT_DRIVE)
|
else if (item->Type == FSOBJECT_DIR || item->Type == FSOBJECT_DRIVE)
|
||||||
@ -2827,7 +2829,8 @@ void Button_Brush_Factory(void)
|
|||||||
if (item->Type == FSOBJECT_DRIVE)
|
if (item->Type == FSOBJECT_DRIVE)
|
||||||
{
|
{
|
||||||
// Selecting one drive root
|
// Selecting one drive root
|
||||||
strcpy(selected_file, PARENT_DIR);
|
free(selected_file);
|
||||||
|
selected_file = strdup(PARENT_DIR);
|
||||||
free(Config.Scripts_directory);
|
free(Config.Scripts_directory);
|
||||||
Config.Scripts_directory = strdup(item->Full_name);
|
Config.Scripts_directory = strdup(item->Full_name);
|
||||||
}
|
}
|
||||||
@ -2835,7 +2838,26 @@ void Button_Brush_Factory(void)
|
|||||||
{
|
{
|
||||||
// Going down one or up by one directory
|
// Going down one or up by one directory
|
||||||
if (strcmp(item->Full_name, PARENT_DIR) == 0)
|
if (strcmp(item->Full_name, PARENT_DIR) == 0)
|
||||||
Append_path(Config.Scripts_directory, item->Full_name, selected_file);
|
{
|
||||||
|
char * separator_pos = Find_last_separator(Config.Scripts_directory);
|
||||||
|
if (separator_pos != NULL && separator_pos[1] == '\0')
|
||||||
|
{
|
||||||
|
// remove trailing separator
|
||||||
|
separator_pos[0] = '\0';
|
||||||
|
separator_pos = Find_last_separator(Config.Scripts_directory);
|
||||||
|
}
|
||||||
|
free(selected_file);
|
||||||
|
if (separator_pos == NULL)
|
||||||
|
{
|
||||||
|
selected_file = Config.Scripts_directory; // steal heap buffer
|
||||||
|
Config.Scripts_directory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selected_file = strdup(separator_pos + 1);
|
||||||
|
separator_pos[0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char * new_dir = Filepath_append_to_dir(Config.Scripts_directory, item->Full_name);
|
char * new_dir = Filepath_append_to_dir(Config.Scripts_directory, item->Full_name);
|
||||||
@ -2861,7 +2883,7 @@ void Button_Brush_Factory(void)
|
|||||||
Close_window();
|
Close_window();
|
||||||
Unselect_button(BUTTON_BRUSH_EFFECTS);
|
Unselect_button(BUTTON_BRUSH_EFFECTS);
|
||||||
|
|
||||||
if (clicked_button == 5) // Run the script
|
if (clicked_button == 5 && selected_file != NULL) // Run the script
|
||||||
{
|
{
|
||||||
Run_script(Config.Scripts_directory, selected_file);
|
Run_script(Config.Scripts_directory, selected_file);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1462,6 +1462,8 @@ short Find_file_in_fileselector(T_Fileselector *list, const char * fname)
|
|||||||
short index;
|
short index;
|
||||||
short close_match = -1;
|
short close_match = -1;
|
||||||
|
|
||||||
|
if (fname == NULL)
|
||||||
|
return -1;
|
||||||
index=0;
|
index=0;
|
||||||
for (item=list->First; item!=NULL; item=item->Next)
|
for (item=list->First; item!=NULL; item=item->Next)
|
||||||
{
|
{
|
||||||
|
|||||||
5
src/io.c
5
src/io.c
@ -262,6 +262,9 @@ int Write_dword_be(FILE *file, dword dw)
|
|||||||
char * Find_last_separator(const char * str)
|
char * Find_last_separator(const char * str)
|
||||||
{
|
{
|
||||||
const char * position = NULL;
|
const char * position = NULL;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
for (; *str != '\0'; str++)
|
for (; *str != '\0'; str++)
|
||||||
if (*str == PATH_SEPARATOR[0]
|
if (*str == PATH_SEPARATOR[0]
|
||||||
#if defined(__WIN32__) || defined(WIN32)
|
#if defined(__WIN32__) || defined(WIN32)
|
||||||
@ -292,7 +295,7 @@ word * Find_last_separator_unicode(const word * str)
|
|||||||
char * Filepath_append_to_dir(const char * dir, const char * filename)
|
char * Filepath_append_to_dir(const char * dir, const char * filename)
|
||||||
{
|
{
|
||||||
char * path;
|
char * path;
|
||||||
size_t len = strlen(dir);
|
size_t len = dir == NULL ? 0 : strlen(dir);
|
||||||
if (len == 0) // no directory
|
if (len == 0) // no directory
|
||||||
return strdup(filename);
|
return strdup(filename);
|
||||||
if (dir[len-1] == PATH_SEPARATOR[0]
|
if (dir[len-1] == PATH_SEPARATOR[0]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user