diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ba603..5baa8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Change log * 💊 Fix handling of `--file` parameter, as it did not work as advertised * 💊 Improve desktop error output, restricting application to single instance +* 🎁 Open METAR file via CLI parameter (or double-click on desktop app) 1.2.4 ----- diff --git a/src/WettergeraetDesktop/Frame.cpp b/src/WettergeraetDesktop/Frame.cpp index c2fee4c..47089a5 100644 --- a/src/WettergeraetDesktop/Frame.cpp +++ b/src/WettergeraetDesktop/Frame.cpp @@ -214,6 +214,9 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr, // ---------------------------------------------------- this->loadMainMcf(); + if (strlen(this->argumentor.metarfile) != 0) { + this->loadMetarFile(this->argumentor.metarfile); + } this->addIcaoChoice("KDEN"); // Denver this->addIcaoChoice("KJFK"); // New York - JFK this->addIcaoChoice("KLAS"); // Las Vegas @@ -361,6 +364,19 @@ void Frame::actionParse(wxCommandEvent& WXUNUSED(event)) } } +void Frame::loadMetarFile(wxString filename) { + wxTextFile tfile; + tfile.Open(filename); + + auto metarString = tfile.GetFirstLine(); + if (!tfile.Eof()) { + metarString += "\n" + tfile.GetNextLine(); + } + this->metarInput->SetValue(metarString); + this->saveButton->SetFocus(); + this->markAsDirty(); +} + void Frame::actionSave(wxCommandEvent& WXUNUSED(event)) { if (!this->argumentor.isDryRun) { @@ -404,21 +420,11 @@ void Frame::actionAbout(wxCommandEvent& WXUNUSED(event)) void Frame::actionOpenMetarFile(wxCommandEvent& WXUNUSED(event)) { - wxFileDialog openFileDialog(this, _("Open METAR file"), "", "", "Text files (*.txt, *.rwx)|*.txt;*.rwx", wxFD_OPEN | wxFD_FILE_MUST_EXIST); + wxFileDialog openFileDialog(this, _("Open METAR file"), "", "", "Text files (*.txt, *.rwx)|*.txt;*.rwx", wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (openFileDialog.ShowModal() == wxID_CANCEL) { return; } - - wxTextFile tfile; - tfile.Open(openFileDialog.GetPath()); - - auto metarString = tfile.GetFirstLine(); - if (!tfile.Eof()) { - metarString += "\n" + tfile.GetNextLine(); - } - this->metarInput->SetValue(metarString); - this->saveButton->SetFocus(); - this->markAsDirty(); + return this->loadMetarFile(openFileDialog.GetPath()); } void Frame::actionSaveMetarFile(wxCommandEvent& WXUNUSED(event)) diff --git a/src/WettergeraetDesktop/Frame.h b/src/WettergeraetDesktop/Frame.h index c0da9f3..1cc7202 100644 --- a/src/WettergeraetDesktop/Frame.h +++ b/src/WettergeraetDesktop/Frame.h @@ -80,6 +80,9 @@ class Frame : public wxFrame // Parse METAR data into Aerofly values virtual void actionParse(wxCommandEvent&); + // Copy METAR information from file to METAR input field + virtual void loadMetarFile(wxString filename); + // Save Aerofly values into config file virtual void actionSave(wxCommandEvent&); diff --git a/src/WettergeraetLib/Argumentor.cpp b/src/WettergeraetLib/Argumentor.cpp index b912289..af179fd 100644 --- a/src/WettergeraetLib/Argumentor.cpp +++ b/src/WettergeraetLib/Argumentor.cpp @@ -159,12 +159,20 @@ void Argumentor::getArgs(int argc, char * argv[]) else if (currentArg == "--metar") { strcpy_s(this->metarString, 512, argv[++i]); } + else if (currentArg == "--metarfile") { + strcpy_s(this->metarfile, 512, argv[++i]); + } else if (currentArg == "--hours") { this->hours = std::stoi(argv[++i]); } } else { - strcpy_s(this->filename, 512, argv[i]); + if (strstr(argv[i], ".rwx") != NULL || strstr(argv[i], ".txt") != NULL) { + strcpy_s(this->metarfile, 512, argv[i]); + } + else { + strcpy_s(this->filename, 512, argv[i]); + } } } } diff --git a/src/WettergeraetLib/Argumentor.h b/src/WettergeraetLib/Argumentor.h index 909e2ae..5dfafbb 100644 --- a/src/WettergeraetLib/Argumentor.h +++ b/src/WettergeraetLib/Argumentor.h @@ -27,6 +27,9 @@ class Argumentor char metarString[512] = ""; + // Initially loaded METAR file + char metarfile[512] = ""; + int hours = 0; bool isDryRun = false;