FireBirdLib - Topfield TMS PVR TAP Programming Library
HDD_GetFileDir.c
Go to the documentation of this file.
1#include <string.h>
2#include "libFireBird.h"
3
4#define MAX_DIRDEPTH 16
5
6static char dirstack[MAX_DIRDEPTH][MAX_FILE_NAME_SIZE + 1];
7static int dirdepth = -1;
8
9static bool push_dir (const char *dir)
10{
11 if (dirdepth + 1 < MAX_DIRDEPTH && strlen(dir) <= MAX_FILE_NAME_SIZE)
12 {
13 strcpy(dirstack[++dirdepth], dir);
14 return TRUE;
15 }
16 else return FALSE;
17}
18
19static bool pop_dir (char *dir)
20{
21 if (dirdepth >= 0)
22 {
23 strcpy(dir, dirstack[dirdepth--]);
24 return TRUE;
25 }
26 else return FALSE;
27}
28
29static bool GetFileDir (const char *FileName, const char *Dir, const char *ext)
30{
31 dword files;
32 TYPE_FolderEntry entry;
33
34 TAP_Hdd_ChangeDir(Dir);
35
36 files = TAP_Hdd_FindFirst(&entry, ext);
37
38 while (files--)
39 {
40 if (entry.attr == ATTR_FOLDER) push_dir(entry.name);
41 else if (strcmp(entry.name, FileName) == 0) return TRUE;
42
43 TAP_Hdd_FindNext(&entry);
44 }
45
46 return FALSE;
47}
48
49bool HDD_GetFileDir (const char *FileName, eRootDirs Root, char *Dir)
50{
51 const char *ext = NULL;
52 char dirname[MAX_FILE_NAME_SIZE + 1];
53 bool result;
54
55 TRACEENTER();
56
57 if (!FileName || !Dir || ((int) Root < DIR_ROOT || Root > DIR_TMP))
58 {
59 TRACEEXIT();
60 return FALSE;
61 }
62
63 if (strlen(FileName) > 4) ext = strrchr(FileName, '.');
64
65 switch (Root)
66 {
67 case DIR_ROOT:
68 strcpy(Dir, "/");
69 break;
70
71 case DIR_DATA_FILES:
72 strcpy(Dir, "/DataFiles");
73 break;
74
76 strcpy(Dir, "/ProgramFiles");
77 break;
78
79 case DIR_MP3_FILES:
80 strcpy(Dir, "/MP3Files");
81 break;
82
83 case DIR_INCOMING:
84 strcpy(Dir, "/Incoming");
85 break;
86
87 case DIR_MEDIA_FILES:
88 strcpy(Dir, "/MediaFiles");
89 break;
90
91 case DIR_PHOTO_FILES:
92 strcpy(Dir, "/PhotoFiles");
93 break;
94
96 strcpy(Dir, "/SystemFiles");
97 break;
98
99 case DIR_TMP:
100 strcpy(Dir, "/tmp");
101 break;
102 }
103
105
106 result = GetFileDir(FileName, Dir, ext);
107
108 while (!result && pop_dir(dirname))
109 {
110 if (*dirname == '/')
111 {
112 strcpy(Dir, dirname);
113 continue;
114 }
115
116 if (strlen(Dir) + strlen(dirname) + 1 < FBLIB_DIR_SIZE)
117 {
118 if (!push_dir(Dir)) break;
119
120 if (strcmp(Dir, "/") != 0) strcat(Dir, "/");
121
122 strcat(Dir, dirname);
123
124 result = GetFileDir(FileName, Dir, ext);
125 }
126 }
127
128 if (!result) *Dir = 0;
129
131
132 TRACEEXIT();
133
134 return result;
135}
#define MAX_DIRDEPTH
Definition: HDD_GetFileDir.c:4
bool HDD_GetFileDir(const char *FileName, eRootDirs Root, char *Dir)
bool HDD_TAP_PushDir(void)
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
bool HDD_TAP_PopDir(void)
Definition: HDD_TAP_PopDir.c:3
eRootDirs
Definition: libFireBird.h:1887
@ DIR_DATA_FILES
Definition: libFireBird.h:1889
@ DIR_MEDIA_FILES
Definition: libFireBird.h:1894
@ DIR_TMP
Definition: libFireBird.h:1897
@ DIR_INCOMING
Definition: libFireBird.h:1893
@ DIR_MP3_FILES
Definition: libFireBird.h:1892
@ DIR_SYSTEM_FILES
Definition: libFireBird.h:1896
@ DIR_PROGRAM_FILES
Definition: libFireBird.h:1890
@ DIR_ROOT
Definition: libFireBird.h:1888
@ DIR_PHOTO_FILES
Definition: libFireBird.h:1895