//Il sorgente va scritto in notazione ungherese. //Le variabili seguono la seguente regola: 'acronimo tipo'+'nome variabile cammellata' //Es. wxArrayString 'as' + 'AcceptRefuse' -> asAcceptRefuse #include "wxinc.h" #include #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #endif extern "C" { #include "../xvaga/hlapi_c.h" #include "../xvaga/skeylink.h" } #define HGAP 4 #define VGAP 2 /////////////////////////////////////////////////////////// // Utilities /////////////////////////////////////////////////////////// void ErrorBox(LPCSTR str) { wxMessageBox(str, "Installazione", wxOK | wxICON_ERROR); } void WarningBox(LPCSTR str) { wxMessageBox(str, "Installazione", wxOK | wxICON_EXCLAMATION); } wxString GetDefaultDestination() { wxString strDest; //scelta della directory di installazione di default #ifdef WIN32 TCHAR strFolder[MAX_PATH]; ::SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, strFolder); strDest = strFolder; #endif if (strDest.IsEmpty()) { // Forse è la cartella base dove è installato Word? wxFileType* pDoc = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("doc")); if (pDoc != NULL) { wxFileName strFilename = pDoc->GetOpenCommand(wxT("pippo.doc")); while (strFilename.GetDirCount() > 1) strFilename.RemoveLastDir(); strDest = strFilename.GetPath().After('"'); if (strDest.StartsWith(wxT("C\\"))) strDest = wxT("C:") + strDest.Mid(1); } } return strDest; } class RSDirCopier : public wxDirTraverser { wxString m_strSrc, m_strDst; protected: virtual wxDirTraverseResult OnDir(const wxString& dirname); virtual wxDirTraverseResult OnFile(const wxString& filename); public: void RenameDLL(const wxString& strDLL, bool bOpenGL) const; bool Copy(const wxString& src, const wxString& dst, bool bOpenGL); }; wxDirTraverseResult RSDirCopier::OnDir(const wxString& dirname) { return wxDIR_CONTINUE; } wxDirTraverseResult RSDirCopier::OnFile(const wxString& filename) { wxFileName strSource(filename); strSource.MakeRelativeTo(m_strSrc); wxString str = m_strDst; str += strSource.GetPathSeparator(); str += strSource.GetFullPath(); wxFileName strDest(str); if (!strDest.DirExists()) strDest.Mkdir(); ::wxCopyFile(filename, str); return wxDIR_CONTINUE; } void RSDirCopier::RenameDLL(const wxString& strDLL, bool bOpenGL) const { wxFileName file1(m_strDst, strDLL); file1.SetExt(bOpenGL ? wxT("dll") : wxT("old")); if (file1.FileExists()) { wxFileName file2(file1); file2.SetExt(bOpenGL ? wxT("old") : wxT("dll")); wxRename(file1.GetFullPath(), file2.GetFullPath()); } } bool RSDirCopier::Copy(const wxString& src, const wxString& dst, bool bOpenGL) { wxBusyCursor hourglass; m_strSrc = src; m_strDst = dst; if (!wxDirExists(m_strDst)) // Utile precauzione wxMkdir(m_strDst); wxDir dir(m_strSrc); dir.Traverse(*this); RenameDLL(wxT("OpenGL32.dll"), bOpenGL); RenameDLL(wxT("glu32.dll"), bOpenGL); return true; } #ifdef WIN32 bool WriteRootRegistryKey(const wxChar* strKey, const wxString& strValue) { HKEY hKey = NULL; DWORD dw = 0; bool ok = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, strKey, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw) == ERROR_SUCCESS; if (ok) { ok = ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)(const wxChar*)strValue, DWORD(2*strValue.Len()+2)) == ERROR_SUCCESS; ::RegCloseKey(hKey); } return ok; } bool CreateDesktopIcon(const wxFileName& strExeFile) { TCHAR szDesktopPath[MAX_PATH] = wxT(""); HRESULT hres = ::SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, szDesktopPath); if (szDesktopPath[0] != '\0') { CoInitialize(NULL); // Get a pointer to the IShellLink interface. IShellLink* psl; hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; // Set the path to the shortcut target and add the description. psl->SetPath(strExeFile.GetFullPath()); psl->SetWorkingDirectory(strExeFile.GetPath()); psl->SetDescription(APPNAME); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); if (SUCCEEDED(hres)) { wxFileName strLnk(szDesktopPath, wxT("Campo.lnk")); // Save the link by calling IPersistFile::Save. wxString stringa = strLnk.GetFullPath(); wchar_t buff[256]; wxConvLocal.MB2WC(buff, stringa, stringa.Len()); hres = ppf->Save(buff, true); ppf->Release(); } psl->Release(); } CoUninitialize(); } return true; } void AssociateExtension(const wxFileName& strExeFile, const wxChar* strExt) { // Register icon and application WriteRootRegistryKey(strExt, APPNAME); wxString str = strExeFile.GetFullPath(); str += wxT(",0"); WriteRootRegistryKey(wxT("Campo\\DefaultIcon"), str); str = strExeFile.GetFullPath(); str += wxT(" \"%1\""); WriteRootRegistryKey(wxT("Campo\\shell\\open\\command"), str); } #endif /////////////////////////////////////////////////////////// // CampoWizardPage /////////////////////////////////////////////////////////// class CampoWizardPage; //predefinizione di CampoWizardPage (magia nera!!) //predefinizione pure della CampoWizard con tutti i suoi metodi per poterlo usare nel metodo GetWizard (magia nerissima!!) class CampoWizard : public wxWizard { enum { m_nPages = 11 }; CampoWizardPage* m_pPage[m_nPages]; wxString _destination_path; //path di aggiornamento/installazione unsigned int _installation_type; //tipo di installazione selezionata (standard,server,client...) protected: int Pages() const { return m_nPages; } CampoWizardPage* Page(int p) const { return m_pPage[p]; } public: bool Run(); wxString Get(wxWindowID id) const; int GetSelection(wxWindowID id) const; bool GetBool(wxWindowID id) const; void SetDestinationPath(const wxString& path); const wxString& GetDestinationPath() const; void SetInstallationType(const unsigned int type); const unsigned int GetInstallationType() const; CampoWizard(wxWindow* pParent); }; //Campo wizard page (pagina generica del programma, di cui saranno figlie le singole pagine) class CampoWizardPage : public wxWizardPageSimple { wxHtmlWindow* m_pText; protected: CampoWizard& GetWizard() const {return *(CampoWizard*)GetParent();} void SetHTMLText(const wxString strTitle, const wxString strBody); void SetHTMLPage(const wxString strFile); void AddLabel(wxSizer* pSizer, const wxChar* label); void AddLabel(wxGridBagSizer* pSizer, const wxChar* label, unsigned int row, unsigned int column); public: wxString Get(wxWindowID id) const; bool Set(wxWindowID id, const wxString& str); int GetSelection(wxWindowID id) const; CampoWizardPage(wxWizard* parent); }; wxString CampoWizardPage::Get(wxWindowID id) const { wxWindow* pWnd = FindWindowById(id); return pWnd ? pWnd->GetLabel() : wxEmptyString; } bool CampoWizardPage::Set(wxWindowID id, const wxString& str) { wxWindow* pWnd = FindWindowById(id); if (pWnd) pWnd->SetLabel(str); return (pWnd != NULL); } int CampoWizardPage::GetSelection(wxWindowID id) const { int n = -1; wxWindow* pWnd = FindWindowById(id); if (pWnd) { wxChoice* pList = (wxChoice*)pWnd; n = pList->GetSelection(); } return n; } void CampoWizardPage::SetHTMLPage(const wxString strFile) { m_pText->LoadPage(strFile); } //parte html della finestra standard void CampoWizardPage::SetHTMLText(wxString strTitle, wxString strBody) { wxString strAppName = wxT(" "); strAppName += APPNAME; strAppName += wxT(" "); strTitle.Replace(wxT("APPNAME"), strAppName); strBody.Replace(wxT("APPNAME"), strAppName); wxString str; str += wxT(""); str += wxT("

"); str += strTitle; str += wxT("

"); str += wxT("
"); str += wxT("
"); str += strBody; str += wxT("
"); str += wxT(""); m_pText->SetPage(str); } //metodo per aggiungere i prompt agli oggetti contenuti nelle GridSize e similia void CampoWizardPage::AddLabel(wxSizer* pSizer, const wxChar* label) { pSizer->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL|wxALIGN_CENTER_VERTICAL); } void CampoWizardPage::AddLabel(wxGridBagSizer* pSizer, const wxChar* label, unsigned int row, unsigned int column) { pSizer->Add(new wxStaticText(this, wxID_ANY, label), wxGBPosition(row, column)); } //costruttore della finestra standard CampoWizardPage::CampoWizardPage(wxWizard* parent) : wxWizardPageSimple(parent) { wxBoxSizer* pSizer = new wxBoxSizer(wxVERTICAL); m_pText = new wxHtmlWindow(this, 100, wxDefaultPosition, wxSize(512, 256)); pSizer->Add(m_pText, 0, wxALL, 0); pSizer->AddSpacer(5); SetSizer(pSizer); } /**********************************************************************************************************/ /* 1 Pagina di benvenuto */ /**********************************************************************************************************/ class CampoWizardPage1 : public CampoWizardPage { public: CampoWizardPage1(wxWizard* parent); }; CampoWizardPage1::CampoWizardPage1(wxWizard* parent) : CampoWizardPage(parent) { //contenuto della prima schermata (pagina benvenuto) wxString strTitle = wxT("Benvenuti in APPNAME"); wxString strBody = wxT("

Questo programma vi guiderà passo a passo nell'installazione / aggiornamento del software.

"); strBody += wxT("

Prima di proseguire con l'installazione assicurarsi di avere effettuato il login a Windows con un utente di tipo 'Amministratore'.

"); SetHTMLText(strTitle, strBody); } /**********************************************************************************************************/ /* 2 Pagina con la scelta di Aggiornamento / Tipo Installazione */ /**********************************************************************************************************/ class CampoWizardPage2 : public CampoWizardPage { wxRadioBox* m_pRadioBox; protected: virtual bool TransferDataFromWindow(); public: CampoWizardPage2(wxWizard* parent); }; bool CampoWizardPage2::TransferDataFromWindow() { const int last_row = m_pRadioBox->GetRowCount() - 1; const int selected_row = m_pRadioBox->GetSelection(); wxString path; if (selected_row < last_row) path = m_pRadioBox->GetStringSelection(); GetWizard().SetDestinationPath(path); return true; } CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent) { //deve cercare campo.stp wxFileConfig campo_stp("", "", "", "C:\\campo.stp", wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_NO_ESCAPE_CHARACTERS); wxString group; long index; const wxString program = "Program"; wxArrayString asGroups, asCampi; //cerca se esiste campo.stp;se lo trova cerca quelle che sono le installazioni valide;se ne trova.. //..le aggiunge ad un array di stringhe (asCampi) da cui genera un radiobutton di scelte for (bool ok = campo_stp.GetFirstGroup(group, index); ok; ok = campo_stp.GetNextGroup(group, index)) { asGroups.Add(group); } int prechecked = -1; for (unsigned int i = 0; i < asGroups.GetCount(); i++) { wxFileConfig campo_stp("", "", "", "C:\\campo.stp", wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_NO_ESCAPE_CHARACTERS); campo_stp.SetPath(asGroups[i]); wxString path = campo_stp.Read(program); //sono installazioni valide quelle che presentano la coppia di files campo.ini e campo.aut (senza.. //..questi 2 soggetti il programma non parte) wxString campo_ini = path; campo_ini << "\\campo.ini"; wxString campo_aut = path; campo_aut << "\\campo.aut"; if (wxFileName::FileExists(campo_ini) && wxFileName::FileExists(campo_aut)) { asCampi.Add(path); //cerca l'eventuale installazione server se ci sono piu' installazioni sulla stessa macchina if (prechecked < 0) { wxFileConfig ini("", "", "", campo_ini, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_NO_ESCAPE_CHARACTERS); ini.SetPath("Main"); wxString test_database = ini.Read("TestDatabase"); if (test_database == "X" || test_database == "Y") prechecked = i; } } } wxString strTitle, strBody; //se non ci sono delle installazioni da aggiornare propone solo installazioni.. if (asCampi.IsEmpty()) { strTitle += wxT("Scelta Installazione"); strBody += wxT("

E' possibile INSTALLARE Campo in un nuovo direttorio.

"); asCampi.Add("Nuova installazione"); //voce di nuova installazione! m_pRadioBox = new wxRadioBox(this, 201, "Installazione del software", wxDefaultPosition, wxDefaultSize, asCampi, 0, wxRA_SPECIFY_ROWS); } //..senno' propone di aggiornare else { strTitle += wxT("Scelta Aggiornamento / Installazione"); strBody += wxT("

E' possibile AGGIORNARE (scelta consigliata) una installazione di Campo gia' presente oppure INSTALLARE in un nuovo direttorio.

"); strBody += wxT("

Selezionare l'opzione desiderata nel riquadro sottostante.

"); //radiobutton con le scelte aggiornamento asCampi.Add("Nuova installazione"); m_pRadioBox = new wxRadioBox(this, 201, "Selezionare l'installazione da aggiornare (consigliato) o Nuova installazione", wxDefaultPosition, wxDefaultSize, asCampi, 0, wxRA_SPECIFY_ROWS); if (prechecked > 0) m_pRadioBox->SetSelection(prechecked); } strBody += wxT("

Prima di proseguire accertarsi che non vi sia alcuna sessione di Campo attiva! "); strBody += wxT("Terminare quindi le eventuali sessioni di Campo attive e proseguire.

"); SetHTMLText(strTitle, strBody); GetSizer()->Add(m_pRadioBox); } /**********************************************************************************************************/ // 3 Pagina con Accetta / Rifiuta la licenza //*********************************************************************************************************/ class CampoWizardPage3 : public CampoWizardPage { protected: virtual bool TransferDataFromWindow(); public: CampoWizardPage3(wxWizard* parent); }; bool CampoWizardPage3::TransferDataFromWindow() { if (GetSelection(301) == 1) { wxMessageBox("Impossibile proseguire se non si accetta la licenza sul software!!", APPNAME, wxICON_ERROR|wxOK); return false; } return true; } CampoWizardPage3::CampoWizardPage3(wxWizard* parent) : CampoWizardPage(parent) { SetHTMLPage("licenza.htm"); //radiobutton Accetta / Rifiuta wxArrayString asAccRef; asAccRef.Add("Accetta"); asAccRef.Add("Rifiuta"); wxRadioBox* radio_box = new wxRadioBox(this, 301, "Selezionare 'Accetta' per proseguire con l'installazione, 'Rifiuta' per terminare l'installazione", wxDefaultPosition, wxDefaultSize, asAccRef, 0, wxRA_SPECIFY_COLS); radio_box->SetSelection(1); GetSizer()->Add(radio_box); } /**********************************************************************************************************/ /* 4 Pagina con la gestione della chiave di protezione */ /**********************************************************************************************************/ class CampoWizardPage4 : public CampoWizardPage { int _dongle_type; wxButton* _butt_HL; wxButton* _butt_EU; protected: DECLARE_EVENT_TABLE(); void OnHLPick(wxCommandEvent& e); void OnEUPick(wxCommandEvent& e); int DongleTest(); int ThisYear(); wxString DecodeString(const wxString& data); int VersionYear(); void BuildKey(char* key); bool HardlockGarble(unsigned short* data); unsigned short HardlockLogin(int& year); void EncodeEutronPassword(char* str); unsigned short EutronLogin(int& year); public: CampoWizardPage4(wxWizard* parent); }; //metodi per la gestione dei bottoni per l'esecuzione dei programmi di installazione delle chiavi BEGIN_EVENT_TABLE(CampoWizardPage4, CampoWizardPage) EVT_BUTTON(401, OnHLPick) EVT_BUTTON(402, OnEUPick) END_EVENT_TABLE() void CampoWizardPage4::OnHLPick(wxCommandEvent& e) { wxString path("./chiavi/hardlock/hldrv32.exe"); wxExecute(path, wxEXEC_SYNC); } void CampoWizardPage4::OnEUPick(wxCommandEvent& e) { wxString path("./chiavi/eutron/sdi.exe"); wxExecute(path, wxEXEC_SYNC); } /////////////////////////////// // Gestione chiave Hardlock // /////////////////////////////// bool CampoWizardPage4::HardlockGarble(unsigned short* data) { HL_CODE(data, 1); return true; } unsigned short CampoWizardPage4::HardlockLogin(int& year) { unsigned short serno = 0xFFFF; unsigned char REFKEY[16] = "CAMPOKEY"; unsigned char VERKEY[16] = "ìpÙˆ¬cê<"; if (HL_LOGIN(26952, LOCAL_DEVICE, REFKEY, VERKEY) == STATUS_OK) { unsigned short eprom[64]; memset(eprom, 0, sizeof(eprom)); HL_READBL((unsigned char*)eprom); unsigned short data[4]; memcpy(data, eprom, sizeof(data)); HardlockGarble(data); if (data[0] == 0xFAE8) serno = data[1]; else serno = 0; memcpy(data, &eprom[60], sizeof(data)); if (HardlockGarble(data)) year = (int)data[0]; } return serno; } /////////////////////////////// // Gestione chiave Eutron // /////////////////////////////// void CampoWizardPage4::EncodeEutronPassword(char* str) { const char* const key = "QSECOFR-"; char tmp[16]; int i; for (i = 0; str[i]; i++) tmp[i] = str[i] + (i < 8 ? key[i] : str[i - 8]); tmp[i] = '\0'; strcpy(str, tmp); } unsigned short CampoWizardPage4::EutronLogin(int& year) { unsigned short serno = 0xFFFF; const char* const login[2] = { "AGA.CAMPO", "25EBAI" }; for (int i = 0; i < 2; i++) { KEY_NET eutron_key; memset(&eutron_key, 0, sizeof(KEY_NET)); eutron_key.net_command = NET_KEY_OPEN; eutron_key.command = LOCATING_MODE; const char* const chiaro = login[i]; char cifrato[16]; strcpy(cifrato, chiaro); EncodeEutronPassword(cifrato); memset(eutron_key.label, 0, LABEL_LENGTH); strcpy((char*)eutron_key.label, chiaro); memset(eutron_key.password, 0, PASSWORD_LENGTH); strcpy((char*)eutron_key.password, cifrato); smartlink(&eutron_key); if (eutron_key.status == ST_OK) { eutron_key.net_command = NET_KEY_ACCESS; eutron_key.command = BLOCK_READING_MODE; short* pointer = (short*)(&eutron_key.data[0]); short* number = (short*)(&eutron_key.data[2]); *pointer = 0; // Posizione in cui leggere *number = 8; // Words da leggere smartlink(&eutron_key); if (eutron_key.status == ST_OK) { serno = (unsigned short)atol((const char*)eutron_key.data+4); if (i == 0) { const unsigned short y = *(unsigned short*)(eutron_key.data+12); if (y > 2000 && y < 3000) year = y; } else year = ThisYear(); break; } } } return serno; } ///////////////////////////////////////////////////////// // Metodi generici per le chiavi ed i relativi codici // ///////////////////////////////////////////////////////// void CampoWizardPage4::BuildKey(char* key) { for (int i = 0; i < 8; i++) key[i] = 'A'+ rand()%26; } int CampoWizardPage4::ThisYear() { int anno = 2006; time_t lt; if (time(<) == 0) { struct tm* timeloc = localtime(<) ; if (timeloc != NULL) anno = timeloc->tm_year + 1900; } return anno; } wxString CampoWizardPage4::DecodeString(const wxString& data) { char key[8] = ""; BuildKey(key); char tmp[256]; int i; for (i = 0; data[i]; i++) tmp[i] = data[i] - (i < 8 ? key[i] : tmp[i - 8]); tmp[i] = '\0'; return tmp; } int CampoWizardPage4::VersionYear() { char ver[32]; GetPrivateProfileString("ba", "Versione", "", ver, sizeof(ver), "./program/zip/install.ini"); ver[4] = '\0'; return atoi(ver); } int CampoWizardPage4::DongleTest() { _dongle_type = 0; int yearKey = 0; unsigned int serno = HardlockLogin(yearKey); if (serno == 0xFFFF) { serno = EutronLogin(yearKey); if (serno != 0xFFFF) _dongle_type = 2; //chiave eutron } else _dongle_type = 1; //chiave hardlock if (serno == 0) // Chiave di sviluppo return _dongle_type; if (serno == 0xFFFF) // Chiave inesistente o invisibile = Prima installazione o demo return _dongle_type; const int verYear = VersionYear(); if (yearKey < verYear) // Chiave già programmata con assistenza pagata { bool ok = false; wxFileInputStream file("./program/zip/dninst.zip"); if (file.IsOk()) { wxTextInputStream keys(file); wxString line = keys.ReadLine(); srand(883); DecodeString(line); const int ass_year = atoi(line); if (ass_year > yearKey) // Non devo abbassare l'anno di assistenza! { srand(ass_year); while (!file.Eof()) { line = keys.ReadLine(); line = DecodeString(line); unsigned int sn = (unsigned int)atol(line); if (sn == serno || line[0] == '*') { ok = true; break; } } if (ok) { const int n = ass_year%10; const int y = (ass_year / 1000) * 1000 + (ass_year%1000) /10; line.Printf("Il contratto di manutenzione %d/%d verrà attivato automaticamente", y, n); WarningBox(line); } else { line.Printf("È necessario contattare l'assistenza tecnica\n" "per l'abilitazione del contratto di manutenzione %d", verYear); WarningBox(line); } } } else { ErrorBox("Impossibile verificare il contratto di manutenzione"); } } return _dongle_type; } CampoWizardPage4::CampoWizardPage4(wxWizard* parent) : CampoWizardPage(parent) { _dongle_type = DongleTest(); //controlla se la chiave c'e' ed eventualmente quale e' wxString strTitle = wxT("Controllo della chiave hardware di protezione"); wxString strBody = wxT("

La versione commerciale del software richiede l'installazione e la presenza della chiave hardware di protezione

"); switch (_dongle_type) { case 1: strBody += wxT("

E' stata rilevata una chiave tipo Hardlock:

"); strBody += wxT("

"); strBody += wxT("

Si puo' procedere con l'installazione /aggiornamento del software Campo. Premere il pulsante \"Next\".

"); break; case 2: strBody += wxT("

E' stata rilevata una chiave tipo Eutron:

"); strBody += wxT("

"); strBody += wxT("

Si puo' procedere con l'installazione /aggiornamento del software Campo. Premere il pulsante \"Next\".

"); break; //case 3: e' il caso del server di chiavi;la DongleTest() per ora non lo fa //break; default: strBody += wxT("

Non e' stata rilevata alcuna chiave hardware installata !

"); strBody += wxT("

Per procedere all'installazione dei driver della chiave hardware collegata al computer premere il bottone corrispondente alla tipologia della chiave stessa.

"); strBody += wxT("

Se si desidera proseguire nell'installazione del software senza installare la chiave hardware cliccare su \"Next\".

"); strBody += wxT("

Quest'ultima procedura e' consigliata solo in caso di installazione tipo Client di rete senza chiave propria, ma che utilizza un server di autorizzazioni gia' installato e funzionante in rete.

"); //procedura per la costruzione dei bottoni e delle immagini per l'installazione dei driver di chiave //"griglia" contenitrice degli oggetti wxBoxSizer* butt_box = new wxBoxSizer(wxHORIZONTAL); GetSizer()->Add(butt_box, 0, wxALIGN_CENTER_HORIZONTAL, 0); //Hardlock img e button wxBitmap bmp_HL("hardlock.gif", wxBITMAP_TYPE_GIF); wxStaticBitmap* s_bmp_HL = new wxStaticBitmap(this, wxID_ANY, bmp_HL); butt_box->Add(s_bmp_HL, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); _butt_HL = new wxButton(this, 401, "Hardlock", wxDefaultPosition, wxSize(100, 50)); butt_box->Add(_butt_HL, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); //spaziatore centrale butt_box->AddSpacer(24); //Eutron img e button _butt_EU = new wxButton(this, 402, "Eutron", wxDefaultPosition, wxSize(100, 50)); butt_box->Add(_butt_EU, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); wxBitmap bmp_EU("eutron.gif", wxBITMAP_TYPE_GIF); wxStaticBitmap* s_bmp_EU = new wxStaticBitmap(this, wxID_ANY, bmp_EU); butt_box->Add(s_bmp_EU, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); break; } SetHTMLText(strTitle, strBody); } /**********************************************************************************************************/ // 5 Scelta tipo installazione /**********************************************************************************************************/ class CampoWizardPage5 : public CampoWizardPage { wxRadioBox* m_pRadioBox; protected: virtual bool TransferDataFromWindow(); public: CampoWizardPage5(wxWizard* parent); }; bool CampoWizardPage5::TransferDataFromWindow() { const unsigned int type = m_pRadioBox->GetSelection(); GetWizard().SetInstallationType(type); return true; } CampoWizardPage5::CampoWizardPage5(wxWizard* parent) : CampoWizardPage(parent) { //Istruzioni per l'uso! wxString strTitle = wxT("Scelta del tipo di installazione"); wxString strBody = wxT("

Standard (scelta consigliata). Installazione su postazione singola, con programmi e dati sul disco locale del computer

"); strBody += wxT("

Installazioni di rete (per utenti esperti)

"); strBody += wxT("

Server: Computer in rete sul quale sono presenti una copia, utilizzata o meno, dei programmi (server programmi) e l’area dati (server dati). "); strBody += wxT("In una installazione in rete di Campo e' necessario sia presente un unica postazione di tipo server, "); strBody += wxT("e deve essere installata per prima!

"); strBody += wxT("

Client: Computer in rete sul quale e' presente una copia dei programmi ma non l'area dati. "); strBody += wxT("I client possono essere installati solo dopo l'installazione del server!

"); SetHTMLText(strTitle, strBody); //radiobutton con i tipi di installazione wxArrayString asInstType; asInstType.Add("Standard"); asInstType.Add("Server"); asInstType.Add("Client"); m_pRadioBox = new wxRadioBox(this, 501, "Selezionare il tipo di installazione", wxDefaultPosition, wxDefaultSize, asInstType, 0, wxRA_SPECIFY_ROWS); //setta il default a Standard m_pRadioBox->SetSelection(0); GetSizer()->Add(m_pRadioBox); } /**********************************************************************************************************/ // 6 Installazione standard /**********************************************************************************************************/ class CampoWizardPage6 : public CampoWizardPage { protected: DECLARE_EVENT_TABLE(); void OnDirPick(wxCommandEvent& e); public: CampoWizardPage6(wxWizard* parent); }; BEGIN_EVENT_TABLE(CampoWizardPage6, CampoWizardPage) EVT_BUTTON(602, OnDirPick) EVT_BUTTON(604, OnDirPick) END_EVENT_TABLE() void CampoWizardPage6::OnDirPick(wxCommandEvent& e) { const wxWindowID wiTargetField = e.GetId() - 1; wxString strPath = Get(wiTargetField); wxDirDialog dlg(this, wxDirSelectorPromptStr, strPath, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (dlg.ShowModal() == wxID_OK) { strPath = dlg.GetPath(); Set(wiTargetField, strPath); } } CampoWizardPage6::CampoWizardPage6(wxWizard* parent) : CampoWizardPage(parent) { wxString strTitle = wxT("Installazione di tipo Standard"); wxString strBody = wxT("

Digitare nel campo 'Cartella programma' il percorso completo della cartella dove si desidera installare il programma. "); strBody += wxT("Il percorso di default (consigliato) e' C:\\Campo32

"); strBody += wxT("

Digitare nel campo 'Cartella Dati' il percorso completo della cartella dove si desidera installare l'area dati. "); strBody += wxT("Il percorso di default (consigliato) e' C:\\Campo32\\dati

"); SetHTMLText(strTitle, strBody); //griglia per sistemare i campi wxGridBagSizer* gbsSizer = new wxGridBagSizer(VGAP, HGAP); GetSizer()->Add(gbsSizer); //prima riga della griglia //prompt AddLabel(gbsSizer, "Cartella programmi", 0, 0); //campo testo wxString strPath; strPath = "C:\\"; strPath += APPNAME; wxTextCtrl* tcPrgPath = new wxTextCtrl(this, 601, strPath, wxDefaultPosition, wxSize(320,-1), wxTE_READONLY); gbsSizer->Add(tcPrgPath, wxGBPosition(0, 1)); //bottone 'sfoglia' wxButton* bPrgButton = new wxButton(this, 602, wxT("Sfoglia"), wxDefaultPosition, wxSize(48, -1)); gbsSizer->Add(bPrgButton, wxGBPosition(0, 2)); //seconda riga della griglia //prompt AddLabel(gbsSizer, "Cartella dati", 1, 0); //campo testo strPath += "\\dati"; wxTextCtrl* tcDataPath = new wxTextCtrl(this, 603, strPath, wxDefaultPosition, wxSize(320,-1), wxTE_READONLY); gbsSizer->Add(tcDataPath, wxGBPosition(1, 1)); //bottone 'sfoglia' wxButton* bDataButton = new wxButton(this, 604, wxT("Sfoglia"), wxDefaultPosition, wxSize(48, -1)); gbsSizer->Add(bDataButton, wxGBPosition(1, 2)); } /**********************************************************************************************************/ // 7 Installazione server /**********************************************************************************************************/ class CampoWizardPage7 : public CampoWizardPage { protected: public: CampoWizardPage7(wxWizard* parent); }; CampoWizardPage7::CampoWizardPage7(wxWizard* parent) : CampoWizardPage(parent) { wxString strTitle = wxT("Installazione di tipo Server"); wxString strBody = wxT("Pagina 7. Installazione Server"); SetHTMLText(strTitle, strBody); } /**********************************************************************************************************/ // 8 Installazione client /**********************************************************************************************************/ class CampoWizardPage8 : public CampoWizardPage { protected: public: CampoWizardPage8(wxWizard* parent); }; CampoWizardPage8::CampoWizardPage8(wxWizard* parent) : CampoWizardPage(parent) { wxString strTitle = wxT("Installazione di tipo Client"); wxString strBody = wxT("Pagina 8. Installazione Client"); SetHTMLText(strTitle, strBody); } /**********************************************************************************************************/ //pagina con la selezione di destinazione /**********************************************************************************************************/ class CampoWizardPage9 : public CampoWizardPage { protected: DECLARE_EVENT_TABLE(); void OnDirPick(wxCommandEvent& e); public: CampoWizardPage9(wxWizard* parent); }; BEGIN_EVENT_TABLE(CampoWizardPage9, CampoWizardPage) EVT_BUTTON(202, OnDirPick) END_EVENT_TABLE() void CampoWizardPage9::OnDirPick(wxCommandEvent& e) { wxFileName strPath = Get(201); wxDirDialog dlg(this, wxDirSelectorPromptStr, strPath.GetPath(), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (dlg.ShowModal() == wxID_OK) { strPath.Assign(dlg.GetPath(), APPNAME); Set(201, strPath.GetFullPath()); } } CampoWizardPage9::CampoWizardPage9(wxWizard* parent) : CampoWizardPage(parent) { //seconda pagina wxString strTitle = wxT("Selezione della cartella di destinazione"); wxString strBody = wxT("APPNAME verrà installato nella cartella selezionata"); SetHTMLText(strTitle, strBody); wxBoxSizer* pSizer = new wxBoxSizer(wxHORIZONTAL); GetSizer()->Add(pSizer); const wxFileName strPath(GetDefaultDestination(), APPNAME); wxTextCtrl* pPath = new wxTextCtrl(this, 201, strPath.GetFullPath(), wxDefaultPosition, wxSize(320,-1), wxTE_READONLY); pSizer->Add(pPath, 0, wxALL, 0); wxButton* pButton = new wxButton(this, 202, wxT("..."), wxDefaultPosition, wxSize(24, -1)); pSizer->Add(pButton, 0, wxALL, 0); } class CampoWizardPage10 : public CampoWizardPage { public: CampoWizardPage10(wxWizard* parent); }; CampoWizardPage10::CampoWizardPage10(wxWizard* parent) : CampoWizardPage(parent) { wxString strTitle = wxT(""); wxString strBody; strBody += wxT("Attivando questa opzione verrà utilizzata l'accelerazione "); strBody += wxT("hardware della scheda video installata, altrimenti il rendering "); strBody += wxT("delle mappe sarà implementato via software (Mesa)"); SetHTMLText(strTitle, strBody); wxArrayString aMode; aMode.Add(wxT("Hardware (Maggiori prestazioni, minore compatibilità)")); aMode.Add(wxT("Software (Maggiore compatibilità, minori prestazioni)")); wxRadioBox* pBox = new wxRadioBox(this, 301, wxT("Accelerazione OpenGL"), wxDefaultPosition, wxDefaultSize, aMode, 0, wxRA_VERTICAL); GetSizer()->Add(pBox, 0, wxALL, 0); } class CampoWizardPage11 : public CampoWizardPage { public: CampoWizardPage11(wxWizard* parent); }; CampoWizardPage11::CampoWizardPage11(wxWizard* parent) : CampoWizardPage(parent) { wxString strTitle = wxT("Collegamenti"); wxString strBody; strBody += wxT("E' possibile creare l'icona di APPNAME sul desktop "); //strBody += wxT("ed associare l'estensione .rs1 al programma."); SetHTMLText(strTitle, strBody); wxCheckBox* pIcon = new wxCheckBox(this, 401, wxT("Creare l'icona sul desktop")); pIcon->SetValue(true); GetSizer()->Add(pIcon, 0, wxALL, 0); GetSizer()->AddSpacer(5); //wxCheckBox* pLink = new wxCheckBox(this, 402, wxT("Associare i file .rs1 al programma")); //pLink->SetValue(true); //GetSizer()->Add(pLink, 0, wxALL, 0); } /////////////////////////////////////////////////////////// // CampoWizard /////////////////////////////////////////////////////////// //la dichiarazione della classe e' prima in quanto alcuni suoi metodi sono usati da altre classi scritte piu' su bool CampoWizard::Run() { return RunWizard(Page(0)); } wxString CampoWizard::Get(wxWindowID id) const { wxWindow* pWnd = FindWindowById(id); return pWnd ? pWnd->GetLabel() : wxEmptyString; } int CampoWizard::GetSelection(wxWindowID id) const { int n = -1; wxWindow* pWnd = FindWindowById(id); if (pWnd) { wxChoice* pList = (wxChoice*)pWnd; n = pList->GetSelection(); } return n; } bool CampoWizard::GetBool(wxWindowID id) const { wxCheckBox* pWnd = (wxCheckBox*)FindWindowById(id); return pWnd != NULL && pWnd->IsChecked(); } void CampoWizard::SetDestinationPath(const wxString& path) { _destination_path = path; //Se il path di destinazione e' vuoto -> nuova installazione, senno' e' un aggiornamento della installazione.. //..che sta in _destination_path if (_destination_path.IsEmpty()) { m_pPage[2]->Chain(m_pPage[1], m_pPage[2]); } else { m_pPage[2]->Chain(m_pPage[3], m_pPage[8]); } } const wxString& CampoWizard::GetDestinationPath() const { return _destination_path; } void CampoWizard::SetInstallationType(const unsigned int type) { _installation_type = type; //in base al tipo di installazione spara l'utente alla pagina corretta switch (_installation_type) { case 0: //standard m_pPage[5]->Chain(m_pPage[4], m_pPage[5]); break; case 1: //server m_pPage[5]->Chain(m_pPage[4], m_pPage[6]); break; case 2: //client m_pPage[5]->Chain(m_pPage[4], m_pPage[7]); break; default: //standard m_pPage[5]->Chain(m_pPage[4], m_pPage[5]); break; } } const unsigned int CampoWizard::GetInstallationType() const { return _installation_type; } CampoWizard::CampoWizard(wxWindow* pParent) { wxBitmap bitmap; wxString strName = wxT("logo.gif"); bitmap.LoadFile(strName, wxBITMAP_TYPE_GIF); Create(pParent, wxID_ANY, APPNAME, bitmap); m_pPage[0] = new CampoWizardPage1(this); //pagina benvenuto con logo m_pPage[1] = new CampoWizardPage2(this); //pagina scelta aggiornamento/tipo installazione m_pPage[2] = new CampoWizardPage3(this); //pagina licenza m_pPage[3] = new CampoWizardPage4(this); //pagina test ed installazione chiavi m_pPage[4] = new CampoWizardPage5(this); //pagina selezione tipo installazione m_pPage[5] = new CampoWizardPage6(this); //pagina installazione standard m_pPage[6] = new CampoWizardPage7(this); //pagina installazione server m_pPage[7] = new CampoWizardPage8(this); //pagina installazione client m_pPage[8] = new CampoWizardPage9(this); m_pPage[9] = new CampoWizardPage10(this); m_pPage[10] = new CampoWizardPage11(this); for (int p = 1; p < m_nPages; p++) m_pPage[p]->Chain(m_pPage[p-1], m_pPage[p]); GetPageAreaSizer()->Add(m_pPage[0]); } /////////////////////////////////////////////////////////// // RSFrame /////////////////////////////////////////////////////////// class RSFrame : public wxFrame { protected: DECLARE_EVENT_TABLE(); virtual void OnErase(wxEraseEvent& e); public: RSFrame(); }; BEGIN_EVENT_TABLE(RSFrame, wxFrame) EVT_ERASE_BACKGROUND(RSFrame::OnErase) END_EVENT_TABLE() void RSFrame::OnErase(wxEraseEvent& e) { //preparazione background wxDC& dc = *e.GetDC(); const wxRect rect = GetClientSize(); wxColour c0 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); wxColour c1 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColour c2 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); wxRect rect1 = rect; rect1.SetBottom(rect.GetBottom() / 2); dc.GradientFillLinear(rect1, c0, c1, wxSOUTH); wxRect rect2 = rect; rect2.SetTop(rect.GetBottom() / 2); dc.GradientFillLinear(rect2, c1, c2, wxDOWN); const int nHeight = rect.GetHeight()/8; wxFont* pFont = wxTheFontList->FindOrCreateFont(nHeight, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_BOLD); dc.SetFont(*pFont); dc.SetBackgroundMode(wxTRANSPARENT); const int k = nHeight / 16 + 1; dc.SetTextForeground(c2); dc.DrawText(APPNAME, k, k); dc.SetTextForeground(c1); dc.DrawText(APPNAME, k/2, k/2); int w, h; const wxString strSetup = wxT("Setup"); dc.GetTextExtent(strSetup, &w, &h); dc.SetTextForeground(c2); dc.DrawText(strSetup, rect.GetRight()-w-k/2, rect.GetHeight()-h-k/2); dc.SetTextForeground(c1); dc.DrawText(strSetup, rect.GetRight()-w-k, rect.GetHeight()-h-k); } RSFrame::RSFrame() : wxFrame(NULL, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0) { ShowFullScreen(true); } /////////////////////////////////////////////////////////// // RSSetup /////////////////////////////////////////////////////////// class RSSetup : public wxApp { RSFrame* m_pMainFrame; wxLocale m_locale; protected: DECLARE_EVENT_TABLE() void OnTimer(wxTimerEvent& e); public: virtual bool OnInit(); }; IMPLEMENT_APP(RSSetup) BEGIN_EVENT_TABLE(RSSetup, wxApp) EVT_TIMER(883, OnTimer) END_EVENT_TABLE() void RSSetup::OnTimer(wxTimerEvent& WXUNUSED(e)) { CampoWizard* pWizard = new CampoWizard(m_pMainFrame); if (pWizard->Run()) { wxFileName strPath = argv[0]; strPath.SetCwd(); const wxString strSrc = strPath.GetPath(); const wxString strDest = pWizard->Get(201); const bool bOpenGL = pWizard->GetSelection(301)==0; RSDirCopier dc; dc.Copy(strSrc, strDest, bOpenGL); const wxFileName strExe(strDest, wxT("ba0.exe")); if (pWizard->GetBool(401)) CreateDesktopIcon(strExe); //if (pWizard->GetBool(402)) // AssociateExtension(strExe, wxT(".rs1")); } pWizard->Destroy(); ::wxMessageBox(wxT("Installazione terminata"), APPNAME, wxOK | wxICON_INFORMATION); m_pMainFrame->Destroy(); } bool RSSetup::OnInit() { wxInitAllImageHandlers(); m_locale.Init(); m_pMainFrame = new RSFrame; SetTopWindow(m_pMainFrame); wxTimerEvent e(883); AddPendingEvent(e); return true; }