Skip to content

Commit

Permalink
Merge pull request #57 from treasurebox/arguments
Browse files Browse the repository at this point in the history
Pass command line arguments to downloaded installer
  • Loading branch information
vslavik committed Apr 25, 2015
2 parents adc56a8 + 238169b commit 9e056f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/appcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace
#define ATTR_VERSION NS_SPARKLE_NAME("version")
#define ATTR_SHORTVERSION NS_SPARKLE_NAME("shortVersionString")
#define ATTR_OS NS_SPARKLE_NAME("os")
#define ATTR_ARGUMENTS NS_SPARKLE_NAME("installerArguments")
#define NODE_VERSION ATTR_VERSION // These can be nodes or
#define NODE_SHORTVERSION ATTR_SHORTVERSION // attributes.
#define OS_MARKER "windows"
Expand Down Expand Up @@ -167,6 +168,8 @@ void XMLCALL OnStartElement(void *data, const char *name, const char **attrs)
ctxt.items[size-1].ShortVersionString = value;
else if ( strcmp(name, ATTR_OS) == 0 )
ctxt.items[size-1].Os = value;
else if ( strcmp(name, ATTR_ARGUMENTS) == 0 )
ctxt.items[size-1].InstallerArguments = value;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/appcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ struct Appcast
// Minimum OS version required for update
std::string MinOSVersion;

// Arguments passed on the the updater executable
std::string InstallerArguments;

/**
Initializes the struct with data from XML appcast feed.
Expand Down
30 changes: 25 additions & 5 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class UpdateDialog : public WinSparkleDialog
// update download progress
void DownloadProgress(size_t downloaded, size_t total);
// change state into "update downloaded"
void StateUpdateDownloaded(const std::wstring& updateFile);
void StateUpdateDownloaded(const std::wstring& updateFile, const std::string &installerArguments);

private:
void EnablePulsing(bool enable);
Expand All @@ -425,6 +425,8 @@ class UpdateDialog : public WinSparkleDialog

void OnRunInstaller(wxCommandEvent&);

bool RunInstaller();

void SetMessage(const wxString& text, int width = MESSAGE_AREA_WIDTH);
void ShowReleaseNotes(const Appcast& info);

Expand All @@ -450,6 +452,8 @@ class UpdateDialog : public WinSparkleDialog
Appcast m_appcast;
// current update file (only valid after StateUpdateDownloaded)
wxString m_updateFile;
// space separated arguments to update file (only valid after StateUpdateDownloaded)
std::string m_installerArguments;
// downloader (only valid between OnInstall and OnUpdateDownloaded)
UpdateDownloader* m_downloader;

Expand Down Expand Up @@ -640,7 +644,7 @@ void UpdateDialog::OnRunInstaller(wxCommandEvent&)
m_message->SetLabel(_("Launching the installer..."));
m_runInstallerButton->Disable();

if ( !wxLaunchDefaultApplication(m_updateFile) )
if ( !RunInstaller() )
{
wxMessageDialog dlg(this,
_("Failed to launch the installer."),
Expand All @@ -655,6 +659,20 @@ void UpdateDialog::OnRunInstaller(wxCommandEvent&)
}
}

bool UpdateDialog::RunInstaller()
{
if (m_installerArguments.empty())
{
// keep old way of calling updater to not accidentally break any existing code
return wxLaunchDefaultApplication(m_updateFile);
}
else
{
// wxExecute() returns a process id, or zero on failure
long processId = wxExecute(m_updateFile + " " + m_installerArguments);
return processId != 0;
}
}

void UpdateDialog::SetMessage(const wxString& text, int width)
{
Expand Down Expand Up @@ -855,13 +873,14 @@ void UpdateDialog::DownloadProgress(size_t downloaded, size_t total)
}


void UpdateDialog::StateUpdateDownloaded(const std::wstring& updateFile)
void UpdateDialog::StateUpdateDownloaded(const std::wstring& updateFile, const std::string& installerArguments)
{
m_downloader->Join();
delete m_downloader;
m_downloader = NULL;

m_updateFile = updateFile;
m_installerArguments = installerArguments;

LayoutChangesGuard guard(this);

Expand Down Expand Up @@ -1223,7 +1242,7 @@ void App::OnUpdateDownloaded(wxThreadEvent& event)
if ( m_win )
{
EventPayload payload(event.GetPayload<EventPayload>());
m_win->StateUpdateDownloaded(payload.updateFile);
m_win->StateUpdateDownloaded(payload.updateFile, payload.appcast.InstallerArguments);
}
}

Expand Down Expand Up @@ -1391,11 +1410,12 @@ void UI::NotifyDownloadProgress(size_t downloaded, size_t total)


/*static*/
void UI::NotifyUpdateDownloaded(const std::wstring& updateFile)
void UI::NotifyUpdateDownloaded(const std::wstring& updateFile, const Appcast &appcast)
{
UIThreadAccess uit;
EventPayload payload;
payload.updateFile = updateFile;
payload.appcast = appcast;
uit.App().SendMsg(MSG_UPDATE_DOWNLOADED, &payload);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class UI : public Thread
/**
Notifies the UI that an update was downloaded.
*/
static void NotifyUpdateDownloaded(const std::wstring& updateFile);
static void NotifyUpdateDownloaded(const std::wstring& updateFile, const Appcast &appcast);

/**
Shows the WinSparkle window in "checking for updates..." state.
Expand Down
2 changes: 1 addition & 1 deletion src/updatedownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void UpdateDownloader::Run()
UpdateDownloadSink sink(*this, tmpdir);
DownloadFile(m_appcast.DownloadURL, &sink);
sink.Close();
UI::NotifyUpdateDownloaded(sink.GetFilePath());
UI::NotifyUpdateDownloaded(sink.GetFilePath(), m_appcast);
}
catch ( ... )
{
Expand Down

0 comments on commit 9e056f9

Please sign in to comment.