2006-11-30 22:29:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Peter D'Hoye
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2006-11-30 22:29:48 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
bool its_a_dir = false;
|
|
|
|
|
|
|
|
char str_filename[MAX_PATH];
|
|
|
|
char str_dirname[MAX_PATH];
|
|
|
|
char str_size[64];
|
|
|
|
char str_dircount[64];
|
|
|
|
char str_filecount[64];
|
|
|
|
char str_date[64];
|
|
|
|
char str_time[64];
|
2007-08-14 12:28:19 +00:00
|
|
|
|
2007-08-14 11:56:15 +00:00
|
|
|
char str_title[MAX_PATH];
|
2021-09-16 02:51:22 +00:00
|
|
|
char str_composer[MAX_PATH];
|
2007-08-14 11:56:15 +00:00
|
|
|
char str_artist[MAX_PATH];
|
2021-09-16 02:27:31 +00:00
|
|
|
char str_albumartist[MAX_PATH];
|
2007-08-14 11:56:15 +00:00
|
|
|
char str_album[MAX_PATH];
|
2021-09-16 02:37:03 +00:00
|
|
|
char str_genre[MAX_PATH];
|
2021-09-16 02:43:16 +00:00
|
|
|
char str_comment[MAX_PATH];
|
2021-09-16 03:06:37 +00:00
|
|
|
char str_year[MAX_PATH];
|
2021-09-16 03:21:38 +00:00
|
|
|
char str_discnum[MAX_PATH];
|
2021-09-16 03:18:12 +00:00
|
|
|
char str_tracknum[MAX_PATH];
|
2009-02-21 22:22:05 +00:00
|
|
|
char str_duration[32];
|
2021-09-16 23:50:56 +00:00
|
|
|
char str_bitrate[32];
|
2021-09-16 23:12:12 +00:00
|
|
|
char str_frequency[32];
|
2007-08-14 11:56:15 +00:00
|
|
|
|
2019-07-24 18:09:52 +00:00
|
|
|
unsigned nseconds;
|
|
|
|
unsigned long nsize;
|
|
|
|
int32_t size_unit;
|
|
|
|
struct tm tm;
|
|
|
|
|
2007-08-14 11:56:15 +00:00
|
|
|
int num_properties;
|
2006-11-30 22:29:48 +00:00
|
|
|
|
2019-07-24 18:09:52 +00:00
|
|
|
static const unsigned char* const props_file[] =
|
2012-04-08 18:52:44 +00:00
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
ID2P(LANG_PROPERTIES_PATH), str_dirname,
|
|
|
|
ID2P(LANG_PROPERTIES_FILENAME), str_filename,
|
|
|
|
ID2P(LANG_PROPERTIES_SIZE), str_size,
|
|
|
|
ID2P(LANG_PROPERTIES_DATE), str_date,
|
|
|
|
ID2P(LANG_PROPERTIES_TIME), str_time,
|
2021-09-16 02:51:22 +00:00
|
|
|
ID2P(LANG_PROPERTIES_COMPOSER), str_composer,
|
2019-07-24 18:09:52 +00:00
|
|
|
ID2P(LANG_PROPERTIES_ARTIST), str_artist,
|
2021-09-16 02:27:31 +00:00
|
|
|
ID2P(LANG_PROPERTIES_ALBUMARTIST), str_albumartist,
|
2019-07-24 18:09:52 +00:00
|
|
|
ID2P(LANG_PROPERTIES_TITLE), str_title,
|
|
|
|
ID2P(LANG_PROPERTIES_ALBUM), str_album,
|
2021-09-16 02:37:03 +00:00
|
|
|
ID2P(LANG_PROPERTIES_GENRE), str_genre,
|
2021-09-16 02:43:16 +00:00
|
|
|
ID2P(LANG_PROPERTIES_COMMENT), str_comment,
|
2021-09-16 03:06:37 +00:00
|
|
|
ID2P(LANG_PROPERTIES_YEAR), str_year,
|
2021-09-16 03:21:38 +00:00
|
|
|
ID2P(LANG_PROPERTIES_DISCNUM), str_discnum,
|
2021-09-16 03:18:12 +00:00
|
|
|
ID2P(LANG_PROPERTIES_TRACKNUM), str_tracknum,
|
2019-07-24 18:09:52 +00:00
|
|
|
ID2P(LANG_PROPERTIES_DURATION), str_duration,
|
2021-09-16 23:50:56 +00:00
|
|
|
ID2P(LANG_PROPERTIES_BITRATE), str_bitrate,
|
2021-09-16 23:12:12 +00:00
|
|
|
ID2P(LANG_PROPERTIES_FREQUENCY), str_frequency,
|
2012-04-08 18:52:44 +00:00
|
|
|
};
|
2019-07-24 18:09:52 +00:00
|
|
|
static const unsigned char* const props_dir[] =
|
2012-04-08 18:52:44 +00:00
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
ID2P(LANG_PROPERTIES_PATH), str_dirname,
|
|
|
|
ID2P(LANG_PROPERTIES_SUBDIRS), str_dircount,
|
|
|
|
ID2P(LANG_PROPERTIES_FILES), str_filecount,
|
|
|
|
ID2P(LANG_PROPERTIES_SIZE), str_size,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int32_t units[] =
|
|
|
|
{
|
|
|
|
LANG_BYTE,
|
|
|
|
LANG_KIBIBYTE,
|
|
|
|
LANG_MEBIBYTE,
|
|
|
|
LANG_GIBIBYTE
|
2012-04-08 18:52:44 +00:00
|
|
|
};
|
|
|
|
|
2011-12-26 23:39:43 +00:00
|
|
|
static unsigned human_size_log(unsigned long long size)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
const size_t n = sizeof(units)/sizeof(units[0]);
|
2010-08-28 21:46:27 +00:00
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
/* margin set at 10K boundary: 10239 B +1 => 10 KB */
|
|
|
|
for(i=0; i < n-1 && size >= 10*1024; i++)
|
2006-11-30 22:29:48 +00:00
|
|
|
size >>= 10; /* div by 1024 */
|
2010-08-28 21:46:27 +00:00
|
|
|
|
|
|
|
return i;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
static bool file_properties(const char* selected_file)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
2019-07-24 18:08:56 +00:00
|
|
|
static struct mp3entry id3;
|
2007-07-20 17:06:55 +00:00
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
dir = rb->opendir(str_dirname);
|
2006-11-30 22:29:48 +00:00
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while(0 != (entry = rb->readdir(dir)))
|
|
|
|
{
|
2010-09-01 21:29:34 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
2019-07-24 18:08:56 +00:00
|
|
|
if(!rb->strcmp(entry->d_name, str_filename))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2010-08-28 21:46:27 +00:00
|
|
|
unsigned log;
|
2011-12-26 23:39:43 +00:00
|
|
|
log = human_size_log((unsigned long)info.size);
|
2019-07-24 18:09:52 +00:00
|
|
|
nsize = ((unsigned long)info.size) >> (log*10);
|
|
|
|
size_unit = units[log];
|
|
|
|
rb->snprintf(str_size, sizeof str_size, "%lu %s", nsize, rb->str(size_unit));
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
rb->gmtime_r(&info.mtime, &tm);
|
2012-04-08 18:52:44 +00:00
|
|
|
rb->snprintf(str_date, sizeof str_date, "%04d/%02d/%02d",
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
|
|
|
rb->snprintf(str_time, sizeof str_time, "%02d:%02d:%02d",
|
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
2007-08-14 11:56:15 +00:00
|
|
|
|
|
|
|
num_properties = 5;
|
|
|
|
|
2007-08-14 12:44:50 +00:00
|
|
|
int fd = rb->open(selected_file, O_RDONLY);
|
2007-08-14 13:19:22 +00:00
|
|
|
if (fd >= 0 &&
|
2007-09-19 10:40:55 +00:00
|
|
|
rb->get_metadata(&id3, fd, selected_file))
|
2007-08-14 11:56:15 +00:00
|
|
|
{
|
2009-02-21 22:22:05 +00:00
|
|
|
long dur = id3.length / 1000; /* seconds */
|
2021-09-16 02:51:22 +00:00
|
|
|
rb->snprintf(str_composer, sizeof str_composer,
|
|
|
|
"%s", id3.composer ? id3.composer : "");
|
2007-08-14 13:19:22 +00:00
|
|
|
rb->snprintf(str_artist, sizeof str_artist,
|
2012-04-08 18:52:44 +00:00
|
|
|
"%s", id3.artist ? id3.artist : "");
|
2021-09-16 02:27:31 +00:00
|
|
|
rb->snprintf(str_albumartist, sizeof str_albumartist,
|
|
|
|
"%s", id3.albumartist ? id3.albumartist : "");
|
2007-08-14 13:19:22 +00:00
|
|
|
rb->snprintf(str_title, sizeof str_title,
|
2012-04-08 18:52:44 +00:00
|
|
|
"%s", id3.title ? id3.title : "");
|
2007-08-14 13:19:22 +00:00
|
|
|
rb->snprintf(str_album, sizeof str_album,
|
2012-04-08 18:52:44 +00:00
|
|
|
"%s", id3.album ? id3.album : "");
|
2021-09-16 02:37:03 +00:00
|
|
|
rb->snprintf(str_genre, sizeof str_genre,
|
|
|
|
"%s", id3.genre_string ? id3.genre_string : "");
|
2021-09-16 02:43:16 +00:00
|
|
|
rb->snprintf(str_comment, sizeof str_comment,
|
|
|
|
"%s", id3.comment ? id3.comment : "");
|
2021-12-04 21:02:57 +00:00
|
|
|
|
|
|
|
if (id3.year_string)
|
|
|
|
rb->snprintf(str_year, sizeof str_year,
|
|
|
|
"%s", id3.year_string);
|
|
|
|
else if (id3.year)
|
|
|
|
rb->snprintf(str_year, sizeof str_year,
|
|
|
|
"%d", id3.year);
|
|
|
|
else
|
|
|
|
rb->snprintf(str_year, sizeof str_year,
|
|
|
|
"%s", "");
|
|
|
|
|
|
|
|
if (id3.disc_string)
|
|
|
|
rb->snprintf(str_discnum, sizeof str_discnum,
|
|
|
|
"%s", id3.disc_string);
|
|
|
|
else if (id3.discnum)
|
|
|
|
rb->snprintf(str_discnum, sizeof str_discnum,
|
|
|
|
"%d", id3.discnum);
|
|
|
|
else
|
|
|
|
rb->snprintf(str_discnum, sizeof str_discnum,
|
|
|
|
"%s", "");
|
|
|
|
|
|
|
|
if (id3.track_string)
|
|
|
|
rb->snprintf(str_tracknum, sizeof str_tracknum,
|
|
|
|
"%s", id3.track_string);
|
|
|
|
else if(id3.tracknum)
|
|
|
|
rb->snprintf(str_tracknum, sizeof str_tracknum,
|
|
|
|
"%d", id3.tracknum);
|
|
|
|
else
|
|
|
|
rb->snprintf(str_tracknum, sizeof str_tracknum,
|
|
|
|
"%s", "");
|
|
|
|
|
2021-09-16 23:50:56 +00:00
|
|
|
rb->snprintf(str_bitrate, sizeof str_bitrate,
|
|
|
|
"%d kbps", id3.bitrate ? : 0);
|
2021-09-16 23:12:12 +00:00
|
|
|
rb->snprintf(str_frequency, sizeof str_frequency,
|
|
|
|
"%ld Hz", id3.frequency ? : 0);
|
2021-09-16 23:50:56 +00:00
|
|
|
num_properties += 12;
|
2009-02-21 22:22:05 +00:00
|
|
|
|
|
|
|
if (dur > 0)
|
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
nseconds = dur;
|
2009-02-21 22:22:05 +00:00
|
|
|
if (dur < 3600)
|
|
|
|
rb->snprintf(str_duration, sizeof str_duration,
|
2012-04-08 18:52:44 +00:00
|
|
|
"%d:%02d", (int)(dur / 60),
|
2009-02-21 22:22:05 +00:00
|
|
|
(int)(dur % 60));
|
|
|
|
else
|
|
|
|
rb->snprintf(str_duration, sizeof str_duration,
|
2012-04-08 18:52:44 +00:00
|
|
|
"%d:%02d:%02d",
|
|
|
|
(int)(dur / 3600),
|
2009-02-21 22:22:05 +00:00
|
|
|
(int)(dur % 3600 / 60),
|
|
|
|
(int)(dur % 60));
|
|
|
|
num_properties++;
|
|
|
|
}
|
2007-08-14 11:56:15 +00:00
|
|
|
}
|
2007-08-14 13:19:22 +00:00
|
|
|
rb->close(fd);
|
2006-11-30 22:29:48 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char dirname[MAX_PATH];
|
|
|
|
int len;
|
|
|
|
unsigned int dc;
|
|
|
|
unsigned int fc;
|
2011-12-26 23:39:43 +00:00
|
|
|
unsigned long long bc;
|
2006-11-30 22:29:48 +00:00
|
|
|
} DPS;
|
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
static bool _dir_properties(DPS *dps)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
/* recursively scan directories in search of files
|
|
|
|
and informs the user of the progress */
|
|
|
|
bool result;
|
2010-12-16 05:49:30 +00:00
|
|
|
static long lasttick=0;
|
2006-11-30 22:29:48 +00:00
|
|
|
int dirlen;
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
|
|
|
|
2006-12-13 19:52:08 +00:00
|
|
|
result = true;
|
2006-11-30 22:29:48 +00:00
|
|
|
dirlen = rb->strlen(dps->dirname);
|
|
|
|
dir = rb->opendir(dps->dirname);
|
|
|
|
if (!dir)
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
{
|
|
|
|
rb->splashf(HZ*2, "%s", dps->dirname);
|
2006-11-30 22:29:48 +00:00
|
|
|
return false; /* open error */
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
}
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
/* walk through the directory content */
|
2006-12-13 19:52:08 +00:00
|
|
|
while(result && (0 != (entry = rb->readdir(dir))))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2010-09-01 21:29:34 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
2006-11-30 22:29:48 +00:00
|
|
|
/* append name to current directory */
|
|
|
|
rb->snprintf(dps->dirname+dirlen, dps->len-dirlen, "/%s",
|
|
|
|
entry->d_name);
|
|
|
|
|
2010-09-01 21:29:34 +00:00
|
|
|
if (info.attribute & ATTR_DIRECTORY)
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
2006-11-30 22:29:48 +00:00
|
|
|
if (!rb->strcmp((char *)entry->d_name, ".") ||
|
|
|
|
!rb->strcmp((char *)entry->d_name, ".."))
|
|
|
|
continue; /* skip these */
|
|
|
|
|
|
|
|
dps->dc++; /* new directory */
|
2010-12-16 05:49:30 +00:00
|
|
|
if (*rb->current_tick - lasttick > (HZ/8))
|
|
|
|
{
|
2021-07-22 05:37:38 +00:00
|
|
|
unsigned log;
|
2010-12-16 05:49:30 +00:00
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0,0,"SCANNING...");
|
|
|
|
rb->lcd_puts(0,1,dps->dirname);
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->lcd_putsf(0,2,"Directories: %d", dps->dc);
|
|
|
|
rb->lcd_putsf(0,3,"Files: %d", dps->fc);
|
2010-12-16 05:49:30 +00:00
|
|
|
log = human_size_log(dps->bc);
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->lcd_putsf(0,4,"Size: %lu %cB", (unsigned long)(dps->bc >> (10*log)),
|
|
|
|
rb->str(units[log]));
|
2010-12-16 05:49:30 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
}
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
/* recursion */
|
|
|
|
result = _dir_properties(dps);
|
|
|
|
}
|
|
|
|
else
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
2006-11-30 22:29:48 +00:00
|
|
|
dps->fc++; /* new file */
|
2010-09-01 21:29:34 +00:00
|
|
|
dps->bc += info.size;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
2006-12-13 19:52:08 +00:00
|
|
|
if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
|
|
|
|
result = false;
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
static bool dir_properties(const char* selected_file, DPS *dps)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2010-08-28 21:46:27 +00:00
|
|
|
unsigned log;
|
2019-07-24 18:08:56 +00:00
|
|
|
|
|
|
|
rb->strlcpy(dps->dirname, selected_file, MAX_PATH);
|
2010-08-28 21:46:27 +00:00
|
|
|
|
2010-12-16 05:49:30 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(true);
|
|
|
|
#endif
|
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
if (!_dir_properties(dps))
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
2006-12-13 19:52:08 +00:00
|
|
|
return false;
|
2019-07-24 18:08:56 +00:00
|
|
|
}
|
2006-11-30 22:29:48 +00:00
|
|
|
|
2010-12-16 05:49:30 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(str_dirname, selected_file, MAX_PATH);
|
2019-07-24 18:08:56 +00:00
|
|
|
rb->snprintf(str_dircount, sizeof str_dircount, "%d", dps->dc);
|
|
|
|
rb->snprintf(str_filecount, sizeof str_filecount, "%d", dps->fc);
|
|
|
|
log = human_size_log(dps->bc);
|
2019-07-24 18:09:52 +00:00
|
|
|
nsize = (long) (dps->bc >> (log*10));
|
|
|
|
size_unit = units[log];
|
|
|
|
rb->snprintf(str_size, sizeof str_size, "%ld %s", nsize, rb->str(size_unit));
|
2007-08-14 11:56:15 +00:00
|
|
|
num_properties = 4;
|
2006-11-30 22:29:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 18:09:52 +00:00
|
|
|
static const unsigned char* p2str(const unsigned char* p)
|
|
|
|
{
|
|
|
|
int id = P2ID(p);
|
|
|
|
return (id != -1) ? rb->str(id) : p;
|
|
|
|
}
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char * get_props(int selected_item, void* data,
|
|
|
|
char *buffer, size_t buffer_len)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2012-04-08 18:52:44 +00:00
|
|
|
if(its_a_dir)
|
|
|
|
{
|
|
|
|
if(selected_item >= (int)(sizeof(props_dir) / sizeof(props_dir[0])))
|
|
|
|
{
|
|
|
|
rb->strlcpy(buffer, "ERROR", buffer_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->strlcpy(buffer, p2str(props_dir[selected_item]), buffer_len);
|
2012-04-08 18:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2012-04-08 18:52:44 +00:00
|
|
|
if(selected_item >= (int)(sizeof(props_file) / sizeof(props_file[0])))
|
|
|
|
{
|
|
|
|
rb->strlcpy(buffer, "ERROR", buffer_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->strlcpy(buffer, p2str(props_file[selected_item]), buffer_len);
|
2012-04-08 18:52:44 +00:00
|
|
|
}
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2019-07-24 18:09:52 +00:00
|
|
|
static int speak_property_selection(int selected_item, void *data)
|
|
|
|
{
|
|
|
|
DPS *dps = data;
|
|
|
|
int32_t id = P2ID((its_a_dir ? props_dir : props_file)[selected_item]);
|
|
|
|
rb->talk_id(id, false);
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case LANG_PROPERTIES_PATH:
|
|
|
|
if (str_dirname[0] == '/')
|
|
|
|
{
|
|
|
|
char *start = str_dirname;
|
|
|
|
char *ptr;
|
|
|
|
while (0 != (ptr = rb->strchr(start, '/')))
|
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
rb->talk_dir_or_spell(str_dirname, NULL, true);
|
|
|
|
*ptr = '/';
|
|
|
|
rb->talk_id(VOICE_CHAR_SLASH, true);
|
|
|
|
start = ptr + 1;
|
|
|
|
}
|
|
|
|
if (*start)
|
|
|
|
rb->talk_dir_or_spell(str_dirname, NULL, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->talk_spell(str_dirname, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_FILENAME:
|
|
|
|
rb->talk_file_or_spell(str_dirname, str_filename, NULL, true);
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_SIZE:
|
|
|
|
rb->talk_number(nsize, true);
|
|
|
|
rb->talk_id(size_unit, true);
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_DATE:
|
|
|
|
rb->talk_date(&tm, true);
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_TIME:
|
|
|
|
rb->talk_time(&tm, true);
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_DURATION:
|
2021-08-18 05:23:26 +00:00
|
|
|
rb->talk_value_decimal(nseconds, UNIT_TIME, 0, true);
|
2019-07-24 18:09:52 +00:00
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_SUBDIRS:
|
|
|
|
rb->talk_number(dps->dc, true);
|
|
|
|
break;
|
|
|
|
case LANG_PROPERTIES_FILES:
|
|
|
|
rb->talk_number(dps->fc, true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb->talk_spell(props_file[selected_item + 1], true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
|
|
|
struct gui_synclist properties_lists;
|
|
|
|
int button;
|
2009-12-21 13:32:43 +00:00
|
|
|
bool quit = false, usb = false;
|
2019-07-24 18:08:56 +00:00
|
|
|
const char *file = parameter;
|
2009-07-29 13:56:23 +00:00
|
|
|
if(!parameter) return PLUGIN_ERROR;
|
2011-02-27 09:30:33 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
rb->touchscreen_set_mode(rb->global_settings->touch_mode);
|
|
|
|
#endif
|
2006-11-30 22:29:48 +00:00
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
static DPS dps = {
|
|
|
|
.len = MAX_PATH,
|
|
|
|
.dc = 0,
|
|
|
|
.fc = 0,
|
|
|
|
.bc = 0,
|
|
|
|
};
|
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
/* determine if it's a file or a directory */
|
|
|
|
bool found = false;
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
2008-05-13 09:57:56 +00:00
|
|
|
char* ptr = rb->strrchr(file, '/') + 1;
|
|
|
|
int dirlen = (ptr - file);
|
2019-07-24 18:08:56 +00:00
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(str_dirname, file, dirlen + 1);
|
2019-07-24 18:08:56 +00:00
|
|
|
rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen);
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
dir = rb->opendir(str_dirname);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while(0 != (entry = rb->readdir(dir)))
|
|
|
|
{
|
2019-07-24 18:08:56 +00:00
|
|
|
if(!rb->strcmp(entry->d_name, str_filename))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2010-09-01 21:29:34 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
|
|
|
its_a_dir = info.attribute & ATTR_DIRECTORY ? true : false;
|
2006-11-30 22:29:48 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
|
|
|
/* now we know if it's a file or a dir or maybe something failed */
|
2009-12-21 13:32:43 +00:00
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
if(!found)
|
|
|
|
{
|
|
|
|
/* weird: we couldn't find the entry. This Should Never Happen (TM) */
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(0, "File/Dir not found: %s", file);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->action_userabort(TIMEOUT_BLOCK);
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-03 23:18:14 +00:00
|
|
|
/* get the info depending on its_a_dir */
|
2019-07-24 18:08:56 +00:00
|
|
|
if(!(its_a_dir ? dir_properties(file, &dps) : file_properties(file)))
|
2006-11-30 22:29:48 +00:00
|
|
|
{
|
2007-07-03 23:38:22 +00:00
|
|
|
/* something went wrong (to do: tell user what it was (nesting,...) */
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->splash(0, ID2P(LANG_PROPERTIES_FAIL));
|
2007-07-03 23:18:14 +00:00
|
|
|
rb->action_userabort(TIMEOUT_BLOCK);
|
|
|
|
return PLUGIN_OK;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 13:32:43 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
rb->viewportmanager_theme_enable(i, true, NULL);
|
|
|
|
|
2019-07-24 18:08:56 +00:00
|
|
|
rb->gui_synclist_init(&properties_lists, &get_props, &dps, false, 2, NULL);
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->gui_synclist_set_title(&properties_lists, rb->str(its_a_dir ? LANG_PROPERTIES_DIRECTORY_PROPERTIES : LANG_PROPERTIES_FILE_PROPERTIES), NOICON);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->gui_synclist_set_icon_callback(&properties_lists, NULL);
|
2019-07-24 18:09:52 +00:00
|
|
|
if (rb->global_settings->talk_menu)
|
|
|
|
rb->gui_synclist_set_voice_callback(&properties_lists, speak_property_selection);
|
2012-04-08 18:52:44 +00:00
|
|
|
rb->gui_synclist_set_nb_items(&properties_lists, num_properties * 2);
|
2006-11-30 22:29:48 +00:00
|
|
|
rb->gui_synclist_limit_scroll(&properties_lists, true);
|
|
|
|
rb->gui_synclist_select_item(&properties_lists, 0);
|
|
|
|
rb->gui_synclist_draw(&properties_lists);
|
2019-07-24 18:09:52 +00:00
|
|
|
rb->gui_synclist_speak_item(&properties_lists);
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
|
|
while(!quit)
|
|
|
|
{
|
2009-12-21 13:32:43 +00:00
|
|
|
button = rb->get_action(CONTEXT_LIST, HZ);
|
|
|
|
/* HZ so the status bar redraws corectly */
|
2007-09-17 10:08:50 +00:00
|
|
|
if (rb->gui_synclist_do_button(&properties_lists,&button,LIST_WRAP_ON))
|
2006-11-30 22:29:48 +00:00
|
|
|
continue;
|
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
case ACTION_STD_CANCEL:
|
|
|
|
quit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2009-12-21 13:32:43 +00:00
|
|
|
{
|
|
|
|
quit = true;
|
|
|
|
usb = true;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-21 13:32:43 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
rb->viewportmanager_theme_undo(i, false);
|
|
|
|
|
|
|
|
return usb? PLUGIN_USB_CONNECTED: PLUGIN_OK;
|
2006-11-30 22:29:48 +00:00
|
|
|
}
|