Ejemplo n.º 1
0
Spectrogram3DVisualizerFactory::Spectrogram3DVisualizerFactory(const IniParser& ini)
{
    this->dB_min = ini.getOptionAsFloat("general", "dB_min");
    this->dB_max = ini.getOptionAsFloat("general", "dB_max");
    this->dB_clip = ini.getOptionAsFloat("general", "dB_clip");
    this->fft_size = ini.getOptionAsUnsignedInteger("fft", "fft_size");
}
Ejemplo n.º 2
0
bool IniParser::save() noexcept
{
	// Check if current file is correct
	IniParser oldFileParser = *this;
	oldFileParser.load();
	if (mIniTree == oldFileParser.mIniTree) return true;

	// Opens the file and clears it
	std::ofstream file{mPath, std::ofstream::out | std::ofstream::trunc};
	if (!file.is_open()) return false;

	// Adds the global items first
	auto globalItr = mIniTree.find("");
	if (globalItr != mIniTree.end()) {
		for (auto& keyPair : globalItr->second) {
			file << keyPair.first << "=" << keyPair.second << "\n";
		}
		file << "\n";
	}

	// Adds the rest of the sections and items
	for (auto& sectionPair : mIniTree) {
		if (sectionPair.first == "") continue;
		file << "[" << sectionPair.first << "]" << "\n";
		
		for (auto& keyPair : sectionPair.second) {
			file << keyPair.first << "=" << keyPair.second << "\n";
		}
		file << "\n";
	}

	file.flush();
	return true;
}
Ejemplo n.º 3
0
int main (int argc, char* argv[]) {
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = &sig_handler;

    sigaction(SIGINT, &sa, NULL);


    IniParser* ini = new IniParser("server.ini");
    documentRoot = ini->get("document_root");
    std::string port = ini->get("port");
    delete(ini);
    
    ServerSocket* server = new ServerSocket(port);
    ClientSocket* client = NULL;

    while (!stop) {
        client = server->accept(true);
        
        if (client != NULL) {
            pthread_t tid;
            pthread_create(&tid, NULL, &clientThread, client);
            pthread_detach(tid);
        }
    }
    
    delete(server);

    std::cout << "Shutdown complete." << std::endl;
    
    return 0;
}
Ejemplo n.º 4
0
void UpdateDlg::InternetUpdate(bool forceDownload)
{
    UpdateStatus(_("Please wait..."));
    m_HasUpdated = false;
    m_Net.SetServer(GetCurrentServer());

    EnableButtons(false);
    forceDownload = forceDownload || !XRCCTRL(*this, "chkCache", wxCheckBox)->GetValue();

    bool forceDownloadMirrors = forceDownload || !wxFileExists(GetMirrorsFilename());
    if (forceDownloadMirrors)
    {
        if (!m_Net.DownloadFile(_T("mirrors.cfg"), GetMirrorsFilename()))
        {
            UpdateStatus(_("Error downloading list of mirrors"), 0, 0);
            return;
        }
        else
        {
            FillServers();
            m_Net.SetServer(GetCurrentServer()); // update server based on mirrors
        }
    }

    wxString config = GetConfFilename();
    forceDownload = forceDownload || !wxFileExists(config);
    if (forceDownload && !m_Net.DownloadFile(_T("webupdate.conf"), config))
    {
        UpdateStatus(_("Error downloading list of updates"), 0, 0);
        return;
    }
    else
    {
        IniParser ini;
        if (!ini.ParseFile(config))
        {
            UpdateStatus(_("Failed to retrieve the list of updates"), 0, 0);
            return;
        }
        ini.Sort();

        if (m_Recs)
            delete[] m_Recs;

        // remember to delete[] m_Recs when we 're done with it!!!
        // it's our responsibility once given to us
        m_Recs = ReadConf(ini, &m_RecsCount, GetCurrentServer(), GetPackagePath());

        FillGroups();
    }
    EnableButtons();
    UpdateStatus(_("Ready"), 0, 0);

    m_HasUpdated = true;
}
Ejemplo n.º 5
0
SpectrumVisualizerFactory::SpectrumVisualizerFactory(const IniParser& ini)
{
    this->dB_min = ini.getOptionAsFloat("general", "dB_min");
    this->dB_max = ini.getOptionAsFloat("general", "dB_max");
    this->dB_clip = ini.getOptionAsFloat("general", "dB_clip");
    this->fft_size = ini.getOptionAsUnsignedInteger("fft", "fft_size");
    this->fill = ini.getOptionAsBool("spectrum", "fill");
    this->enable_grid = ini.getOptionAsBool("spectrum", "grid");

    if (this->fill)
        throw "spectrum.fill has not been implemented yet.";
}
Ejemplo n.º 6
0
  FileSource* CreateModFileSource(Arena* arena, const string& module_file_path)
  {
    string dir;
    {
      auto dirpos = module_file_path.find_last_of("\\/");
      if(dirpos != string::npos)
        dir = module_file_path.substr(0, dirpos + 1);
    }

    IniParser ini;
    {
      auto module_file = MapPhysicalFileA(module_file_path.c_str());
      ini.parse(arena, module_file->mapAll());
    }
    AggregateFileSource* afs = arena->alloc<AggregateFileSource>();
    AddFileSources(arena, dir, ini, afs);
    return afs;
  }
Ejemplo n.º 7
0
int Daemon::loadValuesFile (const char *filename)
{
	if (filename == NULL)
		return 0;
	
	IniParser *autosave = new IniParser (true);
	int ret = autosave->loadFile (filename);
	if (ret)
	{
		logStream (MESSAGE_WARNING) << "cannot open autosave file " << filename << ", ignoring the error" << sendLog;
		return 0;
	}

	if (autosave->size () == 0)
	{
		logStream (MESSAGE_WARNING) << "empty autosave file. Perharps you should set some values with RTS2_VALUE_AUTOSAVE flag?" << sendLog;
		return 0;
	}

	ret = setSectionValues ((*autosave)[0], 0, false);

	delete autosave;
	return ret;
}
Ejemplo n.º 8
0
int Daemon::loadCreateFile ()
{
	if (valueFile == NULL)
		return 0;
	
	IniParser *created = new IniParser (true);
	int ret = created->loadFile (valueFile);
	if (ret)
	{
		logStream (MESSAGE_WARNING) << "cannot open values file " << valueFile << ", probable cause " << strerror (errno) << sendLog;
		return -1;
	}

	if (created->size () == 0)
	{
		logStream (MESSAGE_WARNING) << "cannot find any value to create" << sendLog;
		return 0;
	}

	ret = createSectionValues ((*created)[0]);

	delete created;
	return ret;
}
Ejemplo n.º 9
0
void Game::quit()
{
	m_running = false;

	// Save configuration to settings file
	IniParser config;
	config.seek_section("Wallbreaker");
	config.set("highscore",  Settings::highscore);
	config.set("app_width",  m_window.getSize().x);
	config.set("app_height", m_window.getSize().y);
	config.set("sound",      SoundSystem::isSoundEnabled());
	config.set("music",      SoundSystem::isMusicEnabled());
	config.save(m_app_dir + WB_SETTINGS_FILE);
}
Ejemplo n.º 10
0
void Game::init(const std::string& path)
{
	// Set application directory
	size_t last_dir = path.find_last_of("/\\");
	m_app_dir = path.substr(0, last_dir + 1);
	if (m_app_dir.empty())
		m_app_dir = "./";

	// Init resources search directory
	Resources::setSearchPath(m_app_dir + "/resources/");

	// Init levels
	std::cout << "* loading levels from " << WB_LEVEL_FILE << std::endl;
	LevelManager::getInstance().openFromFile(m_app_dir + WB_LEVEL_FILE);

	// Init GUI module
	gui::Theme::loadFont(m_app_dir + "/resources/images/font.png");

	SoundSystem::openMusicFromFile(m_app_dir + "/resources/musics/evolution_sphere.ogg");

	// Load configuration from settings file
	IniParser config;
	std::cout << "* loading settings from " << WB_SETTINGS_FILE << std::endl;
	if (config.load(m_app_dir + WB_SETTINGS_FILE))
	{
		config.seek_section("Wallbreaker");
		size_t app_width = config.get("app_width", APP_WIDTH * 2);
		size_t app_height = config.get("app_height", APP_HEIGHT * 2);
		setResolution(app_width, app_height);

		Settings::highscore = config.get("highscore", 0);

		SoundSystem::enableSound(config.get("sound", true));
		SoundSystem::enableMusic(config.get("music", true));
	}
	else
	{
		setResolution(APP_WIDTH * 2, APP_HEIGHT * 2);
	}

	SoundSystem::playMusic();
}
Ejemplo n.º 11
0
void UpdateDlg::FillServers()
{
    wxComboBox* cmb = XRCCTRL(*this, "cmbServer", wxComboBox);
    cmb->Clear();
    m_Servers.Clear();

    IniParser ini;
    ini.ParseFile(GetMirrorsFilename());
    int group = ini.FindGroupByName(_T("WebUpdate mirrors"));
    for (int i = 0; group != -1 && i < ini.GetKeysCount(group); ++i)
    {
        cmb->Append(ini.GetKeyName(group, i));
        m_Servers.Add(ini.GetKeyValue(group, i));
    }
    if (cmb->GetCount() == 0)
    {
        cmb->Append(_("devpaks.org Community Devpaks"));
        m_Servers.Add(_T("http://devpaks.sourceforge.net/"));
    }
    cmb->SetSelection(0);
}
Ejemplo n.º 12
0
 bool LoadFromFile(const string& filename,string& errmsg)
 {
  IniParser inip;
  if(inip.ReadFromFile(filename)==false)
    {
     errmsg="failed to load file "+filename;
     return false;
    }
  string s;
  if(inip.Get("mainbase","http_server_port",s)==false)
    {
     errmsg="failed to load item http_server_port";
     return false;
    }
  http_server_port=atoi(s.c_str());
  if(inip.Get("mainbase","mainbase_unix_socket_path",s)==false)
    {
     errmsg="failed to load item mainbase_unix_socket_path";
     return false;
    }
  mainbase_unix_socket_path=s;
  if(inip.Get("mainbase","remote_pair",s)==false||remote_pair.FromStr(s)==false)
    {
     errmsg="failed to load item remote_pair";
     return false;
    }
  if(inip.Get("watcher","watcher_unix_socket_path",s)==false)
    {
     errmsg="failed to load item watcher_unix_socket_path";
     return false;
    }
  watcher_unix_socket_path=s;
  if(inip.Get("watcher","local_dir",s)==false)
    {
     errmsg="failed to load item local_dir";
     return false;
    }
  local_dir=s;
  if(inip.Get("watcher","rlog_path",s)==false)
    {
     errmsg="failed to load item rlog";
     return false;
    }
  rlog_path=s;
  if(inip.Get("watcher","rlog_file_max_size",s)==false)
    {
     errmsg="failed to load item rlog_file_max_size";
     return false;
    }
  rlog_file_max_size=StringToByteSize(s);
  if(inip.Get("watcher","rlog_max_file_number",s)==false)
    {
     errmsg="failed to load item rlog_max_file_number";
     return false;
    }
  rlog_max_file_number=atoi(s.c_str());
  if(inip.Get("sender","sender_unix_socket_path",s)==false)
    {
     errmsg="failed to load item sender_unix_socket_path";
     return false;
    }
  sender_unix_socket_path=s;
  if(inip.Get("sender","sender_tmp_path",s)==false)
    {
     errmsg="failed to load item sender_tmp_path";
     return false;
    }
  sender_tmp_path=s;
  if(inip.Get("sender","remote_dir",s)==false)
    {
     errmsg="failed to load item remote_dir";
     return false;
    }
  remote_dir=s;
  if(inip.Get("sender","rsync_bwlimit",s)==false)
    {
     errmsg="failed to load item rsync_bwlimit";
     return false;
    }
  rsync_bwlimit=StringToByteSize(s);
  if(inip.Get("sender","rlog_reader_batch_item_number",s)==false)
    {
     errmsg="failed to load item rlog_reader_batch_item_number";
     return false;
    }
  rlog_reader_batch_item_number=atoi(s.c_str());
  if(inip.Get("sender","stat_file_path",s)==false)
    {
     errmsg="failed to load item stat_file_path";
     return false;
    }
  stat_file_path=s;
  if(inip.Get("log","log_switch",s)==false)
    {
     errmsg="failed to load item log_switch";
     return false;
    }
  log_switch=s=="on";
  if(inip.Get("log","log_path",s)==false)
    {
     errmsg="failed to load item log_path";
     return false;
    }
  log_path=s;
 
  if(IsValid(errmsg)==false)
     return false;
  return true;
 }//end LoadFromFile
Ejemplo n.º 13
0
UpdateRec* ReadConf(const IniParser& ini, int* recCount, const wxString& currentServer, const wxString& appPath)
{
    *recCount = 0;
    int groupsCount = ini.GetGroupsCount();
    if (groupsCount == 0)
        return 0;

    UpdateRec* list = new UpdateRec[ini.GetGroupsCount()];
    for (int i = 0; i < groupsCount; ++i)
    {
        UpdateRec& rec = list[i];

        rec.title = ini.GetGroupName(i);

        // fix title
        // devpaks.org has changed the title to contain some extra info
        // e.g.: [libunicows   Library version: 1.1.1   Devpak revision: 1sid]
        int pos = rec.title.Lower().Find(_T("library version:"));
        if (pos != -1)
        {
            int revpos = rec.title.Lower().Find(_T("devpak revision:"));
            if (revpos != -1) {
                rec.revision = rec.title.Mid(revpos).AfterFirst(_T(':')).Trim(false);
                rec.revision.Replace(_T("\t"), _T(" "));
                rec.revision = rec.revision.BeforeFirst(_T(' '));
            }

            rec.title.Truncate(pos);
            rec.title = rec.title.Trim(false);
            rec.title = rec.title.Trim(true);
        }

        rec.name = ini.GetKeyValue(i, _T("Name"));
        rec.desc = ini.GetKeyValue(i, _T("Description"));
        rec.remote_file = ini.GetKeyValue(i, _T("RemoteFilename"));
        rec.local_file = ini.GetKeyValue(i, _T("LocalFilename"));
        rec.groups = GetArrayFromString(ini.GetKeyValue(i, _T("Group")), _T(","));
        rec.install_path = ini.GetKeyValue(i, _T("InstallPath"));
        rec.version = ini.GetKeyValue(i, _T("Version"));
        ini.GetKeyValue(i, _T("Size")).ToLong(&rec.bytes);
        rec.date = ini.GetKeyValue(i, _T("Date"));
        rec.installable = ini.GetKeyValue(i, _T("Execute")) == _T("1");

        // read .entry file (if exists)
        rec.entry = (!rec.name.IsEmpty() ? rec.name : wxFileName(rec.local_file).GetName()) + _T(".entry");
        IniParser p;
        p.ParseFile(appPath + rec.entry);
        rec.installed_version = p.GetValue(_T("Setup"), _T("AppVersion"));

        rec.downloaded = wxFileExists(appPath + _T("/") + rec.local_file);
        rec.installed = !rec.installed_version.IsEmpty();

        // calculate size
        rec.size = GetSizeString(rec.bytes);

        // fix-up
        if (rec.name.IsEmpty())
            rec.name = rec.title;
        rec.desc.Replace(_T("<CR>"), _T("\n"));
        rec.desc.Replace(_T("<LF>"), _T("\r"));
        wxURL url(rec.remote_file);
        if (!url.GetServer().IsEmpty())
        {
            rec.remote_server = url.GetScheme() + _T("://") + url.GetServer();
            int pos = rec.remote_file.Find(url.GetServer());
            if (pos != wxNOT_FOUND)
                rec.remote_file.Remove(0, pos + url.GetServer().Length() + 1);
        }
        else
            rec.remote_server = currentServer;
    }

    *recCount = groupsCount;
    return list;
}
Ejemplo n.º 14
0
void UserSettings::loadFromConfig(IniParser& config)
{
	config.seekSection("Settings");
	// language
	std::string lang = config.get("language");
	if (lang.empty() || !I18n::getInstance().loadFromCode(lang))
	{
		I18n::getInstance().loadFromLocale();
	}

	// Panel position
	panel_on_top = config.get("panel_on_top", panel_on_top);

	config.seekSection("Player");

	int level = config.get("last_unlocked_level", 1);
	LevelManager::getInstance().setLastUnlocked(level);

	level = config.get("current_level", 1);
	LevelManager::getInstance().setCurrent(level);

	s_credits = config.get("credits", 0);
	s_highscore = config.get("arcade_highscore", 0);

	s_items[Item::WEAPON] =   config.get("lvl_laser", 1);
	s_items[Item::SHIELD] =   config.get("lvl_shield", 1);
	s_items[Item::HULL] =     config.get("lvl_hull", 1);
	s_items[Item::ENGINE] =   config.get("lvl_engine", 1);
	s_items[Item::HEATSINK] = config.get("lvl_heatsink", 1);
	for (int i = 0; i < Item::_COUNT; ++i)
	{
		setItemLevel((Item::Type) i, s_items[i]);
	}

	config.seekSection("Keyboard");
	Input::setKeyBinding(config.get("move_up",    Input::getKeyBinding(Action::UP)), Action::UP);
	Input::setKeyBinding(config.get("move_down",  Input::getKeyBinding(Action::DOWN)), Action::DOWN);
	Input::setKeyBinding(config.get("move_left",  Input::getKeyBinding(Action::LEFT)), Action::LEFT);
	Input::setKeyBinding(config.get("move_right", Input::getKeyBinding(Action::RIGHT)), Action::RIGHT);
	Input::setKeyBinding(config.get("laser",      Input::getKeyBinding(Action::USE_LASER)), Action::USE_LASER);
	Input::setKeyBinding(config.get("cooler",     Input::getKeyBinding(Action::USE_COOLER)), Action::USE_COOLER);
	Input::setKeyBinding(config.get("missile",    Input::getKeyBinding(Action::USE_MISSILE)), Action::USE_MISSILE);

	config.seekSection("Joystick");
	Input::setButtonBinding(config.get("pause",   Input::getButtonBinding(Action::PAUSE)), Action::PAUSE);
	Input::setButtonBinding(config.get("laser",   Input::getButtonBinding(Action::USE_LASER)), Action::USE_LASER);
	Input::setButtonBinding(config.get("cooler",  Input::getButtonBinding(Action::USE_COOLER)), Action::USE_COOLER);
	Input::setButtonBinding(config.get("missile", Input::getButtonBinding(Action::USE_MISSILE)), Action::USE_MISSILE);
	Input::setJoystickDeadzone(config.get("sensitivity", Input::getJoystickDeadzone()));

	config.seekSection("Audio");
	SoundSystem::enableMusic(config.get("enable_music", true));
	SoundSystem::setMusicVolume(config.get("music_volume", 100));
	SoundSystem::enableSound(config.get("enable_sound", true));
	SoundSystem::setSoundVolume(config.get("sound_volume", 100));
}
Ejemplo n.º 15
0
void UserSettings::saveToConfig(IniParser& config)
{
	config.seekSection("Settings");
	config.set("panel_on_top", panel_on_top);
	config.set("language", I18n::getInstance().getCurrentLanguage());

	config.seekSection("Player");
	config.set("current_level",       LevelManager::getInstance().getCurrent());
	config.set("last_unlocked_level", LevelManager::getInstance().getLastUnlocked());
	config.set("credits",             s_credits);
	config.set("arcade_highscore",    s_highscore);
	config.set("lvl_laser",    s_items[Item::WEAPON]);
	config.set("lvl_shield",   s_items[Item::SHIELD]);
	config.set("lvl_hull",     s_items[Item::HULL]);
	config.set("lvl_engine",   s_items[Item::ENGINE]);
	config.set("lvl_heatsink", s_items[Item::HEATSINK]);

	config.seekSection("Keyboard");
	config.set("move_up",    Input::getKeyBinding(Action::UP));
	config.set("move_down",  Input::getKeyBinding(Action::DOWN));
	config.set("move_left",  Input::getKeyBinding(Action::LEFT));
	config.set("move_right", Input::getKeyBinding(Action::RIGHT));
	config.set("laser",      Input::getKeyBinding(Action::USE_LASER));
	config.set("cooler",     Input::getKeyBinding(Action::USE_COOLER));
	config.set("missile",    Input::getKeyBinding(Action::USE_MISSILE));

	config.seekSection("Joystick");
	config.set("pause",       Input::getButtonBinding(Action::PAUSE));
	config.set("laser",       Input::getButtonBinding(Action::USE_LASER));
	config.set("cooler",      Input::getButtonBinding(Action::USE_COOLER));
	config.set("missile",     Input::getButtonBinding(Action::USE_MISSILE));
	config.set("sensitivity", Input::getJoystickDeadzone());

	config.seekSection("Audio");
	config.set("enable_music", SoundSystem::isMusicEnabled());
	config.set("music_volume", SoundSystem::getMusicVolume());
	config.set("enable_sound", SoundSystem::isSoundEnabled());
	config.set("sound_volume", SoundSystem::getSoundVolume());
}