Skip to content

Latest commit

 

History

History
258 lines (213 loc) · 6.28 KB

gui.c

File metadata and controls

258 lines (213 loc) · 6.28 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Dec 9, 2006
Dec 9, 2006
10
#include "platform.h"
11
12
13
14
15
#include "fileio.h"
typedef struct S_PLUGINLIST
{
void *lib;
Dec 7, 2006
Dec 7, 2006
16
const MojoGui *gui;
17
MojoGuiPluginPriority priority;
Nov 3, 2018
Nov 3, 2018
18
19
uint32 imglen;
uint8 *img;
20
21
22
struct S_PLUGINLIST *next;
} PluginList;
Dec 7, 2006
Dec 7, 2006
23
24
const MojoGui *GGui = NULL;
static PluginList *pluginDetails = NULL;
Aug 10, 2020
Aug 10, 2020
26
27
28
29
30
31
32
33
typedef struct StaticGuiPlugin
{
const char* name;
const MojoGuiEntryPoint entry;
} StaticGuiPlugin;
#define STATIC_GUI_PLUGIN(name) {#name, MojoGuiPlugin_##name}
static StaticGuiPlugin staticGui[] =
Mar 27, 2006
Mar 27, 2006
34
{
Nov 29, 2006
Nov 29, 2006
35
#if GUI_STATIC_LINK_STDIO
Aug 10, 2020
Aug 10, 2020
36
STATIC_GUI_PLUGIN(stdio),
Nov 29, 2006
Nov 29, 2006
37
#endif
May 6, 2009
May 6, 2009
38
#if GUI_STATIC_LINK_COCOA
Aug 10, 2020
Aug 10, 2020
39
STATIC_GUI_PLUGIN(cocoa),
Dec 1, 2006
Dec 1, 2006
40
#endif
Nov 3, 2018
Nov 3, 2018
41
#if GUI_STATIC_LINK_GTKPLUS3
Aug 10, 2020
Aug 10, 2020
42
STATIC_GUI_PLUGIN(gtkplus3),
Nov 3, 2018
Nov 3, 2018
43
#endif
May 10, 2007
May 10, 2007
44
#if GUI_STATIC_LINK_GTKPLUS2
Aug 10, 2020
Aug 10, 2020
45
STATIC_GUI_PLUGIN(gtkplus2),
May 19, 2007
May 19, 2007
46
#endif
Jun 1, 2007
Jun 1, 2007
47
#if GUI_STATIC_LINK_WWW
Aug 10, 2020
Aug 10, 2020
48
STATIC_GUI_PLUGIN(www),
Jun 1, 2007
Jun 1, 2007
49
#endif
May 19, 2007
May 19, 2007
50
#if GUI_STATIC_LINK_NCURSES
Aug 10, 2020
Aug 10, 2020
51
STATIC_GUI_PLUGIN(ncurses),
Nov 29, 2006
Nov 29, 2006
52
#endif
Aug 10, 2020
Aug 10, 2020
53
{NULL, NULL}
Mar 27, 2006
Mar 27, 2006
54
};
Aug 10, 2020
Aug 10, 2020
55
#undef STATIC_GUI_PLUGIN
Mar 27, 2006
Mar 27, 2006
56
57
Dec 7, 2006
Dec 7, 2006
58
static MojoGuiPluginPriority calcGuiPriority(const MojoGui *gui)
Mar 27, 2006
Mar 27, 2006
59
60
61
{
MojoGuiPluginPriority retval;
Nov 21, 2007
Nov 21, 2007
62
retval = gui->priority(MojoPlatform_istty());
Mar 27, 2006
Mar 27, 2006
63
64
65
66
67
// If the plugin isn't saying "don't try me at all" then see if the
// user explicitly wants this one.
if (retval != MOJOGUI_PRIORITY_NEVER_TRY)
{
Dec 10, 2006
Dec 10, 2006
68
69
70
static const char *envr = NULL;
if (envr == NULL)
envr = cmdlinestr("ui", "MOJOSETUP_UI", NULL);
Dec 7, 2006
Dec 7, 2006
71
if ((envr != NULL) && (strcasecmp(envr, gui->name()) == 0))
Mar 27, 2006
Mar 27, 2006
72
73
74
75
76
77
78
retval = MOJOGUI_PRIORITY_USER_REQUESTED;
} // if
return retval;
} // calcGuiPriority
Aug 10, 2020
Aug 10, 2020
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const MojoGui *MojoSetup_loadGuiPlugin(const uint8 *img, uint32 len, void **lib)
{
*lib = MojoPlatform_dlopen(img, len);
if (*lib != NULL)
{
void *addr = MojoPlatform_dlsym(*lib, MOJOGUI_ENTRY_POINT_STR);
MojoGuiEntryPoint entry = (MojoGuiEntryPoint) addr;
if (entry != NULL)
return entry(MOJOGUI_INTERFACE_REVISION, &GEntryPoints);
} // if
return NULL;
} // MojoSetup_loadGuiPlugin
Mar 27, 2006
Mar 27, 2006
94
95
96
97
98
99
100
101
static PluginList *initGuiPluginsByPriority(PluginList *plugins)
{
MojoGuiPluginPriority p;
for (p = MOJOGUI_PRIORITY_USER_REQUESTED; p < MOJOGUI_PRIORITY_TOTAL; p++)
{
PluginList *i;
for (i = plugins->next; i != NULL; i = i->next)
{
Nov 3, 2018
Nov 3, 2018
102
103
104
105
if (i->priority != p)
continue;
if (i->img != NULL)
Aug 10, 2020
Aug 10, 2020
106
i->gui = MojoSetup_loadGuiPlugin(i->img, i->imglen, &i->lib);
Nov 3, 2018
Nov 3, 2018
107
108
if (i->gui && i->gui->init())
May 18, 2007
May 18, 2007
109
{
Jan 12, 2008
Jan 12, 2008
110
logInfo("Selected '%0' UI.", i->gui->name());
Mar 27, 2006
Mar 27, 2006
111
return i;
May 18, 2007
May 18, 2007
112
} // if
Nov 3, 2018
Nov 3, 2018
113
114
115
116
117
if (i->lib)
{
MojoPlatform_dlclose(i->lib);
i->lib = NULL;
Aug 10, 2020
Aug 10, 2020
118
i->gui = NULL;
Nov 3, 2018
Nov 3, 2018
119
} // if
Mar 27, 2006
Mar 27, 2006
120
121
122
123
124
125
126
127
128
129
130
131
} // for
} // for
return NULL;
} // initGuiPluginsByPriority
static void deleteGuiPlugin(PluginList *plugin)
{
if (plugin != NULL)
{
if (plugin->gui)
Dec 7, 2006
Dec 7, 2006
132
plugin->gui->deinit();
Mar 27, 2006
Mar 27, 2006
133
if (plugin->lib)
Dec 9, 2006
Dec 9, 2006
134
MojoPlatform_dlclose(plugin->lib);
Nov 3, 2018
Nov 3, 2018
135
free(plugin->img);
Mar 27, 2006
Mar 27, 2006
136
137
138
139
140
free(plugin);
} // if
} // deleteGuiPlugin
Aug 10, 2020
Aug 10, 2020
141
static PluginList *addGuiPlugin(PluginList *plugins, const MojoGui *gui, MojoGuiPluginPriority priority)
Mar 27, 2006
Mar 27, 2006
142
{
Aug 10, 2020
Aug 10, 2020
143
144
145
146
147
148
PluginList *plug = xmalloc(sizeof (PluginList));
plug->lib = NULL;
plug->gui = gui;
plug->priority = priority;
plug->next = plugins->next;
plugins->next = plug;
Dec 9, 2006
Dec 9, 2006
149
Nov 3, 2018
Nov 3, 2018
150
return plug;
Aug 10, 2020
Aug 10, 2020
151
} // addGuiPlugin
Dec 9, 2006
Dec 9, 2006
152
153
154
155
156
static void loadStaticGuiPlugins(PluginList *plugins)
{
int i;
Aug 10, 2020
Aug 10, 2020
157
158
for (i = 0; staticGui[i].entry != NULL; i++)
{
Aug 10, 2020
Aug 10, 2020
159
const MojoGui *gui;
Aug 10, 2020
Aug 10, 2020
160
logInfo("Testing static GUI plugin %0", staticGui[i].name);
Aug 10, 2020
Aug 10, 2020
161
162
163
gui = staticGui[i].entry(MOJOGUI_INTERFACE_REVISION, &GEntryPoints);
if (gui != NULL)
addGuiPlugin(plugins, gui, calcGuiPriority(gui));
Aug 10, 2020
Aug 10, 2020
164
}
Mar 27, 2006
Mar 27, 2006
165
166
167
} // loadStaticGuiPlugins
Dec 9, 2006
Dec 9, 2006
168
static boolean loadDynamicGuiPlugin(PluginList *plugins, MojoArchive *ar)
Nov 3, 2018
Nov 3, 2018
170
PluginList *plug = NULL;
171
MojoInput *io = ar->openCurrentEntry(ar);
Dec 9, 2006
Dec 9, 2006
172
if (io != NULL)
Dec 9, 2006
Dec 9, 2006
174
175
const uint32 imglen = (uint32) io->length(io);
uint8 *img = (uint8 *) xmalloc(imglen);
Sep 25, 2007
Sep 25, 2007
176
const uint32 br = (uint32) io->read(io, img, imglen);
Dec 9, 2006
Dec 9, 2006
177
178
io->close(io);
if (br == imglen)
Aug 10, 2020
Aug 10, 2020
180
181
182
MojoGuiPluginPriority priority;
priority = MojoPlatform_getGuiPriority(img, imglen);
if (priority != MOJOGUI_PRIORITY_NEVER_TRY)
Nov 3, 2018
Nov 3, 2018
183
{
Aug 10, 2020
Aug 10, 2020
184
185
186
187
plug = addGuiPlugin(plugins, NULL, priority);
plug->img = img;
plug->imglen = imglen;
}
188
189
190
} // if
} // if
Nov 3, 2018
Nov 3, 2018
191
return plug != NULL;
Mar 27, 2006
Mar 27, 2006
192
} // loadDynamicGuiPlugin
Mar 27, 2006
Mar 27, 2006
195
static void loadDynamicGuiPlugins(PluginList *plugins)
May 4, 2007
May 4, 2007
197
if (GBaseArchive->enumerate(GBaseArchive))
Apr 29, 2007
Apr 29, 2007
199
const MojoArchiveEntry *entinfo;
Mar 27, 2006
Mar 27, 2006
200
while ((entinfo = GBaseArchive->enumNext(GBaseArchive)) != NULL)
Mar 27, 2006
Mar 27, 2006
202
203
if (entinfo->type != MOJOARCHIVE_ENTRY_FILE)
continue;
Nov 3, 2018
Nov 3, 2018
204
else if (strncmp(entinfo->filename, "guis/", 5) != 0)
May 4, 2007
May 4, 2007
205
206
continue;
Aug 10, 2020
Aug 10, 2020
207
logInfo("Testing dynamic GUI plugin %0", entinfo->filename);
Dec 9, 2006
Dec 9, 2006
208
loadDynamicGuiPlugin(plugins, GBaseArchive);
Mar 27, 2006
Mar 27, 2006
209
} // while
Mar 27, 2006
Mar 27, 2006
211
} // loadDynamicGuiPlugins
Dec 7, 2006
Dec 7, 2006
214
const MojoGui *MojoGui_initGuiPlugin(void)
215
216
{
PluginList plugins;
Dec 13, 2006
Dec 13, 2006
217
PluginList *i = NULL;
218
219
220
221
222
if (pluginDetails != NULL)
return pluginDetails->gui;
memset(&plugins, '\0', sizeof (plugins));
Mar 26, 2006
Mar 26, 2006
223
assert(GGui == NULL);
Mar 27, 2006
Mar 27, 2006
225
loadDynamicGuiPlugins(&plugins);
Mar 27, 2006
Mar 27, 2006
226
loadStaticGuiPlugins(&plugins);
227
228
229
230
pluginDetails = initGuiPluginsByPriority(&plugins);
// cleanout unused plugins...
Dec 13, 2006
Dec 13, 2006
231
i = plugins.next;
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
while (i != NULL)
{
PluginList *next = i->next;
if (i != pluginDetails)
deleteGuiPlugin(i);
i = next;
} // while
if (pluginDetails != NULL)
{
GGui = pluginDetails->gui;
pluginDetails->next = NULL;
} // if
return GGui;
} // MojoGui_findGuiPlugin
void MojoGui_deinitGuiPlugin(void)
{
GGui = NULL;
deleteGuiPlugin(pluginDetails);
pluginDetails = NULL;
} // MojoGui_deinitGuiPlugin
// end of gui.c ...