Add missing function headers
Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
340
source/main.c
340
source/main.c
@@ -22,6 +22,185 @@
|
||||
|
||||
volatile bool runThreads = true;
|
||||
|
||||
/**
|
||||
* Prints the current key mappings to stdio.
|
||||
*/
|
||||
static void showControls(void)
|
||||
{
|
||||
printf("Button mappings:\n"
|
||||
"Pause: L+R or L+Up\n"
|
||||
"Stop: L+B\n"
|
||||
"A: Open File\n"
|
||||
"B: Go up folder\n"
|
||||
"Start: Exit\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the playback thread to return any error messages that it may
|
||||
* encounter.
|
||||
*
|
||||
* \param infoIn Struct containing addresses of the event, the error code,
|
||||
* and an optional error string.
|
||||
*/
|
||||
void playbackWatchdog(void* infoIn)
|
||||
{
|
||||
struct watchdogInfo* info = infoIn;
|
||||
|
||||
while(runThreads)
|
||||
{
|
||||
svcWaitSynchronization(*info->errInfo->failEvent, U64_MAX);
|
||||
svcClearEvent(*info->errInfo->failEvent);
|
||||
consoleSelect(info->screen);
|
||||
|
||||
if(*info->errInfo->error != 0)
|
||||
{
|
||||
printf("Error %d: %s", *info->errInfo->error,
|
||||
ctrmus_strerror(*info->errInfo->error));
|
||||
|
||||
if(info->errInfo->errstr != NULL)
|
||||
{
|
||||
printf(" %s", info->errInfo->errstr);
|
||||
delete(info->errInfo->errstr);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the currently playing file (if there is one) and play another file.
|
||||
*
|
||||
* \param ep_file File to play.
|
||||
* \param playbackInfo Information that the playback thread requires to
|
||||
* play file.
|
||||
*/
|
||||
static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
|
||||
{
|
||||
s32 prio;
|
||||
static Thread thread = NULL;
|
||||
|
||||
/**
|
||||
* If music is playing, stop it. Only one playback thread should be playing
|
||||
* at any time.
|
||||
*/
|
||||
if(thread != NULL)
|
||||
{
|
||||
/* Tell the thread to stop playback before we join it */
|
||||
stopPlayback();
|
||||
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
thread = NULL;
|
||||
|
||||
/* free allocated file string */
|
||||
delete(playbackInfo->file);
|
||||
}
|
||||
|
||||
if(ep_file == NULL || playbackInfo == NULL)
|
||||
return 0;
|
||||
|
||||
playbackInfo->file = strdup(ep_file);
|
||||
printf("Playing: %s\n", playbackInfo->file);
|
||||
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate(playFile, playbackInfo, 32 * 1024, prio - 1, -2, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* List current directory.
|
||||
*
|
||||
* \param from First entry in directory to list.
|
||||
* \param max Maximum number of entries to list. Must be > 0.
|
||||
* \param select File to show as selected. Must be > 0.
|
||||
* \return Number of entries listed or negative on error.
|
||||
*/
|
||||
static int listDir(int from, int max, int select)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int fileNum = 0;
|
||||
int listed = 0;
|
||||
char* wd = getcwd(NULL, 0);
|
||||
|
||||
if(wd == NULL)
|
||||
goto err;
|
||||
|
||||
consoleClear();
|
||||
printf("Dir: %.33s\n", wd);
|
||||
|
||||
if((dp = opendir(wd)) == NULL)
|
||||
goto err;
|
||||
|
||||
if(from == 0)
|
||||
{
|
||||
printf("%c../\n", select == 0 ? '>' : ' ');
|
||||
listed++;
|
||||
}
|
||||
|
||||
while((ep = readdir(dp)) != NULL)
|
||||
{
|
||||
fileNum++;
|
||||
|
||||
if(fileNum <= from)
|
||||
continue;
|
||||
|
||||
listed++;
|
||||
|
||||
printf("%c%s%.37s%s\n",
|
||||
select == fileNum ? '>' : ' ',
|
||||
ep->d_type == DT_DIR ? "\x1b[34;1m" : "",
|
||||
ep->d_name,
|
||||
ep->d_type == DT_DIR ? "/\x1b[0m" : "");
|
||||
|
||||
if(fileNum == max + from)
|
||||
break;
|
||||
}
|
||||
|
||||
if(closedir(dp) != 0)
|
||||
goto err;
|
||||
|
||||
out:
|
||||
free(wd);
|
||||
return listed;
|
||||
|
||||
err:
|
||||
listed = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of files in current working folder
|
||||
*
|
||||
* \return Number of files in current working folder, -1 on failure with
|
||||
* errno set.
|
||||
*/
|
||||
int getNumberFiles(void)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int ret = 0;
|
||||
|
||||
if((dp = opendir(".")) == NULL)
|
||||
goto err;
|
||||
|
||||
while((ep = readdir(dp)) != NULL)
|
||||
ret++;
|
||||
|
||||
closedir(dp);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
|
||||
err:
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
PrintConsole topScreen;
|
||||
@@ -262,164 +441,3 @@ err:
|
||||
goto out;
|
||||
}
|
||||
|
||||
static void showControls(void)
|
||||
{
|
||||
printf("Button mappings:\n"
|
||||
"Pause: L+R or L+Up\n"
|
||||
"Stop: L+B\n"
|
||||
"A: Open File\n"
|
||||
"B: Go up folder\n"
|
||||
"Start: Exit\n");
|
||||
}
|
||||
|
||||
void playbackWatchdog(void* infoIn)
|
||||
{
|
||||
struct watchdogInfo* info = infoIn;
|
||||
|
||||
while(runThreads)
|
||||
{
|
||||
svcWaitSynchronization(*info->errInfo->failEvent, U64_MAX);
|
||||
svcClearEvent(*info->errInfo->failEvent);
|
||||
consoleSelect(info->screen);
|
||||
|
||||
if(*info->errInfo->error != 0)
|
||||
{
|
||||
printf("Error %d: %s", *info->errInfo->error,
|
||||
ctrmus_strerror(*info->errInfo->error));
|
||||
|
||||
if(info->errInfo->errstr != NULL)
|
||||
{
|
||||
printf(" %s", info->errInfo->errstr);
|
||||
delete(info->errInfo->errstr);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
|
||||
{
|
||||
s32 prio;
|
||||
static Thread thread = NULL;
|
||||
|
||||
/**
|
||||
* If music is playing, stop it. Only one playback thread should be playing
|
||||
* at any time.
|
||||
*/
|
||||
if(thread != NULL)
|
||||
{
|
||||
/* Tell the thread to stop playback before we join it */
|
||||
stopPlayback();
|
||||
|
||||
threadJoin(thread, U64_MAX);
|
||||
threadFree(thread);
|
||||
thread = NULL;
|
||||
|
||||
/* free allocated file string */
|
||||
delete(playbackInfo->file);
|
||||
}
|
||||
|
||||
if(ep_file == NULL || playbackInfo == NULL)
|
||||
return 0;
|
||||
|
||||
playbackInfo->file = strdup(ep_file);
|
||||
printf("Playing: %s\n", playbackInfo->file);
|
||||
|
||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||
thread = threadCreate(playFile, playbackInfo, 32 * 1024, prio - 1, -2, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* List current directory.
|
||||
*
|
||||
* \param from First entry in directory to list.
|
||||
* \param max Maximum number of entries to list. Must be > 0.
|
||||
* \param select File to show as selected. Must be > 0.
|
||||
* \return Number of entries listed or negative on error.
|
||||
*/
|
||||
int listDir(int from, int max, int select)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int fileNum = 0;
|
||||
int listed = 0;
|
||||
char* wd = getcwd(NULL, 0);
|
||||
|
||||
if(wd == NULL)
|
||||
goto err;
|
||||
|
||||
consoleClear();
|
||||
printf("Dir: %.33s\n", wd);
|
||||
|
||||
if((dp = opendir(wd)) == NULL)
|
||||
goto err;
|
||||
|
||||
if(from == 0)
|
||||
{
|
||||
printf("%c../\n", select == 0 ? '>' : ' ');
|
||||
listed++;
|
||||
}
|
||||
|
||||
while((ep = readdir(dp)) != NULL)
|
||||
{
|
||||
fileNum++;
|
||||
|
||||
if(fileNum <= from)
|
||||
continue;
|
||||
|
||||
listed++;
|
||||
|
||||
printf("%c%s%.37s%s\n",
|
||||
select == fileNum ? '>' : ' ',
|
||||
ep->d_type == DT_DIR ? "\x1b[34;1m" : "",
|
||||
ep->d_name,
|
||||
ep->d_type == DT_DIR ? "/\x1b[0m" : "");
|
||||
|
||||
if(fileNum == max + from)
|
||||
break;
|
||||
}
|
||||
|
||||
if(closedir(dp) != 0)
|
||||
goto err;
|
||||
|
||||
out:
|
||||
free(wd);
|
||||
return listed;
|
||||
|
||||
err:
|
||||
listed = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of files in current working folder
|
||||
*
|
||||
* \return Number of files in current working folder, -1 on failure with
|
||||
* errno set.
|
||||
*/
|
||||
int getNumberFiles(void)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int ret = 0;
|
||||
|
||||
if((dp = opendir(".")) == NULL)
|
||||
goto err;
|
||||
|
||||
while((ep = readdir(dp)) != NULL)
|
||||
ret++;
|
||||
|
||||
closedir(dp);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
|
||||
err:
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user