| 40 | } |
| 41 | |
| 42 | bool DbgController::connect() |
| 43 | { |
| 44 | LogFunc << VAR(path_); |
| 45 | |
| 46 | image_paths_.clear(); |
| 47 | image_index_ = 0; |
| 48 | connected_ = false; |
| 49 | |
| 50 | std::error_code ec; |
| 51 | if (!std::filesystem::exists(path_, ec)) { |
| 52 | LogError << "path does not exist" << VAR(path_); |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | if (std::filesystem::is_regular_file(path_, ec)) { |
| 57 | if (is_image_path(path_)) { |
| 58 | image_paths_.push_back(path_); |
| 59 | } |
| 60 | } |
| 61 | else if (std::filesystem::is_directory(path_, ec)) { |
| 62 | for (const auto& entry : std::filesystem::recursive_directory_iterator(path_, ec)) { |
| 63 | if (ec) { |
| 64 | LogWarn << "recursive_directory_iterator error" << VAR(ec.message()); |
| 65 | break; |
| 66 | } |
| 67 | if (!entry.is_regular_file()) { |
| 68 | continue; |
| 69 | } |
| 70 | if (is_image_path(entry.path())) { |
| 71 | image_paths_.push_back(entry.path()); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | std::ranges::sort(image_paths_, [](const std::filesystem::path& a, const std::filesystem::path& b) { |
| 77 | return MAA_NS::path_to_utf8_string(a) < MAA_NS::path_to_utf8_string(b); |
| 78 | }); |
| 79 | |
| 80 | if (image_paths_.empty()) { |
| 81 | LogError << "no image files found" << VAR(path_); |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | connected_ = true; |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool DbgController::connected() const |
| 90 | { |
nothing calls this directly
no test coverage detected