void CIP2Country::DownloadFinished(uint32 result) { if (result == HTTP_Success) { Disable(); // download succeeded. Switch over to new database. wxString newDat = m_DataBasePath + wxT(".download"); // Try to unpack the file, might be an archive wxWCharBuffer dataBaseName = m_DataBaseName.wc_str(); const wxChar* geoip_files[] = { dataBaseName, NULL }; if (UnpackArchive(CPath(newDat), geoip_files).second == EFT_Error) { AddLogLineC(_("Download of GeoIP.dat file failed, aborting update.")); return; } if (wxFileExists(m_DataBasePath)) { if (!wxRemoveFile(m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to remove %s file, aborting update.")) % m_DataBaseName); return; } } if (!wxRenameFile(newDat, m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to rename %s file, aborting update.")) % m_DataBaseName); return; } Enable(); if (m_geoip) { AddLogLineN(CFormat(_("Successfully updated %s")) % m_DataBaseName); } else { AddLogLineC(_("Error updating GeoIP.dat")); } } else if (result == HTTP_Skipped) { AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % m_DataBaseName); } else { AddLogLineC(CFormat(_("Failed to download %s from %s")) % m_DataBaseName % thePrefs::GetGeoIPUpdateUrl()); // if it failed and there is no database, turn it off if (!wxFileExists(m_DataBasePath)) { thePrefs::SetGeoIPEnabled(false); } } }
bool CServerList::LoadServerMet(const CPath& path) { AddLogLineN(CFormat(_("Loading server.met file: %s")) % path); bool merge = !m_servers.empty(); if (!path.FileExists()) { AddLogLineN(_("Server.met file not found!")); return false; } // Try to unpack the file, might be an archive const wxChar* mets[] = { wxT("server.met"), NULL }; // Try to unpack the file, might be an archive if (UnpackArchive(path, mets).second != EFT_Met) { AddLogLineC(CFormat(_("Failed to load server.met file '%s', unknown format encountered.")) % path); return false; } CFile servermet(path, CFile::read); if ( !servermet.IsOpened() ){ AddLogLineN(_("Failed to open server.met!") ); return false; } try { Notify_ServerFreeze(); byte version = servermet.ReadUInt8(); if (version != 0xE0 && version != MET_HEADER) { AddLogLineC(CFormat(_("Server.met file corrupt, found invalid versiontag: 0x%x, size %i")) % version % sizeof(version)); Notify_ServerThaw(); return false; } uint32 fservercount = servermet.ReadUInt32(); ServerMet_Struct sbuffer; uint32 iAddCount = 0; for ( uint32 j = 0; j < fservercount; ++j ) { sbuffer.ip = servermet.ReadUInt32(); sbuffer.port = servermet.ReadUInt16(); sbuffer.tagcount = servermet.ReadUInt32(); CServer* newserver = new CServer(&sbuffer); // Load tags for ( uint32 i = 0; i < sbuffer.tagcount; ++i ) { newserver->AddTagFromFile(&servermet); } // Server priorities are not in sorted order // High = 1, Low = 2, Normal = 0, so we have to check // in a less logical fashion. int priority = newserver->GetPreferences(); if (priority < SRV_PR_MIN || priority > SRV_PR_MAX) { newserver->SetPreference(SRV_PR_NORMAL); } // set listname for server if ( newserver->GetListName().IsEmpty() ) { newserver->SetListName(wxT("Server ") +newserver->GetAddress()); } if ( !theApp->AddServer(newserver) ) { CServer* update = GetServerByAddress(newserver->GetAddress(), newserver->GetPort()); if(update) { update->SetListName( newserver->GetListName()); if(!newserver->GetDescription().IsEmpty()) { update->SetDescription( newserver->GetDescription()); } Notify_ServerRefresh(update); } delete newserver; } else { ++iAddCount; } } Notify_ServerThaw(); if (!merge) { AddLogLineC(CFormat(wxPLURAL("%i server in server.met found", "%i servers in server.met found", fservercount)) % fservercount); } else { AddLogLineC(CFormat(wxPLURAL("%d server added", "%d servers added", iAddCount)) % iAddCount); } } catch (const CInvalidPacket& err) { AddLogLineC(_("Error: the file 'server.met' is corrupted: ") + err.what()); Notify_ServerThaw(); return false; } catch (const CSafeIOException& err) { AddLogLineC(_("IO error while reading 'server.met': ") + err.what()); Notify_ServerThaw(); return false; } return true; }
int main(int argc, char** argv) { Opt2 opt(argc, argv, "rxcpulma:z:qo:", IntRange(1, 999999), "hexdump=x,cat=c,plain=p,unpack=u,list=l,md5=m,recursive=r,quiet=q,prepend=z,append=a,output=o"); const bool hexdump = opt.Has('x', "- produce hexdump"); const bool cat = opt.Has('c', "- do not store keys (file names), just cat uncompressed files"); const bool doNotZip = opt.Has('p', "- do not use compression"); const bool unpack = opt.Has('u', "- unpack archive in current dir"); const bool list = opt.Has('l', "- list files in archive"); const bool listMd5 = opt.Has('m', "- list files in archive with md5"); const bool recursive = opt.Has('r', "- read all files under each directory, recursively"); Quiet = opt.Has('q', "- do not output progress on stderr."); Stroka prepend = opt.Arg('z', "<PREFIX> - prepend string to output", 0); Stroka append = opt.Arg('a', "<SUFFIX> - append string to output", 0); const Stroka outputf = opt.Arg('o', "<FILE> - output to file instead stdout", 0); opt.AutoUsageErr("<file>..."); // "Files or directories to archive." SubstGlobal(append, "\\n", "\n"); SubstGlobal(prepend, "\\n", "\n"); yvector<TRec> recs; for (size_t i = 0; i != opt.Pos.size(); ++i) { Stroka path = opt.Pos[i]; size_t off = 0; #ifdef _win_ if (path[0] > 0 && isalpha(path[0]) && path[1] == ':') off = 2; // skip drive letter ("d:") #endif // _win_ const size_t pos = path.find(':', off); TRec cur; cur.Path = path.substr(0, pos); if (pos != Stroka::npos) cur.Prefix = path.substr(pos + 1); cur.Recursive = recursive; cur.Fix(); recs.push_back(cur); } try { if (listMd5) { for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) { ListArchiveMd5(it->Path); } } else if (list) { for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) { ListArchive(it->Path); } } else if (unpack) { for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) { UnpackArchive(it->Path); } } else { TAutoPtr<TOutputStream> outf(OpenOutput(outputf)); TOutputStream* out = outf.Get(); THolder<TOutputStream> hexout; if (hexdump) { hexout.Reset(new THexOutput(out)); out = hexout.Get(); } outf->Write(~prepend, +prepend); if (cat) { for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) { it->Recurse(*out); } } else { TArchiveWriter w(out, !doNotZip); for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) { it->Recurse(w); } w.Finish(); } outf->Write(~append, +append); try { out->Finish(); } catch (...) { } } } catch (...) { Cerr << CurrentExceptionMessage() << Endl; return 1; } return 0; }