Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,17 @@ std::optional<std::string> Plugin::getStartupScript()
void PluginManager::performForceInstallAndUpdateAsync(const std::string& source)
{
std::thread([source]() {
performForceInstallAndUpdateSync(source);
try {
performForceInstallAndUpdateSync(source);
}
catch (const std::exception& e) {
std::cerr << "[ BetterNCM ] [Plugin Remote Tasks] Update failed on "
<< source << ": " << e.what() << std::endl;
}
catch (...) {
std::cerr << "[ BetterNCM ] [Plugin Remote Tasks] Unknown update error on "
<< source << std::endl;
}
}).detach();
}

Expand Down
10 changes: 7 additions & 3 deletions src/utils/BNString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@ class BNString : public std::wstring {
return static_cast<int>(index);
}

[[nodiscard]] std::vector<std::wstring_view> split(const std::wstring& delimiter) const {
std::vector<std::wstring_view> result;
[[nodiscard]] std::vector<std::wstring> split(const std::wstring& delimiter) const {
if (delimiter.empty()) {
throw std::invalid_argument("split delimiter must not be empty");
}

std::vector<std::wstring> result;
size_t start = 0;
size_t end = 0;
while ((end = this->find(delimiter, start)) != std::wstring::npos) {
result.push_back(this->substr(start, end - start));
result.push_back(this->substr(start, end - start));
start = end + delimiter.length();
}
result.push_back(this->substr(start));
Expand Down
34 changes: 34 additions & 0 deletions tests/bnstring_split.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#include <codecvt>
#include <cstring>
#include <iostream>
#include <locale>
#include <string_view>
#include "../src/utils/BNString.hpp"

static void check(bool condition, const char* message) {
if (!condition) throw std::runtime_error(message);
}

int main() {
const std::wstring url = L"https://gitcode.net/qq_21551787/bncm-plugin-packed/-/raw/master/";
const BNString config(std::wstring(url + L"\n" + url));
auto lines = config.split(L"\n");
check(lines == std::vector<std::wstring>{url, url}, "long URL contents");

// Results must own their data even after a temporary source is destroyed.
auto retained = BNString(std::wstring(url + L"\nshort")).split(L"\n");
std::wstring reuse(4096, L'x');
check(retained == std::vector<std::wstring>{url, L"short"}, "source lifetime");
check(BNString(std::wstring(L"a\n\nb\n")).split(L"\n") ==
std::vector<std::wstring>{L"a", L"", L"b", L""}, "empty fields");
check(BNString(std::wstring(L"")).split(L"\n") ==
std::vector<std::wstring>{L""}, "empty source");
check(BNString(std::wstring(L"a::b")).split(L"::") ==
std::vector<std::wstring>{L"a", L"b"}, "multi-character delimiter");
bool rejected = false;
try { (void)config.split(L""); }
catch (const std::invalid_argument&) { rejected = true; }
check(rejected, "empty delimiter must be rejected");
std::cout << "PASS: BNString split ownership and edge cases\n";
}