Cleanup codebase

for FileSystem.cpp:
Instead of checking if Linux or FreeBSD, check if its not Windows and not OSX. Chances are other operating systems run a DE that adheres to the XDG Desktop standard (.desktop). The check isn't good enough anyways since alternative shells for Windows exist, it will never be an accurate check. In any case this function is unused.

WorldListPage.cpp:
Redo confusing switch statement plagued with fall throughs, now well defined.

LaunchController.cpp:
Remove cringe. Also fix warning and make the unimplemented case(s) more explicit.

VersionProxyModel.cpp:
Add fallthrough for warning suppression.

WorldListPage.cpp:
redo `mceditState`

TranslationsModel.cpp:
Move up definition of `column` variable to when it is needed, clear up switch cases

FlameInstanceCreationTask.cpp:
Fallthrough intentionally

SkinUpload.cpp:
Make `getVariant`

ResourcePack.cpp:
Add new values for 1.19.3+

meta/Index.cpp:
Make clear switch statement behavior

JavaWizardPage.cpp:
Fix case fallthrough

Yggdrasil.cpp:
Fix case fallthrough

AccountList.cpp:
Fix case fallthrough,

WinDarkmode.cpp:
Add an explanation and fix warnings due to FARPROC casts.

Signed-off-by: jdp_ <42700985+jdpatdiscord@users.noreply.github.com>
This commit is contained in:
jdp_ 2023-05-07 03:55:56 -04:00
parent 1f4d9cc12f
commit 9cb6200081
17 changed files with 67 additions and 76 deletions

View File

@ -363,7 +363,7 @@ QString getDesktopDir()
// Cross-platform Shortcut creation // Cross-platform Shortcut creation
bool createShortCut(QString location, QString dest, QStringList args, QString name, QString icon) bool createShortCut(QString location, QString dest, QStringList args, QString name, QString icon)
{ {
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) #if !defined(Q_OS_WIN) && !defined(Q_OS_OSX)
location = PathCombine(location, name + ".desktop"); location = PathCombine(location, name + ".desktop");
QFile f(location); QFile f(location);
@ -389,25 +389,6 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na
f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther);
return true; return true;
#elif defined Q_OS_WIN
// TODO: Fix
// QFile file(PathCombine(location, name + ".lnk"));
// WCHAR *file_w;
// WCHAR *dest_w;
// WCHAR *args_w;
// file.fileName().toWCharArray(file_w);
// dest.toWCharArray(dest_w);
// QString argStr;
// for (int i = 0; i < args.count(); i++)
// {
// argStr.append(args[i]);
// argStr.append(" ");
// }
// argStr.toWCharArray(args_w);
// return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
return false;
#else #else
qWarning("Desktop Shortcuts not supported on your platform!"); qWarning("Desktop Shortcuts not supported on your platform!");
return false; return false;

View File

@ -190,7 +190,7 @@ void LaunchController::login() {
switch(m_accountToUse->accountState()) { switch(m_accountToUse->accountState()) {
case AccountState::Offline: { case AccountState::Offline: {
m_session->wants_online = false; m_session->wants_online = false;
// NOTE: fallthrough is intentional [[fallthrough]];
} }
case AccountState::Online: { case AccountState::Online: {
if(!m_session->wants_online) { if(!m_session->wants_online) {
@ -223,7 +223,6 @@ void LaunchController::login() {
APPLICATION->settings()->set("LastOfflinePlayerName", usedname); APPLICATION->settings()->set("LastOfflinePlayerName", usedname);
} }
m_session->MakeOffline(usedname); m_session->MakeOffline(usedname);
// offline flavored game from here :3
} }
if(m_accountToUse->ownsMinecraft()) { if(m_accountToUse->ownsMinecraft()) {
if(!m_accountToUse->hasProfile()) { if(!m_accountToUse->hasProfile()) {
@ -270,7 +269,7 @@ void LaunchController::login() {
// This means some sort of soft error that we can fix with a refresh ... so let's refresh. // This means some sort of soft error that we can fix with a refresh ... so let's refresh.
case AccountState::Unchecked: { case AccountState::Unchecked: {
m_accountToUse->refresh(); m_accountToUse->refresh();
// NOTE: fallthrough intentional [[fallthrough]];
} }
case AccountState::Working: { case AccountState::Working: {
// refresh is in progress, we need to wait for it to finish to proceed. // refresh is in progress, we need to wait for it to finish to proceed.
@ -283,12 +282,11 @@ void LaunchController::login() {
progDialog.execWithTask(task.get()); progDialog.execWithTask(task.get());
continue; continue;
} }
// FIXME: this is missing - the meaning is that the account is queued for refresh and we should wait for that
/*
case AccountState::Queued: { case AccountState::Queued: {
// FIXME: this is missing - the meaning is that the account is queued for refresh and we should wait for that
qWarning() << "AccountState::Queued is not implemented";
return; return;
} }
*/
case AccountState::Expired: { case AccountState::Expired: {
auto errorString = tr("The account has expired and needs to be logged into manually again."); auto errorString = tr("The account has expired and needs to be logged into manually again.");
QMessageBox::warning( QMessageBox::warning(
@ -325,6 +323,9 @@ void LaunchController::login() {
emitFailed(errorString); emitFailed(errorString);
return; return;
} }
default: {
qWarning() << "Invalid AccountState enum";
}
} }
} }
emitFailed(tr("Failed to launch.")); emitFailed(tr("Failed to launch."));

View File

@ -211,6 +211,7 @@ QVariant VersionProxyModel::data(const QModelIndex &index, int role) const
return tr("Latest"); return tr("Latest");
} }
} }
[[fallthrough]];
} }
default: default:
{ {
@ -254,6 +255,7 @@ QVariant VersionProxyModel::data(const QModelIndex &index, int role) const
} }
return pixmap; return pixmap;
} }
[[fallthrough]];
} }
default: default:
{ {

View File

@ -45,11 +45,9 @@ QVariant Index::data(const QModelIndex &index, int role) const
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
switch (index.column()) if (index.column() == 0)
{ return list->humanReadable();
case 0: return list->humanReadable(); break;
default: break;
}
case UidRole: return list->uid(); case UidRole: return list->uid();
case NameRole: return list->name(); case NameRole: return list->name();
case ListPtrRole: return QVariant::fromValue(list); case ListPtrRole: return QVariant::fromValue(list);
@ -70,10 +68,7 @@ QVariant Index::headerData(int section, Qt::Orientation orientation, int role) c
{ {
return tr("Name"); return tr("Name");
} }
else
{
return QVariant(); return QVariant();
}
} }
bool Index::hasUid(const QString &uid) const bool Index::hasUid(const QString &uid) const

View File

@ -85,6 +85,7 @@ enum class AccountState {
Disabled, Disabled,
Errored, Errored,
Expired, Expired,
Queued,
Gone Gone
}; };

View File

@ -328,6 +328,12 @@ QVariant AccountList::data(const QModelIndex &index, int role) const
case AccountState::Gone: { case AccountState::Gone: {
return tr("Gone", "Account status"); return tr("Gone", "Account status");
} }
case AccountState::Queued: {
qWarning() << "Unhandled account state Queued";
[[fallthrough]];
}
default:
return tr("Unknown", "Account status");
} }
} }
@ -341,8 +347,9 @@ QVariant AccountList::data(const QModelIndex &index, int role) const
else { else {
return tr("No", "Can Migrate?"); return tr("No", "Can Migrate?");
} }
qWarning() << "Unhandled case in MigrationColumn";
[[fallthrough]];
} }
default: default:
return QVariant(); return QVariant();
} }
@ -359,7 +366,7 @@ QVariant AccountList::data(const QModelIndex &index, int role) const
case ProfileNameColumn: case ProfileNameColumn:
return account == m_defaultAccount ? Qt::Checked : Qt::Unchecked; return account == m_defaultAccount ? Qt::Checked : Qt::Unchecked;
} }
[[fallthrough]];
default: default:
return QVariant(); return QVariant();
} }

View File

@ -273,6 +273,7 @@ void Yggdrasil::processReply() {
AccountTaskState::STATE_FAILED_GONE, AccountTaskState::STATE_FAILED_GONE,
tr("The Mojang account no longer exists. It may have been migrated to a Microsoft account.") tr("The Mojang account no longer exists. It may have been migrated to a Microsoft account.")
); );
break;
} }
default: default:
changeState( changeState(

View File

@ -82,6 +82,8 @@ std::pair<int, bool> Mod::compare(const Resource& other, SortType type) const
auto res = Resource::compare(other, type); auto res = Resource::compare(other, type);
if (res.first != 0) if (res.first != 0)
return res; return res;
// FIXME: Determine if this is a legitimate fallthrough
[[fallthrough]];
} }
case SortType::VERSION: { case SortType::VERSION: {
auto this_ver = Version(version()); auto this_ver = Version(version());

View File

@ -66,6 +66,7 @@ std::pair<int, bool> Resource::compare(const Resource& other, SortType type) con
return { 1, type == SortType::ENABLED }; return { 1, type == SortType::ENABLED };
if (!enabled() && other.enabled()) if (!enabled() && other.enabled())
return { -1, type == SortType::ENABLED }; return { -1, type == SortType::ENABLED };
[[fallthrough]];
case SortType::NAME: { case SortType::NAME: {
QString this_name{ name() }; QString this_name{ name() };
QString other_name{ other.name() }; QString other_name{ other.name() };
@ -76,6 +77,7 @@ std::pair<int, bool> Resource::compare(const Resource& other, SortType type) con
auto compare_result = QString::compare(this_name, other_name, Qt::CaseInsensitive); auto compare_result = QString::compare(this_name, other_name, Qt::CaseInsensitive);
if (compare_result != 0) if (compare_result != 0)
return { compare_result, type == SortType::NAME }; return { compare_result, type == SortType::NAME };
[[fallthrough]];
} }
case SortType::DATE: case SortType::DATE:
if (dateTimeChanged() > other.dateTimeChanged()) if (dateTimeChanged() > other.dateTimeChanged())

View File

@ -11,11 +11,18 @@
// Values taken from: // Values taken from:
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta // https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = { static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = {
{ 1, { Version("1.6.1"), Version("1.8.9") } }, { 2, { Version("1.9"), Version("1.10.2") } }, { 1, { Version("1.6.1"), Version("1.8.9") } },
{ 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } }, { 2, { Version("1.9"), Version("1.10.2") } },
{ 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } }, { 3, { Version("1.11"), Version("1.12.2") } },
{ 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } }, { 4, { Version("1.13"), Version("1.14.4") } },
{ 5, { Version("1.15"), Version("1.16.1") } },
{ 6, { Version("1.16.2"), Version("1.16.5") } },
{ 7, { Version("1.17"), Version("1.17.1") } },
{ 8, { Version("1.18"), Version("1.18.2") } },
{ 9, { Version("1.19"), Version("1.19.2") } }, { 9, { Version("1.19"), Version("1.19.2") } },
{ 12, { Version("1.19.3"), Version("1.19.3") } },
{ 13, { Version("1.19.4"), Version("1.19.4") } },
{ 14, { Version("1.20"), Version("1.20") } }
}; };
void ResourcePack::setPackFormat(int new_format_id) void ResourcePack::setPackFormat(int new_format_id)
@ -85,6 +92,7 @@ std::pair<int, bool> ResourcePack::compare(const Resource& other, SortType type)
auto res = Resource::compare(other, type); auto res = Resource::compare(other, type);
if (res.first != 0) if (res.first != 0)
return res; return res;
[[fallthrough]];
} }
case SortType::PACK_FORMAT: { case SortType::PACK_FORMAT: {
auto this_ver = packFormat(); auto this_ver = packFormat();

View File

@ -42,12 +42,13 @@
QByteArray getVariant(SkinUpload::Model model) { QByteArray getVariant(SkinUpload::Model model) {
switch (model) { switch (model) {
default:
qDebug() << "Unknown skin type!";
case SkinUpload::STEVE: case SkinUpload::STEVE:
return "CLASSIC"; return "CLASSIC";
case SkinUpload::ALEX: case SkinUpload::ALEX:
return "SLIM"; return "SLIM";
default:
qDebug() << "Unknown skin type!";
return "CLASSIC";
} }
} }

View File

@ -405,7 +405,8 @@ NetJob::Ptr EnsureMetadataTask::flameProjectsTask()
QHash<QString, QString> addonIds; QHash<QString, QString> addonIds;
for (auto const& hash : m_mods.keys()) { for (auto const& hash : m_mods.keys()) {
if (m_temp_versions.contains(hash)) { if (m_temp_versions.contains(hash)) {
auto const& data = m_temp_versions.find(hash).value(); auto const& dataObj = m_temp_versions.find(hash);
auto const& data = dataObj.value();
auto id_str = data.addonId.toString(); auto id_str = data.addonId.toString();
if (!id_str.isEmpty()) if (!id_str.isEmpty())

View File

@ -420,7 +420,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
switch (result.type) { switch (result.type) {
case Flame::File::Type::Folder: { case Flame::File::Type::Folder: {
logWarning(tr("This 'Folder' may need extracting: %1").arg(relpath)); logWarning(tr("This 'Folder' may need extracting: %1").arg(relpath));
// fall-through intentional, we treat these as plain old mods and dump them wherever. [[fallthrough]];
} }
case Flame::File::Type::SingleFile: case Flame::File::Type::SingleFile:
case Flame::File::Type::Mod: { case Flame::File::Type::Mod: {

View File

@ -418,8 +418,6 @@ QVariant TranslationsModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
int row = index.row(); int row = index.row();
auto column = static_cast<Column>(index.column());
if (row < 0 || row >= d->m_languages.size()) if (row < 0 || row >= d->m_languages.size())
return QVariant(); return QVariant();
@ -428,22 +426,19 @@ QVariant TranslationsModel::data(const QModelIndex& index, int role) const
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
{ {
auto column = static_cast<Column>(index.column());
switch(column) switch(column)
{ {
case Column::Language: case Column::Language:
{
return lang.languageName(); return lang.languageName();
}
case Column::Completeness: case Column::Completeness:
{
return QString("%1%").arg(lang.percentTranslated(), 3, 'f', 1); return QString("%1%").arg(lang.percentTranslated(), 3, 'f', 1);
} default:
return QVariant();
} }
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
{
return tr("%1:\n%2 translated\n%3 fuzzy\n%4 total").arg(lang.key, QString::number(lang.translated), QString::number(lang.fuzzy), QString::number(lang.total)); return tr("%1:\n%2 translated\n%3 fuzzy\n%4 total").arg(lang.key, QString::number(lang.translated), QString::number(lang.fuzzy), QString::number(lang.total));
}
case Qt::UserRole: case Qt::UserRole:
return lang.key; return lang.key;
default: default:

View File

@ -8,16 +8,15 @@ namespace WinDarkmode {
void setDarkWinTitlebar(WId winid, bool darkmode) void setDarkWinTitlebar(WId winid, bool darkmode)
{ {
HWND hwnd = reinterpret_cast<HWND>(winid); HWND hwnd = reinterpret_cast<HWND>(winid);
BOOL dark = (BOOL) darkmode; BOOL dark = (BOOL)darkmode;
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
HMODULE hUser32 = GetModuleHandleW(L"user32.dll"); HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
fnAllowDarkModeForWindow AllowDarkModeForWindow
= reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133))); // For those confused how this works, dlls have export numbers but some can have no name and these have no name. So an address is gotten by export number. If this ever changes, it will break.
fnSetPreferredAppMode SetPreferredAppMode fnAllowDarkModeForWindow AllowDarkModeForWindow = (fnAllowDarkModeForWindow)(PVOID)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133));
= reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135))); fnSetPreferredAppMode SetPreferredAppMode = (fnSetPreferredAppMode)(PVOID)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
fnSetWindowCompositionAttribute SetWindowCompositionAttribute fnSetWindowCompositionAttribute SetWindowCompositionAttribute = (fnSetWindowCompositionAttribute)(PVOID)GetProcAddress(hUser32, "SetWindowCompositionAttribute");
= reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
SetPreferredAppMode(AllowDark); SetPreferredAppMode(AllowDark);
AllowDarkModeForWindow(hwnd, dark); AllowDarkModeForWindow(hwnd, dark);

View File

@ -312,28 +312,22 @@ void WorldListPage::mceditError()
void WorldListPage::mceditState(LoggedProcess::State state) void WorldListPage::mceditState(LoggedProcess::State state)
{ {
bool failed = false;
switch(state) switch(state)
{ {
case LoggedProcess::NotRunning: case LoggedProcess::NotRunning:
case LoggedProcess::Starting: case LoggedProcess::Starting:
return; return;
case LoggedProcess::Running:
case LoggedProcess::Finished:
m_mceditStarting = false;
return;
case LoggedProcess::FailedToStart: case LoggedProcess::FailedToStart:
case LoggedProcess::Crashed: case LoggedProcess::Crashed:
case LoggedProcess::Aborted: case LoggedProcess::Aborted:
{
failed = true;
}
case LoggedProcess::Running:
case LoggedProcess::Finished:
{
m_mceditStarting = false;
break;
}
}
if(failed)
{
mceditError(); mceditError();
return;
default:
qWarning() << "Invalid MCEdit state";
} }
} }

View File

@ -69,6 +69,7 @@ bool JavaWizardPage::validatePage()
case JavaSettingsWidget::ValidationStatus::AllOK: case JavaSettingsWidget::ValidationStatus::AllOK:
{ {
settings->set("JavaPath", m_java_widget->javaPath()); settings->set("JavaPath", m_java_widget->javaPath());
[[fallthrough]];
} }
case JavaSettingsWidget::ValidationStatus::JavaBad: case JavaSettingsWidget::ValidationStatus::JavaBad:
{ {