1 #include "include/usbld.h"
2 #include "include/lang.h"
3 #include "include/gui.h"
4 #include "include/appsupport.h"
5 #include "include/themes.h"
6 #include "include/system.h"
7 #include "include/ioman.h"
9 #include "include/usbsupport.h"
10 #include "include/ethsupport.h"
11 #include "include/hddsupport.h"
13 static int appForceUpdate
= 1;
14 static int appItemCount
= 0;
16 static config_set_t
*configApps
;
18 // forward declaration
19 static item_list_t appItemList
;
21 static struct config_value_t
* appGetConfigValue(int id
) {
22 struct config_value_t
* cur
= configApps
->head
;
31 static char* appGetELFName(char* name
) {
32 // Looking for the ELF name
33 char* pos
= strrchr(name
, '/');
35 pos
= strrchr(name
, ':');
47 configApps
= configGetByType(CONFIG_APPS
);
49 appItemList
.enabled
= 1;
52 item_list_t
* appGetObject(int initOnly
) {
53 if (initOnly
&& !appItemList
.enabled
)
58 static int appNeedsUpdate(void) {
67 static int appUpdateItemList(void) {
69 configClear(configApps
);
70 configRead(configApps
);
72 if (configApps
->head
) {
73 struct config_value_t
* cur
= configApps
->head
;
82 static int appGetItemCount(void) {
86 static char* appGetItemName(int id
) {
87 struct config_value_t
* cur
= appGetConfigValue(id
);
91 static int appGetItemNameLength(int id
) {
95 static char* appGetItemStartup(int id
) {
96 struct config_value_t
* cur
= appGetConfigValue(id
);
97 return appGetELFName(cur
->val
);
101 static void appDeleteItem(int id
) {
102 struct config_value_t
* cur
= appGetConfigValue(id
);
103 fileXioRemove(cur
->val
);
105 configApps
->modified
= 1;
106 configWrite(configApps
);
111 static void appRenameItem(int id
, char* newName
) {
112 struct config_value_t
* cur
= appGetConfigValue(id
);
115 strncpy(value
, cur
->val
, 255);
116 configRemoveKey(configApps
, cur
->key
);
117 configSetStr(configApps
, newName
, value
);
118 configWrite(configApps
);
124 static void appLaunchItem(int id
, config_set_t
* configSet
) {
125 struct config_value_t
* cur
= appGetConfigValue(id
);
126 int fd
= fioOpen(cur
->val
, O_RDONLY
);
130 int exception
= NO_EXCEPTION
;
131 if (strncmp(cur
->val
, "pfs0:", 5) == 0)
132 exception
= UNMOUNT_EXCEPTION
;
135 sprintf(filename
,"%s",cur
->val
);
136 shutdown(exception
); // CAREFUL: shutdown will call appCleanUp, so configApps/cur will be freed
137 sysExecElf(filename
, 0, NULL
);
140 guiMsgBox(_l(_STR_ERR_FILE_INVALID
), 0, NULL
);
143 static config_set_t
* appGetConfig(int id
) {
144 config_set_t
* config
= configAlloc(0, NULL
, NULL
);
145 struct config_value_t
* cur
= appGetConfigValue(id
);
146 configSetStr(config
, CONFIG_ITEM_NAME
, appGetELFName(cur
->val
));
147 configSetStr(config
, CONFIG_ITEM_LONGNAME
, cur
->key
);
148 configSetStr(config
, CONFIG_ITEM_STARTUP
, cur
->val
);
152 static int appGetImage(char* folder
, int isRelative
, char* value
, char* suffix
, GSTEXTURE
* resultTex
, short psm
) {
153 value
= appGetELFName(value
);
154 // We search on ever devices from fatest to slowest (HDD > ETH > USB)
155 static item_list_t
*listSupport
= NULL
;
156 if ( (listSupport
= hddGetObject(1)) ) {
157 if (listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
) >= 0)
161 if ( (listSupport
= ethGetObject(1)) ) {
162 if (listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
) >= 0)
166 if ( (listSupport
= usbGetObject(1)) )
167 return listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
);
172 static void appCleanUp(int exception
) {
173 if (appItemList
.enabled
) {
174 LOG("appCleanUp()\n");
178 static item_list_t appItemList
= {
179 APP_MODE
, 0, NO_COMPAT
, 0, MENU_MIN_INACTIVE_FRAMES
, "Applications", _STR_APPS
, &appInit
, &appNeedsUpdate
, &appUpdateItemList
,
181 &appGetItemCount
, NULL
, &appGetItemName
, &appGetItemNameLength
, &appGetItemStartup
, NULL
, NULL
, &appLaunchItem
,
183 &appGetItemCount
, NULL
, &appGetItemName
, &appGetItemNameLength
, &appGetItemStartup
, &appDeleteItem
, &appRenameItem
, &appLaunchItem
,
186 &appGetConfig
, &appGetImage
, &appCleanUp
, NULL
, APP_ICON
188 &appGetConfig
, &appGetImage
, &appCleanUp
, APP_ICON