Skip to content

Commit

Permalink
fix(C4996): remove deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Dec 15, 2023
1 parent 3e34748 commit f832065
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/RunGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace {
{
// set up the QApplication flags
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
#ifdef Q_OS_WIN32
#if defined(Q_OS_WIN32) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
#endif

Expand Down
62 changes: 21 additions & 41 deletions src/common/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@
#include "common/QLogging.hpp"
#include "util/TypeName.hpp"

#include <QtGlobal>
#include <QVariant>

namespace chatterino {

namespace {

template <typename T>
void warn(const char *envName, T defaultValue)
void warn(const char *envName, const QString &envString, T defaultValue)
{
auto *envString = std::getenv(envName);
if (!envString)
{
// This function is not supposed to be used for non-existant
// environment variables.
return;
}

const auto typeName = QString::fromStdString(
std::string(type_name<decltype(defaultValue)>()));

Expand All @@ -33,54 +26,41 @@ namespace {
.arg(defaultValue);
}

QString readStringEnv(const char *envName, QString defaultValue)
{
auto envString = std::getenv(envName);
if (envString != nullptr)
{
return QString(envString);
}

return defaultValue;
}

std::optional<QString> readOptionalStringEnv(const char *envName)
{
auto envString = std::getenv(envName);
if (envString != nullptr)
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
return QString(envString);
return envString;
}

return std::nullopt;
}

uint16_t readPortEnv(const char *envName, uint16_t defaultValue)
{
auto envString = std::getenv(envName);
if (envString != nullptr)
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
bool ok;
auto val = QString(envString).toUShort(&ok);
bool ok = false;
auto val = envString.toUShort(&ok);
if (ok)
{
return val;
}
else
{
warn(envName, defaultValue);
}

warn(envName, envString, defaultValue);
}

return defaultValue;
}

uint16_t readBoolEnv(const char *envName, bool defaultValue)
bool readBoolEnv(const char *envName, bool defaultValue)
{
auto envString = std::getenv(envName);
if (envString != nullptr)
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
return QVariant(QString(envString)).toBool();
return QVariant(envString).toBool();
}

return defaultValue;
Expand All @@ -90,14 +70,14 @@ namespace {

Env::Env()
: recentMessagesApiUrl(
readStringEnv("CHATTERINO2_RECENT_MESSAGES_URL",
"https://recent-messages.robotty.de/api/v2/"
"recent-messages/%1"))
, linkResolverUrl(readStringEnv(
qEnvironmentVariable("CHATTERINO2_RECENT_MESSAGES_URL",
"https://recent-messages.robotty.de/api/v2/"
"recent-messages/%1"))
, linkResolverUrl(qEnvironmentVariable(
"CHATTERINO2_LINK_RESOLVER_URL",
"https://braize.pajlada.com/chatterino/link_resolver/%1"))
, twitchServerHost(
readStringEnv("CHATTERINO2_TWITCH_SERVER_HOST", "irc.chat.twitch.tv"))
, twitchServerHost(qEnvironmentVariable("CHATTERINO2_TWITCH_SERVER_HOST",
"irc.chat.twitch.tv"))
, twitchServerPort(readPortEnv("CHATTERINO2_TWITCH_SERVER_PORT", 443))
, twitchServerSecure(readBoolEnv("CHATTERINO2_TWITCH_SERVER_SECURE", true))
, proxyUrl(readOptionalStringEnv("CHATTERINO2_PROXY_URL"))
Expand Down
2 changes: 1 addition & 1 deletion src/singletons/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ void WindowManager::applyWindowLayout(const WindowLayout &layout)
// out of bounds windows
auto screens = qApp->screens();
bool outOfBounds =
!getenv("I3SOCK") &&
!qEnvironmentVariableIsSet("I3SOCK") &&
std::none_of(screens.begin(), screens.end(),
[&](QScreen *screen) {
return screen->availableGeometry().intersects(
Expand Down
6 changes: 3 additions & 3 deletions src/util/AttachToConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifdef USEWINSDK
# include <Windows.h>

# include <iostream>
# include <tuple>
#endif

namespace chatterino {
Expand All @@ -13,8 +13,8 @@ void attachToConsole()
#ifdef USEWINSDK
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
std::ignore = freopen_s(nullptr, "CONOUT$", "w", stdout);
std::ignore = freopen_s(nullptr, "CONOUT$", "w", stderr);
}
#endif
}
Expand Down

0 comments on commit f832065

Please sign in to comment.