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
, ':');
44 LOG("APPSUPPORT Init\n");
46 configGetInt(configGetByType(CONFIG_OPL
), "app_frames_delay", &appItemList
.delay
);
47 configApps
= configGetByType(CONFIG_APPS
);
48 appItemList
.enabled
= 1;
51 item_list_t
* appGetObject(int initOnly
) {
52 if (initOnly
&& !appItemList
.enabled
)
57 static int appNeedsUpdate(void) {
66 static int appUpdateItemList(void) {
68 configClear(configApps
);
69 configRead(configApps
);
71 if (configApps
->head
) {
72 struct config_value_t
* cur
= configApps
->head
;
81 static int appGetItemCount(void) {
85 static char* appGetItemName(int id
) {
86 struct config_value_t
* cur
= appGetConfigValue(id
);
90 static int appGetItemNameLength(int id
) {
94 static char* appGetItemStartup(int id
) {
95 struct config_value_t
* cur
= appGetConfigValue(id
);
96 return appGetELFName(cur
->val
);
100 static void appDeleteItem(int id
) {
101 struct config_value_t
* cur
= appGetConfigValue(id
);
102 fileXioRemove(cur
->val
);
104 configApps
->modified
= 1;
105 configWrite(configApps
);
110 static void appRenameItem(int id
, char* newName
) {
111 struct config_value_t
* cur
= appGetConfigValue(id
);
114 strncpy(value
, cur
->val
, 255);
115 configRemoveKey(configApps
, cur
->key
);
116 configSetStr(configApps
, newName
, value
);
117 configWrite(configApps
);
123 static void appLaunchItem(int id
, config_set_t
* configSet
) {
124 struct config_value_t
* cur
= appGetConfigValue(id
);
125 int fd
= fioOpen(cur
->val
, O_RDONLY
);
129 int exception
= NO_EXCEPTION
;
130 if (strncmp(cur
->val
, "pfs0:", 5) == 0)
131 exception
= UNMOUNT_EXCEPTION
;
134 sprintf(filename
,"%s",cur
->val
);
135 shutdown(exception
); // CAREFUL: shutdown will call appCleanUp, so configApps/cur will be freed
136 sysExecElf(filename
, 0, NULL
);
139 guiMsgBox(_l(_STR_ERR_FILE_INVALID
), 0, NULL
);
142 static config_set_t
* appGetConfig(int id
) {
143 config_set_t
* config
= configAlloc(0, NULL
, NULL
);
144 struct config_value_t
* cur
= appGetConfigValue(id
);
145 configSetStr(config
, CONFIG_ITEM_NAME
, appGetELFName(cur
->val
));
146 configSetStr(config
, CONFIG_ITEM_LONGNAME
, cur
->key
);
147 configSetStr(config
, CONFIG_ITEM_STARTUP
, cur
->val
);
151 static int appGetImage(char* folder
, int isRelative
, char* value
, char* suffix
, GSTEXTURE
* resultTex
, short psm
) {
152 value
= appGetELFName(value
);
153 // We search on ever devices from fatest to slowest (HDD > ETH > USB)
154 static item_list_t
*listSupport
= NULL
;
155 if ( (listSupport
= hddGetObject(1)) ) {
156 if (listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
) >= 0)
160 if ( (listSupport
= ethGetObject(1)) ) {
161 if (listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
) >= 0)
165 if ( (listSupport
= usbGetObject(1)) )
166 return listSupport
->itemGetImage(folder
, isRelative
, value
, suffix
, resultTex
, psm
);
171 static void appCleanUp(int exception
) {
172 if (appItemList
.enabled
) {
173 LOG("APPSUPPORT CleanUp\n");
177 static item_list_t appItemList
= {
178 APP_MODE
, 0, NO_COMPAT
, 0, MENU_MIN_INACTIVE_FRAMES
, "Applications", _STR_APPS
, &appInit
, &appNeedsUpdate
, &appUpdateItemList
,
180 &appGetItemCount
, NULL
, &appGetItemName
, &appGetItemNameLength
, &appGetItemStartup
, NULL
, NULL
, &appLaunchItem
,
182 &appGetItemCount
, NULL
, &appGetItemName
, &appGetItemNameLength
, &appGetItemStartup
, &appDeleteItem
, &appRenameItem
, &appLaunchItem
,
185 &appGetConfig
, &appGetImage
, &appCleanUp
, NULL
, APP_ICON
187 &appGetConfig
, &appGetImage
, &appCleanUp
, APP_ICON