| 2180 | } |
| 2181 | |
| 2182 | void MainWindow::openModule(const QString& file) |
| 2183 | { |
| 2184 | try { |
| 2185 | freezeViews(); |
| 2186 | if (tickTimerForRealChip_) tickTimerForRealChip_->stop(); |
| 2187 | else { |
| 2188 | try { |
| 2189 | stream_->stop(); |
| 2190 | } |
| 2191 | catch (std::exception& e) { |
| 2192 | showStreamFailedDialog(e.what()); |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | QFile fp(file); |
| 2197 | if (fp.open(QIODevice::ReadOnly)) { |
| 2198 | io::BinaryContainer container; |
| 2199 | { |
| 2200 | QByteArray&& array = fp.readAll(); |
| 2201 | fp.close(); |
| 2202 | std::move(array.begin(), array.end(), std::back_inserter(container)); |
| 2203 | } |
| 2204 | |
| 2205 | bt_->loadModule(container); |
| 2206 | bt_->setModulePath(file.toStdString()); |
| 2207 | |
| 2208 | loadModule(); |
| 2209 | |
| 2210 | config_.lock()->setWorkingDirectory(QFileInfo(file).dir().path().toStdString()); |
| 2211 | changeFileHistory(file); |
| 2212 | |
| 2213 | goto AFTER_MOD_LOADING; // Skip error handling section |
| 2214 | } |
| 2215 | else { |
| 2216 | FileIOErrorMessageBox::openError(file, true, io::FileType::Mod, this); |
| 2217 | } |
| 2218 | } |
| 2219 | catch (std::exception& e) { |
| 2220 | if (auto ef = dynamic_cast<io::FileIOError*>(&e)) { |
| 2221 | FileIOErrorMessageBox(file, true, *ef, this).exec(); |
| 2222 | } |
| 2223 | else { |
| 2224 | FileIOErrorMessageBox(file, true, io::FileType::Mod, QString(e.what()), this).exec(); |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | // Init module as a plain when something is wrong |
| 2229 | freezeViews(); |
| 2230 | bt_->makeNewModule(); |
| 2231 | loadModule(); |
| 2232 | |
| 2233 | AFTER_MOD_LOADING: // Post process of module loading |
| 2234 | isModifiedForNotCommand_ = false; |
| 2235 | setWindowModified(false); |
| 2236 | if (tickTimerForRealChip_) tickTimerForRealChip_->start(); |
| 2237 | else { |
| 2238 | try { |
| 2239 | stream_->start(); |
nothing calls this directly
no test coverage detected