Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/RA_Integration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@
<ClInclude Include="services\GameIdentifier.hh" />
<ClInclude Include="services\IAudioSystem.hh" />
<ClInclude Include="services\IClipboard.hh" />
<ClInclude Include="services\IConfiguration.hh" />
<ClInclude Include="services\impl\JsonFileWindowConfiguration.hh" />
<ClInclude Include="services\IWindowConfiguration.hh" />
<ClInclude Include="services\ILoginService.hh" />
<ClInclude Include="services\impl\FileLocalStorage.hh" />
<ClInclude Include="services\impl\FileLogger.hh" />
Expand Down
5 changes: 4 additions & 1 deletion src/RA_Integration.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
<ClInclude Include="RA_ImageFactory.h">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="services\IConfiguration.hh">
<ClInclude Include="services\IWindowConfiguration.hh">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="services\impl\JsonFileConfiguration.hh">
Expand Down Expand Up @@ -938,6 +938,9 @@
<ClInclude Include="services\PointerFinder.hh">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="services\impl\JsonFileWindowConfiguration.hh">
<Filter>Services\Impl</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="RA_Shared.rc">
Expand Down
1 change: 1 addition & 0 deletions src/devkit/RADevKit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClInclude Include="data\Value.hh" />
<ClInclude Include="services\Http.hh" />
<ClInclude Include="services\IClock.hh" />
<ClInclude Include="services\IConfiguration.hh" />
<ClInclude Include="services\IDebuggerDetector.hh" />
<ClInclude Include="services\IFileSystem.hh" />
<ClInclude Include="services\IHttpRequester.hh" />
Expand Down
3 changes: 3 additions & 0 deletions src/devkit/RADevKit.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
<ClInclude Include="data\models\AchievementSetModel.hh">
<Filter>data\models</Filter>
</ClInclude>
<ClInclude Include="services\IConfiguration.hh">
<Filter>services</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="util\GSL.cpp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define RA_SERVICES_ICONFIGURATION
#pragma once

#include "ui\Types.hh"
#include "ui\viewmodels\PopupViewModelBase.hh"
#include <string>

namespace ra {
namespace services {
Expand All @@ -21,7 +20,6 @@ enum class Feature
Offline,
};


class IConfiguration
{
public:
Expand Down Expand Up @@ -61,46 +59,20 @@ public:
/// </summary>
virtual void SetFeatureEnabled(Feature nFeature, bool bEnabled) = 0;

/// <summary>
/// Gets where the specified popup should be displayed.
/// </summary>
virtual ra::ui::viewmodels::PopupLocation GetPopupLocation(ra::ui::viewmodels::Popup nPopup) const = 0;

/// <summary>
/// Sets where the specified popup should be displayed.
/// </summary>
virtual void SetPopupLocation(ra::ui::viewmodels::Popup nPopup, ra::ui::viewmodels::PopupLocation nPopupLocation) = 0;

/// <summary>
/// Gets the number of background threads to spawn.
/// </summary>
virtual unsigned int GetNumBackgroundThreads() const = 0;

virtual const std::wstring& GetRomDirectory() const = 0;
virtual void SetRomDirectory(const std::wstring& sValue) = 0;

virtual const std::wstring& GetScreenshotDirectory() const = 0;
virtual void SetScreenshotDirectory(const std::wstring& sValue) = 0;

/// <summary>
/// Gets the remembered position of the window identified by <paramref name="sPositionKey"/>.
/// Gets the directory where screenshots should be stored.
/// </summary>
virtual ra::ui::Position GetWindowPosition(const std::string& sPositionKey) const = 0;

/// <summary>
/// Sets the position to remember for the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual void SetWindowPosition(const std::string& sPositionKey, const ra::ui::Position& oPosition) = 0;

/// <summary>
/// Gets the remembered size of the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual ra::ui::Size GetWindowSize(const std::string& sPositionKey) const = 0;
virtual const std::wstring& GetScreenshotDirectory() const = 0;

/// <summary>
/// Sets the size to remember for the window identified by <paramref name="sPositionKey"/>.
/// Sets the directory where screenshots should be stored.
/// </summary>
virtual void SetWindowSize(const std::string& sPositionKey, const ra::ui::Size& oSize) = 0;
virtual void SetScreenshotDirectory(const std::wstring& sValue) = 0;

/// <summary>
/// Gets whether or not a custom host was provided.
Expand All @@ -117,11 +89,6 @@ public:
/// </summary>
virtual const std::string& GetHostUrl() const = 0;

/// <summary>
/// Gets the URL to the host to communicate with (includes protocol) for image retrieval.
/// </summary>
virtual const std::string& GetImageHostUrl() const = 0;

/// <summary>
/// Saves the current configuration so it can be used in a future session.
/// </summary>
Expand Down
31 changes: 19 additions & 12 deletions src/services/AchievementRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,8 @@ static void HandleAchievementTriggeredEvent(const rc_client_achievement_t& pAchi

ra::services::ServiceLocator::Get<ra::services::IAudioSystem>().PlayAudioFile(sAudioPath);

if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::AchievementTriggered) !=
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::AchievementTriggered) !=
ra::ui::viewmodels::PopupLocation::None)
{
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();
Expand All @@ -1163,8 +1164,8 @@ static void HandleChallengeIndicatorShowEvent(const rc_client_achievement_t& pAc
return;
}

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Challenge) !=
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Challenge) !=
ra::ui::viewmodels::PopupLocation::None)
{
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();
Expand All @@ -1189,8 +1190,8 @@ static void HandleProgressIndicatorUpdateEvent(const rc_client_achievement_t& pA
return;
}

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Progress) != ra::ui::viewmodels::PopupLocation::None)
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Progress) != ra::ui::viewmodels::PopupLocation::None)
{
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();

Expand All @@ -1217,10 +1218,11 @@ static void HandleProgressIndicatorHideEvent()

static void ShowCompletionPopup(uint32_t nGameId, const std::wstring& sTitle, uint32_t nAchievements, uint32_t nPoints, const std::string& sBadgeName)
{
const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Mastery) == ra::ui::viewmodels::PopupLocation::None)
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::Mastery) == ra::ui::viewmodels::PopupLocation::None)
return;

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
const bool bHardcore = pConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore);

const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
Expand Down Expand Up @@ -1293,7 +1295,8 @@ static void HandleLeaderboardStartedEvent(const rc_client_leaderboard_t& pLeader
}

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardStarted) !=
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardStarted) !=
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
Expand All @@ -1315,7 +1318,8 @@ static void HandleLeaderboardFailedEvent(const rc_client_leaderboard_t& pLeaderb
}

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardCanceled) !=
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardCanceled) !=
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
Expand All @@ -1329,7 +1333,8 @@ static void HandleLeaderboardFailedEvent(const rc_client_leaderboard_t& pLeaderb
static void ShowSimplifiedScoreboard(const rc_client_leaderboard_t& pLeaderboard)
{
auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
ra::ui::viewmodels::PopupLocation::None ||
!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
Expand Down Expand Up @@ -1455,7 +1460,8 @@ static void HandleLeaderboardTrackerUpdateEvent(const rc_client_leaderboard_trac
static void HandleLeaderboardTrackerShowEvent(const rc_client_leaderboard_tracker_t& pTracker)
{
const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardTracker) !=
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardTracker) !=
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
Expand All @@ -1475,7 +1481,8 @@ static void HandleLeaderboardScoreboardEvent(const rc_client_leaderboard_scorebo
const rc_client_leaderboard_t& pLeaderboard)
{
auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
const auto& pWindowConfiguration = ra::services::ServiceLocator::Get<ra::services::IWindowConfiguration>();
if (pWindowConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
ra::ui::viewmodels::PopupLocation::None ||
!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
Expand Down
57 changes: 57 additions & 0 deletions src/services/IWindowConfiguration.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef RA_SERVICES_IWINDOWCONFIGURATION
#define RA_SERVICES_IWINDOWCONFIGURATION
#pragma once

#include "ui\Types.hh"
#include "ui\viewmodels\PopupViewModelBase.hh"

namespace ra {
namespace services {

class IWindowConfiguration
{
public:
virtual ~IWindowConfiguration() noexcept = default;
IWindowConfiguration(const IWindowConfiguration&) noexcept = delete;
IWindowConfiguration& operator=(const IWindowConfiguration&) noexcept = delete;
IWindowConfiguration(IWindowConfiguration&&) noexcept = delete;
IWindowConfiguration& operator=(IWindowConfiguration&&) noexcept = delete;

/// <summary>
/// Gets where the specified popup should be displayed.
/// </summary>
virtual ra::ui::viewmodels::PopupLocation GetPopupLocation(ra::ui::viewmodels::Popup nPopup) const = 0;

/// <summary>
/// Sets where the specified popup should be displayed.
/// </summary>
virtual void SetPopupLocation(ra::ui::viewmodels::Popup nPopup, ra::ui::viewmodels::PopupLocation nPopupLocation) = 0;

/// <summary>
/// Gets the remembered position of the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual ra::ui::Position GetWindowPosition(const std::string& sPositionKey) const = 0;

/// <summary>
/// Sets the position to remember for the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual void SetWindowPosition(const std::string& sPositionKey, const ra::ui::Position& oPosition) = 0;

/// <summary>
/// Gets the remembered size of the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual ra::ui::Size GetWindowSize(const std::string& sPositionKey) const = 0;

/// <summary>
/// Sets the size to remember for the window identified by <paramref name="sPositionKey"/>.
/// </summary>
virtual void SetWindowSize(const std::string& sPositionKey, const ra::ui::Size& oSize) = 0;

protected:
IWindowConfiguration() noexcept = default;
};

} // namespace services
} // namespace ra

#endif // !RA_SERVICES_IWINDOWCONFIGURATION
4 changes: 4 additions & 0 deletions src/services/Initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "services\impl\Clock.hh"
#include "services\impl\FileLocalStorage.hh"
#include "services\impl\JsonFileConfiguration.hh"
#include "services\impl\JsonFileWindowConfiguration.hh"
#include "services\impl\LoginService.hh"
#include "services\impl\MessageDispatcher.hh"
#include "services\impl\ThreadPool.hh"
Expand Down Expand Up @@ -141,6 +142,9 @@ void Initialization::RegisterServices(EmulatorID nEmulatorId, const char* sClien
const auto sFilename = ra::util::String::Printf(L"%sRAPrefs_%s.cfg", pFileSystem.BaseDirectory(), sClientName);
pConfiguration->Load(sFilename);

auto pWindowConfiguration = std::make_unique<ra::services::impl::JsonFileWindowConfiguration>(*pConfiguration);
ra::services::ServiceLocator::Provide<ra::services::IWindowConfiguration>(std::move(pWindowConfiguration));

auto pLocalStorage = std::make_unique<ra::services::impl::FileLocalStorage>(pFileSystem);
ra::services::ServiceLocator::Provide<ra::services::ILocalStorage>(std::move(pLocalStorage));

Expand Down
31 changes: 6 additions & 25 deletions src/services/impl/JsonFileConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "services\IFileSystem.hh"
#include "services\ServiceLocator.hh"

#include <rcheevos\src\rapi\rc_api_common.h>

#ifndef RA_UTEST
#include "services\impl\StringTextWriter.hh"
#include "services\impl\WindowsHttpRequester.hh"
Expand Down Expand Up @@ -69,7 +71,6 @@ bool JsonFileConfiguration::Load(const std::wstring& sFilename)
// default values
m_sUsername.clear();
m_sApiToken.clear();
m_sRomDirectory.clear();
m_mWindowPositions.clear();
m_nBackgroundThreads = 8;
m_vEnabledFeatures =
Expand Down Expand Up @@ -133,8 +134,6 @@ bool JsonFileConfiguration::Load(const std::wstring& sFilename)

if (doc.HasMember("Num Background Threads"))
m_nBackgroundThreads = doc["Num Background Threads"].GetUint();
if (doc.HasMember("ROM Directory"))
m_sRomDirectory = ra::util::String::Widen(doc["ROM Directory"].GetString());

if (doc.HasMember("Window Positions"))
{
Expand Down Expand Up @@ -223,9 +222,6 @@ void JsonFileConfiguration::Save() const
doc.AddMember("Prefer Decimal", IsFeatureEnabled(Feature::PreferDecimal), a);
doc.AddMember("Num Background Threads", m_nBackgroundThreads, a);

if (!m_sRomDirectory.empty())
doc.AddMember("ROM Directory", ra::util::String::Narrow(m_sRomDirectory), a);

if (!m_sScreenshotDirectory.empty())
doc.AddMember("Screenshot Directory", ra::util::String::Narrow(m_sScreenshotDirectory), a);

Expand Down Expand Up @@ -330,14 +326,6 @@ const std::string& JsonFileConfiguration::GetHostUrl() const
return m_sHostUrl;
}

const std::string& JsonFileConfiguration::GetImageHostUrl() const
{
if (m_sImageHostUrl.empty())
GSL_SUPPRESS_TYPE3 const_cast<JsonFileConfiguration*>(this)->ReadHostFile();

return m_sImageHostUrl;
}

void JsonFileConfiguration::ReadHostFile()
{
const auto& pFileSystem = ra::services::ServiceLocator::Get<ra::services::IFileSystem>();
Expand All @@ -356,9 +344,7 @@ void JsonFileConfiguration::UpdateHost()
if (m_sHostName.empty())
{
m_bCustomHost = false;
m_sHostName = "retroachievements.org";
m_sHostUrl = "https://retroachievements.org";
m_sImageHostUrl = "http://i.retroachievements.org";
m_sHostUrl = rc_api_default_host();

#ifndef RA_UTEST
const auto sOSVersion = ra::ui::win32::Desktop::GetWindowsVersionString();
Expand Down Expand Up @@ -389,7 +375,7 @@ void JsonFileConfiguration::UpdateHost()
"An error occurred trying to communicate with the server via secure protocols. Switching to non-secure protocols.\n\n"
"retroachievements.org requires TLS 1.2 or higher. You may need to manually enable it on this operating system. Note that non-secure protocols are deprecated and will no longer be allowed at some point in the future.",
"Security Error", MB_OK);
m_sHostUrl = "http://retroachievements.org";
m_sHostUrl.erase(m_sHostUrl.begin() + 4, m_sHostUrl.begin() + 5);
}
}
}
Expand All @@ -402,18 +388,13 @@ void JsonFileConfiguration::UpdateHost()

const auto nIndex = m_sHostName.find("://");
if (nIndex == std::string::npos)
{
m_sHostUrl = "http://" + m_sHostName;
}
else
{
m_sHostUrl.swap(m_sHostName);
m_sHostName = m_sHostUrl.substr(nIndex + 3);
}

m_sImageHostUrl = m_sHostUrl;
}

m_sHostName = m_sHostUrl.substr(m_sHostUrl.find("://") + 3);

RA_LOG_INFO("Using server: %s", m_sHostUrl.c_str());
}

Expand Down
Loading
Loading