mirror of
https://github.com/yawaflua/tzeva-adom.git
synced 2025-12-08 19:39:30 +02:00
Fix language support and compatibility with windows.
This commit is contained in:
@@ -24,28 +24,29 @@ add_executable(tzeva_adom main.cpp
|
||||
models/AlertMessage_OREF.cpp
|
||||
utils/OREFToTzevaAdom.cpp
|
||||
models/OrefAlertResponse.cpp
|
||||
utils/check_file_exists.h
|
||||
)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||
pkg_check_modules(NOTIFY REQUIRED libnotify)
|
||||
pkg_check_modules(SDL REQUIRED libnotify)
|
||||
find_package(fmt REQUIRED)
|
||||
pkg_check_modules(SDL2 REQUIRED libnotify)
|
||||
pkg_check_modules(SDL2_mixer REQUIRED libnotify)
|
||||
pkg_check_modules(fmt REQUIRED fmt)
|
||||
pkg_check_modules(boost_filesystem REQUIRED)
|
||||
|
||||
|
||||
include_directories(lang)
|
||||
include_directories(${GLIB_INCLUDE_DIRS})
|
||||
include_directories(${NOTIFY_INCLUDE_DIRS})
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
include_directories(${fmt_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(SDL2_mixer REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_MIXER_INCLUDE_DIRS})
|
||||
find_package(Boost REQUIRED COMPONENTS filesystem)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
|
||||
# Линкуем библиотеки
|
||||
target_include_directories(tzeva_adom PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} "lang/")
|
||||
target_link_libraries(tzeva_adom PRIVATE SDL2 SDL2_mixer ${Boost_LIBRARIES} CURL::libcurl nlohmann_json::nlohmann_json ${GLIB_LIBRARIES} fmt::fmt ${NOTIFY_LIBRARIES} ${CURL_LIBRARIES})
|
||||
target_link_libraries(tzeva_adom PRIVATE SDL2 SDL2_mixer ${SDL2_LIBRARIES} ${SDL2_MIXER_LIBRARIES} ${fmt_LIBRARIES} ${Boost_LIBRARIES} CURL::libcurl nlohmann_json::nlohmann_json ${GLIB_LIBRARIES} ${NOTIFY_LIBRARIES} ${CURL_LIBRARIES})
|
||||
|
||||
add_custom_command(TARGET tzeva_adom POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
"true": "כן",
|
||||
"false": "לא",
|
||||
"threat": "איום: ",
|
||||
"cities": "הסדר: "
|
||||
"cities": "העירים: "
|
||||
}
|
||||
44
main.cpp
44
main.cpp
@@ -4,12 +4,13 @@
|
||||
#include <thread>
|
||||
#include <curl/curl.h>
|
||||
#include <atomic>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <string_view>
|
||||
#include <libnotify/notify.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "utils/check_file_exists.h"
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
#include "CONFIG.cpp"
|
||||
@@ -18,6 +19,7 @@
|
||||
#include "models/OrefAlertResponse.cpp"
|
||||
#include "utils/image_downloader.cpp"
|
||||
#include "utils/localization_manager.h"
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
class AlertResponse;
|
||||
|
||||
@@ -27,7 +29,7 @@ int64_t lastId = 0;
|
||||
json cities_n_areas_list;
|
||||
bool is_cities_loaded = false;
|
||||
bool is_test = false;
|
||||
std::string this_path = boost::filesystem::current_path().c_str();
|
||||
std::string this_path = std::filesystem::current_path().c_str();
|
||||
std::string lang = "en";
|
||||
std::vector<tzeva_adom::Alert> test_alert_variable;
|
||||
bool is_oref = false;
|
||||
@@ -59,9 +61,9 @@ void process_alert(const std::string& data) {
|
||||
|
||||
std::unique_ptr<tzeva_adom::IAlertResponse> first_alert;
|
||||
if (is_oref) {
|
||||
spdlog::debug("OREF_alertDate: {}", response[0]["alertDate"]);
|
||||
spdlog::debug("OREF_title: {}", response[0]["title"]);
|
||||
spdlog::debug("OREF_data: {}", response[0]["data"]);
|
||||
spdlog::debug("OREF_alertDate: {}", response[0]["alertDate"].get<std::string>());
|
||||
spdlog::debug("OREF_title: {}", response[0]["title"].get<std::string>());
|
||||
spdlog::debug("OREF_data: {}", response[0]["data"].get<std::string>());
|
||||
spdlog::debug("OREF_category: {}",std::to_string(response[0]["category"].get<int>()));
|
||||
spdlog::debug("OREF selected, create oref object");
|
||||
auto response_oref = response.at(0);
|
||||
@@ -96,7 +98,7 @@ void process_alert(const std::string& data) {
|
||||
spdlog::debug("Cities: {}", cities);
|
||||
|
||||
|
||||
std::string icon_url = boost::filesystem::current_path().c_str()+fmt::format("/threat{}.{}", std::to_string(threat), threat == 0 ? "png" : "svg");
|
||||
std::string icon_url = this_path+fmt::format("/threat{}.{}", std::to_string(threat), threat == 0 ? "png" : "svg");
|
||||
|
||||
spdlog::debug("Threat: {}", first_alert->get_threat());
|
||||
spdlog::debug("Threat name: {}", localization_manager.getString(fmt::format("threat_{}", threat)));
|
||||
@@ -104,17 +106,19 @@ void process_alert(const std::string& data) {
|
||||
spdlog::debug("Icon path: {}", icon_url);
|
||||
|
||||
std::string localised_cities_names = "";
|
||||
for (auto city: first_alert->get_cities_arr()) {
|
||||
localised_cities_names += fmt::format("{} ", cities_n_areas_list["cities"][city][lang]);
|
||||
}
|
||||
if (lang != "he")
|
||||
for (auto city: first_alert->get_cities_arr())
|
||||
localised_cities_names += fmt::format("{} ", cities_n_areas_list["cities"][city][lang].get<std::string>());
|
||||
else
|
||||
localised_cities_names = first_alert->get_cities();
|
||||
|
||||
spdlog::debug("Init notification");
|
||||
notify_init(localization_manager.getString(fmt::format("threat_{}", std::to_string(threat))).c_str());
|
||||
NotifyNotification* n = notify_notification_new (localization_manager.getString(fmt::format("threat_{}", std::to_string(threat))).c_str(),
|
||||
fmt::format(
|
||||
"{}: {}\n"\
|
||||
"{}: {}\n"\
|
||||
"{}: {}",
|
||||
"{} {}\n"\
|
||||
"{} {}\n"\
|
||||
"{} {}",
|
||||
localization_manager.getString("cities"),
|
||||
localised_cities_names,
|
||||
localization_manager.getString("threat"),
|
||||
@@ -154,10 +158,10 @@ void fetch_alerts_history(std::atomic<bool>& running) {
|
||||
curl = curl_easy_init();
|
||||
|
||||
// Parse cities and areas names on he, ru and en
|
||||
if (is_oref && lang == "he") {
|
||||
spdlog::error("Lang is not supported. Use TZEVA_ADOM");
|
||||
return;
|
||||
}
|
||||
// if (is_oref && lang == "he") {
|
||||
// spdlog::error("Lang is not supported. Use TZEVA_ADOM");
|
||||
// return;
|
||||
// }
|
||||
if (!is_cities_loaded) {
|
||||
std::string readBuffer;
|
||||
//Only tzeva_adom variable of cities list, because thats easier to work, than oref variable(without linq)
|
||||
@@ -240,7 +244,7 @@ int main(int argc, char** argv) {
|
||||
" -d --debug: Show debug messages\n"\
|
||||
" -t --test: Create test alert end exit\n"\
|
||||
" -l --lang: Choose language: ru, en, he\n"\
|
||||
" -o --oref: Use OREF uri`s for alerts"\
|
||||
" -o --oref: Use OREF api`s for alerts"\
|
||||
"");
|
||||
return 0;
|
||||
}
|
||||
@@ -251,10 +255,10 @@ int main(int argc, char** argv) {
|
||||
last_flag = argv[i];
|
||||
}
|
||||
|
||||
spdlog::debug("Path: {}", boost::filesystem::current_path().c_str());
|
||||
spdlog::debug("Path: {}", this_path);
|
||||
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
if (!boost::filesystem::exists(this_path+fmt::format("/threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg"))) {
|
||||
if (!file_exists(this_path+fmt::format("/threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg"))) {
|
||||
tzeva_adom::download_file(
|
||||
fmt::format(
|
||||
THREAT_IMAGES_URL,
|
||||
@@ -267,7 +271,7 @@ int main(int argc, char** argv) {
|
||||
localization_manager = tzeva_adom::LocalizationManager();
|
||||
localization_manager.setCurrentLanguage(lang);
|
||||
//Download tzeva-adom bell sound
|
||||
if (!boost::filesystem::exists(this_path+fmt::format("/bell.mp3"))) {
|
||||
if (!file_exists(this_path+fmt::format("/bell.mp3"))) {
|
||||
tzeva_adom::download_file(
|
||||
BELL_SOUND_URL,
|
||||
fmt::format("bell.mp3")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "models/Interfaces/IAlertResponse.cpp"
|
||||
#include "models/Interfaces/IAlert.cpp"
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
namespace tzeva_adom {
|
||||
using nlohmann::json;
|
||||
|
||||
@@ -127,7 +127,8 @@ namespace tzeva_adom {
|
||||
std::vector<std::string> get_cities_arr() override {
|
||||
std::vector<std::string> cities_to_return = {} ;
|
||||
for (auto alert : alerts) {
|
||||
cities_to_return.push_back(fmt::format("{}", fmt::join(alert.get_cities(), "")));
|
||||
for (auto city : alert.get_cities())
|
||||
cities_to_return.push_back(city);
|
||||
}
|
||||
return cities_to_return;
|
||||
}
|
||||
|
||||
14
utils/check_file_exists.h
Normal file
14
utils/check_file_exists.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by yawaflua on 15/11/2024.
|
||||
//
|
||||
|
||||
#ifndef CHECK_FILE_EXISTS_H
|
||||
#define CHECK_FILE_EXISTS_H
|
||||
|
||||
|
||||
inline bool file_exists (const std::string& name) {
|
||||
struct stat buffer;
|
||||
return (stat (name.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
#endif //CHECK_FILE_EXISTS_H
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp> // Подключение библиотеки JSON
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace tzeva_adom {
|
||||
class LocalizationManager {
|
||||
|
||||
Reference in New Issue
Block a user