Fix filebackup when saving.
It was the wrong filename that was backuped when using "Save As". Now it is the filename selected.
This commit is contained in:
parent
187c7d53e3
commit
c8bc04e413
@ -3415,25 +3415,24 @@ void Button_Reload(int btn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Backup_filename(const char * fname, char * backup_name)
|
static void Backup_existing_file(const char * filename)
|
||||||
{
|
{
|
||||||
|
char new_filename[MAX_PATH_CHARACTERS]; // full filename of the backup file
|
||||||
|
char * p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
strcpy(backup_name,fname);
|
strncpy(new_filename, filename, sizeof(new_filename));
|
||||||
for (i=strlen(fname)-strlen(Main.backups->Pages->Filename); backup_name[i]!='.' && backup_name[i]!='\0'; i++);
|
new_filename[sizeof(new_filename) - 1] = '\0';
|
||||||
backup_name[i+1]='\0';
|
p = Find_last_separator(new_filename); // pointer to the filename part (after directory)
|
||||||
strcat(backup_name,"BAK");
|
if (p == NULL)
|
||||||
}
|
p = new_filename;
|
||||||
|
else
|
||||||
|
p++;
|
||||||
static void Backup_existing_file(void)
|
i = Position_last_dot(p);
|
||||||
{
|
if (i >= 0)
|
||||||
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
|
strcpy(p + i + 1, "BAK");
|
||||||
char new_filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier backup
|
else
|
||||||
|
strcat(p, ".BAK");
|
||||||
Get_full_filename(filename, Main.backups->Pages->Filename, Main.backups->Pages->File_directory);
|
|
||||||
// Calcul du nom complet du fichier backup
|
|
||||||
Backup_filename(filename,new_filename);
|
|
||||||
|
|
||||||
File_error=0;
|
File_error=0;
|
||||||
|
|
||||||
@ -3512,7 +3511,9 @@ void Save_picture(enum CONTEXT_TYPE type)
|
|||||||
confirm=Confirmation_box("Erase old file ?");
|
confirm=Confirmation_box("Erase old file ?");
|
||||||
if (confirm && (Config.Backup))
|
if (confirm && (Config.Backup))
|
||||||
{
|
{
|
||||||
Backup_existing_file();
|
char full_filename[MAX_PATH_CHARACTERS];
|
||||||
|
Get_full_filename(full_filename, filename, directory);
|
||||||
|
Backup_existing_file(full_filename);
|
||||||
if (File_error)
|
if (File_error)
|
||||||
{
|
{
|
||||||
confirm=0;
|
confirm=0;
|
||||||
@ -3578,7 +3579,7 @@ void Button_Autosave(int btn)
|
|||||||
if ( (!file_already_exists) || Confirmation_box("Erase old file ?") )
|
if ( (!file_already_exists) || Confirmation_box("Erase old file ?") )
|
||||||
{
|
{
|
||||||
if ((file_already_exists) && (Config.Backup))
|
if ((file_already_exists) && (Config.Backup))
|
||||||
Backup_existing_file();
|
Backup_existing_file(filename);
|
||||||
else
|
else
|
||||||
File_error=0;
|
File_error=0;
|
||||||
|
|
||||||
|
|||||||
@ -226,28 +226,6 @@ void Free_fileselector_list(T_Fileselector *list)
|
|||||||
Recount_files(list);
|
Recount_files(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Position_last_dot(const char * fname)
|
|
||||||
{
|
|
||||||
int pos_last_dot = -1;
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
for (c = 0; fname[c]!='\0'; c++)
|
|
||||||
if (fname[c]=='.')
|
|
||||||
pos_last_dot = c;
|
|
||||||
return pos_last_dot;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int Position_last_dot_unicode(const word * fname)
|
|
||||||
{
|
|
||||||
int pos_last_dot = -1;
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
for (c = 0; fname[c]!='\0'; c++)
|
|
||||||
if (fname[c]=='.')
|
|
||||||
pos_last_dot = c;
|
|
||||||
return pos_last_dot;
|
|
||||||
}
|
|
||||||
|
|
||||||
word * Format_filename_unicode(const word * fname, word max_length, int type)
|
word * Format_filename_unicode(const word * fname, word max_length, int type)
|
||||||
{
|
{
|
||||||
static word result[40];
|
static word result[40];
|
||||||
|
|||||||
22
src/io.c
22
src/io.c
@ -292,6 +292,28 @@ void Append_path(char *path, const char *filename, char *reverse_path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Position_last_dot(const char * fname)
|
||||||
|
{
|
||||||
|
int pos_last_dot = -1;
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
for (c = 0; fname[c] != '\0'; c++)
|
||||||
|
if (fname[c] == '.')
|
||||||
|
pos_last_dot = c;
|
||||||
|
return pos_last_dot;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Position_last_dot_unicode(const word * fname)
|
||||||
|
{
|
||||||
|
int pos_last_dot = -1;
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
for (c = 0; fname[c] != '\0'; c++)
|
||||||
|
if (fname[c] == '.')
|
||||||
|
pos_last_dot = c;
|
||||||
|
return pos_last_dot;
|
||||||
|
}
|
||||||
|
|
||||||
int File_exists(const char * fname)
|
int File_exists(const char * fname)
|
||||||
// Détermine si un file passé en paramètre existe ou non dans le
|
// Détermine si un file passé en paramètre existe ou non dans le
|
||||||
// répertoire courant.
|
// répertoire courant.
|
||||||
|
|||||||
6
src/io.h
6
src/io.h
@ -83,6 +83,12 @@ char * Find_last_separator(const char * str);
|
|||||||
#define PATH_SEPARATOR "/"
|
#define PATH_SEPARATOR "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// finds the rightmost '.' character in fullname. Used to find file extension. returns -1 if not found
|
||||||
|
int Position_last_dot(const char * fname);
|
||||||
|
|
||||||
|
/// finds the rightmost '.' character in fullname. Used to find file extension. returns -1 if not found
|
||||||
|
int Position_last_dot_unicode(const word * fname);
|
||||||
|
|
||||||
/// Size of a file, in bytes. Returns 0 in case of error.
|
/// Size of a file, in bytes. Returns 0 in case of error.
|
||||||
unsigned long File_length(const char *fname);
|
unsigned long File_length(const char *fname);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user