Skip to content

Commit

Permalink
Change path to fs path
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletXF committed May 14, 2024
1 parent 84ed1c8 commit 64dba9d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
27 changes: 10 additions & 17 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t>;
std::wstring_convert<convert_typeX, wchar_t> converterX;

return converterX.to_bytes(wstr);
}

void parse_single_metadata(const std::filesystem::path &bmsFile)
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -237,7 +231,6 @@ void find_new_bms_files(std::vector<Diff> &diffs, const std::unordered_set<std::
bool construct_folder_db(const std::filesystem::path &path)
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("bms.db", &db);
if (rc)
Expand Down Expand Up @@ -401,19 +394,19 @@ bool construct_folder_db(const std::filesystem::path &path)
fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
return;
}
sqlite3_bind_text(stmt, 1, diffs[i].path.string().c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 1, chart->Meta.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);
sqlite3_bind_text(stmt, 5, ws2s(chart->Meta.SubTitle).c_str(), -1, SQLITE_TRANSIENT);
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);
Expand Down
14 changes: 7 additions & 7 deletions src/Chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
#include <string>
#include <vector>
#include <unordered_map>

#include <filesystem>
namespace bms_parser
{
class ChartMeta
{
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;
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> 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
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <map>
#include <atomic>
#include <filesystem>
/**
*
*/
Expand All @@ -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<unsigned char>& bytes, Chart **chart, bool addReadyMeasure, bool metaOnly, std::atomic_bool &bCancelled);
static int NoWav;
Expand Down

0 comments on commit 64dba9d

Please sign in to comment.