Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 27, 2024
1 parent f3d92d0 commit 7f409d6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 241 deletions.
28 changes: 14 additions & 14 deletions source/MaaProjectInterface/CLI/interactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ void Interactor::print_config() const

std::cout << "Controller:\n\n";
std::cout << "\t"
<< MaaNS::utf8_to_crt(std::format(
<< MAA_LOG_NS::utf8_to_crt(std::format(
"{}\n\t\t{}\n\t\t{}",
config_.configuration().controller.name,
MaaNS::path_to_utf8_string(config_.configuration().controller.adb_path),
config_.configuration().controller.address))
<< "\n\n";

std::cout << "Resource:\n\n";
std::cout << "\t" << MaaNS::utf8_to_crt(config_.configuration().resource) << "\n\n";
std::cout << "\t" << MAA_LOG_NS::utf8_to_crt(config_.configuration().resource) << "\n\n";

std::cout << "Tasks:\n\n";
print_config_tasks(false);
Expand All @@ -183,11 +183,11 @@ void Interactor::welcome() const
std::cout << "Welcome to use Maa Project Interface CLI!\n";
}
else {
std::cout << MaaNS::utf8_to_crt(config_.interface_data().message) << "\n";
std::cout << MAA_LOG_NS::utf8_to_crt(config_.interface_data().message) << "\n";
}
std::cout << "MaaFramework: " << MAA_VERSION << "\n\n";

std::cout << "Version: " << MaaNS::utf8_to_crt(config_.interface_data().version) << "\n\n";
std::cout << "Version: " << MAA_LOG_NS::utf8_to_crt(config_.interface_data().version) << "\n\n";
}

bool Interactor::interact_once()
Expand Down Expand Up @@ -244,7 +244,7 @@ void Interactor::select_controller()
if (all_controllers.size() != 1) {
std::cout << "### Select controller ###\n\n";
for (size_t i = 0; i < all_controllers.size(); ++i) {
std::cout << MaaNS::utf8_to_crt(
std::cout << MAA_LOG_NS::utf8_to_crt(
std::format("\t{}. {}\n", i + 1, all_controllers[i].name));
}
std::cout << "\n";
Expand Down Expand Up @@ -307,7 +307,7 @@ void Interactor::select_adb_auto_detect()
std::string path = MaaToolkitGetDeviceAdbPath(i);
std::string address = MaaToolkitGetDeviceAdbSerial(i);

std::cout << MaaNS::utf8_to_crt(
std::cout << MAA_LOG_NS::utf8_to_crt(
std::format("\t{}. {}\n\t\t{}\n\t\t{}\n", i + 1, name, path, address));
}
std::cout << "\n";
Expand Down Expand Up @@ -350,7 +350,7 @@ void Interactor::select_resource()
if (all_resources.size() != 1) {
std::cout << "### Select resource ###\n\n";
for (size_t i = 0; i < all_resources.size(); ++i) {
std::cout << MaaNS::utf8_to_crt(
std::cout << MAA_LOG_NS::utf8_to_crt(
std::format("\t{}. {}\n", i + 1, all_resources[i].name));
}
std::cout << "\n";
Expand All @@ -376,7 +376,7 @@ void Interactor::add_task()

std::cout << "### Add task ###\n\n";
for (size_t i = 0; i < all_data_tasks.size(); ++i) {
std::cout << MaaNS::utf8_to_crt(std::format("\t{}. {}\n", i + 1, all_data_tasks[i].name));
std::cout << MAA_LOG_NS::utf8_to_crt(std::format("\t{}. {}\n", i + 1, all_data_tasks[i].name));
}
std::cout << "\n";
auto input_indexes = input_multi(all_data_tasks.size());
Expand All @@ -398,12 +398,12 @@ void Interactor::add_task()
Configuration::Option { option_name, opt.default_case });
continue;
}
std::cout << MaaNS::utf8_to_crt(std::format(
std::cout << MAA_LOG_NS::utf8_to_crt(std::format(
"\n\n## Input option of \"{}\" for \"{}\" ##\n\n",
option_name,
data_task.name));
for (size_t i = 0; i < opt.cases.size(); ++i) {
std::cout << MaaNS::utf8_to_crt(
std::cout << MAA_LOG_NS::utf8_to_crt(
std::format("\t{}. {}\n", i + 1, opt.cases[i].name));
}
std::cout << "\n";
Expand Down Expand Up @@ -477,14 +477,14 @@ void Interactor::print_config_tasks(bool with_index) const
for (size_t i = 0; i < all_config_tasks.size(); ++i) {
const auto& task = all_config_tasks[i];
if (with_index) {
std::cout << MaaNS::utf8_to_crt(std::format("\t{}. {}\n", i + 1, task.name));
std::cout << MAA_LOG_NS::utf8_to_crt(std::format("\t{}. {}\n", i + 1, task.name));
}
else {
std::cout << MaaNS::utf8_to_crt(std::format("\t- {}\n", task.name));
std::cout << MAA_LOG_NS::utf8_to_crt(std::format("\t- {}\n", task.name));
}

for (const auto& [key, value] : task.option) {
std::cout << "\t\t- " << MaaNS::utf8_to_crt(key) << ": " << MaaNS::utf8_to_crt(value)
std::cout << "\t\t- " << MAA_LOG_NS::utf8_to_crt(key) << ": " << MAA_LOG_NS::utf8_to_crt(value)
<< "\n";
}
}
Expand All @@ -507,5 +507,5 @@ void Interactor::on_maafw_notify(
std::ignore = pthis;

std::string entry = json::parse(details_json).value_or(json::value())["entry"].as_string();
std::cout << MaaNS::utf8_to_crt(std::format("on_maafw_notify: {} {}", msg, entry)) << std::endl;
std::cout << MAA_LOG_NS::utf8_to_crt(std::format("on_maafw_notify: {} {}", msg, entry)) << std::endl;
}
3 changes: 3 additions & 0 deletions source/MaaProjectInterface/Impl/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "ProjectInterface/Parser.h"

#include <ranges>
#include <functional>

#include "Utils/Logger.h"

MAA_PROJECT_INTERFACE_NS_BEGIN
Expand Down
30 changes: 29 additions & 1 deletion source/MaaUtils/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,42 @@

#include "Utils/Codec.h"
#include "Utils/ImageIo.h"
#include "Utils/Locale.hpp"
#include "Utils/Platform.h"
#include "Utils/Uuid.h"

#pragma message("MaaUtils MAA_VERSION: " MAA_VERSION)

MAA_LOG_NS_BEGIN

std::string utf8_to_crt(std::string_view utf8_str)
{
#ifdef _WIN32
const char* src_str = utf8_str.data();
const int byte_len = static_cast<int>(utf8_str.length() * sizeof(char));
int len = MultiByteToWideChar(CP_UTF8, 0, src_str, byte_len, nullptr, 0);
const std::size_t wsz_ansi_length = static_cast<std::size_t>(len) + 1U;
auto wsz_ansi = new wchar_t[wsz_ansi_length];
memset(wsz_ansi, 0, sizeof(wsz_ansi[0]) * wsz_ansi_length);
MultiByteToWideChar(CP_UTF8, 0, src_str, byte_len, wsz_ansi, len);

len = WideCharToMultiByte(CP_ACP, 0, wsz_ansi, -1, nullptr, 0, nullptr, nullptr);
const std::size_t sz_ansi_length = static_cast<std::size_t>(len) + 1;
auto sz_ansi = new char[sz_ansi_length];
memset(sz_ansi, 0, sizeof(sz_ansi[0]) * sz_ansi_length);
WideCharToMultiByte(CP_ACP, 0, wsz_ansi, -1, sz_ansi, len, nullptr, nullptr);
std::string strTemp(sz_ansi);

delete[] wsz_ansi;
wsz_ansi = nullptr;
delete[] sz_ansi;
sz_ansi = nullptr;

return strTemp;
#else
return std::string(utf8_str);
#endif
}

constexpr separator separator::none("");
constexpr separator separator::space(" ");
constexpr separator separator::tab("\t");
Expand Down
226 changes: 0 additions & 226 deletions source/include/Utils/Locale.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions source/include/Utils/LoggerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ inline std::ostream& operator<<(std::ostream& os, const std::chrono::millisecond
}
#endif

MAA_UTILS_API std::string utf8_to_crt(std::string_view utf8_str);

enum class level
{
fatal = MaaLoggingLevel_Fatal,
Expand Down

0 comments on commit 7f409d6

Please sign in to comment.