バグ修正
守矢諏訪子 <suwako@076.moe>、2026-06-25 07:05
コミット 91f9bb8ac3e113535e1857cd75cc25cf16837478
・親 887c6a6
・ファイルを見る
3個のファイル、+57 -9
| @@ -113,24 +113,20 @@ | ||
| 113 | 113 | else() |
| 114 | 114 | set(PRODUCTION_BUILD ON CACHE BOOL "リリース版?" FORCE) |
| 115 | 115 | 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) | |
| 117 | 117 | 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) | |
| 123 | 119 | else() |
| 124 | 120 | set(DB_NAME "shaderplayground.db" CACHE STRING "データベースのパス" FORCE) |
| 125 | 121 | endif() |
| 126 | - target_compile_definitions(shaderplayground PRIVATE DB_NAME="${DB_NAME}") | |
| 122 | + target_compile_definitions(shaderplayground PRIVATE PRODUCTION_BUILD DB_NAME="${DB_NAME}") | |
| 127 | 123 | endif() |
| 128 | 124 | |
| 129 | 125 | message(STATUS "DB_NAME = ${DB_NAME}") |
| 130 | 126 | |
| 131 | 127 | if(WIN32) |
| 132 | 128 | 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") | |
| 134 | 130 | else() |
| 135 | 131 | include(GNUInstallDirs) |
| 136 | 132 | set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR}) |
| @@ -179,3 +175,7 @@ | ||
| 179 | 175 | target_include_directories(shaderplayground PRIVATE |
| 180 | 176 | "${CMAKE_CURRENT_SOURCE_DIR}/include" |
| 181 | 177 | ) |
| 178 | + | |
| 179 | +if(MSVC) | |
| 180 | + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT shaderplayground) | |
| 181 | +endif() |
| @@ -51,6 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | GLFWerrorfun Instance::SetErrorCallback() { |
| 54 | + glfwSetErrorCallback(glfw_error_callback); | |
| 54 | 55 | return nullptr; |
| 55 | 56 | } |
| 56 | 57 |
| @@ -37,14 +37,61 @@ | ||
| 37 | 37 | #include <sqlite3.h> |
| 38 | 38 | #include <iostream> |
| 39 | 39 | #include <stdexcept> |
| 40 | +#include <filesystem> | |
| 40 | 41 | #include <version.hh> |
| 41 | 42 | |
| 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> | |
| 43 | 49 | |
| 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 | + | |
| 44 | 81 | namespace sqlite { |
| 45 | 82 | Instance::Instance() { |
| 46 | 83 | 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; | |
| 47 | 93 | if (sqlite3_open(DB_PATH.data(), &m_pDB) != SQLITE_OK) { |
| 94 | +#endif | |
| 48 | 95 | throw std::runtime_error("SQLiteデータベースを開けられません。"); |
| 49 | 96 | } |
| 50 | 97 | } |