1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

Network stack is now configurable, and resolution is also configurable, but loading cursors causes a page-fault?

This commit is contained in:
Christopher Dumas 2019-05-24 21:10:23 -07:00 committed by Andreas Kling
parent 9d2b08e06e
commit d4a16d6031
7 changed files with 160 additions and 34 deletions

View file

@ -21,6 +21,12 @@ Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
return adopt(*new CConfigFile(path));
}
Retained<CConfigFile> CConfigFile::get_for_system(const String& app_name)
{
auto path = String::format("/etc/%s.ini", app_name.characters());
return adopt(*new CConfigFile(path));
}
CConfigFile::CConfigFile(const String& file_name)
: m_file_name(file_name)
{
@ -105,6 +111,30 @@ int CConfigFile::read_num_entry(const String& group, const String &key, int defa
return value;
}
Color CConfigFile::read_color_entry(const String& group, const String &key, Color default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_color_entry(group, key, default_value);
return default_value;
}
Vector<String> shades = read_entry(group, key).split(',');
bool ok = shades.size() >= 3;
Color value;
if (shades.size() == 3)
value = Color(shades[0].to_uint(ok),
shades[1].to_uint(ok),
shades[2].to_uint(ok));
else
value = Color(shades[0].to_uint(ok),
shades[1].to_uint(ok),
shades[2].to_uint(ok),
shades[3].to_uint(ok));
if (!ok)
return default_value;
return value;
}
bool CConfigFile::read_bool_entry(const String& group, const String &key, bool default_value) const
{
return read_entry(group, key, default_value ? "1" : "0") == "1";
@ -120,6 +150,13 @@ void CConfigFile::write_num_entry(const String& group, const String& key, int va
{
write_entry(group, key, String::format("%d", value));
}
void CConfigFile::write_color_entry(const String& group, const String& key, Color value)
{
write_entry(group, key, String::format("%d,%d,%d,%d", value.red(),
value.green(),
value.blue(),
value.alpha()));
}
bool CConfigFile::sync()
{

View file

@ -1,5 +1,6 @@
#pragma once
#include <SharedGraphics/Color.h>
#include <AK/Vector.h>
#include <AK/HashMap.h>
#include <AK/AKString.h>
@ -9,6 +10,7 @@
class CConfigFile : public Retainable<CConfigFile> {
public:
static Retained<CConfigFile> get_for_app(const String& app_name);
static Retained<CConfigFile> get_for_system(const String& app_name);
~CConfigFile();
bool has_group(const String&) const;
@ -20,10 +22,12 @@ public:
String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
int read_num_entry(const String& group, const String& key, int default_value = 0) const;
bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
Color read_color_entry(const String& group, const String &key, Color default_value) const;
void write_entry(const String& group, const String& key, const String &value);
void write_num_entry(const String& group, const String& key, int value);
void write_bool_entry(const String& group, const String& key, bool value);
void write_color_entry(const String& group, const String& key, Color value);
void dump() const;
@ -34,6 +38,8 @@ public:
void remove_group(const String& group);
void remove_entry(const String& group, const String& key);
String file_name() const { return m_file_name; }
private:
explicit CConfigFile(const String& file_name);