Skip to content

Commit d47ce3a

Browse files
Added checks for bitstream file extension (#61)
Previously, using a file extension other than `.LPC` or `.BIN` would result in the GUI depositing an empty file. This commit adds checks for the extension. The program will now warn the user if the requested extension is unsupported, and it will default to `.LPC` in that case
1 parent 8f27b82 commit d47ce3a

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/ui/gui/MainWindow.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,24 @@ void MainWindow::onSaveBitstream() {
204204
"ASCII Bitstream (*.lpc);;" \
205205
"Binary Bitstream (*.bin)");
206206

207-
if (filepath.isNull()) {
207+
if (filepath.isNull() || filepath.isEmpty()) {
208208
qDebug() << "Save bitstream canceled";
209209
return;
210210
}
211211

212+
// Default to ASCII if requested file extension is invalid
213+
QFileInfo fi(filepath);
214+
QString ext = fi.suffix().toLower();
215+
216+
if (ext != "bin" && ext != "lpc") {
217+
QMessageBox::warning(
218+
this,
219+
"Invalid Extension",
220+
"The file must use .bin or .lpc.\nDefaulting to .lpc."
221+
);
222+
}
223+
224+
filepath = fi.path() + "/" + fi.completeBaseName() + ".lpc";
212225
exportBitstream(filepath.toStdString());
213226
}
214227

@@ -569,6 +582,8 @@ void MainWindow::exportBitstream(const std::string& path) {
569582
binOut.write(
570583
reinterpret_cast<char*>(bin.data()),
571584
static_cast<int>(bin.size()));
585+
} else {
586+
qDebug() << "Unrecognized extension for file" << filepath;
572587
}
573588
}
574589

0 commit comments

Comments
 (0)