11#pragma once
22
33#include < DotNameLib/version.h> // first configuration will create this file
4+ #include < Logger/ILogger.hpp>
5+ #include < Assets/AssetContext.hpp>
6+ #include < Utils/Utils.hpp>
47#include < filesystem>
8+ #include < memory>
59#include < string>
610
7- // Public API
11+ namespace dotnamecpp ::v1 {
12+ class DotNameLib {
813
9- namespace dotname {
10- // Version information
11- inline namespace v1 {
14+ private:
15+ const std::string libName_ = " DotNameLib v." DOTNAMELIB_VERSION;
16+ std::shared_ptr<dotnamecpp::logging::ILogger> logger_;
17+ std::filesystem::path assetsPath_;
18+ bool isInitialized_ = false ;
1219
13- class DotNameLib {
14- private:
15- const std::string libName_ = " DotNameLib v." DOTNAMELIB_VERSION;
16- std::filesystem::path assetsPath_;
17- bool isInitialized_ = false ;
20+ public:
21+ explicit DotNameLib (std::shared_ptr<dotnamecpp::logging::ILogger> logger,
22+ const std::filesystem::path& assetsPath)
23+ : logger_ (std::move (logger)), assetsPath_ (assetsPath) {
1824
19- public:
20- DotNameLib ();
21- explicit DotNameLib (const std::filesystem::path& assetsPath);
22- ~DotNameLib ();
25+ if (assetsPath.empty ()) {
26+ logger_->warning (" Empty assets path provided" );
27+ return ;
28+ }
29+ try {
30+ assetsPath_ = assetsPath;
31+ AssetContext::setAssetsPath (assetsPath);
32+ logger_->infoStream () << libName_ << " initialized with assets path: "
33+ << AssetContext::getAssetsPath ();
34+ logger_->debugStream () << " Assets: " << AssetContext::getAssetsPath ();
35+ logger_->debugStream () << DotNameUtils::json::getCustomStringSign ();
36+
37+ // Check if logo file exists before trying to open it
38+ const auto logoPath = AssetContext::getAssetsPath () / " DotNameCppLogo.svg" ;
39+ logger_->debugStream () << " Logo path: " << logoPath;
2340
24- // Rule of 5 for better resource management
25- DotNameLib (const DotNameLib& other) = delete ;
26- DotNameLib& operator = (const DotNameLib& other) = delete ;
27- DotNameLib (DotNameLib&& other) noexcept ;
28- DotNameLib& operator = (DotNameLib&& other) noexcept ;
41+ if (std::filesystem::exists (logoPath)) {
42+ std::ifstream logoFile (logoPath);
43+ if (logoFile.is_open ()) {
44+ logger_->debugStream () << " Logo file successfully opened" ;
45+ isInitialized_ = true ;
46+ } else {
47+ logger_->warningStream () << " Could not open logo file: " << logoPath;
48+ }
49+ } else {
50+ logger_->warningStream () << " Logo file does not exist: " << logoPath;
51+ }
52+ } catch (const std::exception& e) {
53+ logger_->errorStream () << " Error initializing DotNameLib: " << e.what ();
54+ isInitialized_ = false ;
55+ }
56+ }
2957
30- // Public interface
31- [[nodiscard]] bool isInitialized () const noexcept {
32- return isInitialized_;
58+ // Rule of 5 for better resource management
59+ DotNameLib (const DotNameLib& other) = delete ;
60+ DotNameLib& operator = (const DotNameLib& other) = delete ;
61+ DotNameLib (DotNameLib&& other) noexcept : assetsPath_ (std::move (other.assetsPath_)),
62+ isInitialized_ (other.isInitialized_) {
63+ other.isInitialized_ = false ;
64+ logger_->infoStream () << libName_ << " move constructed" ;
65+ }
66+ DotNameLib& operator = (DotNameLib&& other) noexcept {
67+ if (this != &other) {
68+ assetsPath_ = std::move (other.assetsPath_ );
69+ isInitialized_ = other.isInitialized_ ;
70+ other.isInitialized_ = false ;
71+ logger_->infoStream () << libName_ << " move assigned" ;
3372 }
34- [[nodiscard]] const std::filesystem::path& getAssetsPath () const noexcept {
35- return assetsPath_;
73+ return *this ;
74+ }
75+
76+ ~DotNameLib () {
77+ if (isInitialized_) {
78+ logger_->infoStream () << libName_ << " destructed" ;
79+ } else {
80+ logger_->infoStream () << libName_ << " (not initialized) destructed" ;
3681 }
37- };
82+ }
3883
39- } // namespace v1
40- } // namespace dotname
84+ // Public interface
85+ [[nodiscard]] bool isInitialized () const noexcept {
86+ return isInitialized_;
87+ }
88+ [[nodiscard]] const std::filesystem::path& getAssetsPath () const noexcept {
89+ return assetsPath_;
90+ }
91+ };
92+ } // namespace dotnamecpp::v1
4193
42- // MIT License Copyright (c) 2024-2025 Tomáš Mark
94+ // MIT License Copyright (c) 2024-2025 Tomáš Mark
0 commit comments