spelling and formatting

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2023-03-20 16:38:40 -07:00
parent a28193430c
commit 0c986ba4d0
8 changed files with 192 additions and 248 deletions

View File

@ -328,7 +328,7 @@ bool create_link::operator()(const QString& offset, bool dryRun)
}
/**
* @brief make a list off all the links ot make
* @brief make a list off all the links to
* @param offset subdirectory form src to link to dest
* @return if there was an error during the attempt to link
*/
@ -363,7 +363,7 @@ void create_link::make_link_list(const QString& offset)
link_file(src, "");
} else {
if (m_debug)
qDebug() << "linking recursivly:" << src << "to" << dst << "max_depth:" << m_max_depth;
qDebug() << "linking recursively:" << src << "to" << dst << "max_depth:" << m_max_depth;
QDir src_dir(src);
QDirIterator source_it(src, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::Subdirectories);
@ -414,7 +414,7 @@ bool create_link::make_links()
qWarning() << "Failed to link files:" << QString::fromStdString(m_os_err.message());
qDebug() << "Source file:" << src_path;
qDebug() << "Destination file:" << dst_path;
qDebug() << "Error catagory:" << m_os_err.category().name();
qDebug() << "Error category:" << m_os_err.category().name();
qDebug() << "Error code:" << m_os_err.value();
emit linkFailed(src_path, dst_path, QString::fromStdString(m_os_err.message()), m_os_err.value());
} else {
@ -469,7 +469,7 @@ void create_link::runPrivileged(const QString& offset)
in.setDevice(clientConnection);
in.setVersion(QDataStream::Qt_5_0);
qDebug() << "Reading path results from client";
qDebug() << "bytes avalible" << clientConnection->bytesAvailable();
qDebug() << "bytes available" << clientConnection->bytesAvailable();
// Relies on the fact that QDataStream serializes a quint32 into
// sizeof(quint32) bytes
@ -479,7 +479,7 @@ void create_link::runPrivileged(const QString& offset)
in >> blockSize;
qDebug() << "blocksize is" << blockSize;
qDebug() << "bytes avalible" << clientConnection->bytesAvailable();
qDebug() << "bytes available" << clientConnection->bytesAvailable();
if (clientConnection->bytesAvailable() < blockSize || in.atEnd())
return;
@ -506,7 +506,7 @@ void create_link::runPrivileged(const QString& offset)
m_path_results.append(result);
}
gotResults = true;
qDebug() << "results recieved, closing connection";
qDebug() << "results received, closing connection";
clientConnection->close();
});
@ -981,7 +981,7 @@ FilesystemType getFilesystemType(const QString& name)
}
/**
* @brief path to the near ancestor that exsists
* @brief path to the near ancestor that exists
*
*/
QString NearestExistentAncestor(const QString& path)

View File

@ -44,9 +44,9 @@
#include <QDir>
#include <QFlags>
#include <QLocalServer>
#include <QObject>
#include <QThread>
#include <QLocalServer>
namespace FS {
@ -84,7 +84,7 @@ bool ensureFolderPathExists(QString filenamepath);
/**
* @brief Copies a directory and it's contents from src to dest
*/
*/
class copy : public QObject {
Q_OBJECT
public:
@ -167,17 +167,14 @@ class ExternalLinkFileProcess : public QThread {
/**
* @brief links (a file / a directory and it's contents) from src to dest
*/
*/
class create_link : public QObject {
Q_OBJECT
public:
create_link(const QList<LinkPair> path_pairs, QObject* parent = nullptr) : QObject(parent)
{
m_path_pairs.append(path_pairs);
}
create_link(const QList<LinkPair> path_pairs, QObject* parent = nullptr) : QObject(parent) { m_path_pairs.append(path_pairs); }
create_link(const QString& src, const QString& dst, QObject* parent = nullptr) : QObject(parent)
{
LinkPair pair = {src, dst};
LinkPair pair = { src, dst };
m_path_pairs.append(pair);
}
create_link& useHardLinks(const bool useHard)
@ -211,28 +208,23 @@ class create_link : public QObject {
return *this;
}
std::error_code getOSError() {
return m_os_err;
}
std::error_code getOSError() { return m_os_err; }
bool operator()(bool dryRun = false) { return operator()(QString(), dryRun); }
int totalLinked() { return m_linked; }
void runPrivileged() { runPrivileged(QString()); }
void runPrivileged(const QString& offset);
QList<LinkResult> getResults() { return m_path_results; }
signals:
void fileLinked(const QString& srcName, const QString& dstName);
void linkFailed(const QString& srcName, const QString& dstName, const QString& err_msg, int err_value);
void finished();
void finishedPrivileged(bool gotResults);
private:
bool operator()(const QString& offset, bool dryRun = false);
void make_link_list(const QString& offset);
@ -262,9 +254,9 @@ class create_link : public QObject {
* @brief moves a file by renaming it
* @param source source file path
* @param dest destination filepath
*
*
*/
bool move(const QString& source, const QString& dest);
bool move(const QString& source, const QString& dest);
/**
* Delete a folder recursively
@ -274,7 +266,7 @@ bool deletePath(QString path);
/**
* Trash a folder / file
*/
bool trash(QString path, QString *pathInTrash = nullptr);
bool trash(QString path, QString* pathInTrash = nullptr);
QString PathCombine(const QString& path1, const QString& path2);
QString PathCombine(const QString& path1, const QString& path2, const QString& path3);
@ -284,16 +276,15 @@ QString AbsolutePath(const QString& path);
/**
* @brief depth of path. "foo.txt" -> 0 , "bar/foo.txt" -> 1, /baz/bar/foo.txt -> 2, etc.
*
*
* @param path path to measure
* @return int number of componants before base path
* @return int number of components before base path
*/
int PathDepth(const QString& path);
/**
* @brief cut off segments of path untill it is a max of length depth
*
* @brief cut off segments of path until it is a max of length depth
*
* @param path path to truncate
* @param depth max depth of new path
* @return QString truncated path
@ -363,124 +354,118 @@ enum class FilesystemType {
/**
* @brief Ordered Mapping of enum types to reported filesystem names
* this maping is non exsaustive, it just attempts to capture the filesystems which could be reasonalbly be in use .
* this mapping is non exsaustive, it just attempts to capture the filesystems which could be reasonalbly be in use .
* all string values are in uppercase, use `QString.toUpper()` or equivalent during lookup.
*
*
* QMap is ordered
*
*
*/
static const QMap<FilesystemType, QString> s_filesystem_type_names = {
{FilesystemType::FAT, QString("FAT")},
{FilesystemType::NTFS, QString("NTFS")},
{FilesystemType::REFS, QString("REFS")},
{FilesystemType::EXT, QString("EXT")},
{FilesystemType::EXT_2_OLD, QString("EXT_2_OLD")},
{FilesystemType::EXT_2_3_4, QString("EXT2/3/4")},
{FilesystemType::XFS, QString("XFS")},
{FilesystemType::BTRFS, QString("BTRFS")},
{FilesystemType::NFS, QString("NFS")},
{FilesystemType::ZFS, QString("ZFS")},
{FilesystemType::APFS, QString("APFS")},
{FilesystemType::HFS, QString("HFS")},
{FilesystemType::HFSPLUS, QString("HFSPLUS")},
{FilesystemType::HFSX, QString("HFSX")},
{FilesystemType::FUSEBLK, QString("FUSEBLK")},
{FilesystemType::F2FS, QString("F2FS")},
{FilesystemType::UNKNOWN, QString("UNKNOWN")}
};
static const QMap<FilesystemType, QString> s_filesystem_type_names = { { FilesystemType::FAT, QString("FAT") },
{ FilesystemType::NTFS, QString("NTFS") },
{ FilesystemType::REFS, QString("REFS") },
{ FilesystemType::EXT, QString("EXT") },
{ FilesystemType::EXT_2_OLD, QString("EXT_2_OLD") },
{ FilesystemType::EXT_2_3_4, QString("EXT2/3/4") },
{ FilesystemType::XFS, QString("XFS") },
{ FilesystemType::BTRFS, QString("BTRFS") },
{ FilesystemType::NFS, QString("NFS") },
{ FilesystemType::ZFS, QString("ZFS") },
{ FilesystemType::APFS, QString("APFS") },
{ FilesystemType::HFS, QString("HFS") },
{ FilesystemType::HFSPLUS, QString("HFSPLUS") },
{ FilesystemType::HFSX, QString("HFSX") },
{ FilesystemType::FUSEBLK, QString("FUSEBLK") },
{ FilesystemType::F2FS, QString("F2FS") },
{ FilesystemType::UNKNOWN, QString("UNKNOWN") } };
/**
* @brief Ordered Mapping of reported filesystem names to enum types
* this maping is non exsaustive, it just attempts to capture the many way these filesystems could be reported.
* this mapping is non exsaustive, it just attempts to capture the many way these filesystems could be reported.
* all keys are in uppercase, use `QString.toUpper()` or equivalent during lookup.
*
*
* QMap is ordered
*
*
*/
static const QMap<QString, FilesystemType> s_filesystem_type_names_inverse = {
{QString("FAT"), FilesystemType::FAT},
{QString("NTFS"), FilesystemType::NTFS},
{QString("REFS"), FilesystemType::REFS},
{QString("EXT2_OLD"), FilesystemType::EXT_2_OLD},
{QString("EXT_2_OLD"), FilesystemType::EXT_2_OLD},
{QString("EXT2"), FilesystemType::EXT_2_3_4},
{QString("EXT3"), FilesystemType::EXT_2_3_4},
{QString("EXT4"), FilesystemType::EXT_2_3_4},
{QString("EXT2/3/4"), FilesystemType::EXT_2_3_4},
{QString("EXT_2_3_4"), FilesystemType::EXT_2_3_4},
{QString("EXT"), FilesystemType::EXT}, // must come after all other EXT variants to prevent greedy detection
{QString("XFS"), FilesystemType::XFS},
{QString("BTRFS"), FilesystemType::BTRFS},
{QString("NFS"), FilesystemType::NFS},
{QString("ZFS"), FilesystemType::ZFS},
{QString("APFS"), FilesystemType::APFS},
{QString("HFSPLUS"), FilesystemType::HFSPLUS},
{QString("HFSX"), FilesystemType::HFSX},
{QString("HFS"), FilesystemType::HFS},
{QString("FUSEBLK"), FilesystemType::FUSEBLK},
{QString("F2FS"), FilesystemType::F2FS},
{QString("UNKNOWN"), FilesystemType::UNKNOWN}
{ QString("FAT"), FilesystemType::FAT },
{ QString("NTFS"), FilesystemType::NTFS },
{ QString("REFS"), FilesystemType::REFS },
{ QString("EXT2_OLD"), FilesystemType::EXT_2_OLD },
{ QString("EXT_2_OLD"), FilesystemType::EXT_2_OLD },
{ QString("EXT2"), FilesystemType::EXT_2_3_4 },
{ QString("EXT3"), FilesystemType::EXT_2_3_4 },
{ QString("EXT4"), FilesystemType::EXT_2_3_4 },
{ QString("EXT2/3/4"), FilesystemType::EXT_2_3_4 },
{ QString("EXT_2_3_4"), FilesystemType::EXT_2_3_4 },
{ QString("EXT"), FilesystemType::EXT }, // must come after all other EXT variants to prevent greedy detection
{ QString("XFS"), FilesystemType::XFS },
{ QString("BTRFS"), FilesystemType::BTRFS },
{ QString("NFS"), FilesystemType::NFS },
{ QString("ZFS"), FilesystemType::ZFS },
{ QString("APFS"), FilesystemType::APFS },
{ QString("HFSPLUS"), FilesystemType::HFSPLUS },
{ QString("HFSX"), FilesystemType::HFSX },
{ QString("HFS"), FilesystemType::HFS },
{ QString("FUSEBLK"), FilesystemType::FUSEBLK },
{ QString("F2FS"), FilesystemType::F2FS },
{ QString("UNKNOWN"), FilesystemType::UNKNOWN }
};
/**
* @brief Get the string name of Filesystem enum object
*
* @param type
* @return QString
*
* @param type
* @return QString
*/
QString getFilesystemTypeName(FilesystemType type);
/**
* @brief Get the Filesystem enum object from a name
* Does a lookup of the type name and returns an exact match
* Does a lookup of the type name and returns an exact match
*
* @param name
* @return FilesystemType
* @param name
* @return FilesystemType
*/
FilesystemType getFilesystemType(const QString& name);
/**
* @brief Get the Filesystem enum object from a name
* Does a fuzzy lookup of the type name and returns an apropreate match
*
* @param name
* @return FilesystemType
*
* @param name
* @return FilesystemType
*/
FilesystemType getFilesystemTypeFuzzy(const QString& name);
struct FilesystemInfo {
FilesystemType fsType = FilesystemType::UNKNOWN;
QString fsTypeName;
int blockSize;
qint64 bytesAvailable;
qint64 bytesFree;
qint64 bytesTotal;
int blockSize;
qint64 bytesAvailable;
qint64 bytesFree;
qint64 bytesTotal;
QString name;
QString rootPath;
};
/**
* @brief path to the near ancestor that exsists
*
* @brief path to the near ancestor that exists
*
*/
QString NearestExistentAncestor(const QString& path);
/**
* @brief colect information about the filesystem under a file
*
*
*/
FilesystemInfo statFS(const QString& path);
static const QList<FilesystemType> s_clone_filesystems = {
FilesystemType::BTRFS, FilesystemType::APFS, FilesystemType::ZFS,
FilesystemType::XFS, FilesystemType::REFS
};
static const QList<FilesystemType> s_clone_filesystems = { FilesystemType::BTRFS, FilesystemType::APFS, FilesystemType::ZFS,
FilesystemType::XFS, FilesystemType::REFS };
/**
* @brief if the Filesystem is reflink/clone capable
*
* @brief if the Filesystem is reflink/clone capable
*
*/
bool canCloneOnFS(const QString& path);
bool canCloneOnFS(const FilesystemInfo& info);
@ -488,13 +473,13 @@ bool canCloneOnFS(FilesystemType type);
/**
* @brief if the Filesystems are reflink/clone capable and both are on the same device
*
*
*/
bool canClone(const QString& src, const QString& dst);
/**
* @brief Copies a directory and it's contents from src to dest
*/
*/
class clone : public QObject {
Q_OBJECT
public:
@ -535,7 +520,7 @@ class clone : public QObject {
/**
* @brief clone/reflink file from src to dst
*
*
*/
bool clone_file(const QString& src, const QString& dst, std::error_code& ec);
@ -552,8 +537,8 @@ static const QList<FilesystemType> s_non_link_filesystems = {
};
/**
* @brief if the Filesystem is symlink capable
*
* @brief if the Filesystem is symlink capable
*
*/
bool canLinkOnFS(const QString& path);
bool canLinkOnFS(const FilesystemInfo& info);
@ -561,10 +546,10 @@ bool canLinkOnFS(FilesystemType type);
/**
* @brief if the Filesystem is symlink capable on both ends
*
*
*/
bool canLink(const QString& src, const QString& dst);
uintmax_t hardLinkCount(const QString& path);
}
} // namespace FS

View File

@ -1,10 +1,10 @@
#include "InstanceCopyTask.h"
#include "settings/INISettingsObject.h"
#include <QDebug>
#include <QtConcurrentRun>
#include "FileSystem.h"
#include "NullInstance.h"
#include "pathmatcher/RegexpMatcher.h"
#include <QtConcurrentRun>
#include <QDebug>
#include "settings/INISettingsObject.h"
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs)
{
@ -15,17 +15,17 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyP
m_useHardLinks = prefs.isLinkRecursivelyEnabled() && prefs.isUseHardLinksEnabled();
m_copySaves = prefs.isLinkRecursivelyEnabled() && prefs.isDontLinkSavesEnabled() && prefs.isCopySavesEnabled();
m_useClone = prefs.isUseCloneEnabled();
QString filters = prefs.getSelectedFiltersAsRegex();
if (m_useLinks || m_useHardLinks) {
if (!filters.isEmpty()) filters += "|";
if (!filters.isEmpty())
filters += "|";
filters += "instance.cfg";
}
}
qDebug() << "CopyFilters:" << filters;
if (!filters.isEmpty())
{
if (!filters.isEmpty()) {
// Set regex filter:
// FIXME: get this from the original instance type...
auto matcherReal = new RegexpMatcher(filters);
@ -38,14 +38,14 @@ void InstanceCopyTask::executeTask()
{
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
auto copySaves = [&](){
FS::copy savesCopy(FS::PathCombine(m_origInstance->instanceRoot(), "saves") , FS::PathCombine(m_stagingPath, "saves"));
auto copySaves = [&]() {
FS::copy savesCopy(FS::PathCombine(m_origInstance->instanceRoot(), "saves"), FS::PathCombine(m_stagingPath, "saves"));
savesCopy.followSymlinks(true);
return savesCopy();
};
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this, copySaves]{
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this, copySaves] {
if (m_useClone) {
FS::clone folderClone(m_origInstance->instanceRoot(), m_stagingPath);
folderClone.matcher(m_matcher.get());
@ -53,22 +53,22 @@ void InstanceCopyTask::executeTask()
return folderClone();
} else if (m_useLinks || m_useHardLinks) {
FS::create_link folderLink(m_origInstance->instanceRoot(), m_stagingPath);
int depth = m_linkRecursively ? -1 : 0; // we need to at least link the top level instead of the instance folder
int depth = m_linkRecursively ? -1 : 0; // we need to at least link the top level instead of the instance folder
folderLink.linkRecursively(true).setMaxDepth(depth).useHardLinks(m_useHardLinks).matcher(m_matcher.get());
bool there_were_errors = false;
if(!folderLink()){
if (!folderLink()) {
#if defined Q_OS_WIN32
if (!m_useHardLinks) {
qDebug() << "EXPECTED: Link failure, Windows requires permissions for symlinks";
qDebug() << "atempting to run with privelage";
qDebug() << "attempting to run with privelage";
QEventLoop loop;
bool got_priv_results = false;
connect(&folderLink, &FS::create_link::finishedPrivileged, this, [&](bool gotResults){
connect(&folderLink, &FS::create_link::finishedPrivileged, this, [&](bool gotResults) {
if (!gotResults) {
qDebug() << "Privileged run exited without results!";
}
@ -77,7 +77,7 @@ void InstanceCopyTask::executeTask()
});
folderLink.runPrivileged();
loop.exec(); // wait for the finished signal
loop.exec(); // wait for the finished signal
for (auto result : folderLink.getResults()) {
if (result.err_value != 0) {
@ -88,17 +88,17 @@ void InstanceCopyTask::executeTask()
if (m_copySaves) {
there_were_errors |= !copySaves();
}
return got_priv_results && !there_were_errors;
} else {
qDebug() << "Link Failed!" << folderLink.getOSError().value() << folderLink.getOSError().message().c_str();
}
}
#else
qDebug() << "Link Failed!" << folderLink.getOSError().value() << folderLink.getOSError().message().c_str();
#endif
#endif
return false;
}
if (m_copySaves) {
there_were_errors |= !copySaves();
}
@ -119,8 +119,7 @@ void InstanceCopyTask::executeTask()
void InstanceCopyTask::copyFinished()
{
auto successful = m_copyFuture.result();
if(!successful)
{
if (!successful) {
emitFailed(tr("Instance folder copy failed."));
return;
}
@ -130,7 +129,7 @@ void InstanceCopyTask::copyFinished()
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
inst->setName(name());
inst->setIconKey(m_instIcon);
if(!m_keepPlaytime) {
if (!m_keepPlaytime) {
inst->resetTimePlayed();
}
if (m_useLinks)

View File

@ -25,7 +25,6 @@
#include "StringUtils.h"
#include <iostream>
#include <QAccessible>
@ -41,53 +40,47 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdio.h>
#include <windows.h>
#endif
// Snippet from https://github.com/gulrak/filesystem#using-it-as-single-file-header
#ifdef __APPLE__
#include <Availability.h> // for deployment target to support pre-catalina targets without std::fs
#endif // __APPLE__
#include <Availability.h> // for deployment target to support pre-catalina targets without std::fs
#endif // __APPLE__
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif // MacOS min version check
#endif // Other OSes version check
#endif // MacOS min version check
#endif // Other OSes version check
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif
FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv), socket(new QLocalSocket(this))
FileLinkApp::FileLinkApp(int& argc, char** argv) : QCoreApplication(argc, argv), socket(new QLocalSocket(this))
{
#if defined Q_OS_WIN32
// attach the parent console
if(AttachConsole(ATTACH_PARENT_PROCESS))
{
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
// if attach succeeds, reopen and sync all the i/o
if(freopen("CON", "w", stdout))
{
if (freopen("CON", "w", stdout)) {
std::cout.sync_with_stdio();
}
if(freopen("CON", "w", stderr))
{
if (freopen("CON", "w", stderr)) {
std::cerr.sync_with_stdio();
}
if(freopen("CON", "r", stdin))
{
if (freopen("CON", "r", stdin)) {
std::cin.sync_with_stdio();
}
auto out = GetStdHandle (STD_OUTPUT_HANDLE);
auto out = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD written;
const char * endline = "\n";
const char* endline = "\n";
WriteConsole(out, endline, strlen(endline), &written, NULL);
consoleAttached = true;
}
@ -101,10 +94,8 @@ FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv),
QCommandLineParser parser;
parser.setApplicationDescription(QObject::tr("a batch MKLINK program for windows to be used with prismlauncher"));
parser.addOptions({
{{"s", "server"}, "Join the specified server on launch", "pipe name"},
{{"H", "hard"}, "use hard links insted of symbolic", "true/false"}
});
parser.addOptions({ { { "s", "server" }, "Join the specified server on launch", "pipe name" },
{ { "H", "hard" }, "use hard links instead of symbolic", "true/false" } });
parser.addHelpOption();
parser.addVersionOption();
@ -122,63 +113,57 @@ FileLinkApp::FileLinkApp(int &argc, char **argv) : QCoreApplication(argc, argv),
qDebug() << "no server to join";
exit();
}
}
void FileLinkApp::joinServer(QString server)
{
blockSize = 0;
blockSize = 0;
in.setDevice(&socket);
in.setVersion(QDataStream::Qt_5_0);
connect(&socket, &QLocalSocket::connected, this, [&](){
qDebug() << "connected to server";
});
connect(&socket, &QLocalSocket::connected, this, [&]() { qDebug() << "connected to server"; });
connect(&socket, &QLocalSocket::readyRead, this, &FileLinkApp::readPathPairs);
connect(&socket, &QLocalSocket::errorOccurred, this, [&](QLocalSocket::LocalSocketError socketError){
connect(&socket, &QLocalSocket::errorOccurred, this, [&](QLocalSocket::LocalSocketError socketError) {
switch (socketError) {
case QLocalSocket::ServerNotFoundError:
qDebug() << ("The host was not found. Please make sure "
case QLocalSocket::ServerNotFoundError:
qDebug()
<< ("The host was not found. Please make sure "
"that the server is running and that the "
"server name is correct.");
break;
case QLocalSocket::ConnectionRefusedError:
qDebug() << ("The connection was refused by the peer. "
break;
case QLocalSocket::ConnectionRefusedError:
qDebug()
<< ("The connection was refused by the peer. "
"Make sure the server is running, "
"and check that the server name "
"is correct.");
break;
case QLocalSocket::PeerClosedError:
qDebug() << ("The connection was closed by the peer. ");
break;
default:
qDebug() << "The following error occurred: " << socket.errorString();
break;
case QLocalSocket::PeerClosedError:
qDebug() << ("The connection was closed by the peer. ");
break;
default:
qDebug() << "The following error occurred: " << socket.errorString();
}
});
connect(&socket, &QLocalSocket::disconnected, this, [&](){
qDebug() << "dissconnected from server, should exit";
connect(&socket, &QLocalSocket::disconnected, this, [&]() {
qDebug() << "disconnected from server, should exit";
exit();
});
socket.connectToServer(server);
}
void FileLinkApp::runLink()
{
{
std::error_code os_err;
qDebug() << "creating links";
for (auto link : m_links_to_make) {
QString src_path = link.src;
QString dst_path = link.dst;
@ -192,26 +177,25 @@ void FileLinkApp::runLink()
} else {
qDebug() << "making symlink:" << src_path << "to" << dst_path;
fs::create_symlink(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), os_err);
}
}
if (os_err) {
qWarning() << "Failed to link files:" << QString::fromStdString(os_err.message());
qDebug() << "Source file:" << src_path;
qDebug() << "Destination file:" << dst_path;
qDebug() << "Error catagory:" << os_err.category().name();
qDebug() << "Error category:" << os_err.category().name();
qDebug() << "Error code:" << os_err.value();
FS::LinkResult result = {src_path, dst_path, QString::fromStdString(os_err.message()), os_err.value()};
FS::LinkResult result = { src_path, dst_path, QString::fromStdString(os_err.message()), os_err.value() };
m_path_results.append(result);
} else {
FS::LinkResult result = {src_path, dst_path};
FS::LinkResult result = { src_path, dst_path };
m_path_results.append(result);
}
}
sendResults();
qDebug() << "done, should exit soon";
}
void FileLinkApp::sendResults()
@ -245,10 +229,10 @@ void FileLinkApp::sendResults()
}
void FileLinkApp::readPathPairs()
{
{
m_links_to_make.clear();
qDebug() << "Reading path pairs from server";
qDebug() << "bytes avalible" << socket.bytesAvailable();
qDebug() << "bytes available" << socket.bytesAvailable();
if (blockSize == 0) {
// Relies on the fact that QDataStream serializes a quint32 into
// sizeof(quint32) bytes
@ -258,15 +242,15 @@ void FileLinkApp::readPathPairs()
in >> blockSize;
}
qDebug() << "blocksize is" << blockSize;
qDebug() << "bytes avalible" << socket.bytesAvailable();
qDebug() << "bytes available" << socket.bytesAvailable();
if (socket.bytesAvailable() < blockSize || in.atEnd())
return;
quint32 numLinks;
in >> numLinks;
qDebug() << "numLinks" << numLinks;
for(int i = 0; i < numLinks; i++) {
for (int i = 0; i < numLinks; i++) {
FS::LinkPair pair;
in >> pair.src;
in >> pair.dst;
@ -277,17 +261,15 @@ void FileLinkApp::readPathPairs()
runLink();
}
FileLinkApp::~FileLinkApp()
{
{
qDebug() << "link program shutting down";
// Shut down logger by setting the logger function to nothing
qInstallMessageHandler(nullptr);
#if defined Q_OS_WIN32
// Detach from Windows console
if(consoleAttached)
{
if (consoleAttached) {
fclose(stdout);
fclose(stdin);
fclose(stderr);
@ -295,7 +277,3 @@ FileLinkApp::~FileLinkApp()
}
#endif
}

View File

@ -25,30 +25,26 @@
#include <QtCore>
#include <QApplication>
#include <memory>
#include <QDataStream>
#include <QDateTime>
#include <QDebug>
#include <QFlag>
#include <QIcon>
#include <QDateTime>
#include <QUrl>
#include <QDateTime>
#include <QDataStream>
#include <QLocalSocket>
#include <QUrl>
#include <memory>
#define PRISM_EXTERNAL_EXE
#include "FileSystem.h"
class FileLinkApp : public QCoreApplication
{
class FileLinkApp : public QCoreApplication {
// friends for the purpose of limiting access to deprecated stuff
Q_OBJECT
public:
FileLinkApp(int &argc, char **argv);
public:
FileLinkApp(int& argc, char** argv);
virtual ~FileLinkApp();
private:
private:
void joinServer(QString server);
void readPathPairs();
void runLink();

View File

@ -22,10 +22,9 @@
#include "FileLink.h"
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
FileLinkApp ldh(argc, argv);
return ldh.exec();
}

View File

@ -43,15 +43,15 @@
#include "ui/dialogs/IconPickerDialog.h"
#include "BaseVersion.h"
#include "icons/IconList.h"
#include "BaseInstance.h"
#include "InstanceList.h"
#include "FileSystem.h"
#include "BaseVersion.h"
#include "DesktopServices.h"
#include "FileSystem.h"
#include "InstanceList.h"
#include "icons/IconList.h"
CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
:QDialog(parent), ui(new Ui::CopyInstanceDialog), m_original(original)
CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget* parent)
: QDialog(parent), ui(new Ui::CopyInstanceDialog), m_original(original)
{
ui->setupUi(this);
resize(minimumSizeHint());
@ -74,8 +74,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
groupList.push_front("");
ui->groupBox->addItems(groupList);
int index = groupList.indexOf(APPLICATION->instances()->getInstanceGroup(m_original->id()));
if(index == -1)
{
if (index == -1) {
index = 0;
}
ui->groupBox->setCurrentIndex(index);
@ -108,10 +107,8 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
#if defined(Q_OS_WIN)
ui->symbolicLinksCheckbox->setIcon(style()->standardIcon(QStyle::SP_VistaShield));
ui->symbolicLinksCheckbox->setToolTip(
tr("Use symbolic links instead of copying files.") +
tr("\nOn windows symbolic links may require admin permision to create.")
);
ui->symbolicLinksCheckbox->setToolTip(tr("Use symbolic links instead of copying files.") +
tr("\nOn windows symbolic links may require admin permission to create."));
#endif
updateLinkOptions();
@ -119,7 +116,6 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
auto HelpButton = ui->buttonBox->button(QDialogButtonBox::Help);
connect(HelpButton, &QPushButton::clicked, this, &CopyInstanceDialog::help);
}
CopyInstanceDialog::~CopyInstanceDialog()
@ -131,8 +127,7 @@ void CopyInstanceDialog::updateDialogState()
{
auto allowOK = !instName().isEmpty();
auto OkButton = ui->buttonBox->button(QDialogButtonBox::Ok);
if(OkButton->isEnabled() != allowOK)
{
if (OkButton->isEnabled() != allowOK) {
OkButton->setEnabled(allowOK);
}
}
@ -140,8 +135,7 @@ void CopyInstanceDialog::updateDialogState()
QString CopyInstanceDialog::instName() const
{
auto result = ui->instNameTextBox->text().trimmed();
if(result.size())
{
if (result.size()) {
return result;
}
return QString();
@ -162,7 +156,6 @@ const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const
return m_selectedOptions;
}
void CopyInstanceDialog::help()
{
DesktopServices::openUrl(QUrl(BuildConfig.HELP_URL.arg("instance-copy")));
@ -200,7 +193,8 @@ void CopyInstanceDialog::updateLinkOptions()
ui->symbolicLinksCheckbox->setEnabled(m_linkSupported && !ui->hardLinksCheckbox->isChecked() && !ui->useCloneCheckbox->isChecked());
ui->hardLinksCheckbox->setEnabled(m_linkSupported && !ui->symbolicLinksCheckbox->isChecked() && !ui->useCloneCheckbox->isChecked());
ui->symbolicLinksCheckbox->setChecked(m_linkSupported && m_selectedOptions.isUseSymLinksEnabled() && !ui->useCloneCheckbox->isChecked());
ui->symbolicLinksCheckbox->setChecked(m_linkSupported && m_selectedOptions.isUseSymLinksEnabled() &&
!ui->useCloneCheckbox->isChecked());
ui->hardLinksCheckbox->setChecked(m_linkSupported && m_selectedOptions.isUseHardLinksEnabled() && !ui->useCloneCheckbox->isChecked());
bool linksInUse = (ui->symbolicLinksCheckbox->isChecked() || ui->hardLinksCheckbox->isChecked());
@ -220,15 +214,13 @@ void CopyInstanceDialog::on_iconButton_clicked()
IconPickerDialog dlg(this);
dlg.execWithSelection(InstIconKey);
if (dlg.result() == QDialog::Accepted)
{
if (dlg.result() == QDialog::Accepted) {
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
}
}
void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString& arg1)
{
updateDialogState();
}
@ -247,7 +239,6 @@ void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state)
updateSelectAllCheckbox();
}
void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state)
{
m_selectedOptions.enableKeepPlaytime(state == Qt::Checked);
@ -311,7 +302,6 @@ void CopyInstanceDialog::on_recursiveLinkCheckbox_stateChanged(int state)
{
m_selectedOptions.enableLinkRecursively(state == Qt::Checked);
updateLinkOptions();
}
void CopyInstanceDialog::on_dontLinkSavesCheckbox_stateChanged(int state)

View File

@ -22,17 +22,15 @@
class BaseInstance;
namespace Ui
{
namespace Ui {
class CopyInstanceDialog;
}
class CopyInstanceDialog : public QDialog
{
class CopyInstanceDialog : public QDialog {
Q_OBJECT
public:
explicit CopyInstanceDialog(InstancePtr original, QWidget *parent = 0);
public:
explicit CopyInstanceDialog(InstancePtr original, QWidget* parent = 0);
~CopyInstanceDialog();
void updateDialogState();
@ -42,13 +40,12 @@ public:
QString iconKey() const;
const InstanceCopyPrefs& getChosenOptions() const;
public slots:
public slots:
void help();
private
slots:
private slots:
void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1);
void on_instNameTextBox_textChanged(const QString& arg1);
// Checkboxes
void on_selectAllCheckbox_stateChanged(int state);
void on_copySavesCheckbox_stateChanged(int state);
@ -65,14 +62,14 @@ slots:
void on_dontLinkSavesCheckbox_stateChanged(int state);
void on_useCloneCheckbox_stateChanged(int state);
private:
private:
void checkAllCheckboxes(const bool& b);
void updateSelectAllCheckbox();
void updateUseCloneCheckbox();
void updateLinkOptions();
/* data */
Ui::CopyInstanceDialog *ui;
Ui::CopyInstanceDialog* ui;
QString InstIconKey;
InstancePtr m_original;
InstanceCopyPrefs m_selectedOptions;