2 Copyright © 2013-2015, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/locale.h>
11 #include <libraries/mui.h>
12 #include <zune/customclasses.h>
13 #include <zune/prefseditor.h>
14 #include <libraries/asl.h>
17 #include <proto/exec.h>
18 #include <proto/intuition.h>
19 #include <proto/utility.h>
20 #include <proto/muimaster.h>
21 #include <proto/dos.h>
27 #include "booteditor.h"
29 #include <proto/alib.h>
31 #define DEFAULT_WIDTH 1024
32 #define DEFAULT_HEIGHT 768
33 #define DEFAULT_REFRESH 60
34 #define MAX_LINE_LENGTH 500
36 static const TEXT grub_config_path
[] = "SYS:boot/pc/grub/grub.cfg";
37 static const TEXT grub_config_path_tmp
[] = "SYS:boot/pc/grub/grub.cfg.tmp";
38 static const TEXT accept_nums
[] = "0123456789";
39 static CONST_STRPTR ata_buses_list
[5] = {NULL
};
40 static CONST_STRPTR debug_output_list
[4] = {NULL
};
41 static CONST_STRPTR gfx_type_list
[5] = {NULL
};
42 static CONST_STRPTR vesa_depth_list
[4] = {NULL
};
43 static CONST_STRPTR entry_tabs
[3] = {NULL
};
45 struct BootEditor_DATA
55 *vesa_default_refresh
,
83 static struct Hook module_display_hook
;
85 static BOOL
ReadBootArgs(CONST_STRPTR line
, struct BootEditor_DATA
*data
);
86 static BOOL
WriteBootArgs(BPTR file
, struct BootEditor_DATA
*data
);
87 static BOOL
ReadModule(CONST_STRPTR line
, struct BootEditor_DATA
*data
);
88 static BOOL
WriteModule(Object
*obj
, BPTR file
, struct module_entry
*entry
);
89 AROS_UFP3S(LONG
, ModuleDisplayHook
,
90 AROS_UFPA(struct Hook
*, hook
, A0
),
91 AROS_UFPA(char **, array
, A2
),
92 AROS_UFPA(struct module_entry
*, entry
, A1
));
94 static Object
*BootEditor__OM_NEW(Class
*CLASS
, Object
*self
,
95 struct opSet
*message
)
97 struct BootEditor_DATA temp_data
, *data
= &temp_data
;
99 module_display_hook
.h_Entry
= HookEntry
;
100 module_display_hook
.h_SubEntry
= (HOOKFUNC
)ModuleDisplayHook
;
102 entry_tabs
[0] = _(MSG_OPTIONS
);
103 entry_tabs
[1] = _(MSG_MODULES
);
105 gfx_type_list
[0] = _(MSG_GFX_TYPE_AUTO
);
106 gfx_type_list
[1] = _(MSG_GFX_TYPE_NATIVE
);
107 gfx_type_list
[2] = _(MSG_GFX_TYPE_VESA
);
108 gfx_type_list
[3] = _(MSG_GFX_TYPE_VGA
);
110 vesa_depth_list
[0] = _(MSG_GFX_DEPTH_TRUE
);
111 vesa_depth_list
[1] = _(MSG_GFX_DEPTH_HIGH
);
112 vesa_depth_list
[2] = _(MSG_GFX_DEPTH_LOW
);
114 ata_buses_list
[0] = _(MSG_ATA_BUS_ALL
);
115 ata_buses_list
[1] = _(MSG_ATA_BUS_PCI
);
116 ata_buses_list
[2] = _(MSG_ATA_BUS_LEGACY
);
117 ata_buses_list
[3] = _(MSG_ATA_BUS_NONE
);
119 debug_output_list
[0] = _(MSG_DEBUG_OUTPUT_NONE
);
120 debug_output_list
[1] = _(MSG_DEBUG_OUTPUT_MEMORY
);
121 debug_output_list
[2] = _(MSG_DEBUG_OUTPUT_SERIAL
);
123 self
= (Object
*)DoSuperNewTags(CLASS
, self
, NULL
,
124 MUIA_PrefsEditor_Name
, __(MSG_NAME
),
125 MUIA_PrefsEditor_Path
, (IPTR
)grub_config_path
,
126 MUIA_PrefsEditor_CanTest
, FALSE
,
127 MUIA_PrefsEditor_CanUse
, FALSE
,
129 Child
, (IPTR
)RegisterGroup(entry_tabs
),
133 Child
, (IPTR
)ColGroup(2),
135 GroupFrameT(_(MSG_GFX
)),
136 Child
, (IPTR
)ColGroup(2),
137 Child
, (IPTR
)Label2(__(MSG_GFX_TYPE
)),
138 Child
, (IPTR
)(data
->gfx_type
= (Object
*)CycleObject
,
139 MUIA_Cycle_Entries
, (IPTR
)gfx_type_list
,
141 Child
, (IPTR
)(data
->gfx_composition
=
142 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
144 Child
, (IPTR
)Label2(__(MSG_GFX_COMPOSITION
)),
145 Child
, (IPTR
)HVSpace
,
147 Child
, (IPTR
)HVSpace
,
148 Child
, (IPTR
)HVSpace
,
150 Child
, (IPTR
)(data
->vesa_group
= VGroup
,
151 GroupFrameT(_(MSG_GFX_VESAMODE
)),
153 Child
, (IPTR
)(data
->vesa_best_res
=
154 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
155 Child
, (IPTR
)Label2(__(MSG_GFX_BESTRES
)),
156 Child
, (IPTR
)HVSpace
,
158 Child
, (IPTR
)ColGroup(2),
159 Child
, (IPTR
)Label2(__(MSG_GFX_WIDTH
)),
161 Child
, (IPTR
)(data
->vesa_width
=
162 (Object
*)StringObject
,
165 MUIA_String_Accept
, (IPTR
)accept_nums
,
166 MUIA_FixWidthTxt
, (IPTR
)"00000",
168 Child
, (IPTR
)HVSpace
,
170 Child
, (IPTR
)Label2(__(MSG_GFX_HEIGHT
)),
172 Child
, (IPTR
)(data
->vesa_height
=
173 (Object
*)StringObject
,
176 MUIA_String_Accept
, (IPTR
)accept_nums
,
177 MUIA_FixWidthTxt
, (IPTR
)"00000",
179 Child
, (IPTR
)HVSpace
,
181 Child
, (IPTR
)Label2(__(MSG_GFX_DEPTH
)),
182 Child
, (IPTR
)(data
->vesa_depth
=
183 (Object
*)CycleObject
,
184 MUIA_Cycle_Entries
, (IPTR
)vesa_depth_list
,
186 Child
, (IPTR
)Label2(__(MSG_GFX_REFRESH
)),
188 Child
, (IPTR
)(data
->vesa_refresh
=
189 (Object
*)StringObject
,
192 MUIA_String_Accept
, (IPTR
)accept_nums
,
193 MUIA_FixWidthTxt
, (IPTR
)"0000",
195 Child
, (IPTR
)Label2(__(MSG_GFX_HERTZ
)),
196 Child
, (IPTR
)HVSpace
,
200 Child
, (IPTR
)(data
->vesa_default_refresh
=
201 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
202 Child
, (IPTR
)Label2(__(MSG_GFX_DEFAULTREFRESH
)),
203 Child
, (IPTR
)HVSpace
,
209 GroupFrameT(_(MSG_ATA
)),
211 Child
, (IPTR
)Label2(__(MSG_ATA_BUSES
)),
212 Child
, (IPTR
)(data
->ata_buses
=
213 (Object
*)CycleObject
,
214 MUIA_Cycle_Entries
, (IPTR
)ata_buses_list
,
217 Child
, (IPTR
)ColGroup(2),
218 Child
, (IPTR
)(data
->ata_dma
=
219 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
221 Child
, (IPTR
)Label2(__(MSG_ATA_DMA
)),
222 Child
, (IPTR
)HVSpace
,
224 Child
, (IPTR
)(data
->ata_multi
=
225 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
227 Child
, (IPTR
)Label2(__(MSG_ATA_MULTI
)),
228 Child
, (IPTR
)HVSpace
,
230 Child
, (IPTR
)(data
->ata_32bit
=
231 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
233 Child
, (IPTR
)Label2(__(MSG_ATA_32BIT
)),
234 Child
, (IPTR
)HVSpace
,
236 Child
, (IPTR
)(data
->ata_poll
=
237 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
239 Child
, (IPTR
)Label2(__(MSG_ATA_POLL
)),
240 Child
, (IPTR
)HVSpace
,
242 Child
, (IPTR
)HVSpace
,
243 Child
, (IPTR
)HVSpace
,
247 GroupFrameT(_(MSG_DEVICE
)),
248 Child
, (IPTR
)ColGroup(2),
249 Child
, (IPTR
)Label2(__(MSG_DEVICE_NAME
)),
251 Child
, (IPTR
)(data
->device_name
=
252 (Object
*)StringObject
,
255 MUIA_String_Reject
, (IPTR
)":; ",
256 MUIA_FixWidthTxt
, (IPTR
)"000000000",
258 Child
, (IPTR
)HVSpace
,
260 Child
, (IPTR
)Label2(__(MSG_DEVICE_DELAY
)),
262 Child
, (IPTR
)(data
->device_delay
=
263 (Object
*)StringObject
,
266 MUIA_String_Accept
, (IPTR
)accept_nums
,
267 MUIA_FixWidthTxt
, (IPTR
)"000",
269 Child
, (IPTR
)Label2(__(MSG_DEVICE_SECONDS
)),
270 Child
, (IPTR
)HVSpace
,
275 Child
, (IPTR
)ColGroup(2),
276 GroupFrameT(_(MSG_MISC
)),
277 Child
, (IPTR
)(data
->usb_enable
=
278 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
280 Child
, (IPTR
)Label2(__(MSG_USB_ENABLE
)),
281 Child
, (IPTR
)HVSpace
,
283 Child
, (IPTR
)(data
->acpi_enable
=
284 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
286 Child
, (IPTR
)Label2(__(MSG_ACPI_ENABLE
)),
287 Child
, (IPTR
)HVSpace
,
289 Child
, (IPTR
)(data
->floppy_enable
=
290 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
292 Child
, (IPTR
)Label2(__(MSG_FLOPPY_ENABLE
)),
293 Child
, (IPTR
)HVSpace
,
295 Child
, (IPTR
)HVSpace
,
296 Child
, (IPTR
)HVSpace
,
299 GroupFrameT(_(MSG_DEBUG
)),
301 Child
, (IPTR
)Label2(__(MSG_DEBUG_OUTPUT
)),
302 Child
, (IPTR
)(data
->debug_output
=
303 (Object
*)CycleObject
,
304 MUIA_Cycle_Entries
, (IPTR
)debug_output_list
,
307 Child
, (IPTR
)ColGroup(2),
308 Child
, (IPTR
)(data
->debug_mungwall
=
309 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
311 Child
, (IPTR
)Label2(__(MSG_DEBUG_MUNGWALL
)),
312 Child
, (IPTR
)HVSpace
,
314 Child
, (IPTR
)(data
->debug_usb
=
315 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
317 Child
, (IPTR
)Label2(__(MSG_DEBUG_USB
)),
318 Child
, (IPTR
)HVSpace
,
321 Child
, (IPTR
)HVSpace
,
328 Child
, (IPTR
)ListviewObject
,
329 MUIA_Listview_List
, (IPTR
)(data
->module_list
=
330 (Object
*)ListObject
,
332 MUIA_List_AutoVisible
, TRUE
,
333 MUIA_List_Title
, TRUE
,
334 MUIA_List_Format
, (IPTR
)"P=\033c BAR,",
335 MUIA_List_DisplayHook
, (IPTR
)&module_display_hook
,
341 Child
, (IPTR
)(data
->add_button
=
342 SimpleButton(_(MSG_ADD
))),
343 Child
, (IPTR
)(data
->remove_button
=
344 SimpleButton(_(MSG_REMOVE
))),
348 Child
, (IPTR
)Label2(__(MSG_PATH
)),
349 Child
, (IPTR
)(data
->module_pop_string
= PopaslObject
,
350 MUIA_Popasl_Type
, ASL_FileRequest
,
351 MUIA_Popstring_String
,
352 (IPTR
)(data
->module_path
=
353 (Object
*)StringObject
,
355 MUIA_Background
, MUII_TextBack
,
359 MUIA_Popstring_Button
,
360 (IPTR
)PopButton(MUII_PopFile
),
362 Child
, (IPTR
)(data
->module_active
=
363 MUI_MakeObject(MUIO_Checkmark
, NULL
)),
364 Child
, (IPTR
)Label2(_(MSG_ACTIVE
)),
375 data
= INST_DATA(CLASS
, self
);
378 /* Set up notifications */
380 DoMethod(data
->gfx_type
, MUIM_Notify
,
381 MUIA_Cycle_Active
, MUIV_EveryTime
,
382 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
383 DoMethod(data
->gfx_composition
, MUIM_Notify
,
384 MUIA_Selected
, MUIV_EveryTime
,
385 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
386 DoMethod(data
->vesa_width
, MUIM_Notify
,
387 MUIA_String_Acknowledge
, MUIV_EveryTime
,
388 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
389 DoMethod(data
->vesa_height
, MUIM_Notify
,
390 MUIA_String_Acknowledge
, MUIV_EveryTime
,
391 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
392 DoMethod(data
->vesa_depth
, MUIM_Notify
,
393 MUIA_Cycle_Active
, MUIV_EveryTime
,
394 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
395 DoMethod(data
->vesa_refresh
, MUIM_Notify
,
396 MUIA_String_Acknowledge
, MUIV_EveryTime
,
397 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
398 DoMethod(data
->vesa_default_refresh
, MUIM_Notify
,
399 MUIA_Selected
, MUIV_EveryTime
,
400 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
401 DoMethod(data
->vesa_best_res
, MUIM_Notify
,
402 MUIA_Selected
, MUIV_EveryTime
,
403 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
404 DoMethod(data
->ata_buses
, MUIM_Notify
,
405 MUIA_Cycle_Active
, MUIV_EveryTime
,
406 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
407 DoMethod(data
->ata_dma
, MUIM_Notify
,
408 MUIA_Selected
, MUIV_EveryTime
,
409 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
410 DoMethod(data
->ata_multi
, MUIM_Notify
,
411 MUIA_Selected
, MUIV_EveryTime
,
412 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
413 DoMethod(data
->ata_32bit
, MUIM_Notify
,
414 MUIA_Selected
, MUIV_EveryTime
,
415 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
416 DoMethod(data
->ata_poll
, MUIM_Notify
,
417 MUIA_Selected
, MUIV_EveryTime
,
418 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
419 DoMethod(data
->device_name
, MUIM_Notify
,
420 MUIA_String_Acknowledge
, MUIV_EveryTime
,
421 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
422 DoMethod(data
->device_delay
, MUIM_Notify
,
423 MUIA_String_Acknowledge
, MUIV_EveryTime
,
424 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
425 DoMethod(data
->usb_enable
, MUIM_Notify
,
426 MUIA_Selected
, MUIV_EveryTime
,
427 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
428 DoMethod(data
->acpi_enable
, MUIM_Notify
,
429 MUIA_Selected
, MUIV_EveryTime
,
430 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
431 DoMethod(data
->floppy_enable
, MUIM_Notify
,
432 MUIA_Selected
, MUIV_EveryTime
,
433 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
434 DoMethod(data
->debug_output
, MUIM_Notify
,
435 MUIA_Cycle_Active
, MUIV_EveryTime
,
436 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
437 DoMethod(data
->debug_mungwall
, MUIM_Notify
,
438 MUIA_Selected
, MUIV_EveryTime
,
439 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
440 DoMethod(data
->debug_usb
, MUIM_Notify
,
441 MUIA_Selected
, MUIV_EveryTime
,
442 (IPTR
)self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
444 DoMethod(data
->gfx_type
, MUIM_Notify
,
445 MUIA_Cycle_Active
, 0,
446 (IPTR
)data
->vesa_group
, 3, MUIM_Set
, MUIA_Disabled
, FALSE
);
447 DoMethod(data
->gfx_type
, MUIM_Notify
,
448 MUIA_Cycle_Active
, 1,
449 (IPTR
)data
->vesa_group
, 3, MUIM_Set
, MUIA_Disabled
, TRUE
);
450 DoMethod(data
->gfx_type
, MUIM_Notify
,
451 MUIA_Cycle_Active
, 2,
452 (IPTR
)data
->vesa_group
, 3, MUIM_Set
, MUIA_Disabled
, FALSE
);
453 DoMethod(data
->gfx_type
, MUIM_Notify
,
454 MUIA_Cycle_Active
, 3,
455 (IPTR
)data
->vesa_group
, 3, MUIM_Set
, MUIA_Disabled
, TRUE
);
457 DoMethod(data
->vesa_default_refresh
, MUIM_Notify
,
458 MUIA_Selected
, MUIV_EveryTime
,
459 (IPTR
)data
->vesa_refresh
, 3, MUIM_Set
, MUIA_Disabled
,
461 DoMethod(data
->vesa_best_res
, MUIM_Notify
,
462 MUIA_Selected
, MUIV_EveryTime
,
463 (IPTR
)data
->vesa_width
, 3, MUIM_Set
, MUIA_Disabled
,
465 DoMethod(data
->vesa_best_res
, MUIM_Notify
,
466 MUIA_Selected
, MUIV_EveryTime
,
467 (IPTR
)data
->vesa_height
, 3, MUIM_Set
, MUIA_Disabled
,
470 DoMethod(data
->module_list
, MUIM_Notify
, MUIA_List_Active
,
471 MUIV_EveryTime
, (IPTR
)self
, 1, MUIM_BootEditor_ShowModule
);
472 DoMethod(data
->module_path
, MUIM_Notify
, MUIA_String_Contents
,
473 MUIV_EveryTime
, (IPTR
)self
, 1, MUIM_BootEditor_UpdateModule
);
474 DoMethod(data
->module_active
, MUIM_Notify
, MUIA_Selected
,
475 MUIV_EveryTime
, (IPTR
)self
, 1, MUIM_BootEditor_UpdateModule
);
476 DoMethod(data
->add_button
, MUIM_Notify
, MUIA_Pressed
,
477 TRUE
, (IPTR
)self
, 1, MUIM_BootEditor_AddModule
);
478 DoMethod(data
->remove_button
, MUIM_Notify
, MUIA_Pressed
, TRUE
,
479 (IPTR
)self
, 1, MUIM_BootEditor_RemoveModule
);
481 /* Set default values */
483 SET(data
->gfx_composition
, MUIA_Selected
, TRUE
);
484 SET(data
->vesa_width
, MUIA_String_Integer
, DEFAULT_WIDTH
);
485 SET(data
->vesa_height
, MUIA_String_Integer
, DEFAULT_HEIGHT
);
486 SET(data
->vesa_refresh
, MUIA_String_Integer
, DEFAULT_REFRESH
);
488 SET(data
->ata_dma
, MUIA_Selected
, TRUE
);
489 SET(data
->ata_multi
, MUIA_Selected
, TRUE
);
490 SET(data
->ata_32bit
, MUIA_Selected
, TRUE
);
492 SET(data
->device_delay
, MUIA_String_Integer
, 0);
494 SET(data
->usb_enable
, MUIA_Selected
, TRUE
);
495 SET(data
->acpi_enable
, MUIA_Selected
, TRUE
);
497 SET(data
->remove_button
, MUIA_Disabled
, TRUE
);
498 SET(data
->module_active
, MUIA_Disabled
, TRUE
);
499 SET(data
->module_pop_string
, MUIA_Disabled
, TRUE
);
505 static IPTR
BootEditor__MUIM_Setup(Class
*CLASS
, Object
*self
, Msg message
)
507 if (!DoSuperMethodA(CLASS
, self
, message
))
513 static IPTR
BootEditor__MUIM_Cleanup(Class
*CLASS
, Object
*self
, Msg message
)
515 return DoSuperMethodA(CLASS
, self
, message
);
518 static IPTR
BootEditor__MUIM_PrefsEditor_ImportFH(Class
*CLASS
, Object
*self
,
519 struct MUIP_PrefsEditor_ImportFH
*message
)
521 struct BootEditor_DATA
*data
= INST_DATA(CLASS
, self
);
523 TEXT line_buffer
[MAX_LINE_LENGTH
], *line
;
524 BOOL success
= TRUE
, done
= FALSE
;
526 /* Find first AROS boot entry, parse its arguments and put them in
529 file
= Open(grub_config_path
, MODE_OLDFILE
);
537 line
= FGets(file
, line_buffer
, MAX_LINE_LENGTH
);
540 else if (strstr(line
, "multiboot") != NULL
541 && strstr(line
, "bootstrap") != NULL
)
543 if (!ReadBootArgs(line
, data
))
546 else if (strstr(line
, "module ") != NULL
)
548 if (!ReadModule(line
, data
))
551 if (strstr(line
, "}") != NULL
)
562 static IPTR
BootEditor__MUIM_PrefsEditor_ExportFH(Class
*CLASS
, Object
*self
,
563 struct MUIP_PrefsEditor_ExportFH
*message
)
568 static IPTR
BootEditor__MUIM_PrefsEditor_Save(Class
*CLASS
, Object
*self
,
571 struct BootEditor_DATA
*data
= INST_DATA(CLASS
, self
);
572 BPTR old_file
, new_file
;
573 TEXT line_buffer
[MAX_LINE_LENGTH
], *line
;
574 BOOL success
= TRUE
, done
= FALSE
, found
= FALSE
;
575 struct module_entry
*module
;
578 /* Find first AROS boot entry and replace its arguments with those
579 * chosen in the GUI */
581 old_file
= Open(grub_config_path
, MODE_OLDFILE
);
582 new_file
= Open(grub_config_path_tmp
, MODE_NEWFILE
);
583 if (old_file
== BNULL
&& new_file
== BNULL
)
590 line
= FGets(old_file
, line_buffer
, MAX_LINE_LENGTH
);
593 else if (!found
&& strstr(line
, "multiboot") != NULL
594 && strstr(line
, "bootstrap") != NULL
)
596 strstr(line
, ".gz")[3] = '\0';
597 if (FPuts(new_file
, line
) != 0)
599 else if (!WriteBootArgs(new_file
, data
))
603 /* Skip past all module lines */
607 line
= FGets(old_file
, line_buffer
, MAX_LINE_LENGTH
);
610 else if (strchr(line
, '}') != NULL
)
614 /* Write new module lines */
616 for (i
= 0; success
&& DoMethod(data
->module_list
,
617 MUIM_List_GetEntry
, i
, &module
) != (IPTR
)NULL
; i
++)
619 if (!WriteModule(self
, new_file
, module
))
623 /* Keep line with closing curly bracket */
625 if (FPuts(new_file
, line
) != 0)
630 if (FPuts(new_file
, line
) != 0)
635 /* Close both files */
637 if (old_file
!= NULL
)
639 if (new_file
!= NULL
)
640 if (!Close(new_file
))
643 /* Replace old file with new one */
646 success
= DeleteFile(grub_config_path
);
649 success
= Rename(grub_config_path_tmp
, grub_config_path
);
654 IPTR
BootEditor__MUIM_BootEditor_ShowModule(Class
*cl
, Object
*self
,
657 struct BootEditor_DATA
*data
= INST_DATA(cl
, self
);
658 struct module_entry
*module
;
661 DoMethod(data
->module_list
, MUIM_List_GetEntry
,
662 MUIV_List_GetEntry_Active
, &module
);
663 show
= module
!= NULL
;
664 SET(data
->module_pop_string
, MUIA_Disabled
, !show
);
665 SET(data
->module_active
, MUIA_Disabled
, !show
);
666 NNSET(data
->module_path
, MUIA_String_Contents
,
667 (IPTR
)(show
? module
->path
: NULL
));
668 NNSET(data
->module_active
, MUIA_Selected
, show
? module
->active
: FALSE
);
669 SET(data
->remove_button
, MUIA_Disabled
, !show
);
674 IPTR
BootEditor__MUIM_BootEditor_UpdateModule(Class
*cl
, Object
*self
,
677 struct BootEditor_DATA
*data
= INST_DATA(cl
, self
);
678 struct module_entry
*module
;
680 DoMethod(data
->module_list
, MUIM_List_GetEntry
,
681 MUIV_List_GetEntry_Active
, &module
);
684 FreeVec(module
->path
);
686 StrDup((APTR
)XGET(data
->module_path
, MUIA_String_Contents
));
687 module
->active
= XGET(data
->module_active
, MUIA_Selected
);
688 DoMethod(data
->module_list
, MUIM_List_Redraw
,
689 MUIV_List_Redraw_Active
);
694 IPTR
BootEditor__MUIM_BootEditor_AddModule(Class
*cl
, Object
*self
,
697 struct BootEditor_DATA
*data
= INST_DATA(cl
, self
);
698 struct module_entry
*module
;
701 module
= AllocMem(sizeof(struct module_entry
), MEMF_CLEAR
);
707 module
->path
= StrDup("");
708 if (module
->path
== NULL
)
710 module
->active
= TRUE
;
715 if (DoMethod(data
->module_list
, MUIM_List_InsertSingle
, module
,
716 MUIV_List_Insert_Bottom
) == -1)
718 SET(data
->module_list
, MUIA_List_Active
, MUIV_List_Active_Bottom
);
724 IPTR
BootEditor__MUIM_BootEditor_RemoveModule(Class
*cl
, Object
*self
,
727 struct BootEditor_DATA
*data
= INST_DATA(cl
, self
);
728 struct module_entry
*module
;
730 /* Remove entry from list and deallocate it */
732 DoMethod(data
->module_list
, MUIM_List_GetEntry
,
733 MUIV_List_GetEntry_Active
, &module
);
736 DoMethod(data
->module_list
, MUIM_List_Remove
,
737 MUIV_List_Remove_Active
);
738 FreeVec(module
->path
);
739 FreeMem(module
, sizeof(struct module_entry
));
745 static BOOL
ReadBootArgs(CONST_STRPTR line
, struct BootEditor_DATA
*data
)
747 UWORD choice
, width
= 0, height
= 0, depth
= 0, refresh
= 0, delay
= 0;
748 BOOL success
= TRUE
, best_res
= FALSE
, use_refresh
= FALSE
;
754 if (strstr(line
, "nomonitors") != NULL
755 && strstr(line
, "vesa=") == NULL
)
757 else if (strstr(line
, "nomonitors") != NULL
)
759 else if (strstr(line
, "vesa=") == NULL
)
763 SET(data
->gfx_type
, MUIA_Cycle_Active
, choice
);
765 NNSET(data
->gfx_composition
, MUIA_Selected
,
766 strstr(line
, "nocomposition") == NULL
);
770 options
= strstr(line
, "vesa=");
775 while (*options
>= '0' && *options
<= '9')
776 width
= width
* 10 + *options
++ - '0';
777 if (*options
++ == 'x')
779 while (*options
>= '0' && *options
<= '9')
780 height
= height
* 10 + *options
++ - '0';
781 if (*options
++ == 'x')
783 while (*options
>= '0' && *options
<= '9')
784 depth
= depth
* 10 + *options
++ - '0';
791 depth
= width
, width
= DEFAULT_WIDTH
, height
= DEFAULT_HEIGHT
;
794 NNSET(data
->vesa_width
, MUIA_String_Integer
, width
);
795 NNSET(data
->vesa_height
, MUIA_String_Integer
, height
);
796 SET(data
->vesa_best_res
, MUIA_Selected
, best_res
);
798 /* Check for user-set refresh rate */
800 if (*(options
- 1) == '@')
802 while (*options
>= '0' && *options
<= '9')
803 refresh
= refresh
* 10 + *options
++ - '0';
807 refresh
= DEFAULT_REFRESH
;
809 NNSET(data
->vesa_refresh
, MUIA_String_Integer
, refresh
);
810 SET(data
->vesa_default_refresh
, MUIA_Selected
, !use_refresh
);
818 NNSET(data
->vesa_depth
, MUIA_Cycle_Active
, choice
);
823 options
= strstr(line
, "ATA=");
826 if (strstr(options
, "nopci") != NULL
827 && strstr(options
, "nolegacy") != NULL
)
829 else if (strstr(options
, "nopci") != NULL
)
831 else if (strstr(options
, "nolegacy") != NULL
)
835 NNSET(data
->ata_buses
, MUIA_Cycle_Active
, choice
);
837 if (strstr(options
, "nodma") != NULL
)
838 NNSET(data
->ata_dma
, MUIA_Selected
, FALSE
);
839 if (strstr(options
, "nomulti") != NULL
)
840 NNSET(data
->ata_multi
, MUIA_Selected
, FALSE
);
841 if (strstr(options
, "32bit") == NULL
)
842 NNSET(data
->ata_multi
, MUIA_Selected
, FALSE
);
843 if (strstr(options
, "poll") != NULL
)
844 NNSET(data
->ata_poll
, MUIA_Selected
, TRUE
);
849 options
= strstr(line
, "bootdevice=");
854 for (p
= options
; *p
!= ' ' && *p
!= '\n' && *p
!= '\0'; p
++);
857 NNSET(data
->device_name
, MUIA_String_Contents
, options
);
861 options
= strstr(line
, "bootdelay=");
866 while (*options
>= '0' && *options
<= '9')
867 delay
= delay
* 10 + *options
++ - '0';
869 NNSET(data
->device_delay
, MUIA_String_Integer
, delay
);
873 NNSET(data
->usb_enable
, MUIA_Selected
,
874 strstr(line
, "enableusb") != NULL
);
875 NNSET(data
->acpi_enable
, MUIA_Selected
,
876 strstr(line
, "noacpi") == NULL
);
877 NNSET(data
->floppy_enable
, MUIA_Selected
,
878 strstr(line
, "floppy=disabled") == NULL
);
882 if (strstr(line
, "debug=serial") != NULL
)
884 else if (strstr(line
, "debug=memory") != NULL
)
888 NNSET(data
->debug_output
, MUIA_Cycle_Active
, choice
);
890 NNSET(data
->debug_mungwall
, MUIA_Selected
,
891 strstr(line
, "mungwall") != NULL
);
892 NNSET(data
->debug_usb
, MUIA_Selected
,
893 strstr(line
, "usbdebug") != NULL
);
898 static BOOL
WriteBootArgs(BPTR file
, struct BootEditor_DATA
*data
)
900 UWORD count
, choice
, width
, height
, depth
, delay
;
902 CONST_STRPTR name
= NULL
;
906 if((XGET(data
->gfx_type
, MUIA_Cycle_Active
) & 1) == 0)
908 FPrintf(file
, " vesa=");
909 if(!XGET(data
->vesa_best_res
, MUIA_Selected
))
911 width
= XGET(data
->vesa_width
, MUIA_String_Integer
);
912 height
= XGET(data
->vesa_height
, MUIA_String_Integer
);
914 FPrintf(file
, "%ux%ux", width
, height
);
916 FPrintf(file
, "%ux", width
);
917 FPrintf(file
, "%ux", height
);
920 choice
= XGET(data
->vesa_depth
, MUIA_Cycle_Active
);
923 else if (choice
== 1)
927 FPrintf(file
, "%u", depth
);
928 if(!XGET(data
->vesa_default_refresh
, MUIA_Selected
))
929 FPrintf(file
, "@%u", XGET(data
->vesa_refresh
, MUIA_String_Integer
));
934 if(XGET(data
->gfx_type
, MUIA_Cycle_Active
) > 1)
935 FPrintf(file
, " nomonitors");
936 if(!XGET(data
->gfx_composition
, MUIA_Selected
))
937 FPrintf(file
, " nocomposition");
941 if(!XGET(data
->ata_dma
, MUIA_Selected
) ||
942 !XGET(data
->ata_multi
, MUIA_Selected
) ||
943 XGET(data
->ata_32bit
, MUIA_Selected
) ||
944 XGET(data
->ata_poll
, MUIA_Selected
) ||
945 XGET(data
->ata_buses
, MUIA_Cycle_Active
) > 0)
948 FPrintf(file
, " ATA=");
950 choice
= XGET(data
->ata_buses
, MUIA_Cycle_Active
);
953 FPrintf(file
, "nolegacy");
956 else if (choice
== 2)
958 FPrintf(file
, "nopci");
961 else if (choice
== 3)
963 FPrintf(file
, "nopci,nolegacy");
967 if(!XGET(data
->ata_dma
, MUIA_Selected
))
971 FPrintf(file
, "nodma");
974 if(!XGET(data
->ata_multi
, MUIA_Selected
))
978 FPrintf(file
, "nomulti");
981 if(XGET(data
->ata_32bit
, MUIA_Selected
))
985 FPrintf(file
, "32bit");
988 if(XGET(data
->ata_poll
, MUIA_Selected
))
992 FPrintf(file
, "poll");
999 GET(data
->device_name
, MUIA_String_Contents
, &name
);
1001 FPrintf(file
, " bootdevice=%s", name
);
1002 delay
= XGET(data
->device_delay
, MUIA_String_Integer
);
1004 FPrintf(file
, " bootdelay=%u", delay
);
1008 if(XGET(data
->usb_enable
, MUIA_Selected
))
1009 FPrintf(file
, " enableusb");
1010 if(!XGET(data
->acpi_enable
, MUIA_Selected
))
1011 FPrintf(file
, " noacpi");
1012 if(!XGET(data
->floppy_enable
, MUIA_Selected
))
1013 FPrintf(file
, " floppy=disabled");
1017 if(XGET(data
->debug_output
, MUIA_Cycle_Active
) == 1)
1018 FPrintf(file
, " debug=memory");
1019 else if(XGET(data
->debug_output
, MUIA_Cycle_Active
) == 2)
1020 FPrintf(file
, " debug=serial");
1021 if(XGET(data
->debug_mungwall
, MUIA_Selected
))
1022 FPrintf(file
, " mungwall");
1023 if(XGET(data
->debug_usb
, MUIA_Selected
))
1024 FPrintf(file
, " usbdebug");
1026 if (FPrintf(file
, "\n") < 0)
1032 static BOOL
ReadModule(CONST_STRPTR line
, struct BootEditor_DATA
*data
)
1034 BOOL success
= TRUE
;
1035 STRPTR path
, comment
;
1036 struct module_entry
*entry
;
1038 /* Parse module line */
1040 path
= strchr(line
, '/');
1041 comment
= strchr(line
, '#');
1045 /* Create module entry */
1049 entry
= AllocMem(sizeof(struct module_entry
), MEMF_CLEAR
);
1056 path
[strlen(path
) - 1] = '\0';
1057 entry
->path
= AllocVec(strlen(path
) + 4, MEMF_ANY
);
1058 if (entry
->path
== NULL
)
1064 sprintf(entry
->path
, "SYS:%s", path
+ 1);
1066 /* Mark module inactive if there's a comment character before it */
1068 entry
->active
= comment
== NULL
|| comment
> path
;
1071 /* Add module to list */
1075 if (DoMethod(data
->module_list
, MUIM_List_InsertSingle
,
1076 (IPTR
)entry
, MUIV_List_Insert_Bottom
) == -1)
1083 static BOOL
WriteModule(Object
*obj
, BPTR file
, struct module_entry
*entry
)
1085 BOOL success
= TRUE
;
1086 TEXT buffer
[MAX_LINE_LENGTH
], *path
= buffer
, *p
;
1088 Object
*app
= NULL
, *window
= NULL
;
1090 /* Convert path to canonical form */
1092 old_dir
= CurrentDir(BNULL
);
1093 lock
= Lock(entry
->path
, SHARED_LOCK
);
1096 GET(obj
, MUIA_ApplicationObject
, &app
);
1097 GET(obj
, MUIA_Window_Window
, &window
);
1099 MUI_Request(app
, window
, 0, "Error", _(MSG_OK
), _(MSG_BAD_MODULE
),
1106 if (!NameFromLock(lock
, buffer
, MAX_LINE_LENGTH
))
1113 if ((p
= strchr(buffer
, ':')) != NULL
)
1119 FPrintf(file
, "module /%s\n", path
);
1121 CurrentDir(old_dir
);
1126 AROS_UFH3S(LONG
, ModuleDisplayHook
,
1127 AROS_UFHA(struct Hook
*, hook
, A0
),
1128 AROS_UFHA(char **, array
, A2
),
1129 AROS_UFHA(struct module_entry
*, entry
, A1
))
1135 *array
++ = entry
->active
? "*" : "";
1136 *array
= entry
->path
;
1140 *array
++ = (STRPTR
)_(MSG_ACTIVE
);
1141 *array
= (STRPTR
)_(MSG_PATH
);
1151 BootEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
1152 OM_NEW
, struct opSet
*,
1155 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
1156 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
1157 MUIM_PrefsEditor_Save
, Msg
,
1158 MUIM_BootEditor_ShowModule
, Msg
,
1159 MUIM_BootEditor_UpdateModule
, Msg
,
1160 MUIM_BootEditor_AddModule
, Msg
,
1161 MUIM_BootEditor_RemoveModule
, Msg