Fix reading of aegisub config values.

Originally committed to SVN as r5122.
This commit is contained in:
Amar Takhar 2011-01-04 04:23:51 +00:00
parent a0e760c9da
commit 010f3c14e5
3 changed files with 56 additions and 26 deletions

View file

@ -25,6 +25,7 @@
#include "aegisub.h"
#ifdef __WINDOWS__
#include "../src/config.h"
#else
@ -35,14 +36,34 @@ Aegisub::Aegisub() {
wxStandardPathsBase &paths = wxStandardPaths::Get();
// Using ifdefs is a pain but it's much easier to centralise this.
#if defined(__APPLE__)
std::string configdir(wxString::Format("%s-%s", paths.GetUserDataDir(), _T(AEGISUB_VERSION_DATA)));
std::string conf_user(wxString::Format("%s-%s/config.json", paths.GetUserDataDir(), _T(AEGISUB_VERSION_DATA)));
#elif defined(__UNIX__)
std::string configdir(wxString::Format("%s/.aegisub-%s", paths.GetUserConfigDir(), _T(AEGISUB_VERSION_DATA)));
std::string conf_user(wxString::Format("%s/.aegisub-%s/config.json", paths.GetUserConfigDir(), _T(AEGISUB_VERSION_DATA)));
#else
std::string configdir(wxString::Format("%s/Aegisub", paths.GetUserConfigDir()));
std::string conf_user(wxString::Format("%s/Aegisub/config.json", paths.GetUserConfigDir()));
#endif
std::cout << conf_user << std::endl;
std::string default_config("{}");
opt = new agi::Options(conf_user, default_config, agi::Options::FLUSH_SKIP);
}
std::string Aegisub::Read(std::string key) {
Aegisub::~Aegisub() {
delete opt;
}
const std::string Aegisub::GetString(std::string key) {
return opt->Get(key)->GetString();
}
int64_t Aegisub::GetInt(std::string key) {
return opt->Get(key)->GetInt();
}
bool Aegisub::GetBool(std::string key) {
return opt->Get(key)->GetBool();
}

View file

@ -19,17 +19,20 @@
/// @ingroup base
#ifndef R_PRECOMP
#include <wx/fileconf.h>
#endif
#include <libaegisub/option.h>
/// @class Aegisub
/// @brief Gather Aegisub information from the config file or otherwise.
class Aegisub {
private:
wxFileConfig *conf;
agi::Options *opt;
public:
Aegisub();
~Aegisub();
void Config(std::string config);
std::string Read(std::string key);
const agi::OptionValue* Read(std::string key);
const std::string GetString(std::string key);
int64_t GetInt(std::string key);
bool GetBool(std::string key);
};

View file

@ -38,6 +38,7 @@ Report::Report() {
json::Object root;
Platform *p = Platform::GetPlatform();
Aegisub a;
json::Object general;
general["Signature"] = json::String(p->Signature());
@ -54,25 +55,30 @@ Report::Report() {
root["General"] = general;
json::Object aegisub;
/// I'll fix these at the end.
/*
Last Version
Spelling Language
Thesaurus Language
Audio Player
Audio Provider
Video Provider
Subtitles Provider
Save Charset
Grid Font Size
Edit Font Size
Spectrum Enabled
Spectrum Quality
Call Tips Enabled
Medusa Hotkeys Enabled
*/
try {
json::Object aegisub;
aegisub["Last Version"] = json::String(a.GetString("Version/Last Version"));
aegisub["Spelling Language"] = json::String(a.GetString("Tool/Spell Checker/Language"));
aegisub["Thesaurus Language"] = json::String(a.GetString("Tool/Thesaurus/Language"));
aegisub["Audio Player"] = json::String(a.GetString("Audio/Player"));
aegisub["Audio Provider"] = json::String(a.GetString("Audio/Provider"));
aegisub["Video Provider"] = json::String(a.GetString("Video/Provider"));
aegisub["Subtitles Provider"] = json::String(a.GetString("Subtitle/Provider"));
aegisub["Save Charset"] = json::String(a.GetString("App/Save Charset"));
aegisub["Grid Font Size"] = json::Number(a.GetInt("Grid/Font Size"));
aegisub["Edit Font Size"] = json::Number(a.GetInt("Subtitle/Edit Box/Font Size"));
aegisub["Spectrum Enabled"] = json::Boolean(a.GetBool("Audio/Spectrum"));
aegisub["Spectrum Quality"] = json::Number(a.GetInt("Audio/Renderer/Spectrum/Quality"));
aegisub["Call Tips Enabled"] = json::Boolean(a.GetBool("App/Call Tips"));
aegisub["Medusa Hotkeys Enabled"] = json::Boolean(a.GetBool("Audio/Medusa Timing Hotkeys"));
root["Aegisub"] = aegisub;
} catch(...) {
root["Aegisub"]["Error"] = json::String("Config file is corrupted");
}
json::Object hardware;