+// Sets the global configuration filename; will be CONFIG_FILE_NAME unless the
+// "-c" command-line option is set, in which case that takes precedence.
+// If an error is encountered, leaves the value alone (it should be set to
+// CONFIG_FILE_NAME when GlobalConfig is initialized).
+static VOID SetConfigFilename(EFI_HANDLE ImageHandle) {
+ EFI_LOADED_IMAGE *Info;
+ CHAR16 *Options, *FileName;
+ EFI_STATUS Status;
+ INTN Where;
+
+ Status = refit_call3_wrapper(BS->HandleProtocol, ImageHandle, &LoadedImageProtocol, (VOID **) &Info);
+ if ((Status == EFI_SUCCESS) && (Info->LoadOptionsSize > 0)) {
+ Options = (CHAR16 *) Info->LoadOptions;
+ Where = FindSubString(L" -c ", Options);
+ if (Where >= 0) {
+ FileName = StrDuplicate(&Options[Where + 4]);
+ Where = FindSubString(L" ", FileName);
+ if (Where > 0)
+ FileName[Where] = L'\0';
+
+ if (FileExists(SelfDir, FileName)) {
+ GlobalConfig.ConfigFilename = FileName;
+ } else {
+ Print(L"Specified configuration file (%s) doesn't exist; using\n'refind.conf' default\n", FileName);
+ MyFreePool(FileName);
+ } // if/else
+ } // if
+ } // if
+} // VOID SetConfigFilename()
+