Lua: now remembers which directory you last browsed when you quit. Fixed an issue where gfx2.ini isn't saved if there's a file gfx2.$$$ in same directory (Like after a crash)

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1763 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2011-04-03 14:43:16 +00:00
parent e10fe19ae6
commit f34417919f
6 changed files with 61 additions and 51 deletions

View File

@ -15,7 +15,7 @@ $(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h
input.h engine.h pages.h layers.h factory.h loadsave.h io.h
$(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h engine.h errors.h \
filesel.h loadsave.h global.h graph.h io.h misc.h pages.h readline.h \
sdlscreen.h windows.h palette.h input.h help.h
sdlscreen.h windows.h palette.h input.h help.h realpath.h
$(OBJDIR)/fileformats.o: fileformats.c errors.h global.h struct.h const.h \
loadsave.h misc.h io.h windows.h pages.h
$(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h io.h \
@ -82,7 +82,7 @@ $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h graph.
$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxwide2.h
$(OBJDIR)/readini.o: readini.c const.h errors.h global.h struct.h misc.h readini.h \
setup.h
setup.h realpath.h io.h
$(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \
sdlscreen.h readline.h windows.h input.h engine.h
$(OBJDIR)/realpath.o: realpath.c

View File

@ -1308,7 +1308,7 @@ void Draw_script_information(T_Fileselector_item * script_item, const char *full
// Blank the target area
Window_rectangle(7, FILESEL_Y + 89, DESC_WIDTH*6+2, 4*8, MC_Black);
if (script_item && script_item->Full_name && script_item->Full_name[0]!='\0')
if (script_item && script_item->Type==0 && script_item->Full_name && script_item->Full_name[0]!='\0')
{
char full_name[MAX_PATH_CHARACTERS];
strcpy(full_name, full_directory);
@ -1698,28 +1698,11 @@ void Set_script_shortcut(T_Fileselector_item * script_item, const char *full_dir
}
}
void Button_Brush_Factory(void)
void Reload_scripts_list(void)
{
static char selected_file[MAX_PATH_CHARACTERS]="";
static char sub_directory[MAX_PATH_CHARACTERS]="!";
short clicked_button;
T_List_button* scriptlist;
T_Scroller_button* scriptscroll;
T_Special_button* scriptarea;
T_Fileselector_item *item;
int last_selected_item=-1;
if (sub_directory[0]=='!')
{
// Default directory
Realpath(Data_directory, sub_directory);
Append_path(sub_directory, "scripts", NULL);
}
// Reinitialize the list
Free_fileselector_list(&Scripts_selector);
if (sub_directory[0]=='\0')
if (Config.Scripts_directory[0]=='\0')
{
Read_list_of_drives(&Scripts_selector,NAME_WIDTH+1);
}
@ -1727,11 +1710,25 @@ void Button_Brush_Factory(void)
{
Add_element_to_list(&Scripts_selector, PARENT_DIR, Format_filename(PARENT_DIR, NAME_WIDTH+1, 1), 1, ICON_NONE);
// Add each found file to the list
For_each_directory_entry(sub_directory, Add_script);
For_each_directory_entry(Config.Scripts_directory, Add_script);
}
// Sort it
Sort_list_of_files(&Scripts_selector);
Sort_list_of_files(&Scripts_selector);
//
}
void Button_Brush_Factory(void)
{
static char selected_file[MAX_PATH_CHARACTERS]="";
short clicked_button;
T_List_button* scriptlist;
T_Scroller_button* scriptscroll;
T_Special_button* scriptarea;
T_Fileselector_item *item;
int last_selected_item=-1;
Reload_scripts_list();
Open_window(33+8*NAME_WIDTH, 180, "Brush Factory");
@ -1760,7 +1757,7 @@ void Button_Brush_Factory(void)
Window_redraw_list(scriptlist);
Draw_script_information(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
scriptlist->List_start + scriptlist->Cursor_position), Config.Scripts_directory);
Update_window_area(0, 0, Window_width, Window_height);
Display_cursor();
@ -1776,7 +1773,7 @@ void Button_Brush_Factory(void)
do
{
clicked_button = Window_clicked_button();
if (Key==SDLK_BACKSPACE && sub_directory[0]!='\0')
if (Key==SDLK_BACKSPACE && Config.Scripts_directory[0]!='\0')
{
// Make it select first entry (parent directory)
scriptlist->List_start=0;
@ -1802,13 +1799,13 @@ void Button_Brush_Factory(void)
last_selected_item = scriptlist->List_start + scriptlist->Cursor_position;
Hide_cursor();
Draw_script_information(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
scriptlist->List_start + scriptlist->Cursor_position), Config.Scripts_directory);
Display_cursor();
break;
case 6:
Set_script_shortcut(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
scriptlist->List_start + scriptlist->Cursor_position), Config.Scripts_directory);
break;
default:
@ -1844,31 +1841,17 @@ void Button_Brush_Factory(void)
{
// Selecting one drive root
strcpy(selected_file, PARENT_DIR);
strcat(sub_directory, item->Full_name);
strcat(Config.Scripts_directory, item->Full_name);
}
else
{
// Going down one or up by one directory
Append_path(sub_directory, item->Full_name, selected_file);
Append_path(Config.Scripts_directory, item->Full_name, selected_file);
}
// No break: going back up to beginning of loop
// Reinitialize the list
Free_fileselector_list(&Scripts_selector);
if (sub_directory[0]=='\0')
{
Read_list_of_drives(&Scripts_selector,NAME_WIDTH+1);
}
else
{
Add_element_to_list(&Scripts_selector, PARENT_DIR, Format_filename(PARENT_DIR, NAME_WIDTH+1, 1), 1, ICON_NONE);
// Add each found file to the list
For_each_directory_entry(sub_directory, Add_script);
}
// Sort it
Sort_list_of_files(&Scripts_selector);
//
Reload_scripts_list();
scriptlist->Scroller->Nb_elements=Scripts_selector.Nb_elements;
Compute_slider_cursor_length(scriptlist->Scroller);
@ -1882,7 +1865,7 @@ void Button_Brush_Factory(void)
if (clicked_button == 5) // Run the script
{
Run_script(sub_directory, selected_file);
Run_script(Config.Scripts_directory, selected_file);
}
else
{

View File

@ -219,7 +219,11 @@ void Append_path(char *path, const char *filename, char *reverse_path)
// Remove trailing slash
len=strlen(path);
if (len && !strcmp(path+len-1,PATH_SEPARATOR))
if (len && (!strcmp(path+len-1,PATH_SEPARATOR)
#ifdef __WIN32__
|| path[len-1]=='/'
#endif
))
path[len-1]='\0';
slash_pos=Find_last_slash(path);
@ -249,7 +253,11 @@ void Append_path(char *path, const char *filename, char *reverse_path)
long len;
// Add trailing slash if needed
len=strlen(path);
if (len && strcmp(path+len-1,PATH_SEPARATOR))
if (len && (strcmp(path+len-1,PATH_SEPARATOR)
#ifdef __WIN32__
&& path[len-1]!='/'
#endif
))
{
strcpy(path+len, PATH_SEPARATOR);
len+=strlen(PATH_SEPARATOR);

View File

@ -34,6 +34,8 @@
#include "misc.h"
#include "readini.h"
#include "setup.h"
#include "realpath.h"
#include "io.h"
void Load_INI_clear_string(char * str, byte keep_comments)
{
@ -933,7 +935,18 @@ int Load_INI(T_Config * conf)
}
}
// Optional, Location of last directory used for Lua scripts browsing (>=2.3)
conf->Scripts_directory[0]='\0';
if (!Load_INI_get_string (file,buffer,"Scripts_directory",value_label, 1))
{
strcpy(conf->Scripts_directory,value_label);
}
if (conf->Scripts_directory[0]=='\0')
{
// Default when empty:
Realpath(Data_directory, conf->Scripts_directory);
Append_path(conf->Scripts_directory, "scripts", NULL);
}
// Insert new values here

View File

@ -419,7 +419,9 @@ int Save_INI(T_Config * conf)
strcpy(temp_filename,Config_directory);
strcat(temp_filename,INISAVE_FILENAME);
// On renome l'ancienne version du fichier INI vers un fichier temporaire:
// Delete gfx2.$$$
remove(temp_filename);
// Rename current config file as gfx2.$$$
if (rename(filename,temp_filename)!=0)
{
goto Erreur_ERREUR_SAUVEGARDE_INI;
@ -697,6 +699,9 @@ int Save_INI(T_Config * conf)
if ((return_code=Save_INI_set_values (old_file,new_file,buffer,"Swap_buttons",1,values,0)))
goto Erreur_Retour;
if ((return_code=Save_INI_set_strings (old_file,new_file,buffer,"Scripts_directory",conf->Scripts_directory)))
goto Erreur_Retour;
// Insert new values here
Save_INI_flush(old_file,new_file,buffer);

View File

@ -357,7 +357,7 @@ typedef struct
byte Screen_size_in_GIF; ///< Boolean, true to store current resolution in GIF files.
byte Auto_nb_used; ///< Boolean, true to count colors in Palette screen.
byte Default_resolution; ///< Default video mode to use on startup. Index in ::Video_mode.
char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full dierctory name.
char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full directory name.
char Bookmark_label[NB_BOOKMARKS][8+1];///< Bookmarked directories in fileselectors: This is the displayed name.
int Window_pos_x; ///< Last window x position (9999 if unsupportd/irrelevant for the platform)
int Window_pos_y; ///< Last window y position (9999 if unsupportd/irrelevant for the platform)
@ -368,6 +368,7 @@ typedef struct
byte Sync_views; ///< Boolean, true when the Main and Spare should share their viewport settings.
byte Stylus_mode; ///< Boolean, true to tweak some tools (eg:Curve) for single-button stylus.
word Swap_buttons; ///< Sets which key swaps mouse buttons : 0=none, or MOD_CTRL, or MOD_ALT.
char Scripts_directory[MAX_PATH_CHARACTERS];///< Full pathname of directory for Lua scripts
} T_Config;
// Structures utilisées pour les descriptions de pages et de liste de pages.