#include "post_paneli.hpp" #include #include #include #include #include #include #include #include "imgui.h" #include "post/fiko_post.hpp" namespace fikatia { namespace { using post::NcDonusumKomut; using post::PostAyarlari; using post::Tezgah; using post::Tezgahlar; std::wstring genis(const std::string& s) { if (s.empty()) return {}; const int n = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), nullptr, 0); std::wstring w(n, L'\0'); MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (int)s.size(), w.data(), n); return w; } std::string dar(const std::wstring& w) { if (w.empty()) return {}; const int n = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), (int)w.size(), nullptr, 0, nullptr, nullptr); std::string s(n, '\0'); WideCharToMultiByte(CP_UTF8, 0, w.c_str(), (int)w.size(), s.data(), n, nullptr, nullptr); return s; } std::string exeYaniYol(const char* dosya) { wchar_t exeYol[MAX_PATH]{}; GetModuleFileNameW(nullptr, exeYol, MAX_PATH); std::wstring w(exeYol); const size_t son = w.find_last_of(L'\\'); return dar(w.substr(0, son + 1)) + dosya; } // ---- Panel durumu ---- char g_dbYolu[512]{}; char g_cevirici[512]{}; char g_ceviriciParam[256]{}; char g_kuralKlasoru[512]{}; char g_ciktiKlasoru[512]{}; std::optional g_tezgahlar; int g_seciliTezgah = -1; std::vector g_aptler; std::vector g_komutlar; std::string g_durum; bool g_ayarYuklendi = false; // Basit kalici ayar: exe yani fikatia.ini (anahtar=deger, UTF-8) void ayarKaydet() { std::ofstream f(exeYaniYol("fikatia.ini"), std::ios::binary); f << "dbYolu=" << g_dbYolu << "\ncevirici=" << g_cevirici << "\nceviriciParam=" << g_ceviriciParam << "\nkuralKlasoru=" << g_kuralKlasoru << "\nciktiKlasoru=" << g_ciktiKlasoru << "\n"; } void ayarYukle() { g_ayarYuklendi = true; std::ifstream f(exeYaniYol("fikatia.ini"), std::ios::binary); if (!f) return; std::string satir; auto al = [&](const char* anahtar, char* hedef, size_t boy) { const size_t n = strlen(anahtar); if (satir.compare(0, n, anahtar) == 0 && satir[n] == '=') strncpy_s(hedef, boy, satir.c_str() + n + 1, _TRUNCATE); }; while (std::getline(f, satir)) { while (!satir.empty() && (satir.back() == '\r' || satir.back() == '\n')) satir.pop_back(); al("dbYolu", g_dbYolu, sizeof(g_dbYolu)); al("cevirici", g_cevirici, sizeof(g_cevirici)); al("ceviriciParam", g_ceviriciParam, sizeof(g_ceviriciParam)); al("kuralKlasoru", g_kuralKlasoru, sizeof(g_kuralKlasoru)); al("ciktiKlasoru", g_ciktiKlasoru, sizeof(g_ciktiKlasoru)); } } std::string dosyaSec(const wchar_t* filtre) { wchar_t yol[MAX_PATH]{}; OPENFILENAMEW ofn{}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = filtre; ofn.lpstrFile = yol; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; if (!GetOpenFileNameW(&ofn)) return {}; return dar(yol); } void tezgahlariYukle() { try { g_tezgahlar = Tezgahlar::dosyadan(g_dbYolu); g_seciliTezgah = g_tezgahlar->sayisi() > 0 ? 0 : -1; g_durum = "Tezgah listesi yuklendi (" + std::to_string(g_tezgahlar->sayisi()) + ")"; } catch (const std::exception& e) { g_tezgahlar.reset(); g_seciliTezgah = -1; g_durum = std::string("Yukleme hatasi: ") + e.what(); } } void komutCalistir(const std::string& komut) { std::wstring k = genis(komut); STARTUPINFOW si{}; si.cb = sizeof(si); PROCESS_INFORMATION pi{}; if (CreateProcessW(nullptr, k.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) { CloseHandle(pi.hThread); CloseHandle(pi.hProcess); g_durum = "Komut baslatildi."; } else { g_durum = "Komut baslatilamadi (kod " + std::to_string(GetLastError()) + ")"; } } constexpr ImVec4 CAM_GOK = {0.20f, 0.90f, 1.00f, 1.0f}; constexpr ImVec4 KEHRIBAR = {1.00f, 0.62f, 0.15f, 1.0f}; constexpr ImVec4 YESIL = {0.35f, 0.95f, 0.55f, 1.0f}; } // namespace void postPanelIcerikCiz() { if (!g_ayarYuklendi) { ayarYukle(); if (!g_dbYolu[0]) strncpy_s(g_dbYolu, exeYaniYol("tezgahlar.fikoDB").c_str(), _TRUNCATE); } // ---- Tezgah veritabani ---- ImGui::TextColored(CAM_GOK, "TEZGAH VERITABANI"); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 190.0f); ImGui::InputText("##dbYolu", g_dbYolu, sizeof(g_dbYolu)); ImGui::SameLine(); if (ImGui::Button("Gozat##db")) { const std::string y = dosyaSec(L"Tezgah DB (*.fikoDB)\0*.fikoDB\0Tumu\0*.*\0"); if (!y.empty()) { strncpy_s(g_dbYolu, y.c_str(), _TRUNCATE); ayarKaydet(); } } ImGui::SameLine(); if (ImGui::Button("Yukle")) { tezgahlariYukle(); ayarKaydet(); } if (g_tezgahlar && g_tezgahlar->sayisi() > 0) { const auto& liste = g_tezgahlar->tezgahlarTumu(); if (ImGui::BeginTable("tezgahTablo", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_ScrollY, ImVec2(0, 130))) { ImGui::TableSetupColumn("Tezgah"); ImGui::TableSetupColumn("Uzanti", ImGuiTableColumnFlags_WidthFixed, 70.0f); ImGui::TableSetupColumn("Gonderim", ImGuiTableColumnFlags_WidthFixed, 180.0f); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); for (int i = 0; i < (int)liste.size(); ++i) { const Tezgah& t = liste[(size_t)i]; ImGui::TableNextRow(); ImGui::TableNextColumn(); if (ImGui::Selectable(t.ismi.c_str(), g_seciliTezgah == i, ImGuiSelectableFlags_SpanAllColumns)) g_seciliTezgah = i; ImGui::TableNextColumn(); ImGui::TextUnformatted(t.postUzantisi.c_str()); ImGui::TableNextColumn(); const auto plan = t.gonderimPlani(); std::string ozet; for (const auto yol : plan) { if (!ozet.empty()) ozet += " + "; ozet += yol == post::GonderimYolu::KlasoreKopyala ? "Klasor" : yol == post::GonderimYolu::ProgramlaGonder ? "Program" : "FTP"; } ImGui::TextColored(ozet.empty() ? KEHRIBAR : YESIL, "%s", ozet.empty() ? "-" : ozet.c_str()); } ImGui::EndTable(); } } else { ImGui::TextDisabled("Tezgah listesi yuklu degil."); } ImGui::Spacing(); ImGui::Separator(); // ---- NC cevirici ayarlari ---- ImGui::TextColored(CAM_GOK, "NC CEVIRICI"); auto yolSatiri = [](const char* etiket, char* buf, size_t boy, const wchar_t* filtre) { ImGui::TextDisabled("%s", etiket); ImGui::SameLine(130.0f); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 80.0f); ImGui::PushID(etiket); ImGui::InputText("##v", buf, boy); if (filtre) { ImGui::SameLine(); if (ImGui::Button("Gozat")) { const std::string y = dosyaSec(filtre); if (!y.empty()) { strncpy_s(buf, boy, y.c_str(), _TRUNCATE); ayarKaydet(); } } } ImGui::PopID(); }; yolSatiri("Cevirici", g_cevirici, sizeof(g_cevirici), L"Program (*.exe)\0*.exe\0Tumu\0*.*\0"); yolSatiri("Parametre", g_ceviriciParam, sizeof(g_ceviriciParam), nullptr); yolSatiri("Kural klasoru", g_kuralKlasoru, sizeof(g_kuralKlasoru), nullptr); yolSatiri("Cikti klasoru", g_ciktiKlasoru, sizeof(g_ciktiKlasoru), nullptr); ImGui::Spacing(); ImGui::Separator(); // ---- APT listesi ---- ImGui::TextColored(CAM_GOK, "APT DOSYALARI"); ImGui::SameLine(); ImGui::TextDisabled("(%d)", (int)g_aptler.size()); ImGui::SameLine(); if (ImGui::Button("Ekle##apt")) { const std::string y = dosyaSec(L"APT (*.aptsource;*.apt)\0*.aptsource;*.apt\0Tumu\0*.*\0"); if (!y.empty()) g_aptler.push_back(y); } ImGui::SameLine(); if (ImGui::Button("Temizle##apt")) { g_aptler.clear(); g_komutlar.clear(); } for (size_t i = 0; i < g_aptler.size(); ++i) { ImGui::PushID((int)i); if (ImGui::SmallButton("X")) { g_aptler.erase(g_aptler.begin() + (ptrdiff_t)i); ImGui::PopID(); break; } ImGui::SameLine(); ImGui::TextUnformatted(g_aptler[i].c_str()); ImGui::PopID(); } ImGui::Spacing(); // ---- Komut uretimi + calistirma ---- const bool hazir = g_tezgahlar && g_seciliTezgah >= 0 && !g_aptler.empty() && g_cevirici[0]; ImGui::BeginDisabled(!hazir); if (ImGui::Button("NC KOMUTLARINI URET", ImVec2(220, 0))) { const Tezgah& t = g_tezgahlar->tezgahlarTumu()[(size_t)g_seciliTezgah]; PostAyarlari a; a.ncCeviriciProgram = g_cevirici; a.ncCeviriciParametreler = g_ceviriciParam; a.ncKuralDosyasiKlasoru = g_kuralKlasoru; a.ncCiktiKlasoruVarsayilan = !g_ciktiKlasoru[0]; a.ncCiktiKlasoru = g_ciktiKlasoru; post::FikoPost fp("", "", *g_tezgahlar); fp.aptler = g_aptler; g_komutlar = fp.ncDonusumKomutlari(a, t); g_durum = std::to_string(g_komutlar.size()) + " komut uretildi."; ayarKaydet(); } ImGui::EndDisabled(); if (!hazir) { ImGui::SameLine(); ImGui::TextDisabled("(tezgah + APT + cevirici gerekli)"); } for (size_t i = 0; i < g_komutlar.size(); ++i) { ImGui::PushID((int)(1000 + i)); if (ImGui::SmallButton("Calistir")) komutCalistir(g_komutlar[i].komut); ImGui::SameLine(); ImGui::TextColored(YESIL, "%s", g_komutlar[i].ncDosyasi.c_str()); if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", g_komutlar[i].komut.c_str()); ImGui::PopID(); } if (!g_durum.empty()) { ImGui::Spacing(); ImGui::TextColored(KEHRIBAR, "%s", g_durum.c_str()); } } } // namespace fikatia