From: srs5694 Date: Sun, 15 Dec 2013 06:05:54 +0000 (-0500) Subject: Support for multiple default_selection options, to set a series of X-Git-Url: https://code.delx.au/refind/commitdiff_plain/9f59e764bc973af9845d222cad85713395c51cf0 Support for multiple default_selection options, to set a series of values in case one isn't available. --- diff --git a/NEWS.txt b/NEWS.txt index 163936c..da463e5 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,6 +1,12 @@ 0.7.6 (12/??/2013): ------------------- +- Added support for multiple "default_selection" targets. These MUST be + comma-separated AND enclosed in quotes, as in: + default_selection "fred,ginger" + This example will launch "fred" by default if it's available; and if + it's not, rEFInd will attempt to launch "ginger" as the default. + - Added support for time-sensitive "default_selection" setting. This token may now have either one or three options. If one, it's interpreted as it has been in the past, as setting a default that's independent of times. diff --git a/docs/refind/configfile.html b/docs/refind/configfile.html index 9f78ba9..87fcbfa 100644 --- a/docs/refind/configfile.html +++ b/docs/refind/configfile.html @@ -319,7 +319,7 @@ timeout 20 default_selection a substring of a boot loader's title, or a numeric position; optionally followed by two times in HH:MM format - Sets the default boot OS based on the loader's title, which appears in the main menu beneath the icons when you select the loader. You can enter any substring of the title as the default_selection, so long as it's two or more characters in length. It's best to use a unique substring, since rEFInd stops searching when it finds the first match. Because rEFInd sorts entries within a directory in descending order by file modification time, if you specify a directory (or volume name, for loaders in a partition's root directory) as the default_selection, the most recent loader in that directory will be the default. One-character entries are matched against the first character of the title, except for digits, which refer to the numeric order of the boot loader entries. You may optionally follow the match string by two times, in 24-hour format, in which case the entry applies only between those two times. For instance, default_selection Safety 1:30 2:30 boots the entry called Safety by default between the hours of 1:30 and 2:30. These times are specified in whatever format the motherboard clock uses (local time or UTC). If the first value is larger than the second, as in 23:00 1:00, it is interpreted as crossing midnight—11:00 PM to 1:00 AM in this example. The last default_selection setting takes precedence over preceding ones if the time value matches. Thus, you can set a main default_selection without a time specification and then set one or more others to override the main setting at specific times. + Sets the default boot OS based on the loader's title, which appears in the main menu beneath the icons when you select the loader. You can enter any substring of the title as the default_selection, so long as it's two or more characters in length. It's best to use a unique substring, since rEFInd stops searching when it finds the first match. Because rEFInd sorts entries within a directory in descending order by file modification time, if you specify a directory (or volume name, for loaders in a partition's root directory) as the default_selection, the most recent loader in that directory will be the default. One-character entries are matched against the first character of the title, except for digits, which refer to the numeric order of the boot loader entries. If you specify a comma-delimited list of names in quotation marks, rEFInd will search on these in turn until it finds a match. For instance, default_selection "alpha,beta" will launch alpha if it's available, and beta if alpha is not available but beta is. You may optionally follow the match string by two times, in 24-hour format, in which case the entry applies only between those two times. For instance, default_selection Safety 1:30 2:30 boots the entry called Safety by default between the hours of 1:30 and 2:30. These times are specified in whatever format the motherboard clock uses (local time or UTC). If the first value is larger than the second, as in 23:00 1:00, it is interpreted as crossing midnight—11:00 PM to 1:00 AM in this example. The last default_selection setting takes precedence over preceding ones if the time value matches. Thus, you can set a main default_selection without a time specification and then set one or more others to override the main setting at specific times. include diff --git a/docs/refind/todo.html b/docs/refind/todo.html index cd5110f..3beefd5 100644 --- a/docs/refind/todo.html +++ b/docs/refind/todo.html @@ -201,15 +201,6 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com

checks to substitute the GPT partition label if the filesystem label comes up empty. -
  • The default_selection option in refind.conf could - be improved by supporting a list of default options, so that if the - first item isn't found, rEFInd will try to boot the second one in - the list, and so on. This could be handy in case a driver fails to - load, or to provide an override in case the user inserts a specific - removable disk—by placing the removable disk's name first in - the list, it will take precedence over the normal hard disk - default.
  • -
  • Along the lines of the previous item, the default_selection might be expanded to support some form of specification of disk types, as in a special entry for any diff --git a/refind.conf-sample b/refind.conf-sample index 71237d5..30dd55e 100644 --- a/refind.conf-sample +++ b/refind.conf-sample @@ -272,8 +272,23 @@ scan_all_linux_kernels # will be the default. # - Any substring that corresponds to a portion of the loader's title # (usually the OS's name or boot loader's path). +# You may also specify multiple selectors by separating them with commas +# and enclosing the list in quotes. +# If you follow the selector(s) with two times, in 24-hour format, the +# default will apply only between those times. The times are in the +# motherboard's time standard, whether that's UTC or local time, so if +# you use UTC, you'll need to adjust this from local time manually. +# Times may span midnight as in "23:30 00:30", which applies to 11:30 PM +# to 12:30 AM. You may specify multiple default_selection lines, in which +# case the last one to match takes precedence. Thus, you can set a main +# option without a time followed by one or more that include times to +# set different defaults for different times of day. # #default_selection 1 +#default_selection Microsoft +#default_selection "bzImage,vmlinuz" +#default_selection Maintenance 23:30 2:00 +#default_selection "Maintenance,OS X" 1:00 2:30 # Include a secondary configuration file within this one. This secondary # file is loaded as if its options appeared at the point of the "include" diff --git a/refind/config.c b/refind/config.c index f86edc8..e9d2e55 100644 --- a/refind/config.c +++ b/refind/config.c @@ -397,6 +397,8 @@ static VOID SetDefaultByTime(IN CHAR16 **TokenList, OUT CHAR16 **Default) { if ((StartTime <= LAST_MINUTE) && (EndTime <= LAST_MINUTE)) { Status = refit_call2_wrapper(GetTime, &CurrentTime, NULL); + if (Status != EFI_SUCCESS) + return; Now = CurrentTime.Hour * 60 + CurrentTime.Minute; if (Now > LAST_MINUTE) { // Shouldn't happen; just being paranoid diff --git a/refind/menu.c b/refind/menu.c index c2ad279..eb49b92 100644 --- a/refind/menu.c +++ b/refind/menu.c @@ -305,29 +305,34 @@ VOID AddMenuEntry(IN REFIT_MENU_SCREEN *Screen, IN REFIT_MENU_ENTRY *Entry) } -static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Shortcut) +static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Defaults) { - UINTN i; - - if (Shortcut == NULL) - return (-1); - - if (StrLen(Shortcut) == 1) { - if (Shortcut[0] >= 'a' && Shortcut[0] <= 'z') - Shortcut[0] -= ('a' - 'A'); - if (Shortcut[0]) { - for (i = 0; i < Screen->EntryCount; i++) { - if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) { - return i; - } // if - } // for - } // if - } else if (StrLen(Shortcut) > 1) { - for (i = 0; i < Screen->EntryCount; i++) { - if (StriSubCmp(Shortcut, Screen->Entries[i]->Title)) - return i; - } // for - } + UINTN i, j = 0; + CHAR16 *Shortcut; + + while ((Shortcut = FindCommaDelimited(Defaults, j)) != NULL) { + if (StrLen(Shortcut) == 1) { + if (Shortcut[0] >= 'a' && Shortcut[0] <= 'z') + Shortcut[0] -= ('a' - 'A'); + if (Shortcut[0]) { + for (i = 0; i < Screen->EntryCount; i++) { + if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) { + MyFreePool(Shortcut); + return i; + } // if + } // for + } // if + } else if (StrLen(Shortcut) > 1) { + for (i = 0; i < Screen->EntryCount; i++) { + if (StriSubCmp(Shortcut, Screen->Entries[i]->Title)) { + MyFreePool(Shortcut); + return i; + } // if + } // for + } + MyFreePool(Shortcut); + j++; + } // while() return -1; }