#include "ayar_kalici.hpp" #include #include #include #include "fiko/ui/imgui_katman.hpp" namespace fiko { namespace { std::string ayarDosyaYolu() { return exeYaniYol("fikocad.ayar"); } std::map& depo() { static std::map d; static bool yuklendi = false; if (!yuklendi) { yuklendi = true; std::ifstream f(ayarDosyaYolu()); std::string satir; while (std::getline(f, satir)) { const size_t es = satir.find('='); if (es == std::string::npos || es == 0) continue; d[satir.substr(0, es)] = satir.substr(es + 1); } } return d; } void diskeYaz() { std::ofstream f(ayarDosyaYolu(), std::ios::trunc); if (!f) return; for (const auto& [k, v] : depo()) f << k << '=' << v << '\n'; } } // namespace // Exe yanındaki dosya yolu (cwd'den bağımsız — kısayol/farklı cwd sağlam). std::string exeYaniYol(const char* ad) { wchar_t yol[MAX_PATH] = {}; GetModuleFileNameW(nullptr, yol, MAX_PATH); std::wstring w(yol); const size_t kes = w.find_last_of(L"\\/"); if (kes != std::wstring::npos) w.resize(kes + 1); // Ad ASCII kalıbında (fikocad.*); UTF-8 dar çeviri yol kısmı için (ASCII olmayabilir). for (const char* p = ad; *p; ++p) w += (wchar_t)(unsigned char)*p; const int n = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr); std::string s(n > 0 ? n - 1 : 0, '\0'); if (n > 0) WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, s.data(), n, nullptr, nullptr); return s; } bool& pencereKonumHatirla() { static bool v = true; return v; } bool& pencereDisariTasima() { return multiViewportAcik(); } std::string ayarOku(const char* anahtar, const std::string& varsayilan) { const auto& d = depo(); const auto it = d.find(anahtar); return it != d.end() ? it->second : varsayilan; } void ayarYaz(const char* anahtar, const std::string& deger) { auto& d = depo(); auto it = d.find(anahtar); if (it != d.end() && it->second == deger) return; // değişmedi → IO yok d[anahtar] = deger; diskeYaz(); } } // namespace fiko