Skip to content

Commit 64dba9d

Browse files
committed
Change path to fs path
1 parent 84ed1c8 commit 64dba9d

4 files changed

Lines changed: 23 additions & 30 deletions

File tree

example/main.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ std::string ws2s(const std::wstring &wstr)
6767
return std::string().assign(wstr.begin(), wstr.end());
6868
}
6969

70-
std::string ws2s_utf8(const std::wstring &wstr)
71-
{
72-
using convert_typeX = std::codecvt_utf8<wchar_t>;
73-
std::wstring_convert<convert_typeX, wchar_t> converterX;
7470

75-
return converterX.to_bytes(wstr);
76-
}
7771

7872
void parse_single_metadata(const std::filesystem::path &bmsFile)
7973
{
@@ -82,9 +76,9 @@ void parse_single_metadata(const std::filesystem::path &bmsFile)
8276
bms_parser::Chart *chart;
8377
std::atomic_bool cancel = false;
8478
std::cout << "Parsing..." << std::endl;
85-
parser.Parse(wpath, &chart, false, true, cancel);
86-
std::cout << "BmsPath:" << std::filesystem::path(chart->Meta.BmsPath).string() << std::endl;
87-
std::cout << "Folder:" << ws2s_utf8(chart->Meta.Folder) << std::endl;
79+
parser.Parse(bmsFile, &chart, false, true, cancel);
80+
std::cout << "BmsPath:" << chart->Meta.BmsPath.string() << std::endl;
81+
std::cout << "Folder:" << chart->Meta.Folder.string() << std::endl;
8882
std::cout << "MD5: " << chart->Meta.MD5 << std::endl;
8983
std::cout << "SHA256: " << chart->Meta.SHA256 << std::endl;
9084
std::cout << "Title: " << ws2s(chart->Meta.Title) << std::endl;
@@ -94,7 +88,7 @@ void parse_single_metadata(const std::filesystem::path &bmsFile)
9488
std::cout << "Genre: " << ws2s(chart->Meta.Genre) << std::endl;
9589
std::cout << "PlayLevel: " << chart->Meta.PlayLevel << std::endl;
9690
std::cout << "Total: " << chart->Meta.Total << std::endl;
97-
std::cout << "StageFile: " << ws2s_utf8(chart->Meta.StageFile) << std::endl;
91+
std::cout << "StageFile: " << chart->Meta.StageFile.string() << std::endl;
9892
std::cout << "Bpm: " << chart->Meta.MinBpm << "~" << chart->Meta.MaxBpm << " (" << chart->Meta.Bpm << ")" << std::endl;
9993
std::cout << "Rank: " << chart->Meta.Rank << std::endl;
10094
std::cout << "TotalNotes: " << chart->Meta.TotalNotes << std::endl;
@@ -237,7 +231,6 @@ void find_new_bms_files(std::vector<Diff> &diffs, const std::unordered_set<std::
237231
bool construct_folder_db(const std::filesystem::path &path)
238232
{
239233
sqlite3 *db;
240-
char *zErrMsg = 0;
241234
int rc;
242235
rc = sqlite3_open("bms.db", &db);
243236
if (rc)
@@ -401,19 +394,19 @@ bool construct_folder_db(const std::filesystem::path &path)
401394
fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
402395
return;
403396
}
404-
sqlite3_bind_text(stmt, 1, diffs[i].path.string().c_str(), -1, SQLITE_TRANSIENT);
397+
sqlite3_bind_text(stmt, 1, chart->Meta.BmsPath.string().c_str(), -1, SQLITE_TRANSIENT);
405398
sqlite3_bind_text(stmt, 2, (chart->Meta.MD5).c_str(), -1, SQLITE_TRANSIENT);
406399
sqlite3_bind_text(stmt, 3, (chart->Meta.SHA256).c_str(), -1, SQLITE_TRANSIENT);
407400
sqlite3_bind_text(stmt, 4, ws2s(chart->Meta.Title).c_str(), -1, SQLITE_TRANSIENT);
408401
sqlite3_bind_text(stmt, 5, ws2s(chart->Meta.SubTitle).c_str(), -1, SQLITE_TRANSIENT);
409402
sqlite3_bind_text(stmt, 6, ws2s(chart->Meta.Genre).c_str(), -1, SQLITE_TRANSIENT);
410403
sqlite3_bind_text(stmt, 7, ws2s(chart->Meta.Artist).c_str(), -1, SQLITE_TRANSIENT);
411404
sqlite3_bind_text(stmt, 8, ws2s(chart->Meta.SubArtist).c_str(), -1, SQLITE_TRANSIENT);
412-
sqlite3_bind_text(stmt, 9, ws2s_utf8(chart->Meta.Folder).c_str(), -1, SQLITE_TRANSIENT);
413-
sqlite3_bind_text(stmt, 10, ws2s_utf8(chart->Meta.StageFile).c_str(), -1, SQLITE_TRANSIENT);
414-
sqlite3_bind_text(stmt, 11, ws2s_utf8(chart->Meta.Banner).c_str(), -1, SQLITE_TRANSIENT);
415-
sqlite3_bind_text(stmt, 12, ws2s_utf8(chart->Meta.BackBmp).c_str(), -1, SQLITE_TRANSIENT);
416-
sqlite3_bind_text(stmt, 13, ws2s_utf8(chart->Meta.Preview).c_str(), -1, SQLITE_TRANSIENT);
405+
sqlite3_bind_text(stmt, 9, chart->Meta.Folder.string().c_str(), -1, SQLITE_TRANSIENT);
406+
sqlite3_bind_text(stmt, 10, chart->Meta.StageFile.string().c_str(), -1, SQLITE_TRANSIENT);
407+
sqlite3_bind_text(stmt, 11, chart->Meta.Banner.string().c_str(), -1, SQLITE_TRANSIENT);
408+
sqlite3_bind_text(stmt, 12, chart->Meta.BackBmp.string().c_str(), -1, SQLITE_TRANSIENT);
409+
sqlite3_bind_text(stmt, 13, chart->Meta.Preview.string().c_str(), -1, SQLITE_TRANSIENT);
417410
sqlite3_bind_double(stmt, 14, chart->Meta.PlayLevel);
418411
sqlite3_bind_int(stmt, 15, chart->Meta.Difficulty);
419412
sqlite3_bind_double(stmt, 16, chart->Meta.Total);

src/Chart.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
#include <string>
2121
#include <vector>
2222
#include <unordered_map>
23-
23+
#include <filesystem>
2424
namespace bms_parser
2525
{
2626
class ChartMeta
2727
{
2828
public:
2929
std::string SHA256;
3030
std::string MD5;
31-
std::wstring BmsPath;
32-
std::wstring Folder;
31+
std::filesystem::path BmsPath;
32+
std::filesystem::path Folder;
3333
std::wstring Artist = L"";
3434
std::wstring SubArtist = L"";
3535
double Bpm = 0;
@@ -41,10 +41,10 @@ namespace bms_parser
4141
long long PlayLength = 0; // Timing of the last playable note, in microseconds
4242
long long TotalLength = 0;
4343
// Timing of the last timeline(including background note, bga change note, invisible note, ...), in microseconds
44-
std::wstring Banner;
45-
std::wstring StageFile;
46-
std::wstring BackBmp;
47-
std::wstring Preview;
44+
std::filesystem::path Banner;
45+
std::filesystem::path StageFile;
46+
std::filesystem::path BackBmp;
47+
std::filesystem::path Preview;
4848
bool BgaPoorDefault = false;
4949
int Difficulty = 0;
5050
double PlayLevel = 3;

src/Parser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,16 @@ namespace bms_parser
119119
}
120120
return true;
121121
}
122-
void Parser::Parse(std::wstring_view path, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled)
122+
void Parser::Parse(std::filesystem::path fpath, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled)
123123
{
124124
#if BMS_PARSER_VERBOSE == 1
125125
auto startTime = std::chrono::high_resolution_clock::now();
126126
#endif
127127
std::vector<unsigned char> bytes;
128-
std::filesystem::path fpath = path;
129128
std::ifstream file(fpath, std::ios::binary);
130129
if (!file.is_open())
131130
{
132-
std::wcout << "Failed to open file: " << path << std::endl;
131+
std::cout << "Failed to open file: " << fpath << std::endl;
133132
return;
134133
}
135134
#if BMS_PARSER_VERBOSE == 1
@@ -149,9 +148,9 @@ namespace bms_parser
149148
auto new_chart = *chart;
150149
if (new_chart != nullptr)
151150
{
152-
new_chart->Meta.BmsPath = path;
151+
new_chart->Meta.BmsPath = fpath;
153152

154-
new_chart->Meta.Folder = fpath.parent_path().wstring();
153+
new_chart->Meta.Folder = fpath.parent_path();
155154
}
156155
#if BMS_PARSER_VERBOSE == 1
157156
auto endTime = std::chrono::high_resolution_clock::now();

src/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string>
2121
#include <map>
2222
#include <atomic>
23+
#include <filesystem>
2324
/**
2425
*
2526
*/
@@ -30,7 +31,7 @@ namespace bms_parser
3031
public:
3132
Parser();
3233
void SetRandomSeed(int RandomSeed);
33-
void Parse(std::wstring_view path, Chart **Chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled);
34+
void Parse(std::filesystem::path path, Chart **Chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled);
3435
~Parser();
3536
void Parse(const std::vector<unsigned char>& bytes, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled);
3637
static int NoWav;

0 commit comments

Comments
 (0)