A CDBurnerXP-like update box.
Posted: Sat Oct 25, 2008 1:46 pm
I like the CDBurner XP update box. It's not too bad designed and very functional. Therefore i plagiarized it (sorry ).
Here the code:
Content of updateinfo.xml:
Screenshot is better than code:
Here the code:
Code: Select all
/**********************************************************************
* Description: updateDialog header
* Author(s): zoom
* Last modif.: 18/10/08
* Licence: linkware, just put a reference to askorn.free.fr
*********************************************************************/
#ifndef _CLASS_UPDATEDIALOG_H_
#define _CLASS_UPDATEDIALOG_H_
#include <cstdio>
#include <wx/protocol/http.h>
#include <wx/XML/xml.h>
#include <wx/dir.h>
#include <wx/file.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "version.h"
enum
{
ID_WXBOUTON_ANNULER = 2023,//Leave button
ID_WXBOUTON_TELECHARGER = 2022,//Download button
ID_WXBOUTON_MAJDISPO = 2021,//Is update available?
ID_WXBOUTON_PARCOURIR = 2020,//Choose directory button
};
/*updateDialog class*/
class
updateDialog : public wxDialog
{
public:
updateDialog(wxWindowID id);
void OnClose( wxCommandEvent& event );
void GetLastVersion( wxCommandEvent& WXUNUSED(event) );
void GetLastApp( wxCommandEvent& WXUNUSED(event) );
void OnBouttonParcourir( wxCommandEvent& WXUNUSED(event) );
private:
DECLARE_EVENT_TABLE();
wxStaticBox *mySTATICBOX_INFOVERSION;
wxStaticBox *mySTATICBOX_PROGRESSION;
wxTextCtrl *monDossier;
wxGauge *maBarreDeProgression;
wxStaticText *szVersionDispo;
wxStaticText *szNomDuFichierTelecharge;
wxButton *monBoutonTelecharger;
wxString lastappexename;
wxString link;
wxString iDirName;
wxString szapp_size;
unsigned long app_size;
};
//----------------------------------------------------------------------------------------------------
//UPDATE DIALOG
//----------------------------------------------------------------------------------------------------
updateDialog::updateDialog(wxWindowID id)
: wxDialog(NULL,id,_("Update of AppName"),wxDefaultPosition, wxSize(450,290), wxDEFAULT_DIALOG_STYLE,wxT("myAboutFrame"))
{
link = _("mywebsite.com");/*without 'http://'*/
mySTATICBOX_INFOVERSION = new wxStaticBox( this,
wxID_ANY,
wxT("Version info:"),
wxPoint(5,10),
wxSize(this->GetSize().x-15,75),
0,
wxT("myVersionInfo"));
wxInitAllImageHandlers();
/*Icon loading*/
wxStaticBitmap *myIcon = new wxStaticBitmap( mySTATICBOX_INFOVERSION,
-1,
wxBitmap(wxImage(_ ("./img/update.png"),wxBITMAP_TYPE_PNG, -1), -1),
wxPoint( 10, 20));
temp.Printf(_("Your version: %.2f.%d"), AutoVersion::UBUNTU_VERSION_STYLE, AutoVersion::BUILDS_COUNT);
wxStaticText *szMaVersion = new wxStaticText( mySTATICBOX_INFOVERSION,
wxID_ANY,
temp,
wxPoint(22+48,20),/*48x48 are the picture dimensions*/
wxSize(300, 20),
0,
wxT("szMaVersion"));
szMaVersion->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxFONTFLAG_ANTIALIASED, false, _("Arial Black")));
szVersionDispo = new wxStaticText( mySTATICBOX_INFOVERSION,
wxID_ANY,
_("Last version:"),
wxPoint(szMaVersion->GetPosition().x,szMaVersion->GetPosition().y+25),
wxSize(300, 20),
0,
wxT("szMaVersion"));
szVersionDispo->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxFONTFLAG_ANTIALIASED, false, _("Arial Black")));
mySTATICBOX_PROGRESSION = new wxStaticBox( this,
wxID_ANY,
_("Download info:"),
wxPoint(mySTATICBOX_INFOVERSION->GetPosition().x,
mySTATICBOX_INFOVERSION->GetPosition().y + mySTATICBOX_INFOVERSION->GetSize().y+10),
wxSize(this->GetSize().x-15,this->GetSize().y-mySTATICBOX_INFOVERSION->GetSize().y-95),
0,
wxT("myProgression"));
wxStaticText *szDossierDeTelechargement = new wxStaticText( mySTATICBOX_PROGRESSION,
wxID_ANY,
_("Select where the updating file will be downloaded:"),
wxPoint( 9, 20),
wxSize(400, 20),
0,
wxT("szDossierDeTelechargement"));
monDossier = new wxTextCtrl( mySTATICBOX_PROGRESSION,
wxID_ANY,
_(""),
wxPoint( 9, szDossierDeTelechargement->GetPosition().y + 20),
wxSize( 370, 20),
wxTE_READONLY | wxSIMPLE_BORDER | wxTE_LEFT,
wxDefaultValidator,
_("monDossier"));
monDossier->SetBackgroundColour( wxColour( 220, 220, 220 ) );
wxButton *monBoutonParcourir = new wxButton( mySTATICBOX_PROGRESSION,
ID_WXBOUTON_PARCOURIR,
wxT("..."),
wxPoint(mySTATICBOX_PROGRESSION->GetSize().x - 30 - 10,
monDossier->GetPosition().y-1),
wxSize(30,22),
0,
wxDefaultValidator,
wxT("myBParcourir"));
szNomDuFichierTelecharge = new wxStaticText( mySTATICBOX_PROGRESSION,
wxID_ANY,
_("Nom:"),
wxPoint( 9, monDossier->GetPosition().y + 30),
wxSize(400, 20),
0,
wxT("szNomDuFichierTelecharge"));
maBarreDeProgression = new wxGauge( mySTATICBOX_PROGRESSION,
wxID_ANY,
15,
wxPoint( 9, szNomDuFichierTelecharge->GetPosition().y+18),
wxSize(mySTATICBOX_PROGRESSION->GetSize().x-18, 18),
wxGA_HORIZONTAL,
wxDefaultValidator,
_("myGauge"));
wxButton *myBoutonMAJDispo = new wxButton( this,
ID_WXBOUTON_MAJDISPO,
wxT("Avail. Update?"),
wxPoint(mySTATICBOX_PROGRESSION->GetPosition().x,
mySTATICBOX_PROGRESSION->GetPosition().y + mySTATICBOX_PROGRESSION->GetSize().y + 10),
wxSize(80,23),
0,
wxDefaultValidator,
wxT("myBoutonMAJDispo"));
monBoutonTelecharger = new wxButton( this,
ID_WXBOUTON_TELECHARGER,
wxT("Download"),
wxPoint(myBoutonMAJDispo->GetPosition().x + myBoutonMAJDispo->GetSize().x + 10,
myBoutonMAJDispo->GetPosition().y),
wxSize(80,23),
0,
wxDefaultValidator,
wxT("monBoutonTelecharger"));
wxButton *monBoutonAnnuler = new wxButton( this,
ID_WXBOUTON_ANNULER,
wxT("Leave"),
wxPoint(this->GetSize().x - 83 - 8,
myBoutonMAJDispo->GetPosition().y),
wxSize(80,23),
0,
wxDefaultValidator,
wxT("monBoutonAnnuler"));
/*We disable the download button since we don't know if the last version is later than ours*/
monBoutonTelecharger->Disable();
}
//---------------------------------------------------------------------------------------------------------
void
updateDialog::OnClose( wxCommandEvent& WXUNUSED(event) )
{
Close(TRUE);
delete this;
}
/*Get last version of your app*/
void
updateDialog::GetLastVersion( wxCommandEvent& WXUNUSED(event) )
{
wxString lastappversion;
wxString link = _("mywebsite.com");
wxHTTP http;
unsigned int value = 0;
maBarreDeProgression->SetValue(value++);
http.SetTimeout(6);
maBarreDeProgression->SetValue(value++);
http.Connect( link );
maBarreDeProgression->SetValue(value++);
// PHP file sending XML content
wxInputStream *httpStream = http.GetInputStream(_("/updateinfo.xml"));
maBarreDeProgression->SetValue(value++);
if (http.GetError() == wxPROTO_NOERR)
{
maBarreDeProgression->SetValue(value++);
//wxMessageBox(_("Successfully connected!"));
// will crash here, if xml content is not formatted PERFECTLY
wxXmlDocument xml(*httpStream);
maBarreDeProgression->SetValue(value++);
wxXmlNode *node = xml.GetRoot()->GetChildren();
maBarreDeProgression->SetValue(value++);
while (node)
{
if (node->GetName() == _("AppSize"))
{
szapp_size = (node->GetNodeContent()).Trim(true).Trim(false);
szapp_size.ToULong(&app_size);
maBarreDeProgression->SetValue(value++);
}
if (node->GetName() == _("AppExeName"))
{
lastappexename = (node->GetNodeContent()).Trim(true).Trim(false);
maBarreDeProgression->SetValue(value++);
}
if (node->GetName() == _("AppVersion"))
{
lastappversion = (node->GetNodeContent()).Trim(true).Trim(false);
szVersionDispo->SetLabel(_("Last version: ") + lastappversion);
maBarreDeProgression->SetValue(value++);
}
else if(node->GetName() == _("AppURL"))
{
//link_for_app = (node->GetNodeContent()).Trim(true).Trim(false);
maBarreDeProgression->SetValue(value++);
}
node = node->GetNext();
maBarreDeProgression->SetValue(value++);
}
temp.Printf(_(" (%d ko)."), (int)(app_size/1000));
szNomDuFichierTelecharge->SetLabel(_("Name: ") + lastappexename + temp);//szapp_size + _(" ko)."));
}
else
wxMessageBox(_("Connection failed"));
http.Close();
maBarreDeProgression->SetValue(value++);
wxDELETE(httpStream);
maBarreDeProgression->SetValue(value++);
temp.Printf(_("%.2f.%d"), AutoVersion::UBUNTU_VERSION_STYLE, AutoVersion::BUILDS_COUNT);
if(lastappversion != temp)
monBoutonTelecharger->Enable();
maBarreDeProgression->SetValue(value++);
}
/*Get last app*/
void
updateDialog::GetLastApp( wxCommandEvent& WXUNUSED(event) )
{
unsigned int value = 0;
wxDir *myDir;
if(iDirName != _("") && myDir->Exists( iDirName ))
{
maBarreDeProgression->SetRange( 3 );
maBarreDeProgression->SetValue( value++ );
/*Get the full filename*/
wxString szOutFilePath = iDirName + lastappexename;
//wxMessageBox( oFilePath );
/*wxFile *file;
file->Open( szOutFilePath, wxFile::write );*/
fpos_t position;
FILE *pFile;
pFile = fopen( szOutFilePath.mb_str(wxConvUTF8), "wb" );
maBarreDeProgression->SetValue(value++);
if( pFile != NULL )
{
wxHTTP http;
unsigned int value = 0;
http.SetTimeout(6);
http.Connect( link );
maBarreDeProgression->SetValue(value++);
// PHP file sending XML content
wxInputStream *httpStream = http.GetInputStream(_("/updates/") + lastappexename);
maBarreDeProgression->SetValue(value++);
if (http.GetError() == wxPROTO_NOERR && httpStream->CanRead())
{
// will crash here, if xml content is not formatted PERFECTLY
char *buffer[app_size];
//unsigned int nOctetsLus = 0;
/*while (!httpStream->Eof())
{*/
//wxchar *buffer[8192];
httpStream->Read( buffer, sizeof(buffer));
fwrite( buffer, 1, sizeof(buffer), pFile);
/*file->Write( buffer, httpStream->LastRead());*/
maBarreDeProgression->SetValue(value++);
//fseek( pFile, 128, SEEK_END);
//httpStream->SeekI(loop*httpStream->LastRead(), wxFromCurrent);
/*S'il n'y a plus d'octets à lire*/
/*if( httpStream->LastRead() == 0 )
break;
nOctetsLus += httpStream->LastRead();
maBarreDeProgression->SetValue( (int)(100*nOctetsLus/app_size) );
}*/
//wxMessageBox(_("Update has been successfully downloaded!"));
temp.Printf(_(" (%d ko). Update has been successfully downloaded."), (int)(app_size/1000));
szNomDuFichierTelecharge->SetLabel(_("Name: ") + lastappexename + temp);
}
else
wxMessageBox(_("Connection failed!"));
http.Close();
wxDELETE(httpStream);
fclose( pFile );
//file->Close();
maBarreDeProgression->SetValue(value++);
}
}
else
{
monDossier->SetValue(_("INPUT DIRECTORY!"));
}
}
//---------------------------------------------------------------------------------------------------------
void
updateDialog::OnBouttonParcourir( wxCommandEvent& WXUNUSED(event) )
{
iDirName = wxDirSelector(_("Choose folder")) + _("\\");
monDossier->SetValue( iDirName );
}
#endif
Code: Select all
<?xml version="1.0" ?>
<APPINFO>
<AppExeName>
AppName.exe
</AppExeName>
<AppVersion>
1.0.1.8921
</AppVersion>
<AppSize>
921088
</AppSize>
<AppURL>
http://www.mywebsite.com/updates
</AppURL>
</APPINFO>