fdcdb2c058
Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@15723 c028cbd2-c16b-5b4b-a496-9718f37d4682
259 lines
7.5 KiB
C++
Executable File
259 lines
7.5 KiB
C++
Executable File
#include "wxinc.h"
|
|
#include "utils.h"
|
|
|
|
#ifdef WIN32
|
|
#include <shlobj.h>
|
|
#include <lm.h>
|
|
#endif
|
|
|
|
|
|
wxString GetWindowsProgramDirectory()
|
|
{
|
|
//scelta della directory di installazione di default
|
|
#ifdef WIN32
|
|
TCHAR strFolder[MAX_PATH];
|
|
::SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, strFolder);
|
|
return strFolder;
|
|
#endif
|
|
}
|
|
|
|
wxString GetDefaultDestination()
|
|
{
|
|
wxString strDest;
|
|
strDest = GetWindowsProgramDirectory();
|
|
|
|
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;
|
|
}
|
|
|
|
//Magico metodo per stabilire se una directory e' condivisa ed e' su un disco locale!!
|
|
bool IsSharedDirectory (const wxString& strDir)
|
|
{
|
|
bool found = false;
|
|
|
|
wxString strDataDir = strDir.Lower();
|
|
strDataDir.Replace ("/", "\\");
|
|
|
|
NET_API_STATUS res = ERROR_MORE_DATA;
|
|
while (res==ERROR_MORE_DATA && !found)
|
|
{
|
|
PSHARE_INFO_502 shi;
|
|
DWORD nEntriesRead =0, nTotalEntries = 0, nResume = 0;
|
|
res = NetShareEnum(NULL, 502, (LPBYTE *)&shi, -1, &nEntriesRead, &nTotalEntries, &nResume);
|
|
if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
|
|
{
|
|
for (DWORD i = 0; i < nEntriesRead; i++)
|
|
{
|
|
/*Oh ignaro programmatore, questa parte commentata utilizza funzioni native di windows che non si sono riuscite..
|
|
..a far funzionare! Se osi, prova la tua forza rendendole utili!
|
|
//la directory dei dati deve essere leggibile,scrivibile,e filecreabile
|
|
int Result = NetShareGetInfo(NULL, shi[i].shi502_netname, 502, (LPBYTE *)&shi[i]);
|
|
if (shi[i].shi502_permissions & (PERM_FILE_READ | PERM_FILE_WRITE | PERM_FILE_CREATE))*/
|
|
{
|
|
wxString strPath(shi[i].shi502_path);
|
|
strPath.MakeLower();
|
|
//se trova la directory di studio condivisa ed e' su disco locale -> server
|
|
if (strDir.StartsWith(strPath))
|
|
{
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
} //for(DWORD i...
|
|
NetApiBufferFree(shi);
|
|
} //if(res ==...
|
|
} //while (res==ERROR_MORE_DATA...
|
|
|
|
return found;
|
|
}
|
|
|
|
//finestre per messaggi vari
|
|
//---------------------------------------------------------------------------------
|
|
bool ErrorBox(const wxString str)
|
|
{
|
|
wxMessageBox(str, APPNAME, wxOK | wxICON_ERROR);
|
|
return false;
|
|
}
|
|
|
|
bool WarningBox(const wxString str)
|
|
{
|
|
wxMessageBox(str, APPNAME, wxOK | wxICON_EXCLAMATION);
|
|
return false;
|
|
}
|
|
|
|
|
|
//classe per gestire i .Ini di campo
|
|
//-----------------------------------------------------------------------------------
|
|
CampoIniFile::CampoIniFile(const wxString strIniPath, const wxString strParagraph)
|
|
: wxFileConfig (wxEmptyString, wxEmptyString, strIniPath, wxEmptyString,
|
|
wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_NO_ESCAPE_CHARACTERS)
|
|
{
|
|
if (!strParagraph.IsEmpty())
|
|
SetPath(strParagraph);
|
|
}
|
|
|
|
wxString CampoIniFile::Get(const wxString strVariable) const
|
|
{
|
|
return Read(strVariable);
|
|
}
|
|
|
|
bool CampoIniFile::GetBool(const wxString strVariable) const
|
|
{
|
|
wxString strBool = Get(strVariable);
|
|
return strBool == "X" || strBool == "Y";
|
|
}
|
|
|
|
int CampoIniFile::GetInt(const wxString strVariable) const
|
|
{
|
|
wxString str = Get(strVariable);
|
|
long val = 0;
|
|
str.ToLong(&val);
|
|
return val;
|
|
}
|
|
|
|
bool CampoIniFile::Set(const wxString strVariable, const wxString strValue)//, const wxString strParagraph) const
|
|
{
|
|
return Write(strVariable, strValue);
|
|
}
|
|
|
|
bool CampoIniFile::Set(const wxString strVariable, const int uValue)//, const wxString strParagraph) const
|
|
{
|
|
return Write(strVariable, uValue);
|
|
}
|
|
|
|
//metodo per sapere che cavolo di tipo di installazione sta esaminando (serve per leggere e scrivere...
|
|
//...correttamente il campo.ini
|
|
int CampoIniFile::GetInstallationTypeNumber() const
|
|
{
|
|
int nType = GetInt("Type");
|
|
if (nType < 1 || nType > 3)
|
|
{
|
|
nType = 1; //di base e' standalone
|
|
const bool bTestDataBase = GetBool("TestDatabase");
|
|
const bool bTestPrograms = GetBool("TestPrograms");
|
|
|
|
if (bTestDataBase) //se puo' manipolare i dati e' StandAlone o Server..
|
|
{
|
|
//ma e' Standalone o Server?
|
|
//se la directory dei dati e' condivisa in scrittura e' un server (almeno al 99%)
|
|
const wxString strStudy = Get("Study");
|
|
if (IsSharedDirectory(strStudy))
|
|
nType = 2; //e' server
|
|
}
|
|
else //..senno' e' client
|
|
nType = 3;
|
|
}
|
|
return nType;
|
|
}
|
|
|
|
//gestione filesystem
|
|
//--------------------------------------------------------------------------------------
|
|
void CheckAndMakeDir(const wxString& strDir, const wxString& strMsg)
|
|
{
|
|
if (!wxDir::Exists(strDir))
|
|
{
|
|
const wxFileName fname(strDir + "\\*.*");
|
|
const wxArrayString& asDirs = fname.GetDirs();
|
|
wxString strCartella = fname.GetVolume();
|
|
strCartella += fname.GetVolumeSeparator();
|
|
for (size_t i = 0; i < asDirs.GetCount(); i++)
|
|
{
|
|
strCartella += "\\";
|
|
strCartella += asDirs[i];
|
|
if (!wxDir::Exists(strCartella) && !wxMkdir(strCartella))
|
|
{
|
|
wxString strError = "Impossibile creare la cartella ";
|
|
strError += strMsg;
|
|
strError += " ";
|
|
strError += strCartella;
|
|
strError += "\nAssicurarsi di avere il permesso di scrittura sul disco e che vi sia spazio a sufficienza";
|
|
ErrorBox(strMsg);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (!strMsg.IsEmpty()) //se il messaggio e' vuoto NON deve fare alcun controllo (installazione sistema)
|
|
{
|
|
wxDir dirDir(strDir);
|
|
if(dirDir.HasFiles()) //se la dir di destinazione dovesse esistere gia' (installazione abortita) almeno sia vuota
|
|
{
|
|
ErrorBox("La cartella di destinazione non e' vuota!\nInstallazione interrotta!");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//metodi per unzippare i files
|
|
//-------------------------------------------------------------------------------
|
|
static size_t GetZipList(const char* strZipFile, wxArrayString& aFiles)
|
|
{
|
|
wxFFileInputStream fin(strZipFile);
|
|
wxZipInputStream zip(fin);
|
|
for (wxZipEntry* z = zip.GetNextEntry(); z; z = zip.GetNextEntry())
|
|
{
|
|
const wxString str = z->GetInternalName();
|
|
aFiles.Add(str);
|
|
}
|
|
|
|
return aFiles.GetCount();
|
|
}
|
|
|
|
|
|
|
|
bool UnzipFile(const char* strZipFile, const char* strDestDir)
|
|
{
|
|
wxArrayString aFiles;
|
|
const size_t files = GetZipList(strZipFile, aFiles);
|
|
|
|
wxProgressDialog pi("Unzip", "", (int)files, NULL, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
|
|
|
for (unsigned int f = 0; f < files; f++)
|
|
{
|
|
const wxString& strFileName = aFiles[f];
|
|
if (!pi.Update(f, strFileName))
|
|
break;
|
|
|
|
if (wxEndsWithPathSeparator(strFileName) || strFileName.Find('.') < 0) // Is dir name
|
|
{
|
|
wxString strOutDir = strDestDir;
|
|
if (!wxEndsWithPathSeparator(strOutDir))
|
|
strOutDir += wxFILE_SEP_PATH;
|
|
strOutDir += strFileName;
|
|
if (!::wxDirExists(strOutDir))
|
|
::wxMkdir(strOutDir);
|
|
}
|
|
else
|
|
{
|
|
wxZipInputStream fin(strZipFile, strFileName);
|
|
|
|
wxString strOutFile = strDestDir;
|
|
if (!wxEndsWithPathSeparator(strOutFile) && !wxIsPathSeparator(strFileName[0]))
|
|
strOutFile += wxFILE_SEP_PATH;
|
|
strOutFile += strFileName;
|
|
|
|
wxString strPath;
|
|
::wxSplitPath(strOutFile, &strPath, NULL, NULL);
|
|
CheckAndMakeDir(strPath, wxEmptyString);
|
|
|
|
wxFileOutputStream fout(strOutFile);
|
|
fout.Write(fin);
|
|
}
|
|
}
|
|
return files > 0;
|
|
}
|