Skip to content

Commit 41919e5

Browse files
committed
Fix path on windows
1 parent 6d12e44 commit 41919e5

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/Parser.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,10 @@ void Parser::Parse(const std::vector<unsigned char> &bytes, Chart **chart,
308308
continue;
309309
}
310310

311-
if (line.length() >= 7 && std::isdigit(line[1]) && std::isdigit(line[2]) &&
312-
std::isdigit(line[3]) && line[6] == ':') {
311+
if (line.length() >= 7 && std::isdigit(static_cast<unsigned char>(line[1])) &&
312+
std::isdigit(static_cast<unsigned char>(line[2])) &&
313+
std::isdigit(static_cast<unsigned char>(line[3])) &&
314+
line[6] == ':') {
313315
const int measure =
314316
static_cast<int>(std::strtol(line.substr(1, 3).c_str(), nullptr, 10));
315317
lastMeasure = std::max(lastMeasure, measure);
@@ -886,13 +888,13 @@ void Parser::ParseHeader(Chart *Chart, std::string_view cmd,
886888
}
887889
} else if (MatchHeader(cmd, "VOLWAV")) {
888890
} else if (MatchHeader(cmd, "STAGEFILE")) {
889-
Chart->Meta.StageFile = Value;
891+
Chart->Meta.StageFile = utf8_to_path_t(Value);
890892
} else if (MatchHeader(cmd, "BANNER")) {
891-
Chart->Meta.Banner = Value;
893+
Chart->Meta.Banner = utf8_to_path_t(Value);
892894
} else if (MatchHeader(cmd, "BACKBMP")) {
893-
Chart->Meta.BackBmp = Value;
895+
Chart->Meta.BackBmp = utf8_to_path_t(Value);
894896
} else if (MatchHeader(cmd, "PREVIEW")) {
895-
Chart->Meta.Preview = Value;
897+
Chart->Meta.Preview = utf8_to_path_t(Value);
896898
} else if (MatchHeader(cmd, "WAV")) {
897899
if (Xx.empty() || Value.empty()) {
898900
// UE_LOG(LogTemp, Warning, TEXT("WAV command requires two arguments"));
@@ -1006,6 +1008,33 @@ inline int Parser::ParseInt(std::string_view Str, bool forceBase36) const {
10061008
// std::wcout << "ParseInt62: " << Str << " = " << result << std::endl;
10071009
return result;
10081010
}
1011+
#ifdef _WIN32
1012+
std::wstring Parser::utf8_to_path_t(const std::string &input) {
1013+
1014+
// Determine the size of the buffer needed
1015+
int requiredSize =
1016+
MultiByteToWideChar(65001 /* UTF8 */, 0, input.c_str(), -1, NULL, 0);
1017+
1018+
if (requiredSize <= 0) {
1019+
// Conversion failed, return an empty string
1020+
return std::wstring();
1021+
}
1022+
1023+
// Create a string with the required size
1024+
std::wstring result(requiredSize, '\0');
1025+
1026+
// Perform the conversion
1027+
MultiByteToWideChar(65001 /* UTF8 */, 0, input.c_str(), -1, &result[0],
1028+
requiredSize);
1029+
1030+
// Remove the extra null terminator added by MultiByteToWideChar
1031+
result.resize(requiredSize - 1);
1032+
1033+
return result;
1034+
}
1035+
#else
1036+
std::string Parser::utf8_to_path_t(const std::string &input) { return input; }
1037+
#endif
10091038

10101039
Parser::~Parser() = default;
10111040
} // namespace bms_parser

src/Parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,10 @@ class Parser {
5959
unsigned long long B);
6060
inline bool CheckResourceIdRange(int Id) const;
6161
inline int ToWaveId(Chart *Chart, std::string_view Wav, bool metaOnly);
62+
#ifdef _WIN32
63+
static std::wstring utf8_to_path_t(const std::string &input);
64+
#else
65+
static std::string utf8_to_path_t(const std::string &input);
66+
#endif
6267
};
6368
} // namespace bms_parser

0 commit comments

Comments
 (0)