-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilemanager.c
More file actions
79 lines (63 loc) · 2.13 KB
/
filemanager.c
File metadata and controls
79 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "filemanager.h"
#include <pspiofilemgr.h>
#include <string.h>
#include <stdio.h>
// Check if filename ends with .mp3 (case-insensitive)
static int isMp3File(const char *name) {
int len = strlen(name);
if (len < 4) return 0;
const char *ext = name + len - 4;
return (ext[0] == '.' &&
(ext[1] == 'm' || ext[1] == 'M') &&
(ext[2] == 'p' || ext[2] == 'P') &&
(ext[3] == '3'));
}
// Recursive directory scan
static int scanDir(const char *dirPath, MusicLibrary *lib) {
SceUID dir = sceIoDopen(dirPath);
if (dir < 0) return -1;
SceIoDirent entry;
memset(&entry, 0, sizeof(entry));
while (sceIoDread(dir, &entry) > 0) {
if (lib->count >= MAX_SONGS) break;
// Skip . and ..
if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
memset(&entry, 0, sizeof(entry));
continue;
}
// Build full path
char fullPath[MAX_PATH_LEN];
snprintf(fullPath, sizeof(fullPath), "%s/%s", dirPath, entry.d_name);
if (FIO_S_ISDIR(entry.d_stat.st_mode)) {
// Recurse into subdirectory
scanDir(fullPath, lib);
} else if (isMp3File(entry.d_name)) {
// Parse ID3 tags
SongEntry *song = &lib->songs[lib->count];
snprintf(song->filepath, MAX_PATH_LEN, "%s", fullPath);
id3_parse(fullPath, &song->id3, 0); // don't load covers during scan
lib->count++;
}
memset(&entry, 0, sizeof(entry));
}
sceIoDclose(dir);
return 0;
}
int scanMusicFolder(MusicLibrary *lib) {
if (!lib) return -1;
lib->count = 0;
memset(lib->songs, 0, sizeof(lib->songs));
// Scan primary music folder
scanDir("ms0:/MUSIC", lib);
// Also try ms0:/PSP/MUSIC as some users put music there
scanDir("ms0:/PSP/MUSIC", lib);
return lib->count;
}
void freeMusicLibrary(MusicLibrary *lib) {
if (!lib) return;
int i;
for (i = 0; i < lib->count; i++) {
id3_free(&lib->songs[i].id3);
}
lib->count = 0;
}