bool CSettings::Load() { FindConfig(); //! Reset default path variables to the right device SetDefault(); char filepath[300]; snprintf(filepath, sizeof(filepath), "%sGXGlobal.cfg", ConfigPath); FILE * file = fopen(filepath, "r"); if (!file) return false; if(!ValidVersion(file)) { fclose(file); return false; } char line[1024]; while (fgets(line, sizeof(line), file)) { if (line[0] == '#') continue; this->ParseLine(line); } fclose(file); // A valid config file exists on the loader // meaning it is not the first run of the loader. FirstTimeRun = false; return true; }
//--------------------------------------------------------------------------------------- tNdp2kTableDataSources::tNdp2kTableDataSources( tQMutex& apiThreadLock, tDigitalDataSourceSettings& sourceSettings, const char* pName, tTableID tableID, tTableFormat format, const tDataType* pTypes, unsigned numTypes ) : tNDP2kTableSettings( apiThreadLock, *tGlobal<tISettingsWriterFactory>::Instance(), QString("DataSources.") + pName, tableID, format ) , m_pSourceSettings( &sourceSettings ) , m_DefaultFormat( format ) , m_DefaultFormatRows( numTypes ) , m_pDefaultFormatTypes( pTypes ) , m_ExtendedDelay( false ) , m_ShareChanges( false ) , m_UpdateGlobalSettings( false ) , m_SelectionInProgress( false ) , m_Lock( "tNdp2kTableDataSources" ) { Assert( m_DefaultFormatRows <= m_cMaxRows ); // initialise source selection table int version = LoadSettings( Settings() ); if (version >= 0) { m_UpdateGlobalSettings = true; } else { LoadFromGlobalSettings(); version = TABLE_VERSION_UNKNOWN; SaveSettings(); } m_UpdateTimer.setSingleShot( true ); Connect( &m_UpdateTimer, SIGNAL(timeout()), this, SLOT(OnUpdateTimeout()) ); Connect( this, SIGNAL(RowChanged(int)), this, SLOT(OnMyRowChanged(int)), Qt::QueuedConnection ); Connect( this, SIGNAL(TableChanged()), this, SLOT(OnMyTableChanged()), Qt::QueuedConnection ); Register( ValidVersion( version ), TableShare_Watcher, 0 ); }
bool CSettings::Load() { //! Reset default path variables to the right device SetDefault(); std::string filepath = configPath; filepath += "/loadiine_gx2.cfg"; CFile file(filepath, CFile::ReadOnly); if (!file.isOpen()) return false; std::string strBuffer; strBuffer.resize(file.size()); file.read((u8 *) &strBuffer[0], strBuffer.size()); file.close(); //! remove all windows crap signs size_t position; while(1) { position = strBuffer.find('\r'); if(position == std::string::npos) break; strBuffer.erase(position, 1); } std::vector<std::string> lines = stringSplit(strBuffer, "\n"); if(lines.empty() || !ValidVersion(lines[0])) return false; for(u32 i = 0; i < lines.size(); ++i) { std::vector<std::string> valueSplit = stringSplit(lines[i], "="); if(valueSplit.size() != 2) continue; while((valueSplit[0].size() > 0) && valueSplit[0][0] == ' ') valueSplit[0].erase(0, 1); while((valueSplit[1].size() > 0) && valueSplit[1][ valueSplit[1].size() - 1 ] == ' ') valueSplit[1].resize(valueSplit[1].size() - 1); for(u32 n = 0; n < settingsNames.size(); n++) { if(!settingsNames[n]) continue; if(valueSplit[0] == settingsNames[n]) { switch(settingsValues[n].dataType) { case TypeBool: settingsValues[n].bValue = atoi(valueSplit[1].c_str()); break; case TypeS8: settingsValues[n].cValue = atoi(valueSplit[1].c_str()); break; case TypeU8: settingsValues[n].ucValue = atoi(valueSplit[1].c_str()); break; case TypeS16: settingsValues[n].sValue = atoi(valueSplit[1].c_str()); break; case TypeU16: settingsValues[n].usValue = atoi(valueSplit[1].c_str()); break; case TypeS32: settingsValues[n].iValue = atoi(valueSplit[1].c_str()); break; case TypeU32: settingsValues[n].uiValue = strtoul(valueSplit[1].c_str(), 0, 10); break; case TypeF32: settingsValues[n].fValue = atof(valueSplit[1].c_str()); break; case TypeString: if(settingsValues[n].strValue == NULL) settingsValues[n].strValue = new std::string(); *settingsValues[n].strValue = valueSplit[1]; break; default: break; } } } } return true; }
bool CSettingsGame::Load() { std::string filepath = configPath; filepath += "/" +this->filename; CFile file(filepath, CFile::ReadOnly); if (!file.isOpen()) return false; std::string strBuffer; strBuffer.resize(file.size()); file.read((u8 *) &strBuffer[0], strBuffer.size()); file.close(); //! remove all windows crap signs size_t position; while(1) { position = strBuffer.find('\r'); if(position == std::string::npos) break; strBuffer.erase(position, 1); } std::vector<std::string> lines_ = stringSplit(strBuffer, "\n"); if(lines_.empty() || !ValidVersion(lines_[0])) return false; for(u32 j = 1; j < lines_.size(); ++j){ std::vector<std::string> lines = stringSplit(lines_[j], ";"); if(lines.empty()) return false; std::string ID6 = lines[0]; std::vector<CSettingsGame::SettingValue> newValues = getSettingValuesFromGameSettings(std::string(COMMON_UPDATE_PATH), false, GAME_SAVES_DEFAULT, LOADIINE_MODE_DEFAULT, SETTING_OFF); for(u32 i = 1; i < lines.size(); ++i) { std::vector<std::string> valueSplit = stringSplit(lines[i], "="); if(valueSplit.size() != 2) continue; while((valueSplit[0].size() > 0) && valueSplit[0][0] == ' ') valueSplit[0].erase(0, 1); while((valueSplit[1].size() > 0) && valueSplit[1][ valueSplit[1].size() - 1 ] == ' ') valueSplit[1].resize(valueSplit[1].size() - 1); for(u32 n = 0; n < settingsNames.size(); n++) { if(!settingsNames[n]) continue; if(valueSplit[0] == settingsNames[n]) { switch(newValues.at(n).dataType) { case TypeBool: newValues.at(n).bValue = atoi(valueSplit[1].c_str()); break; case TypeS8: newValues.at(n).cValue = atoi(valueSplit[1].c_str()); break; case TypeU8: newValues.at(n).ucValue = atoi(valueSplit[1].c_str()); break; case TypeS16: newValues.at(n).sValue = atoi(valueSplit[1].c_str()); break; case TypeU16: newValues.at(n).usValue = atoi(valueSplit[1].c_str()); break; case TypeS32: newValues.at(n).iValue = atoi(valueSplit[1].c_str()); break; case TypeU32: newValues.at(n).uiValue = strtoul(valueSplit[1].c_str(), 0, 10); break; case TypeF32: newValues.at(n).fValue = atof(valueSplit[1].c_str()); break; case TypeString: if(newValues.at(n).strValue == NULL) newValues.at(n).strValue = new std::string(); *newValues.at(n).strValue = valueSplit[1]; break; default: break; } } } } GameSettings * set = GetGameSettingsBySettingGameValue(ID6,newValues); //Clean pointer for(u32 j = 0; j < newValues.size(); j++){ if(newValues.at(j).dataType == TypeString) delete newValues.at(j).strValue; } settingsGames[ID6] = *set; delete set; } return true; }