Fix `std::filesystem::temp_directory_path()` misuse

pull/192/head
Peter Repukat 2 years ago
parent 29b630df6f
commit a24c16a44e

@ -28,13 +28,21 @@ limitations under the License.
#ifdef _WIN32 #ifdef _WIN32
#include "UWPFetch.h" #include "UWPFetch.h"
#include <Windows.h> #include <Windows.h>
#include <shlobj.h>
#endif #endif
#include "../version.hpp" #include "../version.hpp"
UIModel::UIModel() : QObject(nullptr) UIModel::UIModel() : QObject(nullptr)
{ {
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path(); wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
@ -307,7 +315,14 @@ void UIModel::updateCheck()
QVariantMap UIModel::getDefaultConf() const QVariantMap UIModel::getDefaultConf() const
{ {
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path(); wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
@ -371,8 +386,14 @@ QVariantMap UIModel::getDefaultConf() const
void UIModel::saveDefaultConf(QVariantMap conf) const void UIModel::saveDefaultConf(QVariantMap conf) const
{ {
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path(); wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
path /= "default.json"; path /= "default.json";

@ -26,6 +26,7 @@ limitations under the License.
#include <Windows.h> #include <Windows.h>
#include <VersionHelpers.h> #include <VersionHelpers.h>
#include <dwmapi.h> #include <dwmapi.h>
#include <ShlObj.h>
#pragma comment(lib, "Dwmapi.lib") #pragma comment(lib, "Dwmapi.lib")
#include "ExeImageProvider.h" #include "ExeImageProvider.h"
#endif #endif
@ -89,10 +90,14 @@ void myMessageHandler(QtMsgType type, const QMessageLogContext&, const QString&
break; break;
} }
auto path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
@ -115,11 +120,14 @@ int main(int argc, char* argv[])
#endif #endif
if (argc < 3) { if (argc < 3) {
auto path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path))

@ -20,6 +20,7 @@ limitations under the License.
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
#include <regex> #include <regex>
#include <shlobj_core.h>
#include "Roboto.h" #include "Roboto.h"
#include "Settings.h" #include "Settings.h"
@ -51,10 +52,14 @@ Overlay::Overlay(
ImGui::SFML::UpdateFontTexture(); ImGui::SFML::UpdateFontTexture();
#ifdef _WIN32 #ifdef _WIN32
auto config_path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path config_path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); config_path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
config_path = std::filesystem::path(localAppDataFolder).parent_path();
}
config_path /= "Roaming"; config_path /= "Roaming";
config_path /= "GlosSI"; config_path /= "GlosSI";

@ -26,6 +26,8 @@ limitations under the License.
#ifdef WIN32 #ifdef WIN32
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#include <ShlObj.h>
#include <KnownFolders.h>
#endif #endif
namespace Settings { namespace Settings {
@ -122,10 +124,14 @@ inline void Parse(std::wstring arg1)
arg1 += L".json"; arg1 += L".json";
} }
} }
std::filesystem::path path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";

@ -74,8 +74,8 @@ Application will not function!");
if (!overlay_.expired()) if (!overlay_.expired())
overlay_.lock()->setEnabled(false); overlay_.lock()->setEnabled(false);
steam_overlay_present_ = true; steam_overlay_present_ = true;
launcher_.launchWatchdog();
} }
launcher_.launchWatchdog();
getXBCRebindingEnabled(); getXBCRebindingEnabled();
run_ = true; run_ = true;

@ -17,6 +17,7 @@ limitations under the License.
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#include <DbgHelp.h> #include <DbgHelp.h>
#include <ShlObj.h>
#endif #endif
#include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/basic_file_sink.h>
@ -67,10 +68,14 @@ LONG Win32FaultHandler(struct _EXCEPTION_POINTERS* ExInfo)
MINIDUMP_EXCEPTION_INFORMATION M; MINIDUMP_EXCEPTION_INFORMATION M;
HANDLE hDump_File; HANDLE hDump_File;
auto path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";
@ -119,10 +124,14 @@ int main(int argc, char* argv[])
const auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>(); const auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
console_sink->set_level(spdlog::level::trace); console_sink->set_level(spdlog::level::trace);
#ifdef _WIN32 #ifdef _WIN32
auto path = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path path;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming"; path /= "Roaming";
path /= "GlosSI"; path /= "GlosSI";

@ -16,6 +16,7 @@ limitations under the License.
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#include <ShlObj.h>
#include <filesystem> #include <filesystem>
@ -34,10 +35,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);
auto configDirPath = std::filesystem::temp_directory_path() wchar_t* localAppDataFolder;
.parent_path() std::filesystem::path configDirPath;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path(); configDirPath = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
configDirPath = std::filesystem::path(localAppDataFolder).parent_path();
}
configDirPath /= "Roaming"; configDirPath /= "Roaming";
configDirPath /= "GlosSI"; configDirPath /= "GlosSI";

@ -44,6 +44,7 @@ There are two (known to me, at time of writing) ways to get a working overlay fo
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
#include <ShlObj.h>
#define SUBHOOK_STATIC #define SUBHOOK_STATIC
#include <atomic> #include <atomic>
@ -140,11 +141,14 @@ BOOL APIENTRY DllMain( HMODULE hModule,
{ {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{ {
wchar_t* localAppDataFolder;
auto configDirPath = std::filesystem::temp_directory_path() std::filesystem::path configDirPath;
.parent_path() if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
.parent_path() configDirPath = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
.parent_path(); }
else {
configDirPath = std::filesystem::path(localAppDataFolder).parent_path();
}
configDirPath /= "Roaming"; configDirPath /= "Roaming";
configDirPath /= "GlosSI"; configDirPath /= "GlosSI";

Loading…
Cancel
Save