Skip to content

Commit

Permalink
In the module metadata database, differentiate unread (files not scan…
Browse files Browse the repository at this point in the history
…ned) and files were the file content turned out to be unknown. This drastically speeds up the file browser, especially if there are archives present.

Also fix ALT-R to rescan the file immediately, not on file load.
  • Loading branch information
mywave82 committed Jan 7, 2024
1 parent 2a153f9 commit 8ef13d7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 27 deletions.
18 changes: 12 additions & 6 deletions boot/pmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,15 @@ static int init_modules(int argc, char *argv[])
cfSetProfileComment ("adplug", "retrowave", "; Device to use, e.g. /dev/ttyACM0 /dev/cuaU0 /dev/dtyU0 /dev/cu.usbmodem0000001 COM1");
}

if (epoch < 20230630)
if (epoch < 20240107)
{
cfSetProfileInt("version", "epoch", 20230630, 10);
fprintf(stderr, "ocp.ini update (0.2.107) add [fscolors] UNKN=7\n");
cfSetProfileInt ("fscolors", "UNKN", 7, 10);
}

if (epoch < 20240107)
{
cfSetProfileInt("version", "epoch", 20240107, 10);
cfStoreConfig();
if (isatty(2))
{
Expand All @@ -1017,15 +1023,15 @@ static int init_modules(int argc, char *argv[])
sleep(5);
}
}
if (cfGetProfileInt("version", "epoch", 0, 10) != 20230630)
if (cfGetProfileInt("version", "epoch", 0, 10) != 20240107)
{
if (isatty(2))
{
fprintf(stderr,"\n\033[1m\033[31mWARNING, ocp.ini [version] epoch != 20230630\033[0m\n\n");
fprintf(stderr,"\n\033[1m\033[31mWARNING, ocp.ini [version] epoch != 20240107\033[0m\n\n");
sleep(5);
} else {
fprintf(stderr,"\nWARNING, ocp.ini [version] epoch != 20230630\n\n");
fprintf(stderr,"\nWARNING, ocp.ini [version] epoch != 20240107\n\n");
}
sleep(5);
}

cfScreenSec=cfGetProfileString(cfConfigSec, "screensec", "screen");
Expand Down
6 changes: 4 additions & 2 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@

#undef HAVE_OV_PCM_SEEK

#undef DLLVERSION

/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

Expand Down Expand Up @@ -352,8 +350,12 @@
/* Using a native implementation of iconv in a separate library */
#undef USE_LIBICONV_NATIVE

#undef DLLVERSION
#undef PACKAGE_VERSION
#define VERSION PACKAGE_VERSION
#undef OCP_MAJOR_VERSION
#undef OCP_MINOR_VERSION
#undef OCP_PATCH_VERSION

#undef HAVE_LZW

Expand Down
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,12 @@ MINOR_VERSION=2

PATCH_VERSION=106

printf "%s\n" "#define OCP_MAJOR_VERSION 0" >>confdefs.h

printf "%s\n" "#define OCP_MINOR_VERSION 2" >>confdefs.h

printf "%s\n" "#define OCP_PATCH_VERSION 106" >>confdefs.h




Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ AC_DEFINE_UNQUOTED(DLLVERSION, `printf 0x%04x%02x%02x MAJOR_VERSION MINOR_VERSIO
AC_SUBST([MAJOR_VERSION], [MAJOR_VERSION])
AC_SUBST([MINOR_VERSION], [MINOR_VERSION])
AC_SUBST([PATCH_VERSION], [PATCH_VERSION])
AC_DEFINE([OCP_MAJOR_VERSION], [MAJOR_VERSION])
AC_DEFINE([OCP_MINOR_VERSION], [MINOR_VERSION])
AC_DEFINE([OCP_PATCH_VERSION], [PATCH_VERSION])

AC_CANONICAL_HOST

Expand Down
51 changes: 41 additions & 10 deletions filesel/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ struct modinfoentry
uint32_t style_ref; /* 40 */
uint32_t comment_ref; /* 44 */
uint32_t album_ref; /* 48 */
uint8_t reserved[12]; /* 52-63*/
uint8_t lastscanversion[3];/* 52-54*/
uint8_t reserved[8]; /* 55-63*/
} general;
struct __attribute__((packed))
{
Expand Down Expand Up @@ -149,7 +150,19 @@ int mdbInfoIsAvailable (uint32_t mdb_ref)
DEBUG_PRINT ("mdbInfoIsAvailable(0x%08"PRIx32") => 1 due to modtype != mtUnRead\n", mdb_ref);
}

return mdbData[mdb_ref].mie.general.modtype.integer.i != 0;
if (mdbData[mdb_ref].mie.general.modtype.integer.i == mtUnknown)
{ /* Avoid rescan, if file is already scanned by this version or newer */
if (mdbData[mdb_ref].mie.general.lastscanversion[0] < OCP_MAJOR_VERSION) return 0;
if (mdbData[mdb_ref].mie.general.lastscanversion[0] > OCP_MAJOR_VERSION) return 1;

if (mdbData[mdb_ref].mie.general.lastscanversion[1] < OCP_MINOR_VERSION) return 0;
if (mdbData[mdb_ref].mie.general.lastscanversion[1] > OCP_MINOR_VERSION) return 1;

if (mdbData[mdb_ref].mie.general.lastscanversion[2] < OCP_PATCH_VERSION) return 0;
return 1; /* >= is always true here */
}

return mdbData[mdb_ref].mie.general.modtype.integer.i != mtUnRead;
}

/* This thing will end up with a register of all valid pre-interprators for modules and friends
Expand Down Expand Up @@ -206,11 +219,16 @@ int mdbReadInfo (struct moduleinfostruct *m, struct ocpfilehandle_t *f)
maxl = f->read (f, mdbScanBuf, sizeof (mdbScanBuf));
f->seek_set (f, 0);

#ifdef MDB_DEBUG
{
const char *path;
dirdbGetName_internalstr (f->dirdb_ref, &path);
DEBUG_PRINT (" mdbReadInfo(%s %p %d)\n", path, mdbScanBuf, maxl);
char *fp = 0;
dirdbGetFullname_malloc (f->dirdb_ref, &fp, DIRDB_FULLNAME_DRIVE);
DEBUG_PRINT (" mdbReadInfo(%s %p %d) # %s\n", fp ? fp : "", mdbScanBuf, maxl);
free (fp);
}
#endif

m->modtype.integer.i = mtUnRead;

/* slow version that also allows more I/O */
for (rinfos=mdbReadInfos; rinfos; rinfos=rinfos->next)
Expand Down Expand Up @@ -251,7 +269,12 @@ int mdbReadInfo (struct moduleinfostruct *m, struct ocpfilehandle_t *f)
}
}

return m->modtype.integer.i != 0;
if (m->modtype.integer.i == mtUnRead)
{ /* If no file-detection worked out, mark the file as unknown, the mdbWriteModuleInfo will tag the version to disk */
m->modtype.integer.i = mtUnknown;
}

return m->modtype.integer.i != mtUnknown;
}

/* Unit test available */
Expand Down Expand Up @@ -457,6 +480,13 @@ int mdbWriteModuleInfo (uint32_t mdb_ref, struct moduleinfostruct *m)
temp = mdbData[mdb_ref].mie.general.comment_ref; retval |= mdbWriteString (m->comment, &temp); mdbData[mdb_ref].mie.general.comment_ref = temp;
temp = mdbData[mdb_ref].mie.general.album_ref; retval |= mdbWriteString (m->album, &temp); mdbData[mdb_ref].mie.general.album_ref = temp;

if (m->modtype.integer.i == mtUnknown)
{ /* tag the version number to disk */
mdbData[mdb_ref].mie.general.lastscanversion[0] = OCP_MAJOR_VERSION;
mdbData[mdb_ref].mie.general.lastscanversion[1] = OCP_MINOR_VERSION;
mdbData[mdb_ref].mie.general.lastscanversion[2] = OCP_PATCH_VERSION;
}

mdbDirty=1;
mdbDirtyMap[mdb_ref>>3] |= 1 << (mdb_ref & 0x07);

Expand Down Expand Up @@ -643,16 +673,15 @@ int mdbInit (const struct configAPI_t *configAPI)

for (i=0; i<mdbSearchIndexCount; i++)
{
DEBUG_PRINT("%5d => 0x%08"PRIx32" %"PRIu64" 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
DEBUG_PRINT("%5d => 0x%08"PRIx32" %"PRIu64" 0x%02x%02x%02x%02x%02x%02x%02x\n",
i, mdbSearchIndexData[i], mdbData[mdbSearchIndexData[i]].mie.general.size,
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[0],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[1],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[2],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[3],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[4],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[5],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[6],
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[7]);
mdbData[mdbSearchIndexData[i]].mie.general.filename_hash[6]);
}
}

Expand Down Expand Up @@ -790,6 +819,7 @@ static uint32_t mdbGetModuleReference (const char *name, uint64_t size)
struct modinfoentry *m=&mdbData[min[num>>1]];
int ret;
#ifdef MDB_DEBUG
#if MDB_DEBUG > 1
{
uint32_t x;
for (x = 0; x < num; x++)
Expand All @@ -807,6 +837,7 @@ static uint32_t mdbGetModuleReference (const char *name, uint64_t size)
}
DEBUG_PRINT(" ----------\n");
}
#endif
#endif
if (size==m->mie.general.size)
{
Expand Down Expand Up @@ -860,7 +891,7 @@ static uint32_t mdbGetModuleReference (const char *name, uint64_t size)
m = &mdbData[i];
memcpy (m->mie.general.filename_hash, hash + 1, 7);
m->mie.general.size = size;
m->mie.general.modtype.integer.i = 0;
m->mie.general.modtype.integer.i = mtUnRead;
m->mie.general.module_flags = 0;
m->mie.general.channels = 0;
m->mie.general.playtime = 0;
Expand Down
4 changes: 4 additions & 0 deletions filesel/mdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ struct ocpfilehandle_t;

#define MODULETYPE(str) ((uint32_t)(((uint8_t)str[0]) | (((uint8_t)(str[0]?str[1]:0))<<8) | (((uint8_t)((str[0]&&str[1])?str[2]:0))<<16) | (((uint8_t)((str[0]&&str[1]&&str[2])?str[3]:0))<<24)) )

#define mtUnRead 0
#define mtUnknownStr "UNKN"
#define mtUnknown MODULETYPE(mtUnknownStr)

struct __attribute__((packed)) moduletype
{
union
Expand Down
33 changes: 25 additions & 8 deletions filesel/pfilesel.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,12 @@ static const char *DEVv_description[] =
NULL
};

static const char *UNKN_description[] =
{
"The format of the given file is unknown",
NULL
};

int fsPreInit (const struct configAPI_t *configAPI)
{
const char *sec = configAPI->GetProfileString (configAPI->ConfigSec, "fileselsec", "fileselector");
Expand All @@ -971,6 +977,9 @@ int fsPreInit (const struct configAPI_t *configAPI)
return 0;
}

mt.integer.i = mtUnknown;
fsTypeRegister (mt, UNKN_description, 0, 0);

fsRegisterExt("DEV");
mt.integer.i = MODULETYPE("DEVv");
fsTypeRegister (mt, DEVv_description, "VirtualInterface", 0);
Expand Down Expand Up @@ -1037,6 +1046,9 @@ void fsLateClose(void)
{
struct moduletype mt;

mt.integer.i = mtUnknown;
fsTypeUnregister (mt);

mt.integer.i = MODULETYPE("DEVv");
fsTypeUnregister (mt);
}
Expand Down Expand Up @@ -1223,7 +1235,7 @@ static void displayfile(const unsigned int y, unsigned int x, unsigned int width
{
if (m->file)
{
if (mi.modtype.integer.i==0)
if (mi.modtype.integer.i == mtUnRead)
col&=~0x08;
else if (fsColorTypes)
{
Expand Down Expand Up @@ -1296,7 +1308,7 @@ static void displayfile(const unsigned int y, unsigned int x, unsigned int width
}
} else { /* m->file */
char temp[16];
if (mi.modtype.integer.i==0)
if (mi.modtype.integer.i == mtUnRead)
{
col&=~0x08;
} else if (fsColorTypes)
Expand Down Expand Up @@ -2959,7 +2971,7 @@ static int fsEditFileInfo(struct modlistentry *me)
{
return -1;
}
if (mdbEditBuf.modtype.integer.i == 0)
if (mdbEditBuf.modtype.integer.i == mtUnRead)
{
me->flags &= ~MODLIST_FLAG_SCANNED;
}
Expand Down Expand Up @@ -3437,9 +3449,10 @@ signed int fsFileSelect(void)
{
if (!mdbGetModuleInfo(&mdbEditBuf, m->mdb_ref))
return -1;
mdbEditBuf.modtype.integer.i = 0;
mdbEditBuf.modtype.integer.i = mtUnRead;
if (!mdbWriteModuleInfo(m->mdb_ref, &mdbEditBuf))
return -1;
m->flags &= ~MODLIST_FLAG_SCANNED;
}
break;
case KEY_CTRL_BS:
Expand Down Expand Up @@ -4050,12 +4063,20 @@ void plUnregisterInterface(struct interfacestruct *_interface)
void plFindInterface(struct moduletype modtype, const struct interfacestruct **in, const struct cpifaceplayerstruct **cp)
{
int i;
*in = 0;
*cp = 0;

for (i=0; i < fsTypesCount; i++)
{
if (fsTypes[i].modtype.integer.i == modtype.integer.i)
{
struct interfacestruct *curr = plInterfaces;

if (!fsTypes[i].interfacename)
{
return;
}

while (curr)
{
if (!strcmp(curr->name, fsTypes[i].interfacename))
Expand All @@ -4067,13 +4088,9 @@ void plFindInterface(struct moduletype modtype, const struct interfacestruct **i
curr = curr->next;
}
fprintf(stderr, __FILE__ ": Unable to find interface for filetype %s\n", modtype.string.c);
*in = 0;
*cp = 0;
return;
}
}
fprintf(stderr, __FILE__ ": Unable to find moduletype: %4s\n", modtype.string.c);
*in = 0;
*cp = 0;
return;
}
3 changes: 2 additions & 1 deletion ocp.ini.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
epoch=20230630
epoch=20240107

[general]
;link=
Expand Down Expand Up @@ -217,6 +217,7 @@
SAP=13
SPC=13
VGM=13
UNKN=7

[timidity]
configfile= ; leave empty to use system default, or it can specify a specific config file or sound font ending with a .sf2 extension
Expand Down

0 comments on commit 8ef13d7

Please sign in to comment.