diff --git a/setup/Setup.cpp b/setup/Setup.cpp index f99dc4796..405767574 100755 --- a/setup/Setup.cpp +++ b/setup/Setup.cpp @@ -102,11 +102,15 @@ protected: void ClientUpdate(); void NormalSetup(); bool CampoRunning(const wxString& strAppName, const wxString& strMsg) const; + bool LurchRunning() const; //metodi di interfaccia con Windows bool CreateIcon(unsigned int csidl, const wxFileName& strExeFile, const wxString& strLinkName) const; - bool CreateAutostartMode(const LurchMode iSrvAutostartMode, const wxString& strPath); void AssociateExtension(const wxFileName& strExeFile, const wxString strExt); + //...per i servers + bool CreateAutostartMode(const LurchMode iSrvAutostartMode, const wxString& strPath); + long StopLurch(); + long StartLurch(); //metodi di interfaccia con il registry di Windows wxString ReadRootRegistryKey(const wxString strKey) const; @@ -211,6 +215,7 @@ wxString CampoSetup::GetFolderPath(unsigned int uPathID) const return szPath; } + void CampoSetup::AssociateExtension(const wxFileName& strExeFile, const wxString strExt) { // Register icon and application @@ -223,70 +228,6 @@ void CampoSetup::AssociateExtension(const wxFileName& strExeFile, const wxString WriteRootRegistryKey(wxT("Campo\\shell\\open\\command"), str); } -bool CampoSetup::CreateAutostartMode(const LurchMode iSrvAutostartMode, const wxString& strPath) -{ - //creazione dei filenames e dei path necessari in giro per la funzione - //filename (con path quindi) di Lurch.exe - wxFileName strExe(strPath, wxT("lurch.exe")); - strExe.AppendDir("servers"); - //stringa path della cartella Servers in base alle scelte dell'utente - const wxString strSrvPath = strExe.GetPath(); - - //1) Eliminatore di precedenti servers installati come servizi - //cerca se non esiste per caso gia' da una precedente installazione.. - //..non serve piu' a un cazzo ma si e' tenuto come prova in debug di lettura del registry! - const wxString strValue = ReadLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application"); - if (!strValue.IsEmpty()) - { - //elimina un eventuale servizio precedente (senno' col cavolo che lo riesce a modificare!) - //utilizza il programma instsrv.exe dentro la cartella servers installata - wxString strRemove = strSrvPath + "\\instsrv Lurch REMOVE"; - const long lRemove = wxExecute(strRemove, wxEXEC_SYNC); - } - - //2) Eliminatore di precedenti servers installati come programmi in esecuzione automatica - - - switch (iSrvAutostartMode) - { - //esecuzione server come servizi (magia!) - case lm_service: - { - //aggiunge la voce ai servizi di windows (dentro strumenti di amministrazione) - //utilizza i programmi instrv.exe e srvany.exe dentro la cartella servers installata - wxString strCreateService = strSrvPath + "\\instsrv Lurch "; - strCreateService += strSrvPath; - strCreateService += "\\srvany.exe"; - //esegue il programma di installazione servizi di Windows creando la voce - const long lExec = wxExecute(strCreateService, wxEXEC_SYNC); - if (lExec >= 0) - { - //crea le voci nel registry di windows - WriteLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application", strExe.GetFullPath()); - wxString strExecService = GetFolderPath(CSIDL_SYSTEM); - strExecService += "\\NET START Lurch"; - //avvia il servizio - const long lExecLurch = wxExecute(strExecService, wxEXEC_SYNC); - if (lExecLurch < 0) - WarningBox("Impossibile eseguire il servizio del gestore applicazioni.\nLanciarlo manualmente dagli strumenti di amministrazione nel pannello di controllo!"); - } - else - WarningBox("Impossibile registrare il servizio per l'esecuzione automatica del gestore applicazioni.\nSelezionare una diversa modalita' di esecuzione!"); - - } - break; - //link nella cartella esecuzione automatica - case lm_autostart: - { - CreateIcon(CSIDL_COMMON_STARTUP, strExe, "lurch"); - } - break; - default: - break; - } - return true; -} - bool CampoSetup::CreateIcon(unsigned int csidl, const wxFileName& strExeFile, const wxString& strLinkName) const { //csidl = CSIDL_COMMON_DESKTOPDIRECTORY = desktop @@ -350,6 +291,87 @@ bool CampoSetup::CreateIcon(unsigned int csidl, const wxFileName& strExeFile, co } +//------------------------------------------- +// ..per i servers di Campo +//------------------------------------------- +long CampoSetup::StopLurch() +{ + const wxString strValue = ReadLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application"); + wxString strExecService = GetFolderPath(CSIDL_SYSTEM); + strExecService += "\\NET STOP Lurch"; + return wxExecute(strExecService, wxEXEC_SYNC); +} + +long CampoSetup::StartLurch() +{ + const wxString strValue = ReadLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application"); + wxString strExecService = GetFolderPath(CSIDL_SYSTEM); + strExecService += "\\NET START Lurch"; + return wxExecute(strExecService, wxEXEC_SYNC); +} + +bool CampoSetup::CreateAutostartMode(const LurchMode iSrvAutostartMode, const wxString& strPath) +{ + //creazione dei filenames e dei path necessari in giro per la funzione + //filename (con path quindi) di Lurch.exe + wxFileName strExe(strPath, wxT("lurch.exe")); + strExe.AppendDir("servers"); + //stringa path della cartella Servers in base alle scelte dell'utente + const wxString strSrvPath = strExe.GetPath(); + + //1) Cerca di eliminare Lurch se presente come servizio + const wxString strValue = ReadLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application"); + if (!strValue.IsEmpty()) + { + //elimina un eventuale servizio precedente (senno' col cavolo che lo riesce a modificare!) + //utilizza il programma instsrv.exe dentro la cartella servers installata + wxString strRemove = strSrvPath + "\\instsrv Lurch REMOVE"; + const long lRemove = wxExecute(strRemove, wxEXEC_SYNC); + } + //2) Cerca di fermare Lurch se presente come programma in esecuzione automatica + + + switch (iSrvAutostartMode) + { + //esecuzione server come servizi (magia!) + case lm_service: + { + //aggiunge la voce ai servizi di windows (dentro strumenti di amministrazione) + //utilizza i programmi instrv.exe e srvany.exe dentro la cartella servers installata + wxString strCreateService = strSrvPath + "\\instsrv Lurch "; + strCreateService += strSrvPath; + strCreateService += "\\srvany.exe"; + //esegue il programma di installazione servizi di Windows creando la voce + const long lExec = wxExecute(strCreateService, wxEXEC_SYNC); + if (lExec >= 0) + { + //crea le voci nel registry di windows + WriteLocalMachineRegistryKey("SYSTEM\\CurrentControlSet\\Services\\Lurch\\Parameters\\Application", strExe.GetFullPath()); + wxString strExecService = GetFolderPath(CSIDL_SYSTEM); + strExecService += "\\NET START Lurch"; + //avvia il servizio + const long lExecLurch = wxExecute(strExecService, wxEXEC_SYNC); + if (lExecLurch < 0) + WarningBox("Impossibile eseguire il servizio del gestore applicazioni.\nLanciarlo manualmente dagli strumenti di amministrazione nel pannello di controllo!"); + } + else + WarningBox("Impossibile registrare il servizio per l'esecuzione automatica del gestore applicazioni.\nSelezionare una diversa modalita' di esecuzione!"); + + } + break; + //link nella cartella esecuzione automatica + case lm_autostart: + { + CreateIcon(CSIDL_COMMON_STARTUP, strExe, "lurch"); + } + break; + default: + break; + } + return true; +} + + //---------------------------------------------------------------- // Metodi di utility per i vari tipi di aggiornamento //---------------------------------------------------------------- @@ -426,7 +448,7 @@ bool CampoSetup::UnzipModule(const wxString& strPrgLocPath, const wxString& strS //adesso che ha trovato quello sporco ultimo .ini prende versione e patch e le copia nell'install.ini.. //..nella dir dei programmi; lo fa paragrafo x paragrafo ([sy],[sy1]..) //potrebbe sembrare assurdo un for, ma e' per futuri sottomoduli con numero > 1 - UpdateInstallIni(strWrk, strPrgLocPath + "/install.ini", "sy"); + UpdateInstallIni(strWrk, strPrgLocPath + "/install.ini", strModule); } return uFilesToCopy > 0; } @@ -712,7 +734,10 @@ void CampoSetup::ClientUpdate() CampoIniFile iniLocalInstall(fn.GetFullPath(), "Main"); strRemotePath = iniLocalInstall.Get("DiskPath"); } + ClientUpdateModule(strLocalPath, strRemotePath, "sy"); + //ma serve aggiornare SR su un client? + ClientUpdateModule(strLocalPath, strRemotePath, "sr"); wxSetWorkingDirectory(strLocalPath); wxExecute("ba1 -6 /uADMIN"); @@ -732,8 +757,12 @@ void CampoSetup::DiskUpdate() CampoIniFile iniLocalInstall(fn.GetFullPath(), "Main"); strRemotePath = iniLocalInstall.Get("DiskPath"); } - DiskUpdateModule(strLocalPath, strRemotePath, "sy"); + //Attenzione! deve fermare il server di chiavi qui... + DiskUpdateModule(strLocalPath, strRemotePath, "sy"); + DiskUpdateModule(strLocalPath, strRemotePath, "sr"); + + //..e farlo ripartire qui wxSetWorkingDirectory(strLocalPath); wxExecute("ba1 -6 /uADMIN"); } @@ -757,9 +786,12 @@ void CampoSetup::InternetUpdate() strRemotePath = iniLocalInstall.Get("WebPath"); } - //aggiornamento del modulo SY via web + //Attenzione! deve fermare il server di chiavi qui... + //aggiornamento dei moduli SY e SR via web InternetUpdateModule(strLocalPath, strRemotePath, "sy"); + InternetUpdateModule(strLocalPath, strRemotePath, "sr"); + //..e farlo ripartire qui //lanciare ba1.exe -6 in uscita wxSetWorkingDirectory(strLocalPath); wxExecute("ba1 -6 /uADMIN"); @@ -985,8 +1017,7 @@ void CampoSetup::NormalSetup() CampoIniMain.Set("Donglehw", uDongleType); CampoIniMain.Set("Study", strDataPath); CampoIniMain.Set("Firm", "com"); - //client o non client? - //(attenzione che in Campo e' Std=1 Srv=2 Cli=3) + //server,client o standalone? CampoIniMain.Set("Type", uInstallationType); } //paragrafo [Server] @@ -1020,23 +1051,12 @@ void CampoSetup::NormalSetup() CampoInstall.Set("DiskPath", strSrc); } } - - - // 6) CREAZIONE AUTOSTART DEI SERVERS (SE CI SONO) - //------------------------------------------------ - //solo se sta installando campo in postazione server e deve installare un gestore di servizi.. - //..avvia la procedura della creazione dell'autostart(un casino) - const LurchMode iSrvAutostartMode = m_pWizard->GetSrvAutostartMode(); - if (iSrvAutostartMode != lm_none) - { - CreateAutostartMode(iSrvAutostartMode, strPrgLocPath); - } - // 7) AGGIORNAMENTO DEL MODULO SY CON EVENTUALI PATCH PRESENTI IN PROGRAM DEL CD E AGGIORNAMENTO INSTALL.INI + // 6) AGGIORNAMENTO DEL MODULO SY CON EVENTUALI PATCH PRESENTI IN PROGRAM DEL CD E AGGIORNAMENTO INSTALL.INI //---------------------------------------------------------------------------------------------------------- //procede poi al caricamento delle patch eventuali di sistema all'interno della dir 'program' e al.. - //..conseguente riaggiornamento del livello versione/patch del SY in install.ini + //..conseguente riaggiornamento del livello versione/patch di SY ed SR in install.ini const wxString strPrgCDPath = GetSourceDir("program"); if (wxFileName::DirExists(strPrgCDPath)) { @@ -1044,6 +1064,22 @@ void CampoSetup::NormalSetup() const wxString strSetupLocPath = strPrgLocPath + "/setup"; CopyDir(strSetupCDPath, strSetupLocPath); UnzipModule(strPrgLocPath, strPrgCDPath, "sy"); + UnzipModule(strPrgLocPath, strPrgCDPath, "sr"); + } + + + // 7) CREAZIONE AUTOSTART DEI SERVERS (SE CI SONO) + //------------------------------------------------ + //solo se sta installando campo in postazione server e deve installare un gestore di servizi.. + //..avvia la procedura della creazione dell'autostart(un casino). Questa procedura non puo'.. + //..valere per l'aggiornamento, che agisce in modo diverso + if (bNewInstallation) + { + const LurchMode iSrvAutostartMode = m_pWizard->GetSrvAutostartMode(); + if (iSrvAutostartMode != lm_none) + { + CreateAutostartMode(iSrvAutostartMode, strPrgLocPath); + } } @@ -1117,25 +1153,49 @@ bool CampoSetup::CampoRunning(const wxString& strAppName, const wxString& strMsg for (i = 3; i > 0 && sicProgram.IsAnotherRunning(); i--) wxSleep(1); - if (i <= 0) + if (i <= 0 && !strMsg.IsEmpty()) ErrorBox(strMsg); return i <= 0; } +bool CampoSetup::LurchRunning() const +{ + //cerca Lurch che funziona come programma (esecuzione in modalita' avvio automatico)... + bool ok = CampoRunning("Lurch", wxEmptyString); + if (!ok) + { + //...se non lo trova cerca il solo Authoriz sempre come programma... + ok = CampoRunning("Authorization", wxEmptyString); + //se non trova nulla cerca Lurch come servizio... + if (!ok) + { + int year = 0; + wxString strSrv = "127.0.0.1"; + ok = ServerLogin(year, strSrv) != 0xFFFF; + } + } + return ok; +} + //metodo principale che sceglie la modalita' di lancio del programma void CampoSetup::OnTimer(wxTimerEvent& WXUNUSED(e)) { //controllo di eventuali Campo o servers attivi e conseguente interruzione dell'installazione if (CampoRunning("ba0", "Uscire dal programma CAMPO prima di procedere con l'aggiornamento/installazione!") || - CampoRunning("ba1", "Uscire dal programma di manutenzione di CAMPO\n prima di procedere con l'aggiornamento/installazione!") || - CampoRunning("Authorization", "Spegnere il server di autorizzazioni per poter aggiornare/installare il programma CAMPO!")) + CampoRunning("ba1", "Uscire dal programma di manutenzione di CAMPO\n prima di procedere con l'aggiornamento/installazione!")) { m_pMainFrame->Destroy(); return; } + if (LurchRunning()) + { + WarningBox("Per poter aggiornare/installare il programma CAMPO verra' temporaneamente disattivato il gestore delle licenze!\nPrima di proseguire accertarsi che tutti gli utenti spengano il programma CAMPO!!"); + const long lStop = StopLurch(); + } + wxFileName strPath(argv[0]); strPath.MakeAbsolute(); strPath.SetCwd();