Ignore:
Timestamp:
04/26/2009 05:03:05 PM (3 years ago)
Author:
guyru
Message:

Portable Edition 1.9 Preparations.

Removed SQLite support. Fixed configuration file path. Add new MSVC
configuration for the portable edition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/configuration.cpp

    r177 r191  
    5050        getline(conf_file,header); 
    5151        if (header.substr(0,11) != "openyahtzee") { 
    52                 // this is probably an old sqllite file import it. 
    53                 conf_file.close(); 
    54                 importOldFile(); 
     52                /* The file might be an old configuration file or 
     53                 * currupted, anyway re-create it 
     54                 */ 
     55                loadDefaultSettings(); 
     56                save(); 
    5557                return; 
    5658        } 
     
    190192} 
    191193 
    192  
    193 void Configuration::importOldFile() 
    194 { 
    195         loadDefaultSettings(); 
    196         if (old_db.Open(m_file)!=SQLITE_OK) { 
    197                 return; 
    198         } 
    199         importSettings(); 
    200         // importHighscores is called after importSettings() so the 
    201         // highscore size settings will be known 
    202         importHighscores(); 
    203 } 
    204  
    205 string Configuration::getKeyFromDb(string key) 
    206 { 
    207         string tmp_query; 
    208         std::list<string> tmp_value; 
    209          
    210         tmp_query = "SELECT value FROM settings WHERE key = \"" + key + "\""; 
    211  
    212         tmp_value = old_db.Query(tmp_query); 
    213         if (tmp_value.empty()) { //if there was no result return an empty string 
    214                 tmp_query = ""; //use tmp_query for holding a tmp_string 
    215                 return tmp_query; 
    216         } 
    217         return  *(tmp_value.begin()); 
    218 } 
    219  
    220 void Configuration::importSettings() 
    221 { 
    222         string temp_value; 
    223  
    224         temp_value = getKeyFromDb("animate"); 
    225         if (temp_value=="No") { 
    226                 set("dice-animation","False"); 
    227         } 
    228  
    229         temp_value = getKeyFromDb("calculatesubtotal"); 
    230         if (temp_value=="No") { 
    231                 set("calculate-subtotal","False"); 
    232         } 
    233  
    234         temp_value = getKeyFromDb("horizontalayout"); 
    235         if (temp_value=="No") { 
    236                 set("horizontal-layout","False"); 
    237         } 
    238  
    239         temp_value = getKeyFromDb("score_hints"); 
    240         if (temp_value=="No") { 
    241                 set("score-hints","False"); 
    242         } 
    243  
    244         temp_value = getKeyFromDb("highscoresize"); 
    245         if (temp_value=="") { 
    246                 set("highscore-list-size",DEFAULT_HIGHSCORE_SIZE); 
    247         } 
    248 } 
    249  
    250 void Configuration::importHighscores() 
    251 { 
    252         string tmp_query = "SELECT name,date,score FROM highscore LIMIT " 
    253                 + m_settings["highscore-list-size"]; 
    254          
    255         list<string> res = old_db.Query(tmp_query); 
    256         HighscoreItem temp_item; 
    257  
    258         list<string>::iterator it = res.begin(); 
    259         size_t pos; 
    260         while(it!=res.end()) { 
    261                 temp_item.name = (*it++); 
    262  
    263                 // the database saved the the hour before the date, 
    264                 // we need to reverse this 
    265                 pos = it->find(' '); 
    266                 temp_item.date = it->substr(pos+1); // date 
    267                 temp_item.date += " " + it->substr(0,pos-3); // time, without seconds 
    268                 it++; 
    269  
    270                 temp_item.score = atoi((*it++).c_str()); 
    271  
    272                 m_highscores.push_back(temp_item); 
    273         } 
    274 } 
    275  
    276194bool Configuration::isHighscore(int score) { 
    277195        const unsigned int highscore_list_size = atoi(m_settings["highscore-list-size"].c_str()); 
Note: See TracChangeset for help on using the changeset viewer.