void ExtractZipArchive(wxInputStream &stream, const wxString &dest) { wxZipInputStream zipStream(stream); std::auto_ptr<wxZipEntry> entry; while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL) { if (entry->IsDir()) continue; wxString name = entry->GetName(); wxFileName destFile(dest + (name.StartsWith(_("/")) ? _("") : _("/")) + name); destFile.Mkdir(0777, wxPATH_MKDIR_FULL); if (destFile.FileExists()) wxRemoveFile(destFile.GetFullPath()); wxFFileOutputStream outStream(destFile.GetFullPath()); outStream.Write(zipStream); // wxFFile file(destFile.GetFullPath(), _("w")); // // const size_t bufSize = 1024; // void *buffer = new char[bufSize]; // while (!zipStream.Eof()) // { // zipStream.Read(buffer, bufSize); // file.Write(buffer, bufSize); // } // file.Flush(); } }
void VDSymbolSourceLinkMap::Init(const wchar_t *filename) { if (const wchar_t *b = wcschr(filename, L'!')) { std::wstring fn(filename, b - filename); VDFileStream fileStream(fn.c_str()); VDZipArchive zipArchive; zipArchive.Init(&fileStream); sint32 n = zipArchive.GetFileCount(); VDStringA name(VDTextWToA(b+1)); for(int i=0; i<n; ++i) { const VDZipArchive::FileInfo& fileInfo = zipArchive.GetFileInfo(i); if (fileInfo.mFileName == name) { IVDStream *pStream = zipArchive.OpenRawStream(i); VDZipStream zipStream(pStream, fileInfo.mCompressedSize, !fileInfo.mbPacked); Init(&zipStream); return; } } throw "Can't find file in zip archive."; } VDFileStream fileStream(filename); Init(&fileStream); }
void TransferZipArchive(wxInputStream &stream, wxZipOutputStream &out) { wxZipInputStream zipStream(stream); std::auto_ptr<wxZipEntry> entry; while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL) { if (entry->IsDir()) continue; wxString name = entry->GetName(); out.PutNextEntry(name); out.Write(zipStream); } }
bool CompressZipArchive(wxOutputStream &stream, const wxString &srcDir) { wxZipOutputStream zipStream(stream); return CompressRecursively(srcDir, zipStream, srcDir); }
wxThread::ExitCode ModderTask::TaskStart() { // Get the mod list ModList *modList = m_inst->GetModList(); wxFileName mcBin = m_inst->GetBinDir(); wxFileName mcJar = m_inst->GetMCJar(); wxFileName mcBackup = m_inst->GetMCBackup(); // Nothing to do if there are no jar mods to install, no backup and just the mc jar if(mcJar.FileExists() && !mcBackup.FileExists() && modList->empty()) { m_inst->SetNeedsRebuild(false); return (ExitCode)1; } SetStatus(_("Installing mods - backing up minecraft.jar...")); if (!mcBackup.FileExists() && !wxCopyFile(mcJar.GetFullPath(), mcBackup.GetFullPath())) { OnFail(_("Failed to back up minecraft.jar")); return (ExitCode)0; } if (mcJar.FileExists() && !wxRemoveFile(mcJar.GetFullPath())) { OnFail(_("Failed to delete old minecraft.jar")); return (ExitCode)0; } // TODO: good spot for user cancel check? or not... TaskStep(); // STEP 1 SetStatus(_("Installing mods - Opening minecraft.jar")); wxFFileOutputStream jarStream(mcJar.GetFullPath()); wxZipOutputStream zipOut(jarStream); // Files already added to the jar. // These files will be skipped. std::set<wxString> addedFiles; // Modify the jar TaskStep(); // STEP 2 SetStatus(_("Installing mods - Adding mod files...")); for (ModList::const_reverse_iterator iter = modList->rbegin(); iter != modList->rend(); iter++) { wxFileName modFileName = iter->GetFileName(); SetStatus(_("Installing mods - Adding ") + modFileName.GetFullName()); if (iter->IsZipMod()) { wxFFileInputStream modStream(modFileName.GetFullPath()); wxZipInputStream zipStream(modStream); std::auto_ptr<wxZipEntry> entry; while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL) { if (entry->IsDir()) continue; wxString name = entry->GetName(); if (addedFiles.count(name) == 0) { if (!zipOut.CopyEntry(entry.release(), zipStream)) break; addedFiles.insert(name); } } } else { wxFileName destFileName = modFileName; destFileName.MakeRelativeTo(m_inst->GetInstModsDir().GetFullPath()); wxString destFile = destFileName.GetFullPath(); if (addedFiles.count(destFile) == 0) { wxFFileInputStream input(modFileName.GetFullPath()); zipOut.PutNextEntry(destFile); zipOut.Write(input); addedFiles.insert(destFile); } } } { wxFFileInputStream inStream(mcBackup.GetFullPath()); wxZipInputStream zipIn(inStream); std::auto_ptr<wxZipEntry> entry; while (entry.reset(zipIn.GetNextEntry()), entry.get() != NULL) { wxString name = entry->GetName(); if (!name.Matches("META-INF*") && addedFiles.count(name) == 0) { if (!zipOut.CopyEntry(entry.release(), zipIn)) break; addedFiles.insert(name); } } } // Recompress the jar TaskStep(); // STEP 3 SetStatus(_("Installing mods - Recompressing jar...")); m_inst->SetNeedsRebuild(false); m_inst->UpdateVersion(true); return (ExitCode)1; }