diff --git a/lib/common.proto b/lib/common.proto index 1ee781c8..780d6fb1 100644 --- a/lib/common.proto +++ b/lib/common.proto @@ -19,4 +19,36 @@ enum IndexMode { INDEXMODE_360 = 2; } +enum FluxSourceSinkType { + FLUXTYPE_NOT_SET = 0; + FLUXTYPE_A2R = 1; + FLUXTYPE_AU = 2; + FLUXTYPE_CWF = 3; + FLUXTYPE_DRIVE = 4; + FLUXTYPE_ERASE = 5; + FLUXTYPE_FLUX = 6; + FLUXTYPE_FLX = 7; + FLUXTYPE_KRYOFLUX = 8; + FLUXTYPE_SCP = 9; + FLUXTYPE_TEST_PATTERN = 10; + FLUXTYPE_VCD = 11; +} + +enum ImageReaderWriterType { + IMAGETYPE_NOT_SET = 0; + IMAGETYPE_D64 = 1; + IMAGETYPE_D88 = 2; + IMAGETYPE_DIM = 3; + IMAGETYPE_DISKCOPY = 4; + IMAGETYPE_FDI = 5; + IMAGETYPE_IMD = 6; + IMAGETYPE_IMG = 7; + IMAGETYPE_JV3 = 8; + IMAGETYPE_LDBS = 9; + IMAGETYPE_NFD = 10; + IMAGETYPE_NSI = 11; + IMAGETYPE_RAW = 12; + IMAGETYPE_TD0 = 13; +} + diff --git a/lib/config.cc b/lib/config.cc index 07cdcf42..434f4b0e 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -15,6 +15,148 @@ static Config config; +struct FluxConstructor +{ + std::regex pattern; + std::function source; + std::function sink; +}; + +enum ConstructorMode +{ + MODE_RO, + MODE_WO, + MODE_RW +}; + +struct ImageConstructor +{ + std::string extension; + ImageReaderWriterType type; + ConstructorMode mode; +}; + +static const std::vector fluxConstructors = { + {.pattern = std::regex("^(.*\\.flux)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_FLUX); + proto->mutable_fl2()->set_filename(s); + }, .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_FLUX); + proto->mutable_fl2()->set_filename(s); + }}, + { + .pattern = std::regex("^(.*\\.scp)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_SCP); + proto->mutable_scp()->set_filename(s); + }, .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_SCP); + proto->mutable_scp()->set_filename(s); + }, }, + {.pattern = std::regex("^(.*\\.a2r)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_A2R); + proto->mutable_a2r()->set_filename(s); + }, .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_A2R); + proto->mutable_a2r()->set_filename(s); + }}, + {.pattern = std::regex("^(.*\\.cwf)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_CWF); + proto->mutable_cwf()->set_filename(s); + }}, + {.pattern = std::regex("^erase:$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_ERASE); + }}, + {.pattern = std::regex("^kryoflux:(.*)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_KRYOFLUX); + proto->mutable_kryoflux()->set_directory(s); + }}, + {.pattern = std::regex("^testpattern:(.*)"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_TEST_PATTERN); + }}, + {.pattern = std::regex("^drive:(.*)"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_DRIVE); + globalConfig().overrides()->mutable_drive()->set_drive( + std::stoi(s)); + }, .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_DRIVE); + globalConfig().overrides()->mutable_drive()->set_drive( + std::stoi(s)); + }}, + {.pattern = std::regex("^flx:(.*)$"), + .source = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_FLX); + proto->mutable_flx()->set_directory(s); + }}, + {.pattern = std::regex("^vcd:(.*)$"), + .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_VCD); + proto->mutable_vcd()->set_directory(s); + }}, + {.pattern = std::regex("^au:(.*)$"), + .sink = + [](auto& s, auto* proto) + { + proto->set_type(FLUXTYPE_AU); + proto->mutable_au()->set_directory(s); + }}, +}; + +static const std::vector imageConstructors = { + {".adf", IMAGETYPE_IMG, MODE_RW}, + {".d64", IMAGETYPE_D64, MODE_RW}, + {".d81", IMAGETYPE_IMG, MODE_RW}, + {".d88", IMAGETYPE_D88, MODE_RW}, + {".dim", IMAGETYPE_DIM, MODE_RO}, + {".diskcopy", IMAGETYPE_DISKCOPY, MODE_RW}, + {".dsk", IMAGETYPE_IMG, MODE_RW}, + {".fdi", IMAGETYPE_FDI, MODE_RO}, + {".imd", IMAGETYPE_IMD, MODE_RW}, + {".img", IMAGETYPE_IMG, MODE_RW}, + {".jv3", IMAGETYPE_JV3, MODE_RO}, + {".nfd", IMAGETYPE_NFD, MODE_RO}, + {".nsi", IMAGETYPE_NSI, MODE_RW}, + {".st", IMAGETYPE_IMG, MODE_RW}, + {".td0", IMAGETYPE_TD0, MODE_RO}, + {".vgi", IMAGETYPE_IMG, MODE_RW}, + {".xdf", IMAGETYPE_IMG, MODE_RW}, +}; + Config& globalConfig() { return config; @@ -334,72 +476,17 @@ void Config::clearOptions() invalidate(); } -static void setFluxSourceImpl(std::string filename, FluxSourceProto* proto) +static void setFluxSourceImpl( + const std::string& filename, FluxSourceProto* proto) { - static const std::vector>> - formats = { - {std::regex("^(.*\\.flux)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::FLUX); - proto->mutable_fl2()->set_filename(s); - }}, - {std::regex("^(.*\\.scp)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::SCP); - proto->mutable_scp()->set_filename(s); - }}, - {std::regex("^(.*\\.a2r)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::A2R); - proto->mutable_a2r()->set_filename(s); - }}, - {std::regex("^(.*\\.cwf)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::CWF); - proto->mutable_cwf()->set_filename(s); - }}, - {std::regex("^erase:$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::ERASE); - }}, - {std::regex("^kryoflux:(.*)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::KRYOFLUX); - proto->mutable_kryoflux()->set_directory(s); - }}, - {std::regex("^testpattern:(.*)"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::TEST_PATTERN); - }}, - {std::regex("^drive:(.*)"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::DRIVE); - globalConfig().overrides()->mutable_drive()->set_drive( - std::stoi(s)); - }}, - {std::regex("^flx:(.*)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSourceProto::FLX); - proto->mutable_flx()->set_directory(s); - }}, - }; - - for (const auto& it : formats) + for (const auto& it : fluxConstructors) { std::smatch match; - if (std::regex_match(filename, match, it.first)) + if (std::regex_match(filename, match, it.pattern)) { - it.second(match[1], proto); + if (!it.source) + throw new InapplicableValueException(); + it.source(match[1], proto); return; } } @@ -412,56 +499,16 @@ void Config::setFluxSource(std::string filename) setFluxSourceImpl(filename, overrides()->mutable_flux_source()); } -static void setFluxSinkImpl(std::string filename, FluxSinkProto* proto) +static void setFluxSinkImpl(const std::string& filename, FluxSinkProto* proto) { - static const std::vector>> - formats = { - {std::regex("^(.*\\.a2r)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::A2R); - proto->mutable_a2r()->set_filename(s); - }}, - {std::regex("^(.*\\.flux)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::FLUX); - proto->mutable_fl2()->set_filename(s); - }}, - {std::regex("^(.*\\.scp)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::SCP); - proto->mutable_scp()->set_filename(s); - }}, - {std::regex("^vcd:(.*)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::VCD); - proto->mutable_vcd()->set_directory(s); - }}, - {std::regex("^au:(.*)$"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::AU); - proto->mutable_au()->set_directory(s); - }}, - {std::regex("^drive:(.*)"), - [](auto& s, auto* proto) - { - proto->set_type(FluxSinkProto::DRIVE); - globalConfig().overrides()->mutable_drive()->set_drive( - std::stoi(s)); - }}, - }; - - for (const auto& it : formats) + for (const auto& it : fluxConstructors) { std::smatch match; - if (std::regex_match(filename, match, it.first)) + if (std::regex_match(filename, match, it.pattern)) { - it.second(match[1], proto); + if (!it.sink) + throw new InapplicableValueException(); + it.sink(match[1], proto); return; } } @@ -487,34 +534,14 @@ void Config::setVerificationFluxSource(std::string filename) void Config::setImageReader(std::string filename) { - static const std::map> - formats = { - // clang-format off - {".adf", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".d64", [](auto* proto) { proto->set_type(ImageReaderProto::D64); }}, - {".d81", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".d88", [](auto* proto) { proto->set_type(ImageReaderProto::D88); }}, - {".dim", [](auto* proto) { proto->set_type(ImageReaderProto::DIM); }}, - {".diskcopy", [](auto* proto) { proto->set_type(ImageReaderProto::DISKCOPY); }}, - {".dsk", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".fdi", [](auto* proto) { proto->set_type(ImageReaderProto::FDI); }}, - {".imd", [](auto* proto) { proto->set_type(ImageReaderProto::IMD); }}, - {".img", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".jv3", [](auto* proto) { proto->set_type(ImageReaderProto::JV3); }}, - {".nfd", [](auto* proto) { proto->set_type(ImageReaderProto::NFD); }}, - {".nsi", [](auto* proto) { proto->set_type(ImageReaderProto::NSI); }}, - {".st", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".td0", [](auto* proto) { proto->set_type(ImageReaderProto::TD0); }}, - {".vgi", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - {".xdf", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, - // clang-format on - }; - - for (const auto& it : formats) + for (const auto& it : imageConstructors) { - if (endsWith(filename, it.first)) + if (endsWith(filename, it.extension)) { - it.second(overrides()->mutable_image_reader()); + if (it.mode == MODE_WO) + throw new InapplicableValueException(); + + overrides()->mutable_image_reader()->set_type(it.type); overrides()->mutable_image_reader()->set_filename(filename); return; } @@ -525,31 +552,14 @@ void Config::setImageReader(std::string filename) void Config::setImageWriter(std::string filename) { - static const std::map> - formats = { - // clang-format off - {".adf", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".d64", [](auto* proto) { proto->set_type(ImageWriterProto::D64); }}, - {".d81", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".d88", [](auto* proto) { proto->set_type(ImageWriterProto::D88); }}, - {".diskcopy", [](auto* proto) { proto->set_type(ImageWriterProto::DISKCOPY); }}, - {".dsk", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".img", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".imd", [](auto* proto) { proto->set_type(ImageWriterProto::IMD); }}, - {".ldbs", [](auto* proto) { proto->set_type(ImageWriterProto::LDBS); }}, - {".nsi", [](auto* proto) { proto->set_type(ImageWriterProto::NSI); }}, - {".raw", [](auto* proto) { proto->set_type(ImageWriterProto::RAW); }}, - {".st", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".vgi", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - {".xdf", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, - // clang-format on - }; - - for (const auto& it : formats) + for (const auto& it : imageConstructors) { - if (endsWith(filename, it.first)) + if (endsWith(filename, it.extension)) { - it.second(overrides()->mutable_image_writer()); + if (it.mode == MODE_RO) + throw new InapplicableValueException(); + + overrides()->mutable_image_writer()->set_type(it.type); overrides()->mutable_image_writer()->set_filename(filename); return; } @@ -560,7 +570,7 @@ void Config::setImageWriter(std::string filename) bool Config::hasFluxSource() { - return (*this)->flux_source().type() != FluxSourceProto::NOT_SET; + return (*this)->flux_source().type() != FLUXTYPE_NOT_SET; } std::shared_ptr& Config::getFluxSource() @@ -578,7 +588,7 @@ std::shared_ptr& Config::getFluxSource() bool Config::hasVerificationFluxSource() const { - return _verificationFluxSourceProto.type() != FluxSourceProto::NOT_SET; + return _verificationFluxSourceProto.type() != FLUXTYPE_NOT_SET; } std::shared_ptr& Config::getVerificationFluxSource() @@ -596,7 +606,7 @@ std::shared_ptr& Config::getVerificationFluxSource() bool Config::hasImageReader() { - return (*this)->image_reader().type() != ImageReaderProto::NOT_SET; + return (*this)->image_reader().type() != IMAGETYPE_NOT_SET; } std::shared_ptr& Config::getImageReader() @@ -614,7 +624,7 @@ std::shared_ptr& Config::getImageReader() bool Config::hasFluxSink() { - return (*this)->flux_sink().type() != FluxSinkProto::NOT_SET; + return (*this)->flux_sink().type() != FLUXTYPE_NOT_SET; } std::unique_ptr Config::getFluxSink() @@ -627,7 +637,7 @@ std::unique_ptr Config::getFluxSink() bool Config::hasImageWriter() { - return (*this)->image_writer().type() != ImageWriterProto::NOT_SET; + return (*this)->image_writer().type() != IMAGETYPE_NOT_SET; } std::unique_ptr Config::getImageWriter() diff --git a/lib/config.h b/lib/config.h index 2960c320..566285ae 100644 --- a/lib/config.h +++ b/lib/config.h @@ -4,6 +4,7 @@ #include #include "lib/config.pb.h" +#include "lib/common.pb.h" class ConfigProto; class OptionProto; @@ -46,6 +47,14 @@ public: } }; +class InapplicableValueException : public ErrorException +{ +public: + InapplicableValueException(): + ErrorException("selected format cannot be used here") + {} +}; + class Config { public: diff --git a/lib/fluxsink/fluxsink.cc b/lib/fluxsink/fluxsink.cc index 7fda2363..6aa47e30 100644 --- a/lib/fluxsink/fluxsink.cc +++ b/lib/fluxsink/fluxsink.cc @@ -10,26 +10,25 @@ std::unique_ptr FluxSink::create(const FluxSinkProto& config) { switch (config.type()) { - case FluxSinkProto::DRIVE: + case FLUXTYPE_DRIVE: return createHardwareFluxSink(config.drive()); - case FluxSinkProto::A2R: + case FLUXTYPE_A2R: return createA2RFluxSink(config.a2r()); - case FluxSinkProto::AU: + case FLUXTYPE_AU: return createAuFluxSink(config.au()); - case FluxSinkProto::VCD: + case FLUXTYPE_VCD: return createVcdFluxSink(config.vcd()); - case FluxSinkProto::SCP: + case FLUXTYPE_SCP: return createScpFluxSink(config.scp()); - case FluxSinkProto::FLUX: + case FLUXTYPE_FLUX: return createFl2FluxSink(config.fl2()); default: - error("bad output disk config"); return std::unique_ptr(); } } diff --git a/lib/fluxsink/fluxsink.proto b/lib/fluxsink/fluxsink.proto index 5e615817..d2a06c55 100644 --- a/lib/fluxsink/fluxsink.proto +++ b/lib/fluxsink/fluxsink.proto @@ -29,17 +29,8 @@ message Fl2FluxSinkProto { // Next: 10 message FluxSinkProto { - enum FluxSinkType { - NOT_SET = 0; - DRIVE = 1; - A2R = 2; - AU = 3; - VCD = 4; - SCP = 5; - FLUX = 6; - } - - optional FluxSinkType type = 9 [default = NOT_SET, (help) = "flux sink type"]; + optional FluxSourceSinkType type = 9 + [default = FLUXTYPE_NOT_SET, (help) = "flux sink type"]; optional HardwareFluxSinkProto drive = 2; optional A2RFluxSinkProto a2r = 8; diff --git a/lib/fluxsource/fluxsource.cc b/lib/fluxsource/fluxsource.cc index 1502a28e..e5870d32 100644 --- a/lib/fluxsource/fluxsource.cc +++ b/lib/fluxsource/fluxsource.cc @@ -10,35 +10,34 @@ std::unique_ptr FluxSource::create(const FluxSourceProto& config) { switch (config.type()) { - case FluxSourceProto::DRIVE: + case FLUXTYPE_DRIVE: return createHardwareFluxSource(config.drive()); - case FluxSourceProto::ERASE: + case FLUXTYPE_ERASE: return createEraseFluxSource(config.erase()); - case FluxSourceProto::KRYOFLUX: + case FLUXTYPE_KRYOFLUX: return createKryofluxFluxSource(config.kryoflux()); - case FluxSourceProto::TEST_PATTERN: + case FLUXTYPE_TEST_PATTERN: return createTestPatternFluxSource(config.test_pattern()); - case FluxSourceProto::SCP: + case FLUXTYPE_SCP: return createScpFluxSource(config.scp()); - case FluxSourceProto::A2R: + case FLUXTYPE_A2R: return createA2rFluxSource(config.a2r()); - case FluxSourceProto::CWF: + case FLUXTYPE_CWF: return createCwfFluxSource(config.cwf()); - case FluxSourceProto::FLUX: + case FLUXTYPE_FLUX: return createFl2FluxSource(config.fl2()); - case FluxSourceProto::FLX: + case FLUXTYPE_FLX: return createFlxFluxSource(config.flx()); default: - error("bad input disk configuration"); return std::unique_ptr(); } } diff --git a/lib/fluxsource/fluxsource.proto b/lib/fluxsource/fluxsource.proto index 6dea13a3..62d28ebe 100644 --- a/lib/fluxsource/fluxsource.proto +++ b/lib/fluxsource/fluxsource.proto @@ -41,20 +41,8 @@ message FlxFluxSourceProto { // NEXT: 12 message FluxSourceProto { - enum FluxSourceType { - NOT_SET = 0; - DRIVE = 1; - TEST_PATTERN = 2; - ERASE = 3; - KRYOFLUX = 4; - SCP = 5; - CWF = 6; - FLUX = 7; - FLX = 8; - A2R = 9; - } - - optional FluxSourceType type = 9 [default = NOT_SET, (help) = "flux source type"]; + optional FluxSourceSinkType type = 9 + [default = FLUXTYPE_NOT_SET, (help) = "flux source type"]; optional A2rFluxSourceProto a2r = 11; optional CwfFluxSourceProto cwf = 7; diff --git a/lib/imagereader/imagereader.cc b/lib/imagereader/imagereader.cc index 9e36fe61..b5fc7469 100644 --- a/lib/imagereader/imagereader.cc +++ b/lib/imagereader/imagereader.cc @@ -15,37 +15,37 @@ std::unique_ptr ImageReader::create(const ImageReaderProto& config) { switch (config.type()) { - case ImageReaderProto::DIM: + case IMAGETYPE_DIM: return ImageReader::createDimImageReader(config); - case ImageReaderProto::D88: + case IMAGETYPE_D88: return ImageReader::createD88ImageReader(config); - case ImageReaderProto::FDI: + case IMAGETYPE_FDI: return ImageReader::createFdiImageReader(config); - case ImageReaderProto::IMD: + case IMAGETYPE_IMD: return ImageReader::createIMDImageReader(config); - case ImageReaderProto::IMG: + case IMAGETYPE_IMG: return ImageReader::createImgImageReader(config); - case ImageReaderProto::DISKCOPY: + case IMAGETYPE_DISKCOPY: return ImageReader::createDiskCopyImageReader(config); - case ImageReaderProto::JV3: + case IMAGETYPE_JV3: return ImageReader::createJv3ImageReader(config); - case ImageReaderProto::D64: + case IMAGETYPE_D64: return ImageReader::createD64ImageReader(config); - case ImageReaderProto::NFD: + case IMAGETYPE_NFD: return ImageReader::createNFDImageReader(config); - case ImageReaderProto::NSI: + case IMAGETYPE_NSI: return ImageReader::createNsiImageReader(config); - case ImageReaderProto::TD0: + case IMAGETYPE_TD0: return ImageReader::createTd0ImageReader(config); default: diff --git a/lib/imagereader/imagereader.proto b/lib/imagereader/imagereader.proto index 3a9d2f0a..403d685f 100644 --- a/lib/imagereader/imagereader.proto +++ b/lib/imagereader/imagereader.proto @@ -24,22 +24,8 @@ message ImageReaderProto default = false ]; - enum ImageReaderType { - NOT_SET = 0; - IMG = 1; - DISKCOPY = 2; - IMD = 3; - JV3 = 4; - D64 = 5; - NSI = 6; - TD0 = 7; - DIM = 8; - FDI = 9; - D88 = 10; - NFD = 11; - } - - optional ImageReaderType type = 14 [default = NOT_SET, (help) = "input image type"]; + optional ImageReaderWriterType type = 14 + [default = IMAGETYPE_NOT_SET, (help) = "input image type"]; optional ImgInputOutputProto img = 2; optional DiskCopyInputProto diskcopy = 3; diff --git a/lib/imagewriter/imagewriter.cc b/lib/imagewriter/imagewriter.cc index 17b68dbd..9b2ec35a 100644 --- a/lib/imagewriter/imagewriter.cc +++ b/lib/imagewriter/imagewriter.cc @@ -15,28 +15,28 @@ std::unique_ptr ImageWriter::create(const ImageWriterProto& config) { switch (config.type()) { - case ImageWriterProto::IMG: + case IMAGETYPE_IMG: return ImageWriter::createImgImageWriter(config); - case ImageWriterProto::D64: + case IMAGETYPE_D64: return ImageWriter::createD64ImageWriter(config); - case ImageWriterProto::LDBS: + case IMAGETYPE_LDBS: return ImageWriter::createLDBSImageWriter(config); - case ImageWriterProto::DISKCOPY: + case IMAGETYPE_DISKCOPY: return ImageWriter::createDiskCopyImageWriter(config); - case ImageWriterProto::NSI: + case IMAGETYPE_NSI: return ImageWriter::createNsiImageWriter(config); - case ImageWriterProto::RAW: + case IMAGETYPE_RAW: return ImageWriter::createRawImageWriter(config); - case ImageWriterProto::D88: + case IMAGETYPE_D88: return ImageWriter::createD88ImageWriter(config); - case ImageWriterProto::IMD: + case IMAGETYPE_IMD: return ImageWriter::createImdImageWriter(config); default: diff --git a/lib/imagewriter/imagewriter.proto b/lib/imagewriter/imagewriter.proto index 38c9ef63..74a42ae0 100644 --- a/lib/imagewriter/imagewriter.proto +++ b/lib/imagewriter/imagewriter.proto @@ -66,25 +66,14 @@ message ImdOutputProto // NEXT_TAG: 12 message ImageWriterProto { - enum ImageWriterType { - NOT_SET = 0; - IMG = 1; - D64 = 2; - LDBS = 3; - DISKCOPY = 4; - NSI = 5; - RAW = 6; - D88 = 7; - IMD = 8; - } - optional string filename = 1 [ (help) = "filename of output sector image" ]; optional bool filesystem_sector_order = 10 [ (help) = "read/write sector image in filesystem order", default = false ]; - optional ImageWriterType type = 11 [ default = NOT_SET, (help) = "image writer type" ]; + optional ImageReaderWriterType type = 11 + [ default = IMAGETYPE_NOT_SET, (help) = "image writer type" ]; optional ImgInputOutputProto img = 2; optional D64OutputProto d64 = 3; diff --git a/lib/proto.h b/lib/proto.h index fe22521a..1e271575 100644 --- a/lib/proto.h +++ b/lib/proto.h @@ -2,6 +2,7 @@ #define PROTO_H #include +#include "lib/common.pb.h" #include "lib/config.pb.h" class ProtoPathNotFoundException : public ErrorException diff --git a/lib/vfs/vfs.cc b/lib/vfs/vfs.cc index fd56410a..6083a816 100644 --- a/lib/vfs/vfs.cc +++ b/lib/vfs/vfs.cc @@ -236,7 +236,7 @@ std::unique_ptr Filesystem::createFilesystemFromConfig() fluxSource = globalConfig().getFluxSource(); decoder = globalConfig().getDecoder(); } - if (globalConfig()->flux_sink().type() == FluxSinkProto::DRIVE) + if (globalConfig()->flux_sink().type() == FLUXTYPE_DRIVE) { fluxSink = globalConfig().getFluxSink(); encoder = globalConfig().getEncoder(); diff --git a/scripts/mkdocindex.cc b/scripts/mkdocindex.cc index 8363981d..cfdaad12 100644 --- a/scripts/mkdocindex.cc +++ b/scripts/mkdocindex.cc @@ -18,6 +18,8 @@ static std::string supportStatus(SupportStatus status) case SupportStatus::UNSUPPORTED: return ""; } + + return ""; } int main(int argc, const char* argv[]) diff --git a/src/fe-analysedriveresponse.cc b/src/fe-analysedriveresponse.cc index bc817815..a5ca645a 100644 --- a/src/fe-analysedriveresponse.cc +++ b/src/fe-analysedriveresponse.cc @@ -247,10 +247,10 @@ static void draw_x_graticules(Agg2D& painter, int mainAnalyseDriveResponse(int argc, const char* argv[]) { globalConfig().overrides()->mutable_flux_source()->set_type( - FluxSourceProto::DRIVE); + FLUXTYPE_DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig()->flux_sink().type() != FluxSinkProto::DRIVE) + if (globalConfig()->flux_sink().type() != FLUXTYPE_DRIVE) error("this only makes sense with a real disk drive"); usbSetDrive(globalConfig()->drive().drive(), diff --git a/src/fe-inspect.cc b/src/fe-inspect.cc index 37007d6d..d9847719 100644 --- a/src/fe-inspect.cc +++ b/src/fe-inspect.cc @@ -132,7 +132,7 @@ static nanoseconds_t guessClock(const Fluxmap& fluxmap) int mainInspect(int argc, const char* argv[]) { globalConfig().overrides()->mutable_flux_source()->set_type( - FluxSourceProto::DRIVE); + FLUXTYPE_DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, {}); auto& fluxSource = globalConfig().getFluxSource(); diff --git a/src/fe-rawread.cc b/src/fe-rawread.cc index 8b62ff1f..618425c9 100644 --- a/src/fe-rawread.cc +++ b/src/fe-rawread.cc @@ -57,10 +57,10 @@ int mainRawRead(int argc, const char* argv[]) if (argc == 1) showProfiles("rawread", formats); globalConfig().overrides()->mutable_flux_source()->set_type( - FluxSourceProto::DRIVE); + FLUXTYPE_DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig()->flux_sink().type() == FluxSinkProto::DRIVE) + if (globalConfig()->flux_sink().type() == FLUXTYPE_DRIVE) error("you can't use rawread to write to hardware"); std::shared_ptr fluxSource = globalConfig().getFluxSource(); diff --git a/src/fe-rawwrite.cc b/src/fe-rawwrite.cc index c0848742..4731d756 100644 --- a/src/fe-rawwrite.cc +++ b/src/fe-rawwrite.cc @@ -49,7 +49,7 @@ static ActionFlag eraseFlag({"--erase"}, []() { globalConfig().overrides()->mutable_flux_source()->set_type( - FluxSourceProto::ERASE); + FLUXTYPE_ERASE); }); int mainRawWrite(int argc, const char* argv[]) @@ -60,10 +60,10 @@ int mainRawWrite(int argc, const char* argv[]) if (argc == 1) showProfiles("rawwrite", formats); globalConfig().overrides()->mutable_flux_sink()->set_type( - FluxSinkProto::DRIVE); + FLUXTYPE_DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig()->flux_source().type() == FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() == FLUXTYPE_DRIVE) error("you can't use rawwrite to read from hardware"); auto& fluxSource = globalConfig().getFluxSource(); diff --git a/src/fe-read.cc b/src/fe-read.cc index d0e1e067..d0024ad6 100644 --- a/src/fe-read.cc +++ b/src/fe-read.cc @@ -61,10 +61,10 @@ int mainRead(int argc, const char* argv[]) { if (argc == 1) showProfiles("read", formats); - globalConfig().set("flux_source.type", "DRIVE"); + globalConfig().set("flux_source.type", "FLUXTYPE_DRIVE"); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig()->decoder().copy_flux_to().type() == FluxSinkProto::DRIVE) + if (globalConfig()->decoder().copy_flux_to().type() == FLUXTYPE_DRIVE) error("you cannot copy flux to a hardware device"); auto& fluxSource = globalConfig().getFluxSource(); diff --git a/src/fe-rpm.cc b/src/fe-rpm.cc index 46516b47..eac151e4 100644 --- a/src/fe-rpm.cc +++ b/src/fe-rpm.cc @@ -19,7 +19,7 @@ int mainRpm(int argc, const char* argv[]) { flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() != FLUXTYPE_DRIVE) error("this only makes sense with a real disk drive"); usbSetDrive(globalConfig()->drive().drive(), diff --git a/src/fe-seek.cc b/src/fe-seek.cc index bb5fb764..2f6b2df0 100644 --- a/src/fe-seek.cc +++ b/src/fe-seek.cc @@ -23,7 +23,7 @@ int mainSeek(int argc, const char* argv[]) { flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() != FLUXTYPE_DRIVE) error("this only makes sense with a real disk drive"); usbSetDrive(globalConfig()->drive().drive(), diff --git a/src/formats/acornadfs.textpb b/src/formats/acornadfs.textpb index d005e493..1d96b9b2 100644 --- a/src/formats/acornadfs.textpb +++ b/src/formats/acornadfs.textpb @@ -22,7 +22,7 @@ they might require nudging as the side order can't be reliably autodetected. image_writer { filename: "acornadfs.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/acorndfs.textpb b/src/formats/acorndfs.textpb index 367385b5..37623a70 100644 --- a/src/formats/acorndfs.textpb +++ b/src/formats/acorndfs.textpb @@ -25,12 +25,12 @@ documentation: image_reader { filename: "acorndfs.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "acorndfs.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/aeslanier.textpb b/src/formats/aeslanier.textpb index 3dec54c3..1e741932 100644 --- a/src/formats/aeslanier.textpb +++ b/src/formats/aeslanier.textpb @@ -43,7 +43,7 @@ documentation: image_writer { filename: "aeslanier.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/agat.textpb b/src/formats/agat.textpb index baf4dab5..f7f0164c 100644 --- a/src/formats/agat.textpb +++ b/src/formats/agat.textpb @@ -28,7 +28,7 @@ documentation: image_writer { filename: "agat.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/amiga.textpb b/src/formats/amiga.textpb index e5c2fb32..dc9f717f 100644 --- a/src/formats/amiga.textpb +++ b/src/formats/amiga.textpb @@ -31,12 +31,12 @@ documentation: image_reader { filename: "amiga.adf" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "amiga.adf" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/ampro.textpb b/src/formats/ampro.textpb index e5ff2f78..010f38db 100644 --- a/src/formats/ampro.textpb +++ b/src/formats/ampro.textpb @@ -44,7 +44,7 @@ documentation: image_writer { filename: "ampro.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/bk.textpb b/src/formats/bk.textpb index ee3dec8a..bf13827e 100644 --- a/src/formats/bk.textpb +++ b/src/formats/bk.textpb @@ -19,12 +19,12 @@ on what was available at the time, with the same format on both. image_reader { filename: "bk800.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "bk800.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/brother.textpb b/src/formats/brother.textpb index bf3257d9..f5469047 100644 --- a/src/formats/brother.textpb +++ b/src/formats/brother.textpb @@ -116,12 +116,12 @@ file system supports this. image_reader { filename: "brother.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "brother.img" - type: IMG + type: IMAGETYPE_IMG } encoder { diff --git a/src/formats/commodore.textpb b/src/formats/commodore.textpb index 3f8c1332..081ed1bc 100644 --- a/src/formats/commodore.textpb +++ b/src/formats/commodore.textpb @@ -54,12 +54,12 @@ documentation: image_reader { filename: "commodore.d64" - type: D64 + type: IMAGETYPE_D64 } image_writer { filename: "commodore.d64" - type: D64 + type: IMAGETYPE_D64 } filesystem { diff --git a/src/formats/eco1.textpb b/src/formats/eco1.textpb index 5802d630..20e565f1 100644 --- a/src/formats/eco1.textpb +++ b/src/formats/eco1.textpb @@ -37,7 +37,7 @@ documentation: image_writer { filename: "eco1.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/epsonpf10.textpb b/src/formats/epsonpf10.textpb index 61e56801..ce660a4a 100644 --- a/src/formats/epsonpf10.textpb +++ b/src/formats/epsonpf10.textpb @@ -11,7 +11,7 @@ format itself is yet another IBM scheme variant. image_writer { filename: "epsonpf10.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/f85.textpb b/src/formats/f85.textpb index 3b312828..d73feb1b 100644 --- a/src/formats/f85.textpb +++ b/src/formats/f85.textpb @@ -42,7 +42,7 @@ There's amazingly little information about these things. image_writer { filename: "f85.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/fb100.textpb b/src/formats/fb100.textpb index 93463954..c848d201 100644 --- a/src/formats/fb100.textpb +++ b/src/formats/fb100.textpb @@ -43,7 +43,7 @@ documentation: image_writer { filename: "fb100.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/hplif.textpb b/src/formats/hplif.textpb index 99f05b60..96b6994e 100644 --- a/src/formats/hplif.textpb +++ b/src/formats/hplif.textpb @@ -20,12 +20,12 @@ drive { image_reader { filename: "hplif.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "hplif.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/ibm.textpb b/src/formats/ibm.textpb index 1c54c402..90c60138 100644 --- a/src/formats/ibm.textpb +++ b/src/formats/ibm.textpb @@ -84,12 +84,12 @@ versa, so it shouldn't matter. image_reader { filename: "ibm.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "ibm.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/icl30.textpb b/src/formats/icl30.textpb index ac306356..99726e26 100644 --- a/src/formats/icl30.textpb +++ b/src/formats/icl30.textpb @@ -11,7 +11,7 @@ track! Other than that it's another IBM scheme variation. image_writer { filename: "icl30.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/mac.textpb b/src/formats/mac.textpb index 968bc769..0384e24c 100644 --- a/src/formats/mac.textpb +++ b/src/formats/mac.textpb @@ -61,12 +61,12 @@ documentation: image_reader { filename: "mac.dsk" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "mac.dsk" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/micropolis.textpb b/src/formats/micropolis.textpb index 55f96f64..890976cd 100644 --- a/src/formats/micropolis.textpb +++ b/src/formats/micropolis.textpb @@ -67,12 +67,12 @@ drive { image_reader { filename: "micropolis.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "micropolis.img" - type: IMG + type: IMAGETYPE_IMG } layout { @@ -100,12 +100,12 @@ option { config { image_reader { filename: "micropolis.vgi" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "micropolis.vgi" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/mx.textpb b/src/formats/mx.textpb index a816da33..6cbcca2e 100644 --- a/src/formats/mx.textpb +++ b/src/formats/mx.textpb @@ -57,7 +57,7 @@ documentation: image_writer { filename: "mx.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/n88basic.textpb b/src/formats/n88basic.textpb index 58a1d283..053c34fb 100644 --- a/src/formats/n88basic.textpb +++ b/src/formats/n88basic.textpb @@ -19,12 +19,12 @@ drive { image_reader { filename: "n88basic.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "n88basic.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/northstar.textpb b/src/formats/northstar.textpb index 83dd3b80..0516f6a4 100644 --- a/src/formats/northstar.textpb +++ b/src/formats/northstar.textpb @@ -35,12 +35,12 @@ documentation: image_reader { filename: "northstar.nsi" - type: NSI + type: IMAGETYPE_NSI } image_writer { filename: "northstar.nsi" - type: NSI + type: IMAGETYPE_NSI } layout { diff --git a/src/formats/psos.textpb b/src/formats/psos.textpb index fc0680e7..ba4b75c9 100644 --- a/src/formats/psos.textpb +++ b/src/formats/psos.textpb @@ -26,12 +26,12 @@ drive { image_reader { filename: "pme.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "pme.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/rolandd20.textpb b/src/formats/rolandd20.textpb index 7a93e17e..69bc8f84 100644 --- a/src/formats/rolandd20.textpb +++ b/src/formats/rolandd20.textpb @@ -20,7 +20,7 @@ you know anything about it. image_writer { filename: "rolandd20.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/rx50.textpb b/src/formats/rx50.textpb index 434b071e..93457074 100644 --- a/src/formats/rx50.textpb +++ b/src/formats/rx50.textpb @@ -16,12 +16,12 @@ drive { image_reader { filename: "rx50.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "rx50.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/smaky6.textpb b/src/formats/smaky6.textpb index 1e903a19..0df3d3bb 100644 --- a/src/formats/smaky6.textpb +++ b/src/formats/smaky6.textpb @@ -29,7 +29,7 @@ documentation: image_writer { filename: "smaky6.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/tids990.textpb b/src/formats/tids990.textpb index 65f9487a..acb739db 100644 --- a/src/formats/tids990.textpb +++ b/src/formats/tids990.textpb @@ -31,12 +31,12 @@ documentation: image_reader { filename: "tids990.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "tids990.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/tiki.textpb b/src/formats/tiki.textpb index 4ad6a44b..838749ad 100644 --- a/src/formats/tiki.textpb +++ b/src/formats/tiki.textpb @@ -11,7 +11,7 @@ on the precise format. image_writer { filename: "tiki.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/formats/victor9k.textpb b/src/formats/victor9k.textpb index c5a9b392..1f2f9bef 100644 --- a/src/formats/victor9k.textpb +++ b/src/formats/victor9k.textpb @@ -50,12 +50,12 @@ documentation: image_reader { filename: "victor9k.img" - type: IMG + type: IMAGETYPE_IMG } image_writer { filename: "victor9k.img" - type: IMG + type: IMAGETYPE_IMG } layout { diff --git a/src/formats/zilogmcz.textpb b/src/formats/zilogmcz.textpb index ab70b009..d0c3f76f 100644 --- a/src/formats/zilogmcz.textpb +++ b/src/formats/zilogmcz.textpb @@ -40,7 +40,7 @@ documentation: image_writer { filename: "zilogmcz.img" - type: IMG + type: IMAGETYPE_IMG } decoder { diff --git a/src/gui/idlepanel.cc b/src/gui/idlepanel.cc index 69194c0d..96b8ffa9 100644 --- a/src/gui/idlepanel.cc +++ b/src/gui/idlepanel.cc @@ -46,6 +46,18 @@ static wxBitmap createBitmap(const uint8_t* data, size_t length) return wxBitmap(image); } +static void ignoreInapplicableValueExceptions(std::function cb) +{ + try + { + cb(); + } + catch (const InapplicableValueException* e) + { + /* swallow */ + } +} + class IdlePanelImpl : public IdlePanelGen, public IdlePanel { enum @@ -224,15 +236,31 @@ public: case SELECTEDSOURCE_FLUX: { - globalConfig().setFluxSink(_selectedFluxfilename); - globalConfig().setFluxSource(_selectedFluxfilename); + ignoreInapplicableValueExceptions( + [&]() + { + globalConfig().setFluxSink(_selectedFluxfilename); + }); + ignoreInapplicableValueExceptions( + [&]() + { + globalConfig().setFluxSource(_selectedFluxfilename); + }); break; } case SELECTEDSOURCE_IMAGE: { + ignoreInapplicableValueExceptions( + [&]() + { globalConfig().setImageReader(_selectedImagefilename); + }); + ignoreInapplicableValueExceptions( + [&]() + { globalConfig().setImageWriter(_selectedImagefilename); + }); break; } } @@ -587,12 +615,12 @@ private: /* The current set of options is invalid for some reason. Just * swallow the errors. */ } - catch (const ErrorException& e) - { - /* This really isn't supposed to happen, but sometimes does and - * it crashes the whole program. */ - return; - } + catch (const ErrorException& e) + { + /* This really isn't supposed to happen, but sometimes does and + * it crashes the whole program. */ + return; + } assert(!wxGetApp().IsWorkerThreadRunning()); diff --git a/src/gui/main.cc b/src/gui/main.cc index 44a40455..f4817631 100644 --- a/src/gui/main.cc +++ b/src/gui/main.cc @@ -53,11 +53,19 @@ private: bool FluxEngineApp::OnInit() { + try + { wxImage::AddHandler(new wxPNGHandler()); Bind(EXEC_EVENT_TYPE, &FluxEngineApp::OnExec, this); _mainWindow = CreateMainWindow(); _mainWindow->Show(true); return true; + } + catch (const ErrorException* e) + { + fmt::print(stderr, "Exception on startup: {}\n", e->message); + exit(1); + } } wxThread::ExitCode FluxEngineApp::Entry()