バグ修正

守矢諏訪子 <suwako@076.moe>、2026-06-25 07:05
コミット 91f9bb8ac3e113535e1857cd75cc25cf16837478 ・親 887c6a6 ・ファイルを見る

3個のファイル、+57 -9

@@ -113,24 +113,20 @@
113113 else()
114114 set(PRODUCTION_BUILD ON CACHE BOOL "リリース版?" FORCE)
115115 if(WIN32)
116- set(DB_NAME "C:/Program Files/076Studio/ShaderPlayground/data/shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
116+ set(DB_NAME "$ENV{LOCALAPPDATA}/076Studio/ShaderPlayground/data/shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
117117 elseif(UNIX)
118- if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "SunOS")
119- set(DB_NAME "/usr/share/shaderplayground/data/shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
120- else()
121- set(DB_NAME "/usr/local/share/shaderplayground/data/shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
122- endif()
118+ set(DB_NAME "$ENV{HOME}/.local/share/shaderplayground/shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
123119 else()
124120 set(DB_NAME "shaderplayground.db" CACHE STRING "データベースのパス" FORCE)
125121 endif()
126- target_compile_definitions(shaderplayground PRIVATE DB_NAME="${DB_NAME}")
122+ target_compile_definitions(shaderplayground PRIVATE PRODUCTION_BUILD DB_NAME="${DB_NAME}")
127123 endif()
128124
129125 message(STATUS "DB_NAME = ${DB_NAME}")
130126
131127 if(WIN32)
132128 set(INSTALL_BINDIR "C:/Program Files/076Studio/ShaderPlayground")
133- set(INSTALL_DATADIR "C:/User/suwako/AppData/Local/076Studio/ShaderPlayground")
129+ set(INSTALL_DATADIR "$ENV{LOCALAPPDATA}/076Studio/ShaderPlayground")
134130 else()
135131 include(GNUInstallDirs)
136132 set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
@@ -179,3 +175,7 @@
179175 target_include_directories(shaderplayground PRIVATE
180176 "${CMAKE_CURRENT_SOURCE_DIR}/include"
181177 )
178+
179+if(MSVC)
180+ set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT shaderplayground)
181+endif()
@@ -51,6 +51,7 @@
5151 }
5252
5353 GLFWerrorfun Instance::SetErrorCallback() {
54+ glfwSetErrorCallback(glfw_error_callback);
5455 return nullptr;
5556 }
5657
@@ -37,14 +37,61 @@
3737 #include <sqlite3.h>
3838 #include <iostream>
3939 #include <stdexcept>
40+#include <filesystem>
4041 #include <version.hh>
4142
42-constexpr std::string_view DB_PATH = DB_NAME;
43+#if defined(WIN32) || defined(WIN64)
44+#ifndef WIN32_LEAN_AND_MEAN
45+#define WIN32_LEAN_AND_MEAN
46+#endif
47+#include <windows.h>
48+#include <shlobj.h>
4349
50+std::filesystem::path GetLocalAppDataPath() {
51+ PWSTR path = nullptr;
52+ HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &path);
53+ if (FAILED(hr)) throw std::runtime_error("LocalAppDataパスの受取の失敗。");
54+
55+ std::filesystem::path p(path);
56+ CoTaskMemFree(path);
57+
58+ return p;
59+}
60+#endif
61+
62+std::filesystem::path GetUserDataPath() {
63+#if defined(WIN32) || defined(WIN64)
64+ return GetLocalAppDataPath() / "076Studio" / "ShaderPlayground";
65+#elif defined(__APPLE__)
66+ cstr home = std::getenv("HOME");
67+ if (!home) throw std::runtime_error("HOME環境変数がありません。");
68+
69+ return std::filesystem::path(home) / "Library" / "Application Support" / "ShaderPlayground";
70+#else
71+ cstr xdg = std::getenv("XDG_DATA_HOME");
72+ if (xdg) return std::filesystem::path(xdg) / "shaderplayground";
73+
74+ cstr home = std::getenv("HOME");
75+ if (!home) throw std::runtime_error("HOME環境変数がありません。");
76+
77+ return std::filesystem::path(home) / ".local" / "share" / "shaderplayground";
78+#endif
79+}
80+
4481 namespace sqlite {
4582 Instance::Instance() {
4683 m_pDB = nullptr;
84+#ifdef PRODUCTION_BUILD
85+ std::filesystem::path dbPath = GetUserDataPath() / "shaderplayground.db";
86+ if (!std::filesystem::exists(std::filesystem::path(dbPath).parent_path())) {
87+ std::filesystem::create_directories(std::filesystem::path(dbPath).parent_path());
88+ }
89+
90+ if (sqlite3_open(dbPath.string().c_str(), &m_pDB) != SQLITE_OK) {
91+#else
92+ constexpr std::string_view DB_PATH = DB_NAME;
4793 if (sqlite3_open(DB_PATH.data(), &m_pDB) != SQLITE_OK) {
94+#endif
4895 throw std::runtime_error("SQLiteデータベースを開けられません。");
4996 }
5097 }