diff options
| author | SulfurNitride <SulfurNitride@users.noreply.github.com> | 2026-02-11 02:37:39 -0600 |
|---|---|---|
| committer | SulfurNitride <SulfurNitride@users.noreply.github.com> | 2026-02-11 02:37:39 -0600 |
| commit | 7ee008e150bc5bcf76082d726f719ee0fdfda982 (patch) | |
| tree | 27fb39be241fdb5ac2734c574de678977d1856d0 /libs/libbsarch/src/utils | |
Fluorine Manager: full Linux port of Mod Organizer 2
Complete native Linux port with FUSE-based virtual filesystem,
Proton/umu-run integration, and Flatpak packaging.
Key features:
- FUSE VFS replacing Windows USVFS (in-process + standalone helper for Flatpak)
- Proton/GE-Proton/umu-run launcher with env var forwarding
- Flatpak support (sandbox-aware VFS, NXM handler, umu-run)
- Wine prefix management UI
- Case-insensitive path resolution for Linux filesystems
- QSettings-safe INI handling (avoids Bethesda INI corruption)
- Portable instance support with auto-generated launcher scripts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'libs/libbsarch/src/utils')
| -rw-r--r-- | libs/libbsarch/src/utils/convertible_ostream.cpp | 58 | ||||
| -rw-r--r-- | libs/libbsarch/src/utils/convertible_string.cpp | 108 | ||||
| -rw-r--r-- | libs/libbsarch/src/utils/string_convert.cpp | 39 |
3 files changed, 205 insertions, 0 deletions
diff --git a/libs/libbsarch/src/utils/convertible_ostream.cpp b/libs/libbsarch/src/utils/convertible_ostream.cpp new file mode 100644 index 0000000..d5ac238 --- /dev/null +++ b/libs/libbsarch/src/utils/convertible_ostream.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2019 G'k + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#include "convertible_ostream.hpp" + +namespace libbsarch { +convertible_ostream &convertible_ostream::operator<<(const std::string &rh) +{ + std::cout << rh; + return *this; +} +convertible_ostream &convertible_ostream::operator<<(const char *rh) +{ + std::cout << rh; + return *this; +} +convertible_ostream &convertible_ostream::operator<<(const char rh) +{ + std::cout << rh; + return *this; +} +convertible_ostream &convertible_ostream::operator<<(const std::wstring &rh) +{ + std::wcout << rh; + return *this; +} +convertible_ostream &convertible_ostream::operator<<(const void *rh) +{ + std::cout << rh; + return *this; +} +convertible_ostream &convertible_ostream::operator<<(const convertible_string &rh) +{ + return *this << std::string(rh); +} + +convertible_ostream::operator std::ostream &() +{ + return std::cout; +} +convertible_ostream::operator std::wostream &() +{ + return std::wcout; +} + +#ifdef LIBBSARCH_QT_SUPPORT +convertible_ostream::operator QDebug() +{ + return qDebug(); +} +convertible_ostream &convertible_ostream::operator<<(const QString &rh) +{ + qDebug() << rh; + return *this; +} +#endif +} // namespace libbsarch diff --git a/libs/libbsarch/src/utils/convertible_string.cpp b/libs/libbsarch/src/utils/convertible_string.cpp new file mode 100644 index 0000000..c965202 --- /dev/null +++ b/libs/libbsarch/src/utils/convertible_string.cpp @@ -0,0 +1,108 @@ +/* Copyright (C) 2019 G'k + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "convertible_string.hpp" +#include <cwchar> +#include <filesystem> + +namespace libbsarch { +/* conversion ctors */ +convertible_string::convertible_string(std::string value, bool to_native_path) + : str_(std::move(value)) + , auto_convert_to_native_path(to_native_path) +{ + if (auto_convert_to_native_path) + this->to_native_path(); +} + +convertible_string::convertible_string(const char *const val_array, bool to_native_path) + : str_(std::string(val_array)) + , auto_convert_to_native_path(to_native_path) + +{ + if (auto_convert_to_native_path) + this->to_native_path(); +} +convertible_string::convertible_string(const std::wstring &wvalue, bool to_native_path) + : str_(to_string(wvalue)) + , auto_convert_to_native_path(to_native_path) + +{ + if (auto_convert_to_native_path) + this->to_native_path(); +} +convertible_string::convertible_string(wchar_t const *wval_array, bool to_native_path) + : str_(to_string(std::wstring(wval_array))) + , auto_convert_to_native_path(to_native_path) +{ + if (auto_convert_to_native_path) + this->to_native_path(); +} + +/* assignment operators */ +convertible_string &convertible_string::operator=(const std::string &value) +{ + str_ = value; + if (auto_convert_to_native_path) + this->to_native_path(); + return *this; +} +convertible_string &convertible_string::operator=(const std::wstring &wvalue) +{ + str_ = to_string(wvalue); + if (auto_convert_to_native_path) + this->to_native_path(); + return *this; +} + +convertible_string &convertible_string::operator=(const wchar_t *wvalue) +{ + str_ = to_string(std::wstring(wvalue)); + if (auto_convert_to_native_path) + this->to_native_path(); + return *this; +} + +/* implicit conversion operators */ +convertible_string::operator std::string() const +{ + return str_; +} +convertible_string::operator std::wstring() const +{ + return to_wstring(str_); +} +convertible_string::operator const wchar_t *() const +{ + const std::wstring wstr = to_wstring(str_); + wchar_t *wchar_array = new wchar_t[wstr.length() + 1]; +#ifdef _WIN32 + wcscpy_s(wchar_array, wstr.length() + 1, wstr.c_str()); +#else + std::wmemcpy(wchar_array, wstr.c_str(), wstr.length() + 1); +#endif + return wchar_array; +} + +/* Util */ +bool convertible_string::remove_substring(const convertible_string &sub_str) +{ + size_t pos = str_.find(sub_str); + if (pos != std::string::npos) + { + str_.erase(pos, std::string(sub_str).length()); + return true; + } + return false; +} + +convertible_string &convertible_string::to_native_path() +{ + std::filesystem::path path(str_); + str_ = path.make_preferred().string(); + return *this; +} + +} // namespace libbsarch diff --git a/libs/libbsarch/src/utils/string_convert.cpp b/libs/libbsarch/src/utils/string_convert.cpp new file mode 100644 index 0000000..1e8ce9e --- /dev/null +++ b/libs/libbsarch/src/utils/string_convert.cpp @@ -0,0 +1,39 @@ +/* Copyright (C) 2019 G'k + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#include "string_convert.hpp" + +#include <cstdlib> +#include <cstring> + +namespace libbsarch { + +std::string to_string(const std::wstring &str) +{ + if (str.empty()) return {}; + std::mbstate_t state{}; + const wchar_t* src = str.data(); + std::size_t len = std::wcsrtombs(nullptr, &src, 0, &state); + if (len == static_cast<std::size_t>(-1)) return {}; + std::string result(len, '\0'); + src = str.data(); + state = std::mbstate_t{}; + std::wcsrtombs(result.data(), &src, len + 1, &state); + return result; +} + +std::wstring to_wstring(const std::string &str) +{ + if (str.empty()) return {}; + std::mbstate_t state{}; + const char* src = str.data(); + std::size_t len = std::mbsrtowcs(nullptr, &src, 0, &state); + if (len == static_cast<std::size_t>(-1)) return {}; + std::wstring result(len, L'\0'); + src = str.data(); + state = std::mbstate_t{}; + std::mbsrtowcs(result.data(), &src, len + 1, &state); + return result; +} +} // namespace libbsarch |
