diff --git a/example/main.cpp b/example/main.cpp index f5bd98f..00731d5 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -67,13 +67,7 @@ std::string ws2s(const std::wstring &wstr) return std::string().assign(wstr.begin(), wstr.end()); } -std::string ws2s_utf8(const std::wstring &wstr) -{ - using convert_typeX = std::codecvt_utf8; - std::wstring_convert converterX; - return converterX.to_bytes(wstr); -} void parse_single_metadata(const std::filesystem::path &bmsFile) { @@ -82,9 +76,9 @@ void parse_single_metadata(const std::filesystem::path &bmsFile) bms_parser::Chart *chart; std::atomic_bool cancel = false; std::cout << "Parsing..." << std::endl; - parser.Parse(wpath, &chart, false, true, cancel); - std::cout << "BmsPath:" << std::filesystem::path(chart->Meta.BmsPath).string() << std::endl; - std::cout << "Folder:" << ws2s_utf8(chart->Meta.Folder) << std::endl; + parser.Parse(bmsFile, &chart, false, true, cancel); + std::cout << "BmsPath:" << chart->Meta.BmsPath.string() << std::endl; + std::cout << "Folder:" << chart->Meta.Folder.string() << std::endl; std::cout << "MD5: " << chart->Meta.MD5 << std::endl; std::cout << "SHA256: " << chart->Meta.SHA256 << std::endl; std::cout << "Title: " << ws2s(chart->Meta.Title) << std::endl; @@ -94,7 +88,7 @@ void parse_single_metadata(const std::filesystem::path &bmsFile) std::cout << "Genre: " << ws2s(chart->Meta.Genre) << std::endl; std::cout << "PlayLevel: " << chart->Meta.PlayLevel << std::endl; std::cout << "Total: " << chart->Meta.Total << std::endl; - std::cout << "StageFile: " << ws2s_utf8(chart->Meta.StageFile) << std::endl; + std::cout << "StageFile: " << chart->Meta.StageFile.string() << std::endl; std::cout << "Bpm: " << chart->Meta.MinBpm << "~" << chart->Meta.MaxBpm << " (" << chart->Meta.Bpm << ")" << std::endl; std::cout << "Rank: " << chart->Meta.Rank << std::endl; std::cout << "TotalNotes: " << chart->Meta.TotalNotes << std::endl; @@ -237,7 +231,6 @@ void find_new_bms_files(std::vector &diffs, const std::unordered_setMeta.BmsPath.string().c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 2, (chart->Meta.MD5).c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, (chart->Meta.SHA256).c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 4, ws2s(chart->Meta.Title).c_str(), -1, SQLITE_TRANSIENT); @@ -409,11 +402,11 @@ bool construct_folder_db(const std::filesystem::path &path) sqlite3_bind_text(stmt, 6, ws2s(chart->Meta.Genre).c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 7, ws2s(chart->Meta.Artist).c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 8, ws2s(chart->Meta.SubArtist).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 9, ws2s_utf8(chart->Meta.Folder).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 10, ws2s_utf8(chart->Meta.StageFile).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 11, ws2s_utf8(chart->Meta.Banner).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 12, ws2s_utf8(chart->Meta.BackBmp).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 13, ws2s_utf8(chart->Meta.Preview).c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 9, chart->Meta.Folder.string().c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 10, chart->Meta.StageFile.string().c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 11, chart->Meta.Banner.string().c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 12, chart->Meta.BackBmp.string().c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 13, chart->Meta.Preview.string().c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_double(stmt, 14, chart->Meta.PlayLevel); sqlite3_bind_int(stmt, 15, chart->Meta.Difficulty); sqlite3_bind_double(stmt, 16, chart->Meta.Total); diff --git a/src/Chart.h b/src/Chart.h index f49e9fc..75fc586 100644 --- a/src/Chart.h +++ b/src/Chart.h @@ -20,7 +20,7 @@ #include #include #include - +#include namespace bms_parser { class ChartMeta @@ -28,8 +28,8 @@ namespace bms_parser public: std::string SHA256; std::string MD5; - std::wstring BmsPath; - std::wstring Folder; + std::filesystem::path BmsPath; + std::filesystem::path Folder; std::wstring Artist = L""; std::wstring SubArtist = L""; double Bpm = 0; @@ -41,10 +41,10 @@ namespace bms_parser long long PlayLength = 0; // Timing of the last playable note, in microseconds long long TotalLength = 0; // Timing of the last timeline(including background note, bga change note, invisible note, ...), in microseconds - std::wstring Banner; - std::wstring StageFile; - std::wstring BackBmp; - std::wstring Preview; + std::filesystem::path Banner; + std::filesystem::path StageFile; + std::filesystem::path BackBmp; + std::filesystem::path Preview; bool BgaPoorDefault = false; int Difficulty = 0; double PlayLevel = 3; diff --git a/src/Parser.cpp b/src/Parser.cpp index 635bd7f..158e1e4 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -119,17 +119,16 @@ namespace bms_parser } return true; } - void Parser::Parse(std::wstring_view path, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled) + void Parser::Parse(std::filesystem::path fpath, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled) { #if BMS_PARSER_VERBOSE == 1 auto startTime = std::chrono::high_resolution_clock::now(); #endif std::vector bytes; - std::filesystem::path fpath = path; std::ifstream file(fpath, std::ios::binary); if (!file.is_open()) { - std::wcout << "Failed to open file: " << path << std::endl; + std::cout << "Failed to open file: " << fpath << std::endl; return; } #if BMS_PARSER_VERBOSE == 1 @@ -149,9 +148,9 @@ namespace bms_parser auto new_chart = *chart; if (new_chart != nullptr) { - new_chart->Meta.BmsPath = path; + new_chart->Meta.BmsPath = fpath; - new_chart->Meta.Folder = fpath.parent_path().wstring(); + new_chart->Meta.Folder = fpath.parent_path(); } #if BMS_PARSER_VERBOSE == 1 auto endTime = std::chrono::high_resolution_clock::now(); diff --git a/src/Parser.h b/src/Parser.h index 60fe158..af056d5 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -20,6 +20,7 @@ #include #include #include +#include /** * */ @@ -30,7 +31,7 @@ namespace bms_parser public: Parser(); void SetRandomSeed(int RandomSeed); - void Parse(std::wstring_view path, Chart **Chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled); + void Parse(std::filesystem::path path, Chart **Chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled); ~Parser(); void Parse(const std::vector& bytes, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled); static int NoWav;