Example #1
0
int CUpdater::Download(wxString const& url, wxString const& local_file)
{
	engine_->Command(CDisconnectCommand());
	int res = SendConnectCommand(url);
	if( res == FZ_REPLY_OK ) {
		res = SendTransferCommand(url, local_file);
	}

	return res;
}
Example #2
0
void CUpdateWizard::OnPageChanged(wxWizardEvent& event)
{
	if (event.GetPage() == m_pages[0])
	{
		if (m_start_check)
		{
			m_start_check = false;
			StartUpdateCheck();
		}
		return;
	}

	if (event.GetPage() != m_pages[2])
		return;

	wxButton* pNext = wxDynamicCast(FindWindow(wxID_FORWARD), wxButton);
	pNext->Disable();

	m_currentPage = 2;

	wxStaticText *pText = XRCCTRL(*this, "ID_DOWNLOADTEXT", wxStaticText);
	wxString text = wxString::Format(_("Downloading %s"), (CServer::GetPrefixFromProtocol(m_urlProtocol) + _T("://") + m_urlServer + m_urlFile).c_str());
	text.Replace(_T("&"), _T("&&"));
	pText->SetLabel(text);

	m_inTransfer = false;

	if (m_update_options)
		m_update_options->m_use_internal_rootcert = false;

	int res = m_pEngine->Command(CConnectCommand(CServer(m_urlProtocol, DEFAULT, m_urlServer, (m_urlProtocol == HTTPS) ? 443 : 80)));
	if (res == FZ_REPLY_OK)
	{
		XRCCTRL(*this, "ID_DOWNLOADPROGRESSTEXT", wxStaticText)->SetLabel(_("Connecting to server"));
		res = SendTransferCommand();

		XRCCTRL(*this, "ID_DOWNLOADPROGRESS", wxGauge)->SetRange(100);
	}
	if (res == FZ_REPLY_OK)
		ShowPage(m_pages[1]);
	else if (res != FZ_REPLY_WOULDBLOCK)
		FailedTransfer();
	else
	{
		RewrapPage(2);
	}
}
Example #3
0
void CUpdateWizard::StartUpdateCheck()
{
	m_inTransfer = false;

	if (COptions::Get()->GetOptionVal(OPTION_UPDATECHECK_CHECKBETA) != 0)
		m_urlFile += _T("&beta=1");

	m_update_options->m_use_internal_rootcert = true;
	int res = m_pEngine->Command(CConnectCommand(CServer(m_urlProtocol, DEFAULT, m_urlServer, (m_urlProtocol == HTTPS) ? 443 : 80)));
	if (res == FZ_REPLY_OK)
	{
		if (m_loaded)
		{
			XRCCTRL(*this, "ID_CHECKINGTEXTPROGRESS", wxStaticText)->SetLabel(_("Connecting to server"));
			wxGauge* pProgress = XRCCTRL(*this, "ID_CHECKINGPROGRESS", wxGauge);
			pProgress->SetValue(pProgress->GetValue() + 1);
		}
		res = SendTransferCommand();
	}
	wxASSERT(res != FZ_REPLY_OK);
	if (res != FZ_REPLY_WOULDBLOCK)
		FailedTransfer();
}
Example #4
0
void CUpdateWizard::OnEngineEvent(wxEvent& event)
{
	if (!m_pEngine)
		return;

	if (m_currentPage >= 3)
	{
		CNotification *pNotification = m_pEngine->GetNextNotification();
		while (pNotification)
		{
			delete pNotification;
			pNotification = m_pEngine->GetNextNotification();
		}
		return;
	}

	CNotification *pNotification = m_pEngine->GetNextNotification();
	while (pNotification)
	{
		switch (pNotification->GetID())
		{
		case nId_logmsg:
			{
				if (!m_loaded)
					break;

				CLogmsgNotification* pLogMsg = reinterpret_cast<CLogmsgNotification *>(pNotification);
				if (pLogMsg->msgType == Status || pLogMsg->msgType == Command)
				{
					if (!m_currentPage)
					{
						wxStaticText *pText = XRCCTRL(*this, "ID_CHECKINGTEXTPROGRESS", wxStaticText);
						wxString text = pLogMsg->msg;
						text.Replace(_T("&"), _T("&&"));
						WrapText(pText, text, m_pages[0]->GetClientSize().x);
						pText->SetLabel(text);

						m_pages[0]->GetSizer()->Layout();
						wxGauge* pProgress = XRCCTRL(*this, "ID_CHECKINGPROGRESS", wxGauge);
						int value = pProgress->GetValue();
#ifdef __WXDEBUG__
						wxASSERT(value < MAXCHECKPROGRESS);
#endif
						if (value < MAXCHECKPROGRESS)
							pProgress->SetValue(value + 1);
					}
					else if (m_currentPage == 2)
					{
						wxStaticText *pText = XRCCTRL(*this, "ID_DOWNLOADPROGRESSTEXT", wxStaticText);

						wxString text = pLogMsg->msg;
						text.Replace(_T("&"), _T("&&"));
						WrapText(pText, text, m_pages[2]->GetClientSize().x);
						pText->SetLabel(text);
						m_pages[2]->GetSizer()->Layout();
					}
				}

				wxString label;
				switch (pLogMsg->msgType)
				{
				case Error:
					label = _("Error:");
					break;
				case Status:
					label = _("Status:");
					break;
				case Command:
					label = _("Command:");
					break;
				case Response:
					label = _("Response:");
					break;
				default:
					break;
				}
				if (label != _T(""))
					m_update_log += label + _T(" ") + pLogMsg->msg + _T("\n");
			}
			break;
		case nId_operation:
			{
				COperationNotification* pOpMsg = reinterpret_cast<COperationNotification*>(pNotification);
				if (pOpMsg->nReplyCode != FZ_REPLY_OK)
				{
					while (pNotification)
					{
						delete pNotification;
						pNotification = m_pEngine->GetNextNotification();
					}
					FailedTransfer();
					return;
				}
				if (!m_inTransfer)
				{
					if (m_loaded && !m_currentPage)
					{
						wxGauge* pProgress = XRCCTRL(*this, "ID_CHECKINGPROGRESS", wxGauge);
						pProgress->SetValue(pProgress->GetValue() + 1);
					}

					int res = SendTransferCommand();
					if (res == FZ_REPLY_WOULDBLOCK)
						break;
					else if (res != FZ_REPLY_OK)
					{
						FailedTransfer();
						break;
					}
				}

				if (!m_loaded || !m_currentPage)
				{
					m_pEngine->Command(CDisconnectCommand());
					ParseData();
				}
				else if (m_currentPage == 2)
				{
					if (!VerifyChecksum())
						break;

					int pos = m_localFile.Find('.', true);
					wxASSERT(pos > 0);
					wxRenameFile(m_localFile, m_localFile.Left(pos));
					m_localFile = m_localFile.Left(pos);

					wxStaticText* pText = XRCCTRL(*this, "ID_DOWNLOADCOMPLETE", wxStaticText);
					wxASSERT(pText);

					wxButton* pNext = wxDynamicCast(FindWindow(wxID_FORWARD), wxButton);
					pNext->Enable();

					XRCCTRL(*this, "ID_DOWNLOADPROGRESS", wxGauge)->SetValue(100);
#ifdef __WXMSW__
					pText->SetLabel(_("The most recent version has been downloaded. Click on Finish to close FileZilla and to start the installation."));
#else
					pText->SetLabel(_("The most recent version has been downloaded. Please install it the same way you installed this version."));
#endif

					pText->Show();
					RewrapPage(2);

					m_successfully_downloaded = true;
				}
			}
			break;
		case nId_data:
			{
				if (!m_inTransfer)
					break;

				wxASSERT(!m_currentPage);
				CDataNotification* pOpMsg = reinterpret_cast<CDataNotification*>(pNotification);
				int len;
				char* data = pOpMsg->Detach(len);

				if (m_data.Len() + len > 131072)
				{
					delete [] data;
					m_pEngine->Command(CCancelCommand());
					FailedTransfer();
					break;
				}
				for (int i = 0; i < len; i++)
				{
					if (!data[i] || (unsigned char)data[i] > 127)
					{
						delete [] data;
						data = 0;
						m_pEngine->Command(CCancelCommand());
						FailedTransfer();
						break;
					}
				}

				if (data)
				{
					m_data += wxString(data, wxConvUTF8, len);
					delete [] data;
				}
				break;
			}
		case nId_asyncrequest:
			{
				CAsyncRequestNotification* pData = reinterpret_cast<CAsyncRequestNotification *>(pNotification);
				if (pData->GetRequestID() == reqId_fileexists)
				{
					reinterpret_cast<CFileExistsNotification *>(pData)->overwriteAction = CFileExistsNotification::overwrite;
				}
				else if (pData->GetRequestID() == reqId_certificate)
				{
					CCertificateNotification* pCertNotification = (CCertificateNotification*)pData;
					pCertNotification->m_trusted = true;
				}
				m_pEngine->SetAsyncRequestReply(pData);
			}
			break;
		case nId_transferstatus:
			if (!m_loaded)
				break;

			if (m_currentPage == 2)
			{
				CTransferStatusNotification *pTransferStatusNotification = reinterpret_cast<CTransferStatusNotification *>(pNotification);
				const CTransferStatus *pStatus = pTransferStatusNotification->GetStatus();
				SetTransferStatus(pStatus);
			}
			break;
		default:
			break;
		}
		delete pNotification;
		pNotification = m_pEngine->GetNextNotification();
	}
}