Exemple #1
0
void *wxSizeCacherThread::Entry()
{
    wxLogAdvMsg(wxT("wxSizeCacherThread::Entry - caching file sizes"));
    bool allok = TRUE;

    if (m_urls.GetCount() == 0)
        return (void*)FALSE;     // no urls whose size must be cached ?

    // be sure to have n null entries in our cache array, where
    // 'n' is the number of URLs whose size must be cached
    m_urlSizes = new wxArrayLong();
    m_urlSizes->Add((long)0, m_urls.GetCount());

    // begin our loop
    for (int i=0; i<(int)m_urls.GetCount() && !TestDestroy(); i++) {

        // getting the input stream for the url is the only way
        // to get the size of the resource pointed by that url...
        m_urlSizes->Item(i) = wxGetSizeOfURI(m_urls[i]);
        allok &= (m_urlSizes->Item(i) != 0);
    }

    wxLogAdvMsg(wxT("wxSizeCacherThread::Entry - caching of file sizes completed"));
    return (void *)allok;
}
Exemple #2
0
bool wxWebUpdateActionMkdir::SetProperties(const wxArrayString &propnames,
										const wxArrayString &propvalues)
{
	for (int i=0; i < (int)propnames.GetCount(); i++) {
		wxLogAdvMsg(wxT("wxWebUpdateActionMkdir::SetProperties - name: [")
				+ propnames[i] + wxT("], value: [") + propvalues[i] + wxT("]"));

		if (propnames[i] == wxT("dir"))
			m_strTarget = propvalues[i];
		else
			wxLogAdvMsg(wxT("wxWebUpdateActionMkdir::SetProperties - unknown property: ") 
						+ propnames[i]);
	}

	// do substitutions on the paths
	m_strTarget = wxWebUpdateInstaller::Get()->DoSubstitution(m_strTarget);

	// validate the properties
	wxFileName f(m_strTarget);

	// we won't do the wxFileName::FileExists check because the file we need to run
	// could be a file which does not exist yet (e.g. its in the update package)
	//
	// NOTE: wxFileName::IsDir() only checks if the given string ends with a path
	//       separator character (there are no real ways to do a ::IsDir check
	//       without trying to access that path!) and thus we won't use it
	if (m_strTarget.IsEmpty() || !f.IsOk()) 
		return FALSE;

	return TRUE;
}
Exemple #3
0
bool wxWebUpdateActionExtract::SetProperties(const wxArrayString &propnames,
										const wxArrayString &propvalues)
{
	wxString flags;

	for (int i=0; i < (int)propnames.GetCount(); i++) {
		wxLogAdvMsg(wxT("wxWebUpdateActionExtract::SetProperties - name: [")
				+ propnames[i] + wxT("], value: [") + propvalues[i] + wxT("]"));

		if (propnames[i] == wxT("where"))
			m_strWhere = propvalues[i];
		else if (propnames[i] == wxT("file"))
			m_strFile = propvalues[i];
		else if (propnames[i] == wxT("type"))
			m_strType = propvalues[i];
		else if (propnames[i] == wxT("namemap"))
			m_strNameMap = propvalues[i];
		else
			wxLogAdvMsg(wxT("wxWebUpdateActionExtract::SetProperties - unknown property: ") 
						+ propnames[i]);
	}

	// do substitutions on the paths
	m_strWhere = wxWebUpdateInstaller::Get()->DoSubstitution(m_strWhere);
	
	// by default, WebUpdater executables must be extracted with the '_'
	// character prepended
	wxString str = wxWebUpdateInstaller::Get()->GetKeywordValue(wxT("updatername")) +
					wxWebUpdateInstaller::Get()->GetKeywordValue(wxT("exe"));
	m_strNameMap = str + wxT("=_") + str + wxT(",") + m_strNameMap;

	// set defaults
	if (m_strFile.IsEmpty())		// the FILE default value is $(thisfile)
		m_strFile = wxWebUpdateInstaller::Get()->GetKeywordValue(wxT("thisfile"));
	if (m_strWhere.IsEmpty())		// the WHERE default value is $(programdir)
		m_strWhere = wxWebUpdateInstaller::Get()->GetKeywordValue(wxT("programdir"));
	if (m_strType.IsEmpty())		// the TYPE default value is "zip"
		m_strType = wxT("zip");

	// validate the properties
	wxFileName f(m_strWhere), f2(m_strFile);

	// we won't do the wxFileName::FileExists check because the file we need to run
	// could be a file which does not exist yet (e.g. its in the update package)
	//
	// NOTE: wxFileName::IsDir() only checks if the given string ends with a path
	//       separator character (there are no real ways to do a ::IsDir check
	//       without trying to access that path!) and thus we won't use it
	if (m_strWhere.IsEmpty() || m_strFile.IsEmpty() || 
		!f.IsOk() || !f2.IsOk()) 
		return FALSE;

	return TRUE;
}
Exemple #4
0
bool wxWebUpdateActionRun::SetProperties(const wxArrayString &propnames,
										const wxArrayString &propvalues)
{
	wxString flags;

	m_strArgs = wxEmptyString;			// the ARGS default value
	for (int i=0; i < (int)propnames.GetCount(); i++) {
		wxLogDebug(wxT("wxWebUpdateActionRun::SetProperties - name: [")
				+ propnames[i] + wxT("], value: [") + propvalues[i] + wxT("]"));

		if (propnames[i] == wxT("args"))
			m_strArgs = propvalues[i];
		else if (propnames[i] == wxT("file") || propnames[i] == wxT("cmd"))
			m_strFile = propvalues[i];
		else if (propnames[i] == wxT("flags"))
			flags = propvalues[i];
		else
			wxLogAdvMsg(wxT("wxWebUpdateActionRun::SetProperties - unknown property: ") 
						+ propnames[i]);
	}

	// do substitutions on the paths
	m_strFile = wxWebUpdateInstaller::Get()->DoSubstitution(m_strFile);
	m_strArgs = wxWebUpdateInstaller::Get()->DoSubstitution(m_strArgs);

	// set defaults	
	if (flags.IsEmpty())
		m_nExecFlag = wxEXEC_ASYNC;		// the FLAGS default value
	else if (flags == wxT("ASYNC"))
		m_nExecFlag = wxEXEC_ASYNC;
	else if (flags == wxT("SYNC"))
		m_nExecFlag = wxEXEC_SYNC;
	else {
		m_nExecFlag = wxEXEC_ASYNC;
		wxLogAdvMsg(wxT("wxWebUpdateActionRun::SetProperties - unknown exec flag: ") 
						+ flags);
	}

	if (m_strFile.IsEmpty())
		m_strFile = wxWebUpdateInstaller::Get()->GetKeywordValue(wxT("thisfile"));

	// validate the properties
	wxFileName f(m_strFile);			// the FILE property is required !

	// we won't do the wxFileName::FileExists check because the file we need to run
	// could be a file which does not exist yet (e.g. its in the update package)
	if (!f.IsOk()) 
		return FALSE;

	return TRUE;
}
Exemple #5
0
bool wxWebUpdateActionMkdir::Run() const
{
	wxArrayString orig, output;
	wxLogUsrMsg(wxT("wxWebUpdateActionMkdir::Run - going to make the folder [")
				+ m_strTarget + wxT("]"));
	
	// wxFileName wants a path separator at the end of directory names
	wxString dir(m_strTarget);
	if (dir.Last() != wxFileName::GetPathSeparator())
		dir += wxFileName::GetPathSeparator();
	
	wxFileName f(dir);
	if (f.DirExists()) {
		
		wxLogAdvMsg(wxT("wxWebUpdateActionMkdir::Run - the folder \"") + m_strTarget +
			wxT("\" already exist... proceeding anyway"));
		return TRUE;
	}
	
	// create it !
	if (f.Mkdir(0777, wxPATH_MKDIR_FULL))
		wxLogDebug(wxT("wxWebUpdateActionMkdir::Run - created the [") + 
		f.GetPath() + wxT("] folder"));
	else
		wxLogDebug(wxT("wxWebUpdateActionMkdir::Run - could not create the [") + 
		f.GetPath() + wxT("] folder.. proceeding anyway"));
	
	return TRUE;
}
bool wxWebUpdateActionCopy::SetProperties(const wxArrayString &propnames,
										const wxArrayString &propvalues)
{
	// set the defaults
	m_bMove = FALSE;
	m_bCreate = TRUE;
	m_bOverwrite = TRUE;

	for (int i=0; i < (int)propnames.GetCount(); i++) {
		wxLogAdvMsg(wxS("wxWebUpdateActionCopy::SetProperties - name: [")
				+ propnames[i] + wxS("], value: [") + propvalues[i] + wxS("]"));

		if (propnames[i] == wxS("from"))
			m_strFrom = propvalues[i];
		else if (propnames[i] == wxS("to"))
			m_strTo = propvalues[i];
		else if (propnames[i] == wxS("create"))
			m_bCreate = (propvalues[i] == wxS("1"));
		else if (propnames[i] == wxS("move"))
			m_bMove = (propvalues[i] == wxS("1"));
		else if (propnames[i] == wxS("overwrite"))
			m_bOverwrite = (propvalues[i] == wxS("1"));
		else
			wxLogAdvMsg(wxS("wxWebUpdateActionCopy::SetProperties - unknown property: ")
						+ propnames[i]);
	}

	// do substitutions on the paths
	m_strFrom = wxWebUpdateInstaller::Get()->DoSubstitution(m_strFrom);
	m_strTo = wxWebUpdateInstaller::Get()->DoSubstitution(m_strTo);

	// validate the properties
	wxFileName f(m_strFrom), f2(m_strTo);

	// we won't do the wxFileName::FileExists check because the file we need to run
	// could be a file which does not exist yet (e.g. its in the update package)
	//
	// NOTE: wxFileName::IsDir() only checks if the given string ends with a path
	//       separator character (there are no real ways to do a ::IsDir check
	//       without trying to access that path!) and thus we won't use it
	if (m_strFrom.IsEmpty() || m_strTo.IsEmpty() ||
		!f.IsOk() || !f2.IsOk())
		return FALSE;

	return TRUE;
}
Exemple #7
0
wxInputStream *wxGetInputStreamFromURI(const wxString &uri)
{
    wxInputStream *in;

    if (wxIsFileProtocol(uri)) {

        // we can handle file:// protocols ourselves
        wxLogAdvMsg(wxT("wxGetInputStreamFromURI - using wxFileInputStream"));
        wxURI u(uri);
        in = new wxFileInputStream(u.GetPath());

    } else {

#if wxUSE_HTTPENGINE
        wxLogAdvMsg(wxT("wxGetInputStreamFromURI - using wxHTTPBuilder"));
        in = new wxSafeHTTPEngineInputStream(uri,
                wxDownloadThread::m_proxy, wxDownloadThread::m_auth);

        // NOTES:
        // 1) we use the static proxy & auth settings of wxDownloadThread
        //    because this function is an helper function of wxDownloadThread
        // 2) the proxy & auth settings should have been initialized by the
        //    user of wxDownloadThread
        // 3) the wx*Settings classes contain a boolean switch which allows
        //    wxHTTPBuilder to understand if they are marked as "used" or not;
        //    thus, setting them with the Set*() functions below does not
        //    necessarily mean that they will be used.

        // just to help debugging....
        if (wxDownloadThread::m_proxy.m_bUseProxy)
            wxLogAdvMsg(wxT("wxGetInputStreamFromURI - using the proxy settings"));
        if (wxDownloadThread::m_auth.m_authType != wxHTTPAuthSettings::wxHTTP_AUTH_NONE)
            wxLogAdvMsg(wxT("wxGetInputStreamFromURI - using the basic authentication settings"));
#else

        // we won't directly use wxURL because it must be alive together with
        // the wxInputStream it generates... wxURLInputStream solves this problem
        wxLogAdvMsg(wxT("wxGetInputStreamFromURI - using wxURL"));
        in = new wxURLInputStream(uri);
#endif
    }

    return in;
}
Exemple #8
0
bool wxWebUpdateActionCopy::Run() const
{
	wxArrayString orig, output;
	wxLogUsrMsg(wxT("wxWebUpdateActionCopy::Run - going to copy the file(s)/folder(s) [")
				+ m_strFrom + wxT("] in [")	+ m_strTo + wxT("]"));

	// wxFileName wants a path separator at the end of directory names
	wxString dir(m_strTo);
	if (dir.Last() != wxFileName::GetPathSeparator())
		dir += wxFileName::GetPathSeparator();

	// be sure that the destination directory exists
	wxFileName f(dir);
	if (!f.DirExists() && !m_bCreate) {

		wxLogAdvMsg(wxT("wxWebUpdateActionCopy::Run - the folder \"") + m_strTo +
				wxT("\" does not exist and create=0 !"));
		return FALSE;
	}
	
	// do we need to create the destination folder ?
	if (!f.DirExists()) {
		wxASSERT_MSG(m_bCreate, 
			wxT("The create=0 case should have been already catched"));

		if (f.Mkdir(0777, wxPATH_MKDIR_FULL))
			wxLogAdvMsg(wxT("wxWebUpdateActionCopy::Run - created the [") + 
							f.GetPath() + wxT("] folder"));
		else
			wxLogAdvMsg(wxT("wxWebUpdateActionCopy::Run - could not create the [") + 
							f.GetPath() + wxT("] folder.. proceeding anyway"));
	}

	// do the copy
	// FIXME: how to handle the "m_bMove" flag ??
	if (!wxCopyFile(m_strFrom, m_strTo, m_bOverwrite))
		return FALSE;
	return TRUE;
}
void wxWebUpdateListCtrl::OnCacheSizeComplete(wxCommandEvent &ev)
{
    wxArrayLong *arr = (wxArrayLong *)ev.GetClientData();

    for (int i=0; i<(int)m_arrRemotePackages.GetCount(); i++)
        m_arrRemotePackages[i].GetDownload().SetDownloadSize(arr->Item(i));
    delete arr;

    // modify the items currently shown
    for (int j=0; j < GetItemCount(); j++) {

        const wxWebUpdatePackage &p = GetRemotePackage(GetItemText(j));
        wxASSERT_MSG(p.GetDownload().IsDownloadSizeCached(),
                    wxS("Why does this item has not a cached size ?"));
        unsigned long bytesize = p.GetDownload().GetDownloadSize();
        SetItem(j, 3, wxGetSizeStr(bytesize));
    }

    wxLogAdvMsg(wxS("wxWebUpdateListCtrl::OnCacheSizeComplete - sizes cached"));
}
Exemple #10
0
bool wxWebUpdateActionMkfile::Run() const
{
	wxArrayString orig, output;
	wxLogUsrMsg(wxT("wxWebUpdateActionMkfile::Run - going to make the file [")
				+ m_strTarget + wxT("]"));

	// do we have to create a folder ?
	wxFileName f(m_strTarget);
	if (f.FileExists()) {
		
		if (m_bOverwrite)
			wxLogAdvMsg(wxT("wxWebUpdateActionMkfile::Run - the file \"") + m_strTarget +
			wxT("\" already exist... proceeding anyway (overwrite=1)"));
		else
			return TRUE;		// exit
	}
	
	// create it !
	wxFileOutputStream out(f.GetFullPath());
	
	// do the encoding conversion
	wxCSConv converter(m_strEncoding);
	wxCharBuffer buf = m_strContent.mb_str(converter);
	const char *data = (const char*) buf;
	size_t bytes = strlen(data)*sizeof(char);
	
	// write
	if (out.Write(data, bytes).LastWrite() != bytes) {
		wxLogUsrMsg(wxT("wxWebUpdateActionMkfile::Run - could not create the [") + 
			f.GetFullPath() + wxT("] file."));
		//wxDELETEA(data);
		return FALSE;
	}
	
	//wxDELETEA(data);
	wxLogUsrMsg(wxT("wxWebUpdateActionMkfile::Run - created the [") + 
		f.GetFullPath() + wxT("] file with content [") + 
		m_strContent + wxT("]..."));
	
	return TRUE;
}
bool wxWebUpdateActionRun::Run() const
{
	// be sure that the file to run exists
	wxFileName f(m_strFile);
	if (!f.FileExists()) {

		wxLogUsrMsg(_("wxWebUpdateActionRun::Run - the file [%s] does not exist; proceeding anyway (maybe it's in PATH)"), m_strFile.c_str());

		// proceed: the executable could be in the system path...
	}

	int retcode = wxExecute(m_strFile + wxS(" ") + m_strArgs,
 							m_nExecFlag | wxEXEC_NODISABLE);

	// FIXME: how do we know if this retcode means success or not ?
	//        (some programs could not respect the 0=success UNIX standard...)
	if (retcode != 0)
		wxLogAdvMsg(wxS("wxWebUpdateActionRun::Run - got a non-null return code for ")
					wxS("the last command; proceeding anyway..."));
	return TRUE;
}
void wxWebUpdateListCtrl::CacheDownloadSizes()
{
    // it makes sense to cache download sizes even when this listctrl is hidden
    // since we need the download size in any case for the progress bar
    // if (!this->IsShown())
    //    return;
#if 0

    // TO TEST wxGetSizeOfURI
    // 1) try strings that won't be parsable (e.g. abcdhttp://)
    // 2) try strings that will parse but do not point to any real file (e.g. http://myserver.com/nonexistingfile)
    // 3) try with a real file (e.g. http://www.google.com)
    unsigned long n = wxGetSizeOfURI(wxS("http://osdn.dl.sourceforge.net/sourceforge/wxcode/simple-gtk-2.0.3.zipfdsafdas"));
    if (n == 0xfffffff)
        wxMessageBox(wxString::Format(wxS("fake ")));
    else
        wxMessageBox(wxString::Format(wxS("%lu"), n));

#else

    // now load all the packages we need in local cache
    wxSizeCacherThread *p = new wxSizeCacherThread(this);
    for (int i=0; i < (int)m_arrRemotePackages.GetCount(); i++) {
        wxString u = m_arrRemotePackages[i].GetDownload().GetDownloadString();

        wxLogDebug(wxS("wxWebUpdateListCtrl::CacheDownloadSizes - adding [") + u +
                wxS("] to size-caching"));
        p->m_urls.Add(u);
    }

    wxLogAdvMsg(wxS("wxWebUpdateListCtrl::CacheDownloadSizes - launching the size cacher thread"));
    if (p->Create() != wxTHREAD_NO_ERROR ||
        p->Run() != wxTHREAD_NO_ERROR) {
        wxMessageBox(_("Low resources; cannot show the size of the packages...\nClose some applications and then retry."),
                    _("Error"), wxOK | wxICON_ERROR);
    }
#endif
}
Exemple #13
0
bool wxWebUpdateActionExtract::Run() const
{
	wxArrayString orig, output;
	wxLogUsrMsg(wxT("wxWebUpdateActionExtract::Run - going to extract the file [")
				+ m_strFile + wxT("] of type [") + m_strType + wxT("] in [")
				+ m_strWhere + wxT("]"));

	// wxFileName wants a path separator at the end of directory names
	wxString dir(m_strWhere);
	if (dir.Last() != wxFileName::GetPathSeparator())
		dir += wxFileName::GetPathSeparator();

	// be sure that the destination directory exists
	wxFileName f(dir), f2(m_strFile);
	if (!f.DirExists() || !f2.FileExists()) {

		wxLogUsrMsg(wxT("wxWebUpdateActionExtract::Run - the folder \"") + m_strWhere +
				wxT("\" or the file \"") + m_strFile + wxT("\" does not exist !"));
		return FALSE;
	}
	
	// parse the namemap
	wxArrayString compressed, extracted;
	int count = wxWebUpdateInstaller::Get()->ParsePairValueList(m_strNameMap, compressed, extracted);

	// do the substitutions also on the compressed filenames
	for (int i=0; i < count; i++)
		compressed[i] = wxWebUpdateInstaller::Get()->DoSubstitution(compressed[i]);

	// create the archive factory
	wxArchiveClassFactory *factory = NULL;
	if (m_strType == wxT("zip"))
		factory = new wxZipClassFactory;	

	// extract the package 
	wxArchiveEntryPtr entry;
	wxFFileInputStream input(m_strFile);
	wxArchiveInputStream *in = factory->NewStream(input);
	delete factory;

    while (entry.reset(in->GetNextEntry()), entry.get() != NULL)
    {
        // access meta-data
        wxString name = entry->GetName();
        
        // is this file/dir registered in the name map ?
        int idx = compressed.Index(name);
        if (idx != wxNOT_FOUND)
        	name = extracted[idx];
        wxString output = dir + name;

		// can be different from "dir" if "name" includes a relative path...
		wxString outputdir = wxFileName(output).GetPath();

		// intercept directories...
		if (!wxDirExists(outputdir)) {

			if (wxFileName(outputdir).Mkdir(0777, wxPATH_MKDIR_FULL))
				wxLogAdvMsg(wxT("wxWebUpdateActionExtract::Run - created the [") + 
							outputdir + wxT("] folder"));
			else
				wxLogAdvMsg(wxT("wxWebUpdateActionExtract::Run - could not create the [") + 
							outputdir + wxT("] folder.. proceeding anyway"));
		
			continue;		// this entry contains no data
		}

		// this is a file...
		wxLogUsrMsg(wxT("wxWebUpdateActionExtract::Run - extracting [") + name +
			wxT("] as [") + output + wxT("]..."));

        // now just dump this entry to a new uncompressed file...
		wxFileOutputStream out(output);
		if (!out.IsOk() || !out.Write(*in)) {

			wxLogUsrMsg(wxT("wxWebUpdateActionExtract::Run - couldn't decompress ") + name);
			delete in;
			return FALSE;
		}
    }

	delete in;
	return TRUE;
}
void wxWebUpdateListCtrl::RebuildPackageList(wxWebUpdateListCtrlFilter filter)
{
    // remove old contents
    DeleteAllItems();

    int idx = 0;        // could go out of synch with 'i' because
                        // some packages could not be added to the list....
    for (int i=0; i < (int)m_arrRemotePackages.GetCount(); i++, idx++) {

        wxWebUpdatePackage &curr = m_arrRemotePackages[i];
        wxLogAdvMsg(wxS("wxWebUpdateListCtrl::RebuildPackageList - Adding the '") +
            curr.GetName() + wxS("' package..."));


        // set the properties for the first column (NAME)
        // ----------------------------------------------
        InsertItem(idx, curr.GetName());



        // set the properties for the second column (LATEST VERSION)
        // ---------------------------------------------------------
        SetItem(idx, 1, curr.GetLatestVersion());



        // set the properties for the third column (LOCAL VERSION)
        // -------------------------------------------------------

        SetLocalVersionFor(idx, curr);

        // tocheck will be TRUE for outdated items:
        wxWebUpdateCheckFlag f = CompareVersion(curr);
        bool tocheck = (f == wxWUCF_OUTOFDATE || f == wxWUCF_NOTINSTALLED);

        if (IsToDiscard(filter, idx, curr, f)) {

            DeleteItem(idx);
            idx--;
            continue;           // continue with next package
        }



        // set the properties for the fourth column (SIZE)
        // -----------------------------------------------

        // we'll leave the task of updating this field to the
        // wxSizeCacherThread that has been launched by wxWebUpdateDlg
        unsigned long bytesize = 0;
        wxWebUpdateDownload &d = curr.GetDownload();
        if (d.IsDownloadSizeCached())
            bytesize = d.GetDownloadSize();
        SetItem(idx, 3, wxGetSizeStr(bytesize));



        // set the properties for the fifth column (IMPORTANCE)
        // ----------------------------------------------------
        switch (curr.GetImportance()) {
        case wxWUPI_HIGH:
            SetItem(idx, 4, _("high!"));
            Check(idx, tocheck);
            break;
        case wxWUPI_NORMAL:
            SetItem(idx, 4, _("normal"));
            Check(idx, tocheck);
            break;
        case wxWUPI_LOW:
            SetItem(idx, 4, _("low"));
            Check(idx, FALSE);
            break;
        default:
            wxASSERT_MSG(0, wxS("Invalid package !"));
        }


        // set the properties for the sixth column (REQUIRES)
        // ----------------------------------------------------

        wxString str(curr.GetPrerequisites());
        SetItem(idx, 5, str.IsEmpty() ? _("none") : str.c_str());


        // set as item data the index in our remote package array
        SetItemData(idx, i);
    }

    // select the first item of the list
    if (GetItemCount() > 0)
        SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}