Skip to content

Commit c39a598

Browse files
authored
March Fixes (#273)
* String Parsing Fixes - Prevent empty string on readTime - Allow numbers starting with `.` - Prevent NaN as a result. * Clear artist on unload. Leaving leftover data between audio loads. * Make fallback noteskin work. Fixes 2 issues when looking for a valid style noteskin: - Only looks for the 5 priority noteskins. - Default placeholder type is the same as the default noteskin type, so it will never load the fallback if no supported noteskins are found. This changes the placeholder value to be different, and if no priority noteskins support the current style, search through all loaded noteskins before using the fallback. * Fix FileDrop paths. - Fixes utf8 paths from not working. - Fixes directory drops not finding any valid files due to extension now including the dot. - Use path util for extension and osu filename conversion. * Update handleDialogOpening Prevent a double open of a dialog due to requesting it open when already open and never clearing the flag. Also prevent invalid DialogId values from crashing due to dlg being nullptr; * Stop CustomSnap from grabbing focus. It doesn't select the box and eats the inputs when initially open, including for shortcuts.
1 parent 3f86ee5 commit c39a598

7 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/Core/StringUtils.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ bool Str::readBool(const std::string& s, bool alt) {
116116
}
117117

118118
double Str::readTime(const std::string& s, double alt) {
119+
if (s.empty()) return alt;
119120
auto time = Str::split(s, ":", false, false);
120121
double v = 0.0;
121122

@@ -132,7 +133,7 @@ double Str::readTime(const std::string& s, double alt) {
132133
break;
133134
}
134135

135-
if (v == 0 && s.empty()) return alt;
136+
if (v == 0) return alt;
136137
alt = v;
137138
return alt;
138139
}
@@ -670,7 +671,7 @@ static const uint8_t* ParseOperandWithSign(const uint8_t* p, double& out) {
670671
if (*p == '(') {
671672
p = ParseNestedExpression(SkipWs(++p), out);
672673
if (*p == ')') p = SkipWs(++p);
673-
} else if (*p >= '0' && *p <= '9') {
674+
} else if (*p == '.' || (*p >= '0' && *p <= '9')) {
674675
p = ParseNumber(p, out);
675676
}
676677
if (sign == '-') out = -out;
@@ -682,7 +683,7 @@ static const uint8_t* ParseMultiplicationOperand(const uint8_t* p,
682683
if (*p == '(') {
683684
p = ParseNestedExpression(SkipWs(++p), out);
684685
if (*p == ')') p = SkipWs(++p);
685-
} else if (*p >= '0' && *p <= '9') {
686+
} else if (*p == '.' || (*p >= '0' && *p <= '9')) {
686687
p = ParseNumber(p, out);
687688
} else if (*p == '+' || *p == '-') {
688689
p = ParseOperandWithSign(p, out);
@@ -722,6 +723,7 @@ bool Str::parse(const char* expr, double& out) {
722723
double tmp = 0.0;
723724
const uint8_t* begin = SkipWs(reinterpret_cast<const uint8_t*>(expr));
724725
const uint8_t* p = ParseNestedExpression(begin, tmp);
726+
if (!isfinite(tmp)) tmp = 0.0;
725727
if (p > begin) out = tmp;
726728
return (p > begin);
727729
}

src/Dialogs/CustomSnap.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void DialogCustomSnap::myCreateWidgets() {
2424
scol->onChange.bind(this, &DialogCustomSnap::onChange);
2525
scol->setRange(4.0, 192.0);
2626
scol->setPrecision(0, 0);
27-
scol->startCapturingText();
2827
}
2928

3029
void DialogCustomSnap::onChange() {

src/Editor/Editor.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,16 @@ struct EditorImpl : public Editor, public InputHandler {
422422

423423
// Make a list of loadable extensions, from high priority to low
424424
// priority.
425-
static const char* extList[] = {"ssc", "sm", "dwi", "osu",
426-
"ogg", "mp3", "wav"};
425+
static const char* extList[] = {".ssc", ".sm", ".dwi", ".osu",
426+
".ogg", ".mp3", ".wav"};
427427
const char** extEnd = extList + (ignoreAudio ? 4 : 7);
428428

429429
// Check if the path is a directory.
430430
if (fs::is_directory(path)) {
431431
// If so, look for loadable files in the given directory.
432432
auto curPriority = extEnd;
433433
for (auto& file : File::findFiles(path, false)) {
434-
std::string ext(reinterpret_cast<const char*>(
435-
file.extension().u8string().c_str()));
434+
std::string ext(pathToUtf8(file.extension()));
436435
Str::toLower(ext);
437436
auto priority = std::find(extList, extEnd, ext);
438437
if (priority != extEnd && priority < curPriority) {
@@ -738,7 +737,10 @@ struct EditorImpl : public Editor, public InputHandler {
738737

739738
void handleDialogOpening(DialogId id, recti rect) {
740739
auto& entry = myDialogs[id];
741-
if (entry.ptr) return;
740+
if (entry.ptr) {
741+
entry.requestOpen = false;
742+
return;
743+
}
742744

743745
EditorDialog* dlg = nullptr;
744746
switch (id) {
@@ -792,6 +794,8 @@ struct EditorImpl : public Editor, public InputHandler {
792794
break;
793795
};
794796

797+
if (!dlg) return;
798+
795799
dlg->setId(id);
796800

797801
if (rect.w > 0 && rect.h > 0) {
@@ -827,7 +831,7 @@ struct EditorImpl : public Editor, public InputHandler {
827831

828832
void onFileDrop(FileDrop& evt) override {
829833
if (evt.count >= 1) {
830-
fs::path path(evt.files[0]);
834+
fs::path path = utf8ToPath(evt.files[0]);
831835
if (!openSimfile(findSimfile(path, false))) {
832836
if (canConvertAudio(pathToUtf8(path).c_str())) {
833837
gMusic->startAudioConversion(path, true);

src/Editor/Music.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct MusicImpl : public Music, public MixSource {
150150

151151
mySamples.clear();
152152
myTitle.clear();
153+
myArtist.clear();
153154

154155
myLoadState = LOADING_DONE;
155156
}

src/Managers/NoteskinMan.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ struct NoteskinManImpl : public NoteskinMan {
481481
if (myActiveStyle == style) return;
482482
myActiveStyle = style;
483483

484-
int type = -1;
484+
int type = -2;
485485
NoteskinImpl* skin = nullptr;
486486

487487
// Find the noteskin for the style.
@@ -503,6 +503,16 @@ struct NoteskinManImpl : public NoteskinMan {
503503
break;
504504
}
505505
}
506+
507+
// No priority skin found, find one that supports the style.
508+
if (type < 0) {
509+
for (auto i = 0; i < myTypes.size(); ++i) {
510+
if (Supports(myTypes[i], style)) {
511+
type = i;
512+
break;
513+
}
514+
}
515+
}
506516
}
507517

508518
// Replace the active noteskin with the new skin.

src/Simfile/LoadOsu.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ static bool ParseDir(Vector<OsuFile*>& out, fs::path dir, std::string& err) {
512512

513513
out.push_back(new OsuFile);
514514
ParseFile(*out.back(), str);
515-
out.back()->filename = std::string(
516-
reinterpret_cast<const char*>(file.filename().u8string().c_str()));
515+
out.back()->filename = pathToUtf8(file.filename());
517516
}
518517
return true;
519518
}

src/System/System.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ struct SystemImpl : public System {
781781
std::wstring wstr(pathLen, 0);
782782
DragQueryFileW(reinterpret_cast<HDROP>(wp), i,
783783
wstr.data(), pathLen + 1);
784-
files[i] = Narrow(wstr);
784+
files[i] = pathToUtf8(fs::path(wstr));
785785
}
786786

787787
DragFinish(reinterpret_cast<HDROP>(wp));

0 commit comments

Comments
 (0)