diff --git a/CMakeLists.txt b/CMakeLists.txt index 63642b0f59..752c9cd824 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,6 +241,8 @@ foreach(_torch_game SM64 MK64 SF64 PM64 FZERO BK64 MARIO_ARTIST) set(BUILD_${_torch_game} OFF CACHE BOOL "" FORCE) endforeach() +add_compile_definitions(YAML_CPP_STATIC_DEFINE) + add_subdirectory(torch) # Build-time ROM extraction. soh links torch as a static library, which compiles out torch's @@ -258,6 +260,11 @@ add_executable(soh-o2r-packer EXCLUDE_FROM_ALL ) target_link_libraries(soh-o2r-packer PRIVATE torch) +if(MSVC) + set_target_properties(soh-torch soh-o2r-packer PROPERTIES + MSVC_RUNTIME_LIBRARY "$,MultiThreadedDebug,MultiThreaded>") +endif() + # Target to generate OTRs. SOH_ROM_PATH takes roms and/or directories of roms; torch names each # archive (oot.o2r or oot-mq.o2r) from its hash, so a vanilla and a master quest rom produce both # in one run. soh.o2r comes from GenerateSohOtr, chained below. diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index 1924934727..33b45c26e4 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -227,12 +227,6 @@ set(ALL_FILES ################################################################################ add_executable(${PROJECT_NAME} ${ALL_FILES}) -if(MSVC) - # yaml-cpp, reached through torch's headers, trips the dll-interface warnings, and soh - # builds with /WX. - set_source_files_properties(soh/Extractor/TorchExtract.cpp PROPERTIES COMPILE_OPTIONS "/wd4251;/wd4275") -endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Windows") use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}") endif() diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 792194646c..1bf777a52d 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -396,6 +396,19 @@ namespace SohGui { extern std::shared_ptr mSohMenu; } +static bool RemoveArchiveAcrossAppDirs(const std::string& fileName) { + for (const std::string& path : { Ship::Context::GetPathRelativeToAppDirectory(fileName, appShortName), + Ship::Context::GetPathRelativeToAppBundle(fileName), "./" + fileName }) { + std::error_code err; + if (std::filesystem::remove(path, err)) { + SPDLOG_INFO("Removed outdated archive {}", path); + } else if (err) { + SPDLOG_ERROR("Failed to remove outdated archive {}: {}", path, err.message()); + } + } + return !std::filesystem::exists(Ship::Context::LocateFileAcrossAppDirs(fileName, appShortName)); +} + void OTRGlobals::RunExtract(int argc, char* argv[]) { bool extractDone = false; ExtractSteps extractStep = ES_PORT_ARCHIVE; @@ -420,8 +433,8 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) { bool generatedIsMQ = false; std::atomic extractCount = 0, totalExtract = 0; - std::string installPath = Ship::Context::GetAppBundlePath(); - std::string dataPath = Ship::Context::GetAppDirectoryPath(appShortName); + std::string installPath = std::filesystem::absolute(Ship::Context::GetAppBundlePath()).string(); + std::string dataPath = std::filesystem::absolute(Ship::Context::GetAppDirectoryPath(appShortName)).string(); std::string file; #if defined(__SWITCH__) @@ -445,11 +458,18 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) { "re-extract them from the download or.\n\nExiting...", "OK", "", [&]() { exit(1); }); } else if (shouldRegen) { - SohGui::RegisterPopup("Outdated ROM Archives", - "Your oot.o2r or oot-mq.o2r were created with incompatible versions of SoH.\nYou will " - "now be redirected to re-extract them."); - std::filesystem::remove("oot.o2r"); - std::filesystem::remove("oot-mq.o2r"); + if (RemoveArchiveAcrossAppDirs("oot.o2r") && RemoveArchiveAcrossAppDirs("oot-mq.o2r")) { + SohGui::RegisterPopup( + "Outdated ROM Archives", + "Your oot.o2r or oot-mq.o2r were created with incompatible versions of SoH.\nYou will " + "now be redirected to re-extract them."); + } else { + SohGui::RegisterPopup( + "Outdated ROM Archives", + "Your oot.o2r or oot-mq.o2r were created with incompatible\nversions of SoH, but they" + "could not be removed\nautomatically. Please delete them now and re-launch.\nExiting...", + "OK", "", [&]() { exit(1); }); + } } std::shared_ptr threadPool = std::make_shared(1); @@ -637,8 +657,10 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) { extract = Extractor(); extract.SetSearchPath(installPath); extract.GetRoms(args); - extract.SetSearchPath(dataPath); - extract.GetRoms(args); + if (installPath != dataPath) { + extract.SetSearchPath(dataPath); + extract.GetRoms(args); + } if (!args.empty()) { promptStep = PS_WAIT; SohGui::RegisterPopup(