| 114 | } |
| 115 | |
| 116 | void StartWriting() override |
| 117 | { |
| 118 | try |
| 119 | { |
| 120 | SetPage(MainWindow::PAGE_IMAGER); |
| 121 | PrepareConfig(); |
| 122 | if (!globalConfig()->has_image_reader()) |
| 123 | error("This format cannot be read from images."); |
| 124 | |
| 125 | auto filename = wxFileSelector("Choose a image file to read", |
| 126 | /* default_path= */ wxEmptyString, |
| 127 | /* default_filename= */ |
| 128 | globalConfig()->image_reader().filename(), |
| 129 | /* default_extension= */ wxEmptyString, |
| 130 | /* wildcard= */ wxEmptyString, |
| 131 | /* flags= */ wxFD_OPEN | wxFD_FILE_MUST_EXIST); |
| 132 | if (filename.empty()) |
| 133 | return; |
| 134 | |
| 135 | globalConfig().setImageReader(filename.ToStdString()); |
| 136 | globalConfig().setImageWriter(filename.ToStdString()); |
| 137 | visualiser->Clear(); |
| 138 | _currentDisk = nullptr; |
| 139 | |
| 140 | SetState(STATE_WRITING_WORKING); |
| 141 | QueueJob( |
| 142 | [this]() |
| 143 | { |
| 144 | auto image = GetContext().GetImageReader()->readImage(); |
| 145 | auto* encoder = GetContext().GetEncoder(); |
| 146 | auto* fluxSinkFactory = GetContext().GetFluxSink(); |
| 147 | |
| 148 | Decoder* decoder = nullptr; |
| 149 | FluxSource* verificationFluxSource; |
| 150 | if (globalConfig().hasDecoder() && |
| 151 | fluxSinkFactory->isHardware()) |
| 152 | { |
| 153 | decoder = GetContext().GetDecoder(); |
| 154 | verificationFluxSource = |
| 155 | GetContext().GetVerificationFluxSource(); |
| 156 | } |
| 157 | |
| 158 | writeDiskCommand(*image, |
| 159 | *encoder, |
| 160 | *fluxSinkFactory, |
| 161 | decoder, |
| 162 | verificationFluxSource); |
| 163 | }); |
| 164 | } |
| 165 | catch (const ErrorException& e) |
| 166 | { |
| 167 | wxMessageBox(e.message, "Error", wxOK | wxICON_ERROR); |
| 168 | if (_state == STATE_WRITING_WORKING) |
| 169 | SetState(STATE_WRITING_FAILED); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void UpdateState() |
nothing calls this directly
no test coverage detected