-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscotest.c
270 lines (219 loc) · 7.72 KB
/
discotest.c
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <stdio.h> /* for printf, NULL */
#include <stdlib.h> /* for free */
#include <string.h> /* for strdup */
#include "pnd_conf.h"
#include "pnd_container.h"
#include "pnd_apps.h"
#include "pnd_pxml.h"
#include "pnd_discovery.h"
#include "pnd_desktop.h"
#include "pnd_locate.h"
#include "pnd_utility.h"
int main ( int argc, char *argv[] ) {
char *configpath;
char *appspath;
char *overridespath;
unsigned char i;
unsigned char do_exec = 0;
unsigned char do_icon = 0;
unsigned char do_dotdesktop = 0;
char dotdesktoppath [ 1024 ] = "";
for ( i = 1; i < argc; i++ ) {
if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'e' ) {
printf ( "Will attempt a random exec.\n" );
do_exec = 1;
} else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'i' ) {
printf ( "Will attempt to extract icons.\n" );
do_icon = 1;
} else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
printf ( "Will attempt to extract dotdesktop.\n" );
do_dotdesktop = 1;
} else if ( strstr ( argv [ i ], ".desktop" ) ) {
strncpy ( dotdesktoppath, argv [ i ], 1023 );
printf ( "Will scan '%s' instead of performing discovery\n", dotdesktoppath );
} else {
printf ( "%s [-e] [-i] [-d] [dotdesktop-file]\n", argv [ 0 ] );
printf ( "-e\tOptional. Attempt to exec a random app.\n" );
printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
printf ( "dotdesktop-file\tIf path specified and ends with .desktop, try to scan that .desktop instead of pnd-discovery\n" );
exit ( 0 );
}
}
/* attempt to sort out the config file madness
*/
// attempt to fetch a sensible default searchpath for configs
configpath = pnd_conf_query_searchpath();
// attempt to fetch the apps config to pick up a searchpath
pnd_conf_handle apph;
apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
if ( apph ) {
appspath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
if ( ! appspath ) {
appspath = PND_APPS_SEARCHPATH;
}
overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
if ( ! overridespath ) {
overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
}
} else {
// couldn't find a useful app search path so use the default
appspath = PND_APPS_SEARCHPATH;
overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
}
printf ( "Apps searchpath is '%s'\n", appspath );
printf ( "Apps overrides searchpath is '%s'\n", overridespath );
/* find pnd runscript
*/
char *run_searchpath;
char *run_script;
char *pndrun;
if ( apph ) {
run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
pndrun = NULL;
if ( ! run_searchpath ) {
run_searchpath = PND_APPS_SEARCHPATH;
run_script = PND_PNDRUN_FILENAME;
}
} else {
run_searchpath = NULL;
run_script = NULL;
pndrun = PND_PNDRUN_DEFAULT;
}
if ( ! pndrun ) {
pndrun = pnd_locate_filename ( run_searchpath, run_script );
}
if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
/* attempt to discover apps in the path
*/
pnd_box_handle applist;
if ( dotdesktoppath [ 0 ] ) {
pnd_disco_t *p = pnd_parse_dotdesktop ( dotdesktoppath, PND_DOTDESKTOP_LIBPND_ONLY );
pnd_box_handle disco_box = pnd_box_new ( "discovery" );
if ( p ) {
pnd_disco_t *ai = pnd_box_allocinsert ( disco_box, dotdesktoppath, sizeof(pnd_disco_t) );
memmove ( ai, p, sizeof(pnd_disco_t) );
}
applist = disco_box;
} else {
applist = pnd_disco_search ( appspath, overridespath );
}
// list the found apps (if any)
if ( applist ) {
pnd_disco_t *d = pnd_box_get_head ( applist );
while ( d ) {
// display the app 'as is'
printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
printf ( " Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
if ( d -> title_en ) {
printf ( " Name EN: %s\n", d -> title_en );
}
if ( d -> desc_en ) {
printf ( " Desc EN: %s\n", d -> desc_en );
}
if ( d -> icon ) {
printf ( " Icon: %s\n", d -> icon );
}
if ( d -> pnd_icon_pos ) {
printf ( " Icon in pnd might be at: %u\n", d -> pnd_icon_pos );
}
if ( d -> unique_id ) {
printf ( " Unique ID: %s\n", d -> unique_id );
}
if ( d -> main_category ) {
printf ( " Category: %s\n", d -> main_category );
}
if ( d -> exec ) {
printf ( " Executable: %s\n", d -> exec );
}
if ( d -> startdir ) {
printf ( " Start dir: %s\n", d -> startdir );
}
if ( d -> clockspeed ) {
printf ( " Clockspeed: %s\n", d -> clockspeed );
}
if ( d -> preview_pic1 ) {
printf ( " Preview Pic 1: %s\n", d -> preview_pic1 );
}
if ( d -> preview_pic2 ) {
printf ( " Preview Pic 2: %s\n", d -> preview_pic2 );
}
if ( d -> mkdir_sp ) {
printf ( " mkdir requests: %s\n", d -> mkdir_sp );
}
if ( do_icon ) {
if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
printf ( " -> icon dump succeeded\n" );
// fix up icon path to new one..
free ( d -> icon );
char buffer [ FILENAME_MAX ];
sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
d -> icon = strdup ( buffer );
} else {
printf ( " -> icon dump failed\n" );
}
}
if ( do_dotdesktop ) {
if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
printf ( " -> dotdesktop dump succeeded\n" );
} else {
printf ( " -> dotdesktop dump failed\n" );
}
}
// free current disco <o/
pnd_disco_destroy( d );
// next!
d = pnd_box_get_next ( d );
} // while applist
// delete our search
pnd_box_delete( applist );
} else {
printf ( "No applications found in search path\n" );
}
// lets toy with executing an application
if ( do_exec ) {
if ( ! pndrun ) {
printf ( "*** Couldn't locate a pnd runscript.\n" );
} else {
printf ( "Found a pnd runscript of %s\n", pndrun );
pnd_disco_t *d = pnd_box_get_head ( applist );
if ( d ) {
d = pnd_box_get_next ( d );
if ( d ) {
char fullpath [ FILENAME_MAX ];
if ( d -> object_type == pnd_object_type_directory ) {
sprintf ( fullpath, "%s", d -> object_path );
} else if ( d -> object_type == pnd_object_type_pnd ) {
sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
}
printf ( "Guessing appdata path..\n" );
char appdata_path [ 1024 ];
pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 );
printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path );
if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) {
printf ( " Appdata should be: %s\n", appdata_path );
} else {
printf ( " Error determining appdata path..\n" );
}
printf ( "Trying to exec '%s'\n", fullpath );
pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, NULL, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
}
}
}
} // do_exec?
// exeunt with alarums
free ( configpath );
if ( apph ) {
pnd_box_delete ( apph );
}
// extra testing - tilde-substitution
printf ( "Unrelated test..\n" );
char *p = strdup ( "~/.applications" );
printf ( "Tilde substitution: in '%s'\n", p );
char *expand = pnd_expand_tilde ( p );
printf ( " out '%s'\n", expand ); free(expand);
return ( 0 );
}