refactor: move FS's toStdString to StringUtils
This is so that anyone can use it :) Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
353b51f11e
commit
ab6c7244fc
@ -44,7 +44,9 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "DesktopServices.h"
|
#include "DesktopServices.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
#if defined Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
@ -79,22 +81,6 @@ namespace fs = std::filesystem;
|
|||||||
namespace fs = ghc::filesystem;
|
namespace fs = ghc::filesystem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined Q_OS_WIN32
|
|
||||||
|
|
||||||
std::wstring toStdString(QString s)
|
|
||||||
{
|
|
||||||
return s.toStdWString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
std::string toStdString(QString s)
|
|
||||||
{
|
|
||||||
return s.toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace FS {
|
namespace FS {
|
||||||
|
|
||||||
void ensureExists(const QDir& dir)
|
void ensureExists(const QDir& dir)
|
||||||
@ -191,7 +177,7 @@ bool copy::operator()(const QString& offset)
|
|||||||
auto dst_path = PathCombine(dst, relative_dst_path);
|
auto dst_path = PathCombine(dst, relative_dst_path);
|
||||||
ensureFilePathExists(dst_path);
|
ensureFilePathExists(dst_path);
|
||||||
|
|
||||||
fs::copy(toStdString(src_path), toStdString(dst_path), opt, err);
|
fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
|
||||||
if (err) {
|
if (err) {
|
||||||
qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
|
qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
|
||||||
qDebug() << "Source file:" << src_path;
|
qDebug() << "Source file:" << src_path;
|
||||||
@ -213,7 +199,7 @@ bool copy::operator()(const QString& offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the root src is not a directory, the previous iterator won't run.
|
// If the root src is not a directory, the previous iterator won't run.
|
||||||
if (!fs::is_directory(toStdString(src)))
|
if (!fs::is_directory(StringUtils::toStdString(src)))
|
||||||
copy_file(src, "");
|
copy_file(src, "");
|
||||||
|
|
||||||
return err.value() == 0;
|
return err.value() == 0;
|
||||||
@ -223,7 +209,7 @@ bool deletePath(QString path)
|
|||||||
{
|
{
|
||||||
std::error_code err;
|
std::error_code err;
|
||||||
|
|
||||||
fs::remove_all(toStdString(path), err);
|
fs::remove_all(StringUtils::toStdString(path), err);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
qWarning() << "Failed to remove files:" << QString::fromStdString(err.message());
|
qWarning() << "Failed to remove files:" << QString::fromStdString(err.message());
|
||||||
@ -414,7 +400,7 @@ bool overrideFolder(QString overwritten_path, QString override_path)
|
|||||||
fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing;
|
fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing;
|
||||||
|
|
||||||
// FIXME: hello traveller! Apparently std::copy does NOT overwrite existing files on GNU libstdc++ on Windows?
|
// FIXME: hello traveller! Apparently std::copy does NOT overwrite existing files on GNU libstdc++ on Windows?
|
||||||
fs::copy(toStdString(override_path), toStdString(overwritten_path), opt, err);
|
fs::copy(StringUtils::toStdString(override_path), StringUtils::toStdString(overwritten_path), opt, err);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path);
|
qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path);
|
||||||
|
@ -3,5 +3,18 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace StringUtils {
|
namespace StringUtils {
|
||||||
|
|
||||||
|
#if defined Q_OS_WIN32
|
||||||
|
inline std::wstring toStdString(QString s)
|
||||||
|
{
|
||||||
|
return s.toStdWString();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline std::string toStdString(QString s)
|
||||||
|
{
|
||||||
|
return s.toStdString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs);
|
int naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs);
|
||||||
} // namespace StringUtils
|
} // namespace StringUtils
|
||||||
|
Loading…
Reference in New Issue
Block a user