Patch level : 10.0 no patch
Files correlati : pd0398.exe Ricompilazione Demo : [ ] Commento E' possibile ora copiare file da e verso ftp. git-svn-id: svn://10.65.10.50/branches/R_10_00@20986 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
7ab0a6d529
commit
566d5f1852
221
xvaga/xvaga.cpp
221
xvaga/xvaga.cpp
@ -16,11 +16,16 @@
|
||||
#include <wx/fileconf.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/protocol/ftp.h>
|
||||
#include <wx/protocol/http.h>
|
||||
#include <wx/snglinst.h>
|
||||
#include <wx/sysopt.h>
|
||||
#include <wx/thread.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/url.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if wxCHECK_VERSION(2,9,0)
|
||||
#include <wx/propgrid.h>
|
||||
@ -1750,19 +1755,38 @@ long xvt_fsys_file_attr(const char* path, long attr)
|
||||
switch (attr)
|
||||
{
|
||||
case XVT_FILE_ATTR_EXIST:
|
||||
ret = ::wxFileExists(name);
|
||||
ret = xvt_fsys_access(path, 0) == 0;
|
||||
break;
|
||||
case XVT_FILE_ATTR_READ:
|
||||
ret = ::wxAccess(name, 0x1) != 0;
|
||||
ret = xvt_fsys_access(path, 1) == 0;
|
||||
break;
|
||||
case XVT_FILE_ATTR_WRITE:
|
||||
ret = ::wxAccess(name, 0x2) != 0;
|
||||
ret = xvt_fsys_access(path, 2) == 0;
|
||||
break;
|
||||
case XVT_FILE_ATTR_DIRECTORY:
|
||||
ret = ::wxDirExists(name);
|
||||
break;
|
||||
case XVT_FILE_ATTR_SIZE:
|
||||
{
|
||||
wxURL url(path);
|
||||
wxString scheme = url.GetScheme();
|
||||
|
||||
if (scheme == "ftp" || scheme == "http")
|
||||
{
|
||||
SLIST files = xvt_fsys_list_files("", path, false);
|
||||
const int count = xvt_slist_count(files);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
SLIST_ELT e = xvt_slist_get_first(files);
|
||||
|
||||
ret = e->data;
|
||||
}
|
||||
else
|
||||
ret = -1L;
|
||||
xvt_slist_destroy(files);
|
||||
return ret;
|
||||
}
|
||||
const wxULongLong sz = wxFileName::GetSize(name);
|
||||
ret = sz.GetHi() != 0 ? INT_MAX : sz.GetLo();
|
||||
}
|
||||
@ -1791,6 +1815,7 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
|
||||
{
|
||||
SLIST list = xvt_slist_create();
|
||||
|
||||
|
||||
int flags = 0;
|
||||
if (dirs)
|
||||
{
|
||||
@ -1800,19 +1825,58 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
|
||||
else
|
||||
flags = wxFILE;
|
||||
|
||||
wxString f = ::wxFindFirstFile(pat, flags);
|
||||
while (!f.IsEmpty())
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
if (f.StartsWith(".\\"))
|
||||
#else
|
||||
if (f.StartsWith("./"))
|
||||
#endif
|
||||
f = f.Mid(2);
|
||||
xvt_slist_add_at_elt(list, NULL, f, 0L);
|
||||
wxURL url(pat);
|
||||
|
||||
f = ::wxFindNextFile();
|
||||
}
|
||||
if (url.GetScheme() == "ftp")
|
||||
{
|
||||
const wxString strHost = url.GetServer();
|
||||
const wxString strUser = url.GetUser();
|
||||
const wxString strPwd = url.GetPassword();
|
||||
const wxFileName fnPath = url.GetPath();
|
||||
const wxString fnDir = fnPath.GetPath(wxPATH_GET_VOLUME, wxPATH_UNIX);
|
||||
const wxString fnName = fnPath.GetFullName();
|
||||
wxString RemotePath(pat);
|
||||
const int mask = dirs ? (strcmp(type, DIR_TYPE) == 0 ? 2 : 3) : 1;
|
||||
wxFTP ftp;
|
||||
|
||||
RemotePath = RemotePath.BeforeLast('/');
|
||||
if (!strUser.IsEmpty())
|
||||
{
|
||||
ftp.SetUser(strUser);
|
||||
ftp.SetPassword(strPwd);
|
||||
}
|
||||
if (ftp.Connect(strHost))
|
||||
if (ftp.ChDir(fnDir))
|
||||
{
|
||||
wxArrayString files;
|
||||
ftp.GetDirList(files, fnName);
|
||||
for (size_t i = 0; i < files.GetCount(); i++)
|
||||
{
|
||||
int type = files[i][0] == 'd' ? 2 : 1;
|
||||
|
||||
if (type & mask)
|
||||
{
|
||||
wxString f(RemotePath);
|
||||
|
||||
f << '/' << files[i].AfterLast(' ');
|
||||
wxString size = files[i].Mid(30);
|
||||
xvt_slist_add_at_elt(list, NULL, f, type == 2 ? -1 : wxAtol(size));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else //normale list_files
|
||||
{
|
||||
wxString f = ::wxFindFirstFile(pat, flags);
|
||||
while (!f.IsEmpty())
|
||||
{
|
||||
if (f.StartsWith(".\\") || f.StartsWith("./"))
|
||||
f = f.Mid(2);
|
||||
xvt_slist_add_at_elt(list, NULL, f, 0L);
|
||||
|
||||
f = ::wxFindNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@ -1837,6 +1901,87 @@ BOOLEAN xvt_fsys_set_dir(const DIRECTORY *dirp)
|
||||
return ::wxSetWorkingDirectory(dirp->path);
|
||||
}
|
||||
|
||||
BOOLEAN xvt_fsys_fcopy(const char* orig, const char* dest)
|
||||
{
|
||||
wxURL orig_url(orig);
|
||||
wxURL dest_url(dest);
|
||||
wxInputStream * input = orig_url.GetInputStream();
|
||||
wxOutputStream * output = NULL;
|
||||
wxString scheme = dest_url.GetScheme();
|
||||
|
||||
if (input == NULL)
|
||||
input = new wxFileInputStream(orig);
|
||||
if (scheme == "ftp")
|
||||
{
|
||||
wxFTP ftp;
|
||||
const wxString strHost = dest_url.GetServer();
|
||||
const wxString strUser = dest_url.GetUser();
|
||||
const wxString strPwd = dest_url.GetPassword();
|
||||
const wxFileName fnPath = dest_url.GetPath();
|
||||
const wxString fnDir = fnPath.GetPath(wxPATH_GET_VOLUME, wxPATH_UNIX);
|
||||
const wxString fnName = fnPath.GetFullName();
|
||||
|
||||
|
||||
if (!strUser.IsEmpty())
|
||||
{
|
||||
ftp.SetUser(strUser);
|
||||
ftp.SetPassword(strPwd);
|
||||
}
|
||||
|
||||
if (ftp.Connect(strHost))
|
||||
if (ftp.SetBinary())
|
||||
if (ftp.ChDir(fnDir))
|
||||
output = ftp.GetOutputStream(fnName);
|
||||
}
|
||||
else
|
||||
if (scheme == "http")
|
||||
return false;
|
||||
/* {
|
||||
const wxString strHost = dest_url.GetServer();
|
||||
const wxString strUser = dest_url.GetUser();
|
||||
const wxString strPwd = dest_url.GetPassword();
|
||||
const wxFileName fnPath = dest_url.GetPath();
|
||||
|
||||
wxHTTP http;
|
||||
|
||||
if (!strUser.IsEmpty())
|
||||
{
|
||||
http.SetUser(strUser);
|
||||
http.SetPassword(strPwd);
|
||||
}
|
||||
http.SetHeader(_T("Content-type"), _T("application/x-www-form-urlencoded")); //remember to define “Content-type: application/x-www-form-urlencoded”, or remote server can’t get your posted data.
|
||||
wxString PostData("postdata=");
|
||||
|
||||
PostData << fnPath.GetFullPath();
|
||||
http.SetPostBuffer(PostData); //it’s the data to be posted
|
||||
bool httpok = false;
|
||||
if (http.Connect(strHost))
|
||||
{
|
||||
wxInputStream *httpStream = http.GetInputStream(_T("/getfile.php"));
|
||||
httpok = http.GetError() == wxPROTO_NOERR;
|
||||
wxDELETE(httpStream);
|
||||
}
|
||||
return httpok;
|
||||
} */
|
||||
else
|
||||
output = new wxFileOutputStream(dest);
|
||||
|
||||
bool ok = false;
|
||||
if (input != NULL && output != NULL)
|
||||
{
|
||||
input->Read(*output);
|
||||
|
||||
wxStreamError err = output->GetLastError();
|
||||
|
||||
ok = (err == wxSTREAM_NO_ERROR);
|
||||
}
|
||||
if (input != NULL)
|
||||
delete input;
|
||||
if (output != NULL)
|
||||
delete output;
|
||||
return ok;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Images
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -3596,12 +3741,27 @@ BOOLEAN xvt_sys_set_env(const char* varname, const char* value)
|
||||
// BOOLEAN o int? Adso!
|
||||
int xvt_fsys_access(const char *pathname, int mode)
|
||||
{
|
||||
wxURL url(pathname);
|
||||
wxString scheme = url.GetScheme();
|
||||
|
||||
if (scheme == "ftp" || scheme == "http")
|
||||
{
|
||||
if (mode & 4)
|
||||
return ENOEXEC;
|
||||
if (mode & 2 && scheme == "http")
|
||||
return EACCES;
|
||||
SLIST files = xvt_fsys_list_files("", pathname, true);
|
||||
const int count = xvt_slist_count(files);
|
||||
|
||||
xvt_slist_destroy(files);
|
||||
return count > 0 ? 0 : ENOENT;
|
||||
}
|
||||
return wxAccess(pathname, mode) == -1 ? errno : 0;
|
||||
}
|
||||
|
||||
BOOLEAN xvt_fsys_file_exists(const char *pathname)
|
||||
{
|
||||
return xvt_fsys_file_attr(pathname, XVT_FILE_ATTR_EXIST);
|
||||
return xvt_fsys_access(pathname, 0) == 0;
|
||||
}
|
||||
|
||||
BOOLEAN xvt_fsys_mkdir(const char *pathname)
|
||||
@ -3619,7 +3779,34 @@ BOOLEAN xvt_fsys_rmdir(const char *pathname)
|
||||
|
||||
BOOLEAN xvt_fsys_remove_file(const char *pathname)
|
||||
{
|
||||
return wxRemoveFile(pathname);
|
||||
wxURL url(pathname);
|
||||
wxString scheme = url.GetScheme();
|
||||
|
||||
if (scheme == "ftp")
|
||||
{
|
||||
wxFTP ftp;
|
||||
const wxString strHost = url.GetServer();
|
||||
const wxString strUser = url.GetUser();
|
||||
const wxString strPwd = url.GetPassword();
|
||||
const wxFileName fnPath = url.GetPath();
|
||||
const wxString fnDir = fnPath.GetPath(wxPATH_GET_VOLUME, wxPATH_UNIX);
|
||||
const wxString fnName = fnPath.GetFullName();
|
||||
|
||||
if (!strUser.IsEmpty())
|
||||
{
|
||||
ftp.SetUser(strUser);
|
||||
ftp.SetPassword(strPwd);
|
||||
}
|
||||
|
||||
if (ftp.Connect(strHost))
|
||||
if (ftp.ChDir(fnDir))
|
||||
return ftp.RmFile(fnName);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (scheme == "http")
|
||||
return false;
|
||||
return wxRemoveFile(pathname);
|
||||
}
|
||||
|
||||
BOOLEAN xvt_fsys_removefile(const char *pathname)
|
||||
|
@ -182,6 +182,8 @@ XVTDLL void xvt_fsys_restore_dir();
|
||||
XVTDLL void xvt_fsys_save_dir();
|
||||
XVTDLL BOOLEAN xvt_fsys_set_dir(const DIRECTORY* dirp);
|
||||
XVTDLL long xvt_fsys_get_file_attr(const FILE_SPEC *fs, long attr); // Place older
|
||||
XVTDLL BOOLEAN xvt_fsys_fcopy(const char* orig, const char* dest);
|
||||
|
||||
// Added by Guy
|
||||
XVTDLL unsigned long xvt_fsys_get_disk_size(const char* path, char unit);
|
||||
XVTDLL unsigned long xvt_fsys_get_disk_free_space(const char* path, char unit);
|
||||
|
Loading…
x
Reference in New Issue
Block a user