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

Method CommitUpdate

updater/Updater.cpp:357–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355}
356
357bool Updater::CommitUpdate()
358{
359 m_progress->SetStatusText("Committing update...");
360
361 // create directories in target
362 for (const std::string& subdir : m_update_directories)
363 {
364 const std::string dest_subdir = StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s",
365 m_destination_directory.c_str(), subdir.c_str());
366
367 if (!FileSystem::DirectoryExists(dest_subdir.c_str()) && !FileSystem::CreateDirectoryPath(dest_subdir.c_str(), false))
368 {
369 m_progress->DisplayFormattedModalError("Failed to create target directory '%s'", dest_subdir.c_str());
370 return false;
371 }
372 }
373
374 // move files to target
375 for (const FileToUpdate& ftu : m_update_paths)
376 {
377 const std::string staging_file_name = StringUtil::StdStringFromFormat(
378 "%s" FS_OSPATH_SEPARATOR_STR "%s", m_staging_directory.c_str(), ftu.destination_filename.c_str());
379 const std::string dest_file_name = StringUtil::StdStringFromFormat(
380 "%s" FS_OSPATH_SEPARATOR_STR "%s", m_destination_directory.c_str(), ftu.destination_filename.c_str());
381 m_progress->DisplayFormattedInformation("Moving '%s' to '%s'", staging_file_name.c_str(), dest_file_name.c_str());
382#ifdef _WIN32
383 const bool result =
384 MoveFileExW(FileSystem::GetWin32Path(staging_file_name).c_str(),
385 FileSystem::GetWin32Path(dest_file_name).c_str(), MOVEFILE_REPLACE_EXISTING);
386#else
387 const bool result = (rename(staging_file_name.c_str(), dest_file_name.c_str()) == 0);
388#endif
389 if (!result)
390 {
391 m_progress->DisplayFormattedModalError("Failed to rename '%s' to '%s'", staging_file_name.c_str(),
392 dest_file_name.c_str());
393 return false;
394 }
395 }
396
397 return true;
398}
399
400void Updater::CleanupStagingDirectory()
401{

Callers 1

wWinMainFunction · 0.80

Calls 5

StdStringFromFormatFunction · 0.85
SetStatusTextMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected