2002-02-28 14:26:23 +00:00
|
|
|
#include "wxinc.h"
|
2004-03-13 09:45:16 +00:00
|
|
|
#include "incstr.h"
|
2009-12-16 12:10:01 +00:00
|
|
|
|
2002-05-27 13:01:14 +00:00
|
|
|
#include "agasys.h"
|
2009-12-16 12:10:01 +00:00
|
|
|
#include "xvt.h"
|
2002-05-27 13:01:14 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Unzip support
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2003-12-19 10:32:15 +00:00
|
|
|
#include <wx/dir.h>
|
2006-04-21 12:59:47 +00:00
|
|
|
#include <wx/progdlg.h>
|
2002-05-27 13:01:14 +00:00
|
|
|
#include <wx/wfstream.h>
|
2003-05-22 15:25:25 +00:00
|
|
|
#include <wx/zipstrm.h>
|
2002-05-27 13:01:14 +00:00
|
|
|
|
2006-04-21 12:59:47 +00:00
|
|
|
static unsigned int aga_getziplist(const char* zipfile, wxArrayString& aFiles)
|
2003-01-07 12:20:49 +00:00
|
|
|
{
|
2006-04-21 12:05:23 +00:00
|
|
|
wxFFileInputStream fin(zipfile);
|
|
|
|
wxZipInputStream zip(fin);
|
|
|
|
for (wxZipEntry* z = zip.GetNextEntry(); z; z = zip.GetNextEntry())
|
2006-04-21 12:59:47 +00:00
|
|
|
{
|
|
|
|
const wxString str = z->GetInternalName();
|
|
|
|
aFiles.Add(str);
|
|
|
|
}
|
2003-01-07 12:20:49 +00:00
|
|
|
|
|
|
|
return aFiles.GetCount();
|
|
|
|
}
|
|
|
|
|
2006-06-29 15:35:17 +00:00
|
|
|
static int aga_find_slash(const wxString& path, int from)
|
2004-01-22 15:19:05 +00:00
|
|
|
{
|
|
|
|
for (int i = from; path[i]; i++)
|
|
|
|
if (wxIsPathSeparator(path[i]))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-06-29 15:35:17 +00:00
|
|
|
static void aga_create_dir(wxString strPath)
|
2004-01-22 15:19:05 +00:00
|
|
|
{
|
|
|
|
if (!wxEndsWithPathSeparator(strPath))
|
|
|
|
strPath += wxFILE_SEP_PATH;
|
|
|
|
|
|
|
|
for (int i = aga_find_slash(strPath, 0); i > 0; i = aga_find_slash(strPath, i+1))
|
|
|
|
{
|
|
|
|
const wxString strDir = strPath.Mid(0,i);
|
|
|
|
if (!::wxDirExists(strDir))
|
2008-08-08 11:31:32 +00:00
|
|
|
{
|
|
|
|
if (!::wxMkdir(strDir))
|
|
|
|
{
|
|
|
|
wxString strMsg = "Impossibile creare la cartella ";
|
|
|
|
strMsg << strDir << " !!";
|
|
|
|
wxMessageBox(strMsg, "Attenzione!", wxICON_ERROR);
|
|
|
|
}
|
|
|
|
}
|
2004-01-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 12:20:49 +00:00
|
|
|
bool aga_unzip(const char* zipfile, const char* destdir)
|
|
|
|
{
|
|
|
|
wxArrayString aFiles;
|
2006-04-21 12:59:47 +00:00
|
|
|
const unsigned int files = aga_getziplist(zipfile, aFiles);
|
2006-04-21 12:05:23 +00:00
|
|
|
|
|
|
|
wxProgressDialog pi("Unzip", "", files, NULL, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
2008-04-04 16:04:47 +00:00
|
|
|
pi.SetSize(480, 120);
|
|
|
|
pi.Center();
|
2006-04-21 12:05:23 +00:00
|
|
|
|
2003-01-07 12:20:49 +00:00
|
|
|
for (unsigned int f = 0; f < files; f++)
|
|
|
|
{
|
2003-10-03 11:01:47 +00:00
|
|
|
const wxString& strFileName = aFiles[f];
|
2006-04-21 12:05:23 +00:00
|
|
|
if (!pi.Update(f, strFileName))
|
|
|
|
break;
|
|
|
|
|
2006-04-21 12:59:47 +00:00
|
|
|
if (wxEndsWithPathSeparator(strFileName) || strFileName.Find('.') < 0) // Is dir name
|
2003-10-03 11:01:47 +00:00
|
|
|
{
|
|
|
|
wxString strOutDir = destdir;
|
|
|
|
if (!wxEndsWithPathSeparator(strOutDir))
|
|
|
|
strOutDir += wxFILE_SEP_PATH;
|
|
|
|
strOutDir += strFileName;
|
2008-08-08 11:31:32 +00:00
|
|
|
aga_create_dir(strOutDir);
|
2003-10-03 11:01:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxZipInputStream fin(zipfile, strFileName);
|
|
|
|
|
|
|
|
wxString strOutFile = destdir;
|
2004-01-22 15:19:05 +00:00
|
|
|
if (!wxEndsWithPathSeparator(strOutFile) && !wxIsPathSeparator(strFileName[0]))
|
2003-10-03 11:01:47 +00:00
|
|
|
strOutFile += wxFILE_SEP_PATH;
|
|
|
|
strOutFile += strFileName;
|
|
|
|
|
|
|
|
wxString strPath;
|
|
|
|
::wxSplitPath(strOutFile, &strPath, NULL, NULL);
|
2004-01-22 15:19:05 +00:00
|
|
|
aga_create_dir(strPath);
|
|
|
|
|
2003-10-03 11:01:47 +00:00
|
|
|
wxFileOutputStream fout(strOutFile);
|
|
|
|
fout.Write(fin);
|
|
|
|
}
|
2003-01-07 12:20:49 +00:00
|
|
|
}
|
|
|
|
return files > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Zip support
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2003-05-22 15:25:25 +00:00
|
|
|
static void AddFileToZip(const wxString& strPrefix, const wxString& strFile,
|
2006-04-21 12:05:23 +00:00
|
|
|
wxZipOutputStream& zip)
|
2002-05-27 13:01:14 +00:00
|
|
|
{
|
2002-07-30 14:11:47 +00:00
|
|
|
if (!wxFileExists(strFile))
|
|
|
|
return;
|
|
|
|
|
2002-05-27 13:01:14 +00:00
|
|
|
wxString strPath, strName, strExt;
|
|
|
|
wxSplitPath(strFile, &strPath, &strName, &strExt);
|
|
|
|
|
|
|
|
wxString strRelName;
|
|
|
|
strRelName = strPath.Mid(strPrefix.Length());
|
|
|
|
if (!strRelName.IsEmpty())
|
|
|
|
strRelName += '/';
|
|
|
|
strRelName += strName;
|
2003-05-22 15:25:25 +00:00
|
|
|
strRelName += '.';
|
2002-05-27 13:01:14 +00:00
|
|
|
strRelName += strExt;
|
|
|
|
|
2006-04-21 12:05:23 +00:00
|
|
|
zip.PutNextEntry(strRelName);
|
|
|
|
wxFileInputStream fin(strFile);
|
|
|
|
zip.Write(fin); // Scrivo file compresso
|
2002-05-27 13:01:14 +00:00
|
|
|
}
|
|
|
|
|
2003-12-19 10:32:15 +00:00
|
|
|
static bool AddFilesToZip(const wxString& strBase, wxArrayString& aFiles, const char* zipfile)
|
2002-05-27 13:01:14 +00:00
|
|
|
{
|
2006-04-21 12:05:23 +00:00
|
|
|
wxFFileOutputStream out(zipfile);
|
|
|
|
wxZipOutputStream zip(out);
|
2002-05-27 13:01:14 +00:00
|
|
|
|
2006-04-21 12:05:23 +00:00
|
|
|
const size_t nFiles = aFiles.GetCount();
|
|
|
|
wxProgressDialog pi("Zip", "", nFiles, NULL, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
2008-04-04 16:04:47 +00:00
|
|
|
pi.SetSize(480, 120);
|
|
|
|
pi.Center();
|
2002-05-27 13:01:14 +00:00
|
|
|
|
2006-04-21 12:05:23 +00:00
|
|
|
for (size_t i = 0; i < nFiles; i++)
|
|
|
|
{
|
|
|
|
const wxString& str = aFiles[i];
|
|
|
|
if (!pi.Update(i, str))
|
|
|
|
break;
|
|
|
|
AddFileToZip(strBase, str, zip);
|
2002-05-27 13:01:14 +00:00
|
|
|
}
|
2006-04-21 12:05:23 +00:00
|
|
|
return true;
|
2002-05-27 13:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool aga_zip(const char* srcfiles, const char* zipfile)
|
|
|
|
{
|
|
|
|
wxString strBase, strMask, strExt;
|
|
|
|
wxSplitPath(srcfiles, &strBase, &strMask, &strExt);
|
|
|
|
strMask += '.';
|
|
|
|
strMask += strExt;
|
|
|
|
|
2003-12-19 10:32:15 +00:00
|
|
|
wxArrayString aFiles;
|
2006-04-21 12:59:47 +00:00
|
|
|
wxDir::GetAllFiles(strBase, &aFiles, strMask);
|
2002-07-30 14:11:47 +00:00
|
|
|
|
2002-05-27 13:01:14 +00:00
|
|
|
return AddFilesToZip(strBase, aFiles, zipfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool aga_zip_filelist(const char* filelist, const char* zipfile)
|
|
|
|
{
|
2003-12-19 10:32:15 +00:00
|
|
|
wxArrayString aFiles;
|
2002-05-27 13:01:14 +00:00
|
|
|
ifstream fin(filelist);
|
|
|
|
while (!fin.eof())
|
|
|
|
{
|
2003-05-22 15:25:25 +00:00
|
|
|
char name[_MAX_PATH];
|
2002-05-27 13:01:14 +00:00
|
|
|
fin.getline(name, sizeof(name));
|
|
|
|
if (*name)
|
|
|
|
aFiles.Add(name);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return AddFilesToZip("", aFiles, zipfile);
|
|
|
|
}
|
|
|
|
|
2007-03-16 13:33:09 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// DDE
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2009-12-01 10:18:24 +00:00
|
|
|
#ifdef __WXMSW__
|
2007-03-16 13:33:09 +00:00
|
|
|
#include <wx/dde.h>
|
|
|
|
#define wxAgaClient wxDDEClient
|
|
|
|
#define wxAgaConnection wxDDEConnection
|
|
|
|
#else
|
|
|
|
// Forse inutile: forse gia' fatto da wxWidgets
|
|
|
|
#include <wx/sckipc.h>
|
|
|
|
#define wxAgaClient wxTCPClient
|
|
|
|
#define wxAgaConnection wxTCPConnection
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static wxAgaClient* _net_client = NULL;
|
|
|
|
static unsigned long _net_conns = 0;
|
|
|
|
|
|
|
|
unsigned long aga_dde_connect(const char* host, const char* service, const char* topic)
|
|
|
|
{
|
|
|
|
if (_net_client == NULL)
|
|
|
|
{
|
|
|
|
_net_client = new wxAgaClient;
|
|
|
|
_net_conns = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxConnectionBase* conn = _net_client->MakeConnection(host, service, topic);
|
|
|
|
if (conn != NULL)
|
|
|
|
_net_conns++;
|
|
|
|
|
|
|
|
return (unsigned long)conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool aga_dde_execute(unsigned long connection, const char* msg)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if (connection != 0)
|
|
|
|
{
|
|
|
|
wxAgaConnection* conn = (wxAgaConnection*)connection;
|
|
|
|
ok = conn->Execute((char*)msg, -1);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool aga_dde_terminate(unsigned long connection)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if (connection != 0 && _net_client != NULL)
|
|
|
|
{
|
|
|
|
wxAgaConnection* conn = (wxAgaConnection*)connection;
|
|
|
|
ok = conn->Disconnect();
|
|
|
|
if (ok && _net_conns > 0)
|
|
|
|
{
|
|
|
|
_net_conns--;
|
|
|
|
if (_net_conns == 0)
|
|
|
|
{
|
|
|
|
delete _net_client;
|
|
|
|
_net_client = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
2009-12-16 12:10:01 +00:00
|
|
|
|
|
|
|
BOOLEAN xvt_sys_multithread(MULTITHREAD_CALLBACK callback, void* out, const void* in, const void* param,
|
|
|
|
int tot, BOOLEAN WXUNUSED(progind))
|
|
|
|
{
|
|
|
|
BOOLEAN ok = TRUE;
|
|
|
|
for (int i = 0; i < tot && ok; i++)
|
|
|
|
ok = callback(out, in, param, i, tot);
|
|
|
|
return ok;
|
|
|
|
}
|