1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-22 15:20:15 +02:00

Fix command line options

Fixes -v / --verbose.
Fixes file paths (Windows and Linux).

Relative file paths would (before this fix) be wrong unless the command
was launched from the same directory as Audacity's working directory
(Windows and Linux only)
This commit is contained in:
Steve Daulton 2018-11-04 17:03:27 +00:00
parent bc60de2ffa
commit 4c76e598d5

View File

@ -1457,7 +1457,7 @@ bool AudacityApp::OnInit()
if (parser->Found(wxT("v"))) if (parser->Found(wxT("v")))
{ {
wxFprintf(stderr, wxT("Audacity v%s\n"), AUDACITY_VERSION_STRING); wxPrintf("Audacity v%s\n", AUDACITY_VERSION_STRING);
exit(0); exit(0);
} }
@ -1638,7 +1638,7 @@ bool AudacityApp::OnInit()
} }
// As of wx3, there's no need to process the filename arguments as they // As of wx3, there's no need to process the filename arguments as they
// will be sent view the MacOpenFile() method. // will be sent via the MacOpenFile() method.
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++) for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
{ {
@ -1853,7 +1853,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
} }
else if ( checker->IsAnotherRunning() ) { else if ( checker->IsAnotherRunning() ) {
// Parse the command line to ensure correct syntax, but // Parse the command line to ensure correct syntax, but
// ignore options and only use the filenames, if any. // ignore options other than -v, and only use the filenames, if any.
auto parser = ParseCommandLine(); auto parser = ParseCommandLine();
if (!parser) if (!parser)
{ {
@ -1861,6 +1861,22 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
return false; return false;
} }
if (parser->Found(wxT("v")))
{
wxPrintf("Audacity v%s\n", AUDACITY_VERSION_STRING);
return false;
}
// Windows and Linux require absolute file names as command may
// not come from current working directory.
wxArrayString filenames;
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
{
wxFileName filename(parser->GetParam(i));
if (filename.MakeAbsolute())
filenames.Add(filename.GetLongPath());
}
#if defined(__WXMSW__) #if defined(__WXMSW__)
// On Windows, we attempt to make a connection // On Windows, we attempt to make a connection
// to an already active Audacity. If successful, we send // to an already active Audacity. If successful, we send
@ -1876,12 +1892,11 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
if (conn) if (conn)
{ {
bool ok = false; bool ok = false;
if (parser->GetParamCount() > 0) if (filenames.GetCount() > 0)
{ {
// Send each parameter to existing Audacity for (size_t i = 0, cnt = filenames.GetCount(); i < cnt; i++)
for (size_t j = 0, cnt = parser->GetParamCount(); j < cnt; j++)
{ {
ok = conn->Execute(parser->GetParam(j)); ok = conn->Execute(filenames[i]);
} }
} }
else else
@ -1918,12 +1933,11 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
sock->Connect(addr, true); sock->Connect(addr, true);
if (sock->IsConnected()) if (sock->IsConnected())
{ {
if (parser->GetParamCount() > 0) if (filenames.GetCount() > 0)
{ {
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++) for (size_t i = 0, cnt = filenames.GetCount(); i < cnt; i++)
{ {
// Send the filename const wxString param = filenames[i];
wxString param = parser->GetParam(i);
sock->WriteMsg((const wxChar *) param, (param.Len() + 1) * sizeof(wxChar)); sock->WriteMsg((const wxChar *) param, (param.Len() + 1) * sizeof(wxChar));
} }
} }