2008-08-07 14:26:07 +02:00
|
|
|
/*
|
|
|
|
* history.c
|
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* Generic ROM history list managment
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* code by Martin Disibio (6/17/08)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
#include "history.h"
|
|
|
|
|
|
|
|
t_history history;
|
|
|
|
|
|
|
|
void history_save()
|
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
char pathname[MAXPATHLEN];
|
|
|
|
|
|
|
|
if (!fat_enabled) return;
|
2008-10-12 21:56:35 +02:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* first check if directory exist */
|
2008-12-10 19:16:30 +01:00
|
|
|
sprintf (pathname, DEFAULT_PATH);
|
|
|
|
DIR_ITER *dir = diropen(pathname);
|
|
|
|
if (dir == NULL) mkdir(pathname,S_IRWXU);
|
2008-08-07 14:26:07 +02:00
|
|
|
else dirclose(dir);
|
|
|
|
|
|
|
|
/* open file for writing */
|
2008-12-10 19:16:30 +01:00
|
|
|
sprintf (pathname, "%s/history.ini", pathname);
|
|
|
|
FILE *fp = fopen(pathname, "wb");
|
2008-08-07 14:26:07 +02:00
|
|
|
if (fp == NULL) return;
|
|
|
|
|
|
|
|
/* save options */
|
|
|
|
fwrite(&history, sizeof(history), 1, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* history_add_file
|
|
|
|
*
|
|
|
|
* Adds the given file path to the top of the history list, shifting each
|
|
|
|
* existing entry in the history down one place. If given file path is
|
|
|
|
* already in the list then the existing entry is (in effect) moved to the
|
|
|
|
* top instead.
|
|
|
|
****************************************************************************/
|
|
|
|
void history_add_file(char *filepath, char *filename)
|
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
/* Create the new entry for this path. */
|
|
|
|
t_history_entry newentry;
|
|
|
|
strncpy(newentry.filepath, filepath, MAXJOLIET - 1);
|
|
|
|
strncpy(newentry.filename, filename, MAXJOLIET - 1);
|
|
|
|
newentry.filepath[MAXJOLIET - 1] = '\0';
|
|
|
|
newentry.filename[MAXJOLIET - 1] = '\0';
|
|
|
|
|
|
|
|
t_history_entry oldentry; /* Old entry is the one being shuffled down a spot. */
|
|
|
|
t_history_entry currentry; /* Curr entry is the one that just replaced old path. */
|
|
|
|
|
|
|
|
/* Initially set curr entry to the new value. */
|
|
|
|
memcpy(¤try, &newentry, sizeof(t_history_entry));
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i=0; i < NUM_HISTORY_ENTRIES; i++)
|
|
|
|
{
|
|
|
|
/* Save off the next entry. */
|
|
|
|
memcpy(&oldentry, &history.entries[i], sizeof(t_history_entry));
|
|
|
|
|
|
|
|
/* Overwrite with the previous entry. */
|
|
|
|
memcpy(&history.entries[i], ¤try, sizeof(t_history_entry));
|
|
|
|
|
|
|
|
/* Switch the old entry to the curr entry now. */
|
|
|
|
memcpy(¤try, &oldentry, sizeof(t_history_entry));
|
|
|
|
|
|
|
|
/* If the entry in the list at this spot matches
|
|
|
|
the new entry then do nothing and let this
|
|
|
|
entry get deleted. */
|
|
|
|
if(strcmp(newentry.filepath, currentry.filepath) == 0 && strcmp(newentry.filename, currentry.filename) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now save to disk */
|
|
|
|
history_save();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void history_load()
|
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
char pathname[MAXPATHLEN];
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* open file for reading */
|
2008-12-10 19:16:30 +01:00
|
|
|
sprintf (pathname, "%s/history.ini", DEFAULT_PATH);
|
|
|
|
FILE *fp = fopen(pathname, "rb");
|
2008-08-07 14:26:07 +02:00
|
|
|
if (fp == NULL) return;
|
|
|
|
|
|
|
|
/* read file */
|
|
|
|
fread(&history, sizeof(history), 1, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2009-04-15 17:33:51 +02:00
|
|
|
void history_setDefault(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
int i;
|
|
|
|
for(i=0; i < NUM_HISTORY_ENTRIES; i++)
|
|
|
|
{
|
|
|
|
memset(&history.entries[i], 0, sizeof(t_history_entry));
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|