Merge pull request #77 from narayanx/feature/save-parent-position

Save parent position in folder
This commit is contained in:
Mahyar Koshkouei
2025-08-25 14:17:39 +01:00
committed by GitHub
3 changed files with 36 additions and 5 deletions

View File

@@ -15,8 +15,13 @@
/* Default folder */ /* Default folder */
#define DEFAULT_DIR "sdmc:/" #define DEFAULT_DIR "sdmc:/"
/* Maximum number of lines that can be displayed */ /* Maximum number of lines that can be displayed on bottom screen */
#define MAX_LIST 28 #define MAX_LIST 28
/* Arbitrary cap for number of stored parent positions in folder to avoid
* unbounded memory consumption. If directories are added exceeding this,
* dequeues path closest to root to make space.
*/
#define MAX_DIRECTORIES 20
struct watchdogInfo struct watchdogInfo
{ {

View File

@@ -22,7 +22,7 @@ char* ctrmus_strerror(int err)
break; break;
case DECODER_INIT_FAIL: case DECODER_INIT_FAIL:
error = "Unable to initialised decoder"; error = "Unable to initialise decoder";
break; break;
case FILE_NOT_SUPPORTED: case FILE_NOT_SUPPORTED:

View File

@@ -325,6 +325,11 @@ int main(int argc, char **argv)
playbackInfo.errInfo = &errInfo; playbackInfo.errInfo = &errInfo;
/* position of parent folder in parent directory */
int prevPosition[MAX_DIRECTORIES] = {0};
int prevFrom[MAX_DIRECTORIES] = {0};
int oldFileNum, oldFrom;
chdir(DEFAULT_DIR); chdir(DEFAULT_DIR);
chdir("MUSIC"); chdir("MUSIC");
@@ -507,8 +512,15 @@ int main(int argc, char **argv)
consoleClear(); consoleClear();
fileMax = getDir(&dirList); fileMax = getDir(&dirList);
fileNum = 0; fileNum = prevPosition[0];
from = 0; from = prevFrom[0];
for (int i=0; i<MAX_DIRECTORIES-1; i++) {
prevPosition[i] = prevPosition[i+1];
prevFrom[i] = prevFrom[i+1];
}
/* default to first entry */
prevPosition[MAX_DIRECTORIES-1] = 0;
prevFrom[MAX_DIRECTORIES-1] = 0;
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
err_print("Unable to list directory."); err_print("Unable to list directory.");
@@ -523,11 +535,26 @@ int main(int argc, char **argv)
chdir(dirList.directories[fileNum - 1]); chdir(dirList.directories[fileNum - 1]);
consoleClear(); consoleClear();
fileMax = getDir(&dirList); fileMax = getDir(&dirList);
oldFileNum = fileNum;
oldFrom = from;
fileNum = 0; fileNum = 0;
from = 0; from = 0;
if(listDir(from, MAX_LIST, fileNum, dirList) < 0) if(listDir(from, MAX_LIST, fileNum, dirList) < 0)
{
err_print("Unable to list directory."); err_print("Unable to list directory.");
}
else
{
/* save old position in folder */
for (int i=MAX_DIRECTORIES-1; i>0; i--) {
prevPosition[i] = prevPosition[i-1];
prevFrom[i] = prevFrom[i-1];
}
prevPosition[0] = oldFileNum;
prevFrom[0] = oldFrom;
}
continue; continue;
} }
@@ -661,4 +688,3 @@ err:
goto out; goto out;
} }