From 8bd97a153bbcdc3532e9374db7545caee60438b9 Mon Sep 17 00:00:00 2001 From: powerof3 <32599957+powerof3@users.noreply.github.com> Date: Mon, 4 Mar 2024 06:36:38 +0530 Subject: [PATCH] Add `ValidateScreenshotLocation` --- CMakeLists.txt | 2 +- cmake/sourcelist.cmake | 1 + src/Fixes.cpp | 6 ++- src/Fixes.h | 5 ++ src/Fixes/ValidateScreenshotFolder.cpp | 69 ++++++++++++++++++++++++++ src/Settings.cpp | 1 + src/Settings.h | 3 +- vcpkg.json | 2 +- 8 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/Fixes/ValidateScreenshotFolder.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0af7fdf..012690e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) set(NAME "po3_Tweaks" CACHE STRING "") -set(VERSION 1.8.2 CACHE STRING "") +set(VERSION 1.9.0 CACHE STRING "") set(AE_VERSION 1) set(VR_VERSION 2) diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index 44e3da8..b9125f3 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -26,6 +26,7 @@ set(sources ${sources} src/Fixes/ToggleGlobalAI.cpp src/Fixes/UnderwaterCamera.cpp src/Fixes/UseFurnitureInCombat.cpp + src/Fixes/ValidateScreenshotFolder.cpp src/PCH.cpp src/Papyrus.cpp src/Settings.cpp diff --git a/src/Fixes.cpp b/src/Fixes.cpp index a60125c..c1aa0c9 100644 --- a/src/Fixes.cpp +++ b/src/Fixes.cpp @@ -82,11 +82,15 @@ void Fixes::PostPostLoad::Install() void Fixes::DataLoaded::Install() { logger::info("\t[FIXES]"); + const auto& fixes = Settings::GetSingleton()->GetFixes(); FlagSpellsAsNoAbsorb::Install(); - const auto& fixes = Settings::GetSingleton()->GetFixes(); if (fixes.breathingSounds) { BreathingSounds::Install(); } + + if (fixes.validateScreenshotFolder) { + ValidateScreenshotFolder::Install(); + } } diff --git a/src/Fixes.h b/src/Fixes.h index d68719e..fb4d0c3 100644 --- a/src/Fixes.h +++ b/src/Fixes.h @@ -126,4 +126,9 @@ namespace Fixes { void Install(); } + + namespace ValidateScreenshotFolder + { + void Install(); + } } diff --git a/src/Fixes/ValidateScreenshotFolder.cpp b/src/Fixes/ValidateScreenshotFolder.cpp new file mode 100644 index 0000000..b7a5dd5 --- /dev/null +++ b/src/Fixes/ValidateScreenshotFolder.cpp @@ -0,0 +1,69 @@ +#include "Fixes.h" +#include "Settings.h" + +//validates default screenshot path +//defaults to game dir/Screenshots if path doesn't exist + +namespace Fixes::ValidateScreenshotFolder +{ + bool has_root_directory(const std::filesystem::path& a_path) + { + auto path = a_path.string(); + return path.contains(":\\") || path.contains(":/"); + } + + void Install() + { + if (auto setting = RE::GetINISetting("sScreenShotBaseName:Display")) { + std::filesystem::path screenshotFolder; + std::string newBaseName; + + auto folder = setting->GetString(); + bool emptyPath = string::is_empty(folder); + + if (emptyPath) { + screenshotFolder = std::filesystem::current_path(); + newBaseName = "Screenshot"; + } else { + screenshotFolder = folder; + screenshotFolder.make_preferred(); + + if (has_root_directory(screenshotFolder)) { + if (!std::filesystem::exists(screenshotFolder)) { + newBaseName = "Screenshot"; + } + } else { + // folder will be generated in skyrim root + screenshotFolder = std::filesystem::current_path() /= screenshotFolder; + screenshotFolder.remove_filename(); + } + } + + if (!newBaseName.empty()) { + //to-do: port this to clib + if (setting->data.s) { + RE::free(setting->data.s); + } + + std::size_t strLen = newBaseName.length() + 1; + setting->data.s = RE::malloc(strLen); + std::memcpy(setting->data.s, newBaseName.c_str(), sizeof(char) * strLen); + + if (emptyPath) { + RE::ConsoleLog::GetSingleton()->Print("[po3 Tweaks] sScreenShotBaseName:Display ini setting is empty"); + } else { + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) does not exist", screenshotFolder.string()).c_str()); + } + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Defaulting to {} folder\n", std::filesystem::current_path().string()).c_str()); + if (emptyPath) { + logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string()); + } else { + logger::info("\t\tValidated screenshot location ({} -> {})"sv, screenshotFolder.string(), std::filesystem::current_path().string()); + } + } else { + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) validated successfully\n", screenshotFolder.string()).c_str()); + logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string()); + } + } + } +} diff --git a/src/Settings.cpp b/src/Settings.cpp index 51cd2ed..7db0bdd 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -67,6 +67,7 @@ void Settings::Fixes::Load(CSimpleIniA& a_ini) get_value(a_ini, toggleGlobalAIFix, section, "Toggle Global AI Fix", ";TAI console command/Debug.ToggleAI() now toggles all loaded NPC AI"); get_value(a_ini, useFurnitureInCombat, section, "Use Furniture In Combat", ";Use furniture in combat and prevent getting forced out of furniture when attacked.\n;0 - off, 1 - player only, 2 - player and NPCs"); get_value(a_ini, breathingSounds, section, "Breathing Sounds", ";Fix creature breathing sounds persisting after cell change"); + get_value(a_ini, validateScreenshotFolder, section, "Validate Screenshot Location", ";Validates game screenshot location.\n;Defaults to Skyrim root directory if sScreenshotBaseName ini setting is empty or folder path does not exist"); get_value(a_ini, loadEditorIDs, section, "Load EditorIDs", ";Loads editorIDs for skipped forms at runtime"); #ifdef SKYRIMVR get_value(a_ini, fixVRCrosshairRefEvent, section, "VR CrosshairRefEvent Fix", "; Trigger CrossHairRefEvent with hand selection (normally requires game controller to enable crosshair events)"); diff --git a/src/Settings.h b/src/Settings.h index 77b568d..1364300 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -23,8 +23,9 @@ class Settings : public ISingleton bool skinnedDecalDelete{ true }; bool jumpingBonusFix{ true }; bool toggleGlobalAIFix{ true }; - bool breathingSounds{ true }; std::uint32_t useFurnitureInCombat{ 1 }; + bool breathingSounds{ true }; + bool validateScreenshotFolder{ true }; bool loadEditorIDs{ true }; #ifdef SKYRIMVR bool fixVRCrosshairRefEvent{ true }; diff --git a/vcpkg.json b/vcpkg.json index 698db2c..203603f 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "po3tweaks", - "version-string": "1.8.2", + "version-string": "1.9.0", "description": "Collection of bug fixes and tweaks for Skyrim SE/AE/VR", "homepage": "https://github.com/powerof3/po3-Tweaks/", "license": "MIT",