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; }
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 }