Skip to content

Commit

Permalink
Open METAR file via CLI parameter (or double-click on desktop app)
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed May 15, 2019
1 parent 75507c9 commit dc56a1e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
30 changes: 18 additions & 12 deletions src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions src/WettergeraetDesktop/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down
10 changes: 9 additions & 1 deletion src/WettergeraetLib/Argumentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
}
3 changes: 3 additions & 0 deletions src/WettergeraetLib/Argumentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Argumentor

char metarString[512] = "";

// Initially loaded METAR file
char metarfile[512] = "";

int hours = 0;

bool isDryRun = false;
Expand Down

0 comments on commit dc56a1e

Please sign in to comment.