mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-19 13:15:45 -04:00
SDL: Move SDLSettingsInterface (ini) to frontend-common
This commit is contained in:
@ -6,12 +6,10 @@ add_executable(duckstation-sdl
|
||||
opengl_host_display.h
|
||||
sdl_host_interface.cpp
|
||||
sdl_host_interface.h
|
||||
sdl_settings_interface.cpp
|
||||
sdl_settings_interface.h
|
||||
)
|
||||
|
||||
target_include_directories(duckstation-sdl PRIVATE ${SDL2_INCLUDE_DIRS})
|
||||
target_link_libraries(duckstation-sdl PRIVATE core common imgui nativefiledialog glad simpleini frontend-common ${SDL2_LIBRARIES})
|
||||
target_link_libraries(duckstation-sdl PRIVATE core common imgui nativefiledialog glad frontend-common ${SDL2_LIBRARIES})
|
||||
|
||||
if(WIN32)
|
||||
target_sources(duckstation-sdl PRIVATE
|
||||
|
@ -57,14 +57,12 @@
|
||||
<ClCompile Include="opengl_host_display.cpp" />
|
||||
<ClCompile Include="sdl_host_interface.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="sdl_settings_interface.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="d3d11_host_display.h" />
|
||||
<ClInclude Include="imgui_impl_sdl.h" />
|
||||
<ClInclude Include="opengl_host_display.h" />
|
||||
<ClInclude Include="sdl_host_interface.h" />
|
||||
<ClInclude Include="sdl_settings_interface.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Manifest Include="duckstation-sdl.manifest" />
|
||||
|
@ -5,14 +5,12 @@
|
||||
<ClCompile Include="opengl_host_display.cpp" />
|
||||
<ClCompile Include="sdl_host_interface.cpp" />
|
||||
<ClCompile Include="d3d11_host_display.cpp" />
|
||||
<ClCompile Include="sdl_settings_interface.cpp" />
|
||||
<ClCompile Include="imgui_impl_sdl.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="opengl_host_display.h" />
|
||||
<ClInclude Include="sdl_host_interface.h" />
|
||||
<ClInclude Include="d3d11_host_display.h" />
|
||||
<ClInclude Include="sdl_settings_interface.h" />
|
||||
<ClInclude Include="imgui_impl_sdl.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -9,11 +9,11 @@
|
||||
#include "core/system.h"
|
||||
#include "frontend-common/icon.h"
|
||||
#include "frontend-common/imgui_styles.h"
|
||||
#include "frontend-common/ini_settings_interface.h"
|
||||
#include "frontend-common/sdl_audio_stream.h"
|
||||
#include "frontend-common/sdl_controller_interface.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "opengl_host_display.h"
|
||||
#include "sdl_settings_interface.h"
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <imgui.h>
|
||||
@ -268,7 +268,7 @@ void SDLHostInterface::RunLater(std::function<void()> callback)
|
||||
|
||||
void SDLHostInterface::SaveSettings()
|
||||
{
|
||||
SDLSettingsInterface si(GetSettingsFileName().c_str());
|
||||
INISettingsInterface si(GetSettingsFileName().c_str());
|
||||
m_settings_copy.Save(si);
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ std::unique_ptr<SDLHostInterface> SDLHostInterface::Create()
|
||||
std::unique_ptr<SDLHostInterface> intf = std::make_unique<SDLHostInterface>();
|
||||
|
||||
// Settings need to be loaded prior to creating the window for OpenGL bits.
|
||||
SDLSettingsInterface si(intf->GetSettingsFileName().c_str());
|
||||
INISettingsInterface si(intf->GetSettingsFileName().c_str());
|
||||
intf->m_settings_copy.Load(si);
|
||||
intf->m_settings = intf->m_settings_copy;
|
||||
intf->m_fullscreen = intf->m_settings_copy.display_fullscreen;
|
||||
|
@ -1,121 +0,0 @@
|
||||
#include "sdl_settings_interface.h"
|
||||
#include "common/log.h"
|
||||
#include <algorithm>
|
||||
Log_SetChannel(SDLSettingsInterface);
|
||||
|
||||
SDLSettingsInterface::SDLSettingsInterface(const char* filename) : m_filename(filename), m_ini(true, true)
|
||||
{
|
||||
SI_Error err = m_ini.LoadFile(filename);
|
||||
if (err != SI_OK)
|
||||
Log_WarningPrintf("Settings could not be loaded from '%s', defaults will be used.", filename);
|
||||
}
|
||||
|
||||
SDLSettingsInterface::~SDLSettingsInterface()
|
||||
{
|
||||
if (m_dirty)
|
||||
{
|
||||
SI_Error err = m_ini.SaveFile(m_filename.c_str(), false);
|
||||
if (err != SI_OK)
|
||||
Log_WarningPrintf("Failed to save settings to '%s'.", m_filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::Clear()
|
||||
{
|
||||
m_ini.Reset();
|
||||
}
|
||||
|
||||
int SDLSettingsInterface::GetIntValue(const char* section, const char* key, int default_value /*= 0*/)
|
||||
{
|
||||
return static_cast<int>(m_ini.GetLongValue(section, key, default_value));
|
||||
}
|
||||
|
||||
float SDLSettingsInterface::GetFloatValue(const char* section, const char* key, float default_value /*= 0.0f*/)
|
||||
{
|
||||
return static_cast<float>(m_ini.GetDoubleValue(section, key, default_value));
|
||||
}
|
||||
|
||||
bool SDLSettingsInterface::GetBoolValue(const char* section, const char* key, bool default_value /*= false*/)
|
||||
{
|
||||
return m_ini.GetBoolValue(section, key, default_value);
|
||||
}
|
||||
|
||||
std::string SDLSettingsInterface::GetStringValue(const char* section, const char* key,
|
||||
const char* default_value /*= ""*/)
|
||||
{
|
||||
return m_ini.GetValue(section, key, default_value);
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::SetIntValue(const char* section, const char* key, int value)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.SetLongValue(section, key, static_cast<long>(value), nullptr, false, true);
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::SetFloatValue(const char* section, const char* key, float value)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.SetDoubleValue(section, key, static_cast<double>(value), nullptr, true);
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::SetBoolValue(const char* section, const char* key, bool value)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.SetBoolValue(section, key, value, nullptr, true);
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::SetStringValue(const char* section, const char* key, const char* value)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.SetValue(section, key, value, nullptr, true);
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::DeleteValue(const char* section, const char* key)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.Delete(section, key);
|
||||
}
|
||||
|
||||
std::vector<std::string> SDLSettingsInterface::GetStringList(const char* section, const char* key)
|
||||
{
|
||||
std::list<CSimpleIniA::Entry> entries;
|
||||
if (!m_ini.GetAllValues(section, key, entries))
|
||||
return {};
|
||||
|
||||
std::vector<std::string> ret;
|
||||
ret.reserve(entries.size());
|
||||
std::transform(entries.begin(), entries.end(), std::back_inserter(ret),
|
||||
[](const CSimpleIniA::Entry& it) { return std::string(it.pItem); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SDLSettingsInterface::SetStringList(const char* section, const char* key,
|
||||
const std::vector<std::string_view>& items)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_ini.Delete(section, key);
|
||||
|
||||
for (const std::string_view& sv : items)
|
||||
m_ini.SetValue(section, key, std::string(sv).c_str(), nullptr, false);
|
||||
}
|
||||
|
||||
bool SDLSettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
|
||||
{
|
||||
m_dirty = true;
|
||||
return m_ini.DeleteValue(section, key, item, true);
|
||||
}
|
||||
|
||||
bool SDLSettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
|
||||
{
|
||||
std::list<CSimpleIniA::Entry> entries;
|
||||
if (m_ini.GetAllValues(section, key, entries) &&
|
||||
std::find_if(entries.begin(), entries.end(),
|
||||
[item](const CSimpleIniA::Entry& e) { return (std::strcmp(e.pItem, item) == 0); }) != entries.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_dirty = true;
|
||||
m_ini.SetValue(section, key, item, nullptr, false);
|
||||
return true;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include "core/settings.h"
|
||||
|
||||
#include "SimpleIni.h"
|
||||
|
||||
class SDLSettingsInterface : public SettingsInterface
|
||||
{
|
||||
public:
|
||||
SDLSettingsInterface(const char* filename);
|
||||
~SDLSettingsInterface();
|
||||
|
||||
void Clear() override;
|
||||
|
||||
int GetIntValue(const char* section, const char* key, int default_value = 0) override;
|
||||
float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) override;
|
||||
bool GetBoolValue(const char* section, const char* key, bool default_value = false) override;
|
||||
std::string GetStringValue(const char* section, const char* key, const char* default_value = "") override;
|
||||
|
||||
void SetIntValue(const char* section, const char* key, int value) override;
|
||||
void SetFloatValue(const char* section, const char* key, float value) override;
|
||||
void SetBoolValue(const char* section, const char* key, bool value) override;
|
||||
void SetStringValue(const char* section, const char* key, const char* value) override;
|
||||
void DeleteValue(const char* section, const char* key) override;
|
||||
|
||||
std::vector<std::string> GetStringList(const char* section, const char* key) override;
|
||||
void SetStringList(const char* section, const char* key, const std::vector<std::string_view>& items) override;
|
||||
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
|
||||
bool AddToStringList(const char* section, const char* key, const char* item) override;
|
||||
|
||||
private:
|
||||
std::string m_filename;
|
||||
CSimpleIniA m_ini;
|
||||
bool m_dirty = false;
|
||||
};
|
Reference in New Issue
Block a user