Merge pull request #697 from davidgiven/ro

Allow read-only flux and image in the GUI.
This commit is contained in:
David Given
2023-07-24 08:20:39 +02:00
committed by GitHub
52 changed files with 361 additions and 319 deletions

View File

@@ -19,4 +19,36 @@ enum IndexMode {
INDEXMODE_360 = 2; 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;
}

View File

@@ -15,6 +15,148 @@
static Config config; static Config config;
struct FluxConstructor
{
std::regex pattern;
std::function<void(const std::string& filename, FluxSourceProto*)> source;
std::function<void(const std::string& filename, FluxSinkProto*)> sink;
};
enum ConstructorMode
{
MODE_RO,
MODE_WO,
MODE_RW
};
struct ImageConstructor
{
std::string extension;
ImageReaderWriterType type;
ConstructorMode mode;
};
static const std::vector<FluxConstructor> 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<ImageConstructor> 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() Config& globalConfig()
{ {
return config; return config;
@@ -334,72 +476,17 @@ void Config::clearOptions()
invalidate(); invalidate();
} }
static void setFluxSourceImpl(std::string filename, FluxSourceProto* proto) static void setFluxSourceImpl(
const std::string& filename, FluxSourceProto* proto)
{ {
static const std::vector<std::pair<std::regex, for (const auto& it : fluxConstructors)
std::function<void(const std::string&, FluxSourceProto*)>>>
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)
{ {
std::smatch match; 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; return;
} }
} }
@@ -412,56 +499,16 @@ void Config::setFluxSource(std::string filename)
setFluxSourceImpl(filename, overrides()->mutable_flux_source()); 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<std::pair<std::regex, for (const auto& it : fluxConstructors)
std::function<void(const std::string&, FluxSinkProto*)>>>
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)
{ {
std::smatch match; 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; return;
} }
} }
@@ -487,34 +534,14 @@ void Config::setVerificationFluxSource(std::string filename)
void Config::setImageReader(std::string filename) void Config::setImageReader(std::string filename)
{ {
static const std::map<std::string, std::function<void(ImageReaderProto*)>> for (const auto& it : imageConstructors)
formats = { {
// clang-format off if (endsWith(filename, it.extension))
{".adf", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, {
{".d64", [](auto* proto) { proto->set_type(ImageReaderProto::D64); }}, if (it.mode == MODE_WO)
{".d81", [](auto* proto) { proto->set_type(ImageReaderProto::IMG); }}, throw new InapplicableValueException();
{".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) overrides()->mutable_image_reader()->set_type(it.type);
{
if (endsWith(filename, it.first))
{
it.second(overrides()->mutable_image_reader());
overrides()->mutable_image_reader()->set_filename(filename); overrides()->mutable_image_reader()->set_filename(filename);
return; return;
} }
@@ -525,31 +552,14 @@ void Config::setImageReader(std::string filename)
void Config::setImageWriter(std::string filename) void Config::setImageWriter(std::string filename)
{ {
static const std::map<std::string, std::function<void(ImageWriterProto*)>> for (const auto& it : imageConstructors)
formats = { {
// clang-format off if (endsWith(filename, it.extension))
{".adf", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, {
{".d64", [](auto* proto) { proto->set_type(ImageWriterProto::D64); }}, if (it.mode == MODE_RO)
{".d81", [](auto* proto) { proto->set_type(ImageWriterProto::IMG); }}, throw new InapplicableValueException();
{".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) overrides()->mutable_image_writer()->set_type(it.type);
{
if (endsWith(filename, it.first))
{
it.second(overrides()->mutable_image_writer());
overrides()->mutable_image_writer()->set_filename(filename); overrides()->mutable_image_writer()->set_filename(filename);
return; return;
} }
@@ -560,7 +570,7 @@ void Config::setImageWriter(std::string filename)
bool Config::hasFluxSource() bool Config::hasFluxSource()
{ {
return (*this)->flux_source().type() != FluxSourceProto::NOT_SET; return (*this)->flux_source().type() != FLUXTYPE_NOT_SET;
} }
std::shared_ptr<FluxSource>& Config::getFluxSource() std::shared_ptr<FluxSource>& Config::getFluxSource()
@@ -578,7 +588,7 @@ std::shared_ptr<FluxSource>& Config::getFluxSource()
bool Config::hasVerificationFluxSource() const bool Config::hasVerificationFluxSource() const
{ {
return _verificationFluxSourceProto.type() != FluxSourceProto::NOT_SET; return _verificationFluxSourceProto.type() != FLUXTYPE_NOT_SET;
} }
std::shared_ptr<FluxSource>& Config::getVerificationFluxSource() std::shared_ptr<FluxSource>& Config::getVerificationFluxSource()
@@ -596,7 +606,7 @@ std::shared_ptr<FluxSource>& Config::getVerificationFluxSource()
bool Config::hasImageReader() bool Config::hasImageReader()
{ {
return (*this)->image_reader().type() != ImageReaderProto::NOT_SET; return (*this)->image_reader().type() != IMAGETYPE_NOT_SET;
} }
std::shared_ptr<ImageReader>& Config::getImageReader() std::shared_ptr<ImageReader>& Config::getImageReader()
@@ -614,7 +624,7 @@ std::shared_ptr<ImageReader>& Config::getImageReader()
bool Config::hasFluxSink() bool Config::hasFluxSink()
{ {
return (*this)->flux_sink().type() != FluxSinkProto::NOT_SET; return (*this)->flux_sink().type() != FLUXTYPE_NOT_SET;
} }
std::unique_ptr<FluxSink> Config::getFluxSink() std::unique_ptr<FluxSink> Config::getFluxSink()
@@ -627,7 +637,7 @@ std::unique_ptr<FluxSink> Config::getFluxSink()
bool Config::hasImageWriter() bool Config::hasImageWriter()
{ {
return (*this)->image_writer().type() != ImageWriterProto::NOT_SET; return (*this)->image_writer().type() != IMAGETYPE_NOT_SET;
} }
std::unique_ptr<ImageWriter> Config::getImageWriter() std::unique_ptr<ImageWriter> Config::getImageWriter()

View File

@@ -4,6 +4,7 @@
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include "lib/config.pb.h" #include "lib/config.pb.h"
#include "lib/common.pb.h"
class ConfigProto; class ConfigProto;
class OptionProto; class OptionProto;
@@ -46,6 +47,14 @@ public:
} }
}; };
class InapplicableValueException : public ErrorException
{
public:
InapplicableValueException():
ErrorException("selected format cannot be used here")
{}
};
class Config class Config
{ {
public: public:

View File

@@ -10,26 +10,25 @@ std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
{ {
switch (config.type()) switch (config.type())
{ {
case FluxSinkProto::DRIVE: case FLUXTYPE_DRIVE:
return createHardwareFluxSink(config.drive()); return createHardwareFluxSink(config.drive());
case FluxSinkProto::A2R: case FLUXTYPE_A2R:
return createA2RFluxSink(config.a2r()); return createA2RFluxSink(config.a2r());
case FluxSinkProto::AU: case FLUXTYPE_AU:
return createAuFluxSink(config.au()); return createAuFluxSink(config.au());
case FluxSinkProto::VCD: case FLUXTYPE_VCD:
return createVcdFluxSink(config.vcd()); return createVcdFluxSink(config.vcd());
case FluxSinkProto::SCP: case FLUXTYPE_SCP:
return createScpFluxSink(config.scp()); return createScpFluxSink(config.scp());
case FluxSinkProto::FLUX: case FLUXTYPE_FLUX:
return createFl2FluxSink(config.fl2()); return createFl2FluxSink(config.fl2());
default: default:
error("bad output disk config");
return std::unique_ptr<FluxSink>(); return std::unique_ptr<FluxSink>();
} }
} }

View File

@@ -29,17 +29,8 @@ message Fl2FluxSinkProto {
// Next: 10 // Next: 10
message FluxSinkProto { message FluxSinkProto {
enum FluxSinkType { optional FluxSourceSinkType type = 9
NOT_SET = 0; [default = FLUXTYPE_NOT_SET, (help) = "flux sink type"];
DRIVE = 1;
A2R = 2;
AU = 3;
VCD = 4;
SCP = 5;
FLUX = 6;
}
optional FluxSinkType type = 9 [default = NOT_SET, (help) = "flux sink type"];
optional HardwareFluxSinkProto drive = 2; optional HardwareFluxSinkProto drive = 2;
optional A2RFluxSinkProto a2r = 8; optional A2RFluxSinkProto a2r = 8;

View File

@@ -10,35 +10,34 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
{ {
switch (config.type()) switch (config.type())
{ {
case FluxSourceProto::DRIVE: case FLUXTYPE_DRIVE:
return createHardwareFluxSource(config.drive()); return createHardwareFluxSource(config.drive());
case FluxSourceProto::ERASE: case FLUXTYPE_ERASE:
return createEraseFluxSource(config.erase()); return createEraseFluxSource(config.erase());
case FluxSourceProto::KRYOFLUX: case FLUXTYPE_KRYOFLUX:
return createKryofluxFluxSource(config.kryoflux()); return createKryofluxFluxSource(config.kryoflux());
case FluxSourceProto::TEST_PATTERN: case FLUXTYPE_TEST_PATTERN:
return createTestPatternFluxSource(config.test_pattern()); return createTestPatternFluxSource(config.test_pattern());
case FluxSourceProto::SCP: case FLUXTYPE_SCP:
return createScpFluxSource(config.scp()); return createScpFluxSource(config.scp());
case FluxSourceProto::A2R: case FLUXTYPE_A2R:
return createA2rFluxSource(config.a2r()); return createA2rFluxSource(config.a2r());
case FluxSourceProto::CWF: case FLUXTYPE_CWF:
return createCwfFluxSource(config.cwf()); return createCwfFluxSource(config.cwf());
case FluxSourceProto::FLUX: case FLUXTYPE_FLUX:
return createFl2FluxSource(config.fl2()); return createFl2FluxSource(config.fl2());
case FluxSourceProto::FLX: case FLUXTYPE_FLX:
return createFlxFluxSource(config.flx()); return createFlxFluxSource(config.flx());
default: default:
error("bad input disk configuration");
return std::unique_ptr<FluxSource>(); return std::unique_ptr<FluxSource>();
} }
} }

View File

@@ -41,20 +41,8 @@ message FlxFluxSourceProto {
// NEXT: 12 // NEXT: 12
message FluxSourceProto { message FluxSourceProto {
enum FluxSourceType { optional FluxSourceSinkType type = 9
NOT_SET = 0; [default = FLUXTYPE_NOT_SET, (help) = "flux source type"];
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 A2rFluxSourceProto a2r = 11; optional A2rFluxSourceProto a2r = 11;
optional CwfFluxSourceProto cwf = 7; optional CwfFluxSourceProto cwf = 7;

View File

@@ -15,37 +15,37 @@ std::unique_ptr<ImageReader> ImageReader::create(const ImageReaderProto& config)
{ {
switch (config.type()) switch (config.type())
{ {
case ImageReaderProto::DIM: case IMAGETYPE_DIM:
return ImageReader::createDimImageReader(config); return ImageReader::createDimImageReader(config);
case ImageReaderProto::D88: case IMAGETYPE_D88:
return ImageReader::createD88ImageReader(config); return ImageReader::createD88ImageReader(config);
case ImageReaderProto::FDI: case IMAGETYPE_FDI:
return ImageReader::createFdiImageReader(config); return ImageReader::createFdiImageReader(config);
case ImageReaderProto::IMD: case IMAGETYPE_IMD:
return ImageReader::createIMDImageReader(config); return ImageReader::createIMDImageReader(config);
case ImageReaderProto::IMG: case IMAGETYPE_IMG:
return ImageReader::createImgImageReader(config); return ImageReader::createImgImageReader(config);
case ImageReaderProto::DISKCOPY: case IMAGETYPE_DISKCOPY:
return ImageReader::createDiskCopyImageReader(config); return ImageReader::createDiskCopyImageReader(config);
case ImageReaderProto::JV3: case IMAGETYPE_JV3:
return ImageReader::createJv3ImageReader(config); return ImageReader::createJv3ImageReader(config);
case ImageReaderProto::D64: case IMAGETYPE_D64:
return ImageReader::createD64ImageReader(config); return ImageReader::createD64ImageReader(config);
case ImageReaderProto::NFD: case IMAGETYPE_NFD:
return ImageReader::createNFDImageReader(config); return ImageReader::createNFDImageReader(config);
case ImageReaderProto::NSI: case IMAGETYPE_NSI:
return ImageReader::createNsiImageReader(config); return ImageReader::createNsiImageReader(config);
case ImageReaderProto::TD0: case IMAGETYPE_TD0:
return ImageReader::createTd0ImageReader(config); return ImageReader::createTd0ImageReader(config);
default: default:

View File

@@ -24,22 +24,8 @@ message ImageReaderProto
default = false default = false
]; ];
enum ImageReaderType { optional ImageReaderWriterType type = 14
NOT_SET = 0; [default = IMAGETYPE_NOT_SET, (help) = "input image type"];
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 ImgInputOutputProto img = 2; optional ImgInputOutputProto img = 2;
optional DiskCopyInputProto diskcopy = 3; optional DiskCopyInputProto diskcopy = 3;

View File

@@ -15,28 +15,28 @@ std::unique_ptr<ImageWriter> ImageWriter::create(const ImageWriterProto& config)
{ {
switch (config.type()) switch (config.type())
{ {
case ImageWriterProto::IMG: case IMAGETYPE_IMG:
return ImageWriter::createImgImageWriter(config); return ImageWriter::createImgImageWriter(config);
case ImageWriterProto::D64: case IMAGETYPE_D64:
return ImageWriter::createD64ImageWriter(config); return ImageWriter::createD64ImageWriter(config);
case ImageWriterProto::LDBS: case IMAGETYPE_LDBS:
return ImageWriter::createLDBSImageWriter(config); return ImageWriter::createLDBSImageWriter(config);
case ImageWriterProto::DISKCOPY: case IMAGETYPE_DISKCOPY:
return ImageWriter::createDiskCopyImageWriter(config); return ImageWriter::createDiskCopyImageWriter(config);
case ImageWriterProto::NSI: case IMAGETYPE_NSI:
return ImageWriter::createNsiImageWriter(config); return ImageWriter::createNsiImageWriter(config);
case ImageWriterProto::RAW: case IMAGETYPE_RAW:
return ImageWriter::createRawImageWriter(config); return ImageWriter::createRawImageWriter(config);
case ImageWriterProto::D88: case IMAGETYPE_D88:
return ImageWriter::createD88ImageWriter(config); return ImageWriter::createD88ImageWriter(config);
case ImageWriterProto::IMD: case IMAGETYPE_IMD:
return ImageWriter::createImdImageWriter(config); return ImageWriter::createImdImageWriter(config);
default: default:

View File

@@ -66,25 +66,14 @@ message ImdOutputProto
// NEXT_TAG: 12 // NEXT_TAG: 12
message ImageWriterProto 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 string filename = 1 [ (help) = "filename of output sector image" ];
optional bool filesystem_sector_order = 10 [ optional bool filesystem_sector_order = 10 [
(help) = "read/write sector image in filesystem order", (help) = "read/write sector image in filesystem order",
default = false 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 ImgInputOutputProto img = 2;
optional D64OutputProto d64 = 3; optional D64OutputProto d64 = 3;

View File

@@ -2,6 +2,7 @@
#define PROTO_H #define PROTO_H
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include "lib/common.pb.h"
#include "lib/config.pb.h" #include "lib/config.pb.h"
class ProtoPathNotFoundException : public ErrorException class ProtoPathNotFoundException : public ErrorException

View File

@@ -236,7 +236,7 @@ std::unique_ptr<Filesystem> Filesystem::createFilesystemFromConfig()
fluxSource = globalConfig().getFluxSource(); fluxSource = globalConfig().getFluxSource();
decoder = globalConfig().getDecoder(); decoder = globalConfig().getDecoder();
} }
if (globalConfig()->flux_sink().type() == FluxSinkProto::DRIVE) if (globalConfig()->flux_sink().type() == FLUXTYPE_DRIVE)
{ {
fluxSink = globalConfig().getFluxSink(); fluxSink = globalConfig().getFluxSink();
encoder = globalConfig().getEncoder(); encoder = globalConfig().getEncoder();

View File

@@ -18,6 +18,8 @@ static std::string supportStatus(SupportStatus status)
case SupportStatus::UNSUPPORTED: case SupportStatus::UNSUPPORTED:
return ""; return "";
} }
return "";
} }
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])

View File

@@ -247,10 +247,10 @@ static void draw_x_graticules(Agg2D& painter,
int mainAnalyseDriveResponse(int argc, const char* argv[]) int mainAnalyseDriveResponse(int argc, const char* argv[])
{ {
globalConfig().overrides()->mutable_flux_source()->set_type( globalConfig().overrides()->mutable_flux_source()->set_type(
FluxSourceProto::DRIVE); FLUXTYPE_DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, {}); 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"); error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig()->drive().drive(), usbSetDrive(globalConfig()->drive().drive(),

View File

@@ -132,7 +132,7 @@ static nanoseconds_t guessClock(const Fluxmap& fluxmap)
int mainInspect(int argc, const char* argv[]) int mainInspect(int argc, const char* argv[])
{ {
globalConfig().overrides()->mutable_flux_source()->set_type( globalConfig().overrides()->mutable_flux_source()->set_type(
FluxSourceProto::DRIVE); FLUXTYPE_DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, {}); flags.parseFlagsWithConfigFiles(argc, argv, {});
auto& fluxSource = globalConfig().getFluxSource(); auto& fluxSource = globalConfig().getFluxSource();

View File

@@ -57,10 +57,10 @@ int mainRawRead(int argc, const char* argv[])
if (argc == 1) if (argc == 1)
showProfiles("rawread", formats); showProfiles("rawread", formats);
globalConfig().overrides()->mutable_flux_source()->set_type( globalConfig().overrides()->mutable_flux_source()->set_type(
FluxSourceProto::DRIVE); FLUXTYPE_DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats); 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"); error("you can't use rawread to write to hardware");
std::shared_ptr<FluxSource> fluxSource = globalConfig().getFluxSource(); std::shared_ptr<FluxSource> fluxSource = globalConfig().getFluxSource();

View File

@@ -49,7 +49,7 @@ static ActionFlag eraseFlag({"--erase"},
[]() []()
{ {
globalConfig().overrides()->mutable_flux_source()->set_type( globalConfig().overrides()->mutable_flux_source()->set_type(
FluxSourceProto::ERASE); FLUXTYPE_ERASE);
}); });
int mainRawWrite(int argc, const char* argv[]) int mainRawWrite(int argc, const char* argv[])
@@ -60,10 +60,10 @@ int mainRawWrite(int argc, const char* argv[])
if (argc == 1) if (argc == 1)
showProfiles("rawwrite", formats); showProfiles("rawwrite", formats);
globalConfig().overrides()->mutable_flux_sink()->set_type( globalConfig().overrides()->mutable_flux_sink()->set_type(
FluxSinkProto::DRIVE); FLUXTYPE_DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats); 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"); error("you can't use rawwrite to read from hardware");
auto& fluxSource = globalConfig().getFluxSource(); auto& fluxSource = globalConfig().getFluxSource();

View File

@@ -61,10 +61,10 @@ int mainRead(int argc, const char* argv[])
{ {
if (argc == 1) if (argc == 1)
showProfiles("read", formats); showProfiles("read", formats);
globalConfig().set("flux_source.type", "DRIVE"); globalConfig().set("flux_source.type", "FLUXTYPE_DRIVE");
flags.parseFlagsWithConfigFiles(argc, argv, formats); 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"); error("you cannot copy flux to a hardware device");
auto& fluxSource = globalConfig().getFluxSource(); auto& fluxSource = globalConfig().getFluxSource();

View File

@@ -19,7 +19,7 @@ int mainRpm(int argc, const char* argv[])
{ {
flags.parseFlagsWithConfigFiles(argc, 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"); error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig()->drive().drive(), usbSetDrive(globalConfig()->drive().drive(),

View File

@@ -23,7 +23,7 @@ int mainSeek(int argc, const char* argv[])
{ {
flags.parseFlagsWithConfigFiles(argc, 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"); error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig()->drive().drive(), usbSetDrive(globalConfig()->drive().drive(),

View File

@@ -22,7 +22,7 @@ they might require nudging as the side order can't be reliably autodetected.
image_writer { image_writer {
filename: "acornadfs.img" filename: "acornadfs.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -25,12 +25,12 @@ documentation:
image_reader { image_reader {
filename: "acorndfs.img" filename: "acorndfs.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "acorndfs.img" filename: "acorndfs.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -43,7 +43,7 @@ documentation:
image_writer { image_writer {
filename: "aeslanier.img" filename: "aeslanier.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -28,7 +28,7 @@ documentation:
image_writer { image_writer {
filename: "agat.img" filename: "agat.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -31,12 +31,12 @@ documentation:
image_reader { image_reader {
filename: "amiga.adf" filename: "amiga.adf"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "amiga.adf" filename: "amiga.adf"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -44,7 +44,7 @@ documentation:
image_writer { image_writer {
filename: "ampro.img" filename: "ampro.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -19,12 +19,12 @@ on what was available at the time, with the same format on both.
image_reader { image_reader {
filename: "bk800.img" filename: "bk800.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "bk800.img" filename: "bk800.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -116,12 +116,12 @@ file system supports this.
image_reader { image_reader {
filename: "brother.img" filename: "brother.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "brother.img" filename: "brother.img"
type: IMG type: IMAGETYPE_IMG
} }
encoder { encoder {

View File

@@ -54,12 +54,12 @@ documentation:
image_reader { image_reader {
filename: "commodore.d64" filename: "commodore.d64"
type: D64 type: IMAGETYPE_D64
} }
image_writer { image_writer {
filename: "commodore.d64" filename: "commodore.d64"
type: D64 type: IMAGETYPE_D64
} }
filesystem { filesystem {

View File

@@ -37,7 +37,7 @@ documentation:
image_writer { image_writer {
filename: "eco1.img" filename: "eco1.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -11,7 +11,7 @@ format itself is yet another IBM scheme variant.
image_writer { image_writer {
filename: "epsonpf10.img" filename: "epsonpf10.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -42,7 +42,7 @@ There's amazingly little information about these things.
image_writer { image_writer {
filename: "f85.img" filename: "f85.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -43,7 +43,7 @@ documentation:
image_writer { image_writer {
filename: "fb100.img" filename: "fb100.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -20,12 +20,12 @@ drive {
image_reader { image_reader {
filename: "hplif.img" filename: "hplif.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "hplif.img" filename: "hplif.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -84,12 +84,12 @@ versa, so it shouldn't matter.
image_reader { image_reader {
filename: "ibm.img" filename: "ibm.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "ibm.img" filename: "ibm.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -11,7 +11,7 @@ track! Other than that it's another IBM scheme variation.
image_writer { image_writer {
filename: "icl30.img" filename: "icl30.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -61,12 +61,12 @@ documentation:
image_reader { image_reader {
filename: "mac.dsk" filename: "mac.dsk"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "mac.dsk" filename: "mac.dsk"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -67,12 +67,12 @@ drive {
image_reader { image_reader {
filename: "micropolis.img" filename: "micropolis.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "micropolis.img" filename: "micropolis.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {
@@ -100,12 +100,12 @@ option {
config { config {
image_reader { image_reader {
filename: "micropolis.vgi" filename: "micropolis.vgi"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "micropolis.vgi" filename: "micropolis.vgi"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -57,7 +57,7 @@ documentation:
image_writer { image_writer {
filename: "mx.img" filename: "mx.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -19,12 +19,12 @@ drive {
image_reader { image_reader {
filename: "n88basic.img" filename: "n88basic.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "n88basic.img" filename: "n88basic.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -35,12 +35,12 @@ documentation:
image_reader { image_reader {
filename: "northstar.nsi" filename: "northstar.nsi"
type: NSI type: IMAGETYPE_NSI
} }
image_writer { image_writer {
filename: "northstar.nsi" filename: "northstar.nsi"
type: NSI type: IMAGETYPE_NSI
} }
layout { layout {

View File

@@ -26,12 +26,12 @@ drive {
image_reader { image_reader {
filename: "pme.img" filename: "pme.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "pme.img" filename: "pme.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -20,7 +20,7 @@ you know anything about it.
image_writer { image_writer {
filename: "rolandd20.img" filename: "rolandd20.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -16,12 +16,12 @@ drive {
image_reader { image_reader {
filename: "rx50.img" filename: "rx50.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "rx50.img" filename: "rx50.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -29,7 +29,7 @@ documentation:
image_writer { image_writer {
filename: "smaky6.img" filename: "smaky6.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -31,12 +31,12 @@ documentation:
image_reader { image_reader {
filename: "tids990.img" filename: "tids990.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "tids990.img" filename: "tids990.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -11,7 +11,7 @@ on the precise format.
image_writer { image_writer {
filename: "tiki.img" filename: "tiki.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -50,12 +50,12 @@ documentation:
image_reader { image_reader {
filename: "victor9k.img" filename: "victor9k.img"
type: IMG type: IMAGETYPE_IMG
} }
image_writer { image_writer {
filename: "victor9k.img" filename: "victor9k.img"
type: IMG type: IMAGETYPE_IMG
} }
layout { layout {

View File

@@ -40,7 +40,7 @@ documentation:
image_writer { image_writer {
filename: "zilogmcz.img" filename: "zilogmcz.img"
type: IMG type: IMAGETYPE_IMG
} }
decoder { decoder {

View File

@@ -46,6 +46,18 @@ static wxBitmap createBitmap(const uint8_t* data, size_t length)
return wxBitmap(image); return wxBitmap(image);
} }
static void ignoreInapplicableValueExceptions(std::function<void(void)> cb)
{
try
{
cb();
}
catch (const InapplicableValueException* e)
{
/* swallow */
}
}
class IdlePanelImpl : public IdlePanelGen, public IdlePanel class IdlePanelImpl : public IdlePanelGen, public IdlePanel
{ {
enum enum
@@ -223,16 +235,32 @@ public:
} }
case SELECTEDSOURCE_FLUX: case SELECTEDSOURCE_FLUX:
{
ignoreInapplicableValueExceptions(
[&]()
{ {
globalConfig().setFluxSink(_selectedFluxfilename); globalConfig().setFluxSink(_selectedFluxfilename);
});
ignoreInapplicableValueExceptions(
[&]()
{
globalConfig().setFluxSource(_selectedFluxfilename); globalConfig().setFluxSource(_selectedFluxfilename);
});
break; break;
} }
case SELECTEDSOURCE_IMAGE: case SELECTEDSOURCE_IMAGE:
{
ignoreInapplicableValueExceptions(
[&]()
{ {
globalConfig().setImageReader(_selectedImagefilename); globalConfig().setImageReader(_selectedImagefilename);
});
ignoreInapplicableValueExceptions(
[&]()
{
globalConfig().setImageWriter(_selectedImagefilename); globalConfig().setImageWriter(_selectedImagefilename);
});
break; break;
} }
} }

View File

@@ -52,6 +52,8 @@ private:
}; };
bool FluxEngineApp::OnInit() bool FluxEngineApp::OnInit()
{
try
{ {
wxImage::AddHandler(new wxPNGHandler()); wxImage::AddHandler(new wxPNGHandler());
Bind(EXEC_EVENT_TYPE, &FluxEngineApp::OnExec, this); Bind(EXEC_EVENT_TYPE, &FluxEngineApp::OnExec, this);
@@ -59,6 +61,12 @@ bool FluxEngineApp::OnInit()
_mainWindow->Show(true); _mainWindow->Show(true);
return true; return true;
} }
catch (const ErrorException* e)
{
fmt::print(stderr, "Exception on startup: {}\n", e->message);
exit(1);
}
}
wxThread::ExitCode FluxEngineApp::Entry() wxThread::ExitCode FluxEngineApp::Entry()
{ {