From aaa425250e73c128accf0368e92af2d1533af2ec Mon Sep 17 00:00:00 2001 From: VintagePC <53943260+vintagepc@users.noreply.github.com> Date: Tue, 20 Jul 2021 09:01:09 -0400 Subject: [PATCH] Fix crash if no bootloader given & hex is missing --- MK404.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/MK404.cpp b/MK404.cpp index c77924b0..dad6eeb2 100644 --- a/MK404.cpp +++ b/MK404.cpp @@ -406,18 +406,31 @@ int main(int argc, char *argv[]) strFW = argFW.getValue(); } - if (!argStrBoot.isSet()) + std::string strBoot {""}; { - std::cout << "No bootloader specified, using default: " << argStrBoot.getValue() << '\n'; - } else if (argStrBoot.getValue().empty()) - { - std::cout << "Empty bootloader filename provided. NOT loading a bootloader.\n"; - } else { - std::cout << "Using Bootloader: " << argStrBoot.getValue() << '\n'; + auto ifBL = std::ifstream(argStrBoot.getValue()); + if (!argStrBoot.isSet() && ifBL.good()) + { + std::cout << "No bootloader specified, using default: " << argStrBoot.getValue() << '\n'; + strBoot = argStrBoot.getValue(); + } + else if (argStrBoot.getValue().empty()) + { + std::cout << "Empty bootloader filename provided. NOT loading a bootloader.\n"; + } + else if (ifBL.good()) + { + std::cout << "Using Bootloader: " << argStrBoot.getValue() << '\n'; + strBoot = argStrBoot.getValue(); + } + else + { + std::cout << "No bootloader specified, or specified file not found. Skipping!\n"; + } } void *pRawPrinter = PrinterFactory::CreatePrinter(argModel.getValue(),pBoard,printer,argBootloader.isSet(),bArgHacks,argSerial.isSet(), argSD.getValue() , - strFW,argSpam.getValue(), argGDB.isSet(), argVCDRate.getValue(),argStrBoot.getValue()); // this line is the CreateBoard() args. + strFW,argSpam.getValue(), argGDB.isSet(), argVCDRate.getValue(),strBoot); // this line is the CreateBoard() args. pBoard->SetPrimary(true); // This is the primary board, responsible for scripting/dispatch. Blocks contention from sub-boards, e.g. MMU.