MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ParseZip

Method ParseZip

updater/Updater.cpp:182–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180}
181
182bool Updater::ParseZip()
183{
184#ifdef _WIN32
185 std::vector<UInt16> filename_buffer;
186
187 for (u32 file_index = 0; file_index < m_archive.NumFiles; file_index++)
188 {
189 // skip directories, we handle them ourselves
190 if (SzArEx_IsDir(&m_archive, file_index))
191 continue;
192
193 size_t filename_len = SzArEx_GetFileNameUtf16(&m_archive, file_index, nullptr);
194 if (filename_len <= 1)
195 continue;
196
197 filename_buffer.resize(filename_len);
198 SzArEx_GetFileNameUtf16(&m_archive, file_index, filename_buffer.data());
199
200 // TODO: This won't work on Linux (4-byte wchar_t).
201 FileToUpdate entry;
202 entry.file_index = file_index;
203 entry.destination_filename = StringUtil::WideStringToUTF8String(reinterpret_cast<wchar_t*>(filename_buffer.data()));
204 if (entry.destination_filename.empty())
205 continue;
206
207 // replace forward slashes with backslashes
208 for (size_t i = 0; i < entry.destination_filename.length(); i++)
209 {
210 if (entry.destination_filename[i] == '/' || entry.destination_filename[i] == '\\')
211 entry.destination_filename[i] = FS_OSPATH_SEPARATOR_CHARACTER;
212 }
213
214 // should never have a leading slash. just in case.
215 while (entry.destination_filename[0] == FS_OSPATH_SEPARATOR_CHARACTER)
216 entry.destination_filename.erase(0, 1);
217
218 // skip directories (we sort them out later)
219 if (!entry.destination_filename.empty() && entry.destination_filename.back() != FS_OSPATH_SEPARATOR_CHARACTER)
220 {
221 // skip updater itself, since it was already pre-extracted.
222 // also skips portable.ini to not mess with future non-portable installs.
223 if (StringUtil::Strcasecmp(entry.destination_filename.c_str(), "updater.exe") != 0)
224 {
225 m_progress->DisplayFormattedInformation("Found file in zip: '%s'", entry.destination_filename.c_str());
226 m_update_paths.push_back(std::move(entry));
227 }
228 }
229 }
230
231 if (m_update_paths.empty())
232 {
233 m_progress->ModalError("No files found in update zip.");
234 return false;
235 }
236
237 for (const FileToUpdate& ftu : m_update_paths)
238 {
239 const size_t len = ftu.destination_filename.length();

Callers

nothing calls this directly

Calls 15

SzArEx_GetFileNameUtf16Function · 0.85
WideStringToUTF8StringFunction · 0.85
StrcasecmpFunction · 0.85
findFunction · 0.50
resizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45
eraseMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected