Skip to content

Commit

Permalink
passing arguments to installer works
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsolt Szatmari committed Apr 11, 2015
1 parent 5d96c9e commit 32139bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include <exdisp.h>
#include <mshtml.h>

#include <algorithm>
#include <sstream>

#if !wxCHECK_VERSION(2,9,0)
#error "wxWidgets >= 2.9 is required to compile this code"
Expand Down Expand Up @@ -453,7 +455,7 @@ class UpdateDialog : public WinSparkleDialog
// current update file (only valid after StateUpdateDownloaded)
wxString m_updateFile;
// space separated arguments to update file (only valid after StateUpdateDownloaded)
std::string m_updateArguments
std::string m_updateArguments;
// downloader (only valid between OnInstall and OnUpdateDownloaded)
UpdateDownloader* m_downloader;

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

if ( !wxLaunchDefaultApplication(m_updateFile) )
if ( !RunInstaller() )
{
wxMessageDialog dlthis,
wxMessageDialog dlg(this,
_("Failed to launch the installer."),
_("Software Update"),
wxOK | wxOK_DEFAULT | wxICON_EXCLAMATION);
Expand All @@ -668,19 +670,20 @@ bool UpdateDialog::RunInstaller()
// tokenize arguments, which are separated by spaces
std::vector<std::string> tokens;
std::istringstream iss(m_updateArguments);
copy(std::istream_iterator<string>(iss),
std::istream_iterator<string>(),
std::copy(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
std::back_inserter(tokens));

// convert update file path and tokens to char **argv
std::vector<char *> argv;
argv.resize(tokens.size()+1);
std::vector<const char *> argv;
argv.resize(tokens.size()+2);
argv[0] = m_updateFile.c_str();
for (int i = 0 ; i < tokens.size() ; ++i) {
argv[i+1] = tokens[i].c_str();
}
argv[argv.size()-1] = NULL;

long processId = wxExecute(&argv[0]) != -1;
long processId = wxExecute(const_cast<char **>(&argv[0])) != -1;

return processId != 0;
}
Expand Down Expand Up @@ -1165,7 +1168,7 @@ App::App()
Bind(wxEVT_COMMAND_THREAD, &App::OnUpdateAvailable, this, MSG_UPDATE_AVAILABLE);
Bind(wxEVT_COMMAND_THREAD, &App::OnUpdateError, this, MSG_UPDATE_ERROR);
Bind(wxEVT_COMMAND_THREAD, &App::OnDownloadProgress, this, MSG_DOWNLOAD_PROGRESS);
Bind(wxEVT_COMMAND_THREAD, &App::OnUpdateDownloaded, this, MSG_UPDATE_DOWNLOADED);
Bind(wxEVT_COMMAND_THREAD, &App::OnUpdateDownloaded, this, MSG_UPDATE_DOWNLOADED);
Bind(wxEVT_COMMAND_THREAD, &App::OnAskForPermission, this, MSG_ASK_FOR_PERMISSION);
}

Expand Down Expand Up @@ -1244,7 +1247,7 @@ void App::OnDownloadProgress(wxThreadEvent& event)
{
if ( m_win )
{
EventPayload payload(event.GetPayload<EventPayload>());
EventPayload payload(event.GetPayload<EventPayload>());
m_win->DownloadProgress(payload.sizeDownloaded, payload.sizeTotal);
}
}
Expand All @@ -1253,8 +1256,8 @@ void App::OnUpdateDownloaded(wxThreadEvent& event)
{
if ( m_win )
{
EventPayload payload(event.GetPayload<EventPayload>());
m_win->StateUpdateDownloaded(payload.updateFile, payload.updateArguments);
EventPayload payload(event.GetPayload<EventPayload>());
m_win->StateUpdateDownloaded(payload.updateFile, payload.appcast.UpdateArguments);
}
}

Expand Down Expand Up @@ -1422,11 +1425,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 32139bf

Please sign in to comment.