- Timestamp:
- 09/25/2008 08:44:25 PM (4 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
-
MainFrame.cpp (modified) (1 diff)
-
configuration.cpp (modified) (7 diffs)
-
configuration.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/MainFrame.cpp
r157 r158 79 79 wxRenameFile(home_path+wxT("/.OpenYahtzee"),home_path+wxT("/.openyahtzee"),false); 80 80 } 81 Configuration config("/home/guy/.openyahtzee.new"); 81 configuration::Configuration config("/home/guy/.openyahtzee.new"); 82 config.save(); 82 83 m_settingsdb = new SettingsDB(); //Get the settings database connection 83 84 m_highscoredb = new HighScoreTableDB(); -
trunk/src/configuration.cpp
r157 r158 19 19 ***************************************************************************/ 20 20 21 #include <iostream> 21 22 #include "configuration.h" 22 #include <iostream>23 #include "../config.h" 23 24 24 25 using namespace std; 26 using namespace configuration; 25 27 26 28 Configuration::Configuration(string file) … … 31 33 void Configuration::load(string file) 32 34 { 35 m_file = file; 36 33 37 cerr<<"loading file: "<<file<<endl; 34 38 ifstream conf_file (file.c_str()); … … 36 40 // file couldn't be opened, this is due to missing file or 37 41 // permission error. 42 cerr<<"Error openning configuration file for reading: "<<m_file<<endl; 38 43 } 39 44 … … 59 64 } 60 65 } 66 conf_file.close(); 61 67 } 62 68 … … 99 105 string date,hour,name; 100 106 HighscoreItem temp_item; 101 while( !file->eof()) {107 while(file->good()) { 102 108 temp_chr = file->get(); 103 109 file->unget(); … … 109 115 (*file)>>date; 110 116 (*file)>>hour; 117 (*file).get(); // discard space before name 111 118 getline(*file,name); 112 119 temp_item.score = score; … … 115 122 m_highscores.push_back(temp_item); 116 123 cerr<<score<<" "<<name<<" "<<temp_item.date<<endl; 124 125 // The following two lines read one character forword and 126 // return it. This is done in order to raise the eofbit if 127 // we reached the eof (it is raised only after reading 128 // operation failed). 129 temp_chr = file->get(); 130 file->unget(); 117 131 } 118 132 } 133 134 void Configuration::save() 135 { 136 ofstream conf_file (m_file.c_str()); 137 if (!conf_file.is_open()) { 138 // file couldn't be opened, this is due to missing file or 139 // permission error. 140 cerr<<"Error openning configuration file for writing: "<<m_file<<endl; 141 } 142 conf_file<<"openyahtzee="<<VERSION<<endl; 143 144 conf_file<<"[settings]\n"; 145 saveSettings(&conf_file); 146 conf_file<<"[highscores]\n"; 147 saveHighscores(&conf_file); 148 149 conf_file.close(); 150 } 151 152 void Configuration::saveSettings(ofstream *file) 153 { 154 map<string,string>::iterator it; 155 for (it = m_settings.begin(); it!=m_settings.end(); it++) { 156 (*file)<<(*it).first<<"="<<(*it).second<<"\n"; 157 } 158 } 159 160 void Configuration::saveHighscores(ofstream *file) 161 { 162 HighscoreList::iterator it; 163 for (it = m_highscores.begin(); it!=m_highscores.end(); it++) { 164 (*file)<<(*it).score<<" "; 165 (*file)<<(*it).date<<" "; 166 (*file)<<(*it).name<<"\n"; 167 } 168 } -
trunk/src/configuration.h
r157 r158 27 27 #include <list> 28 28 29 namespace configuration { 30 29 31 struct HighscoreItem; 30 32 … … 38 40 */ 39 41 void load(std::string file); 42 43 void save(); 40 44 private: 41 45 /** … … 46 50 void parseSettings(std::ifstream *file); 47 51 void parseHighscores(std::ifstream *file); 52 53 void saveSettings(std::ofstream *file); 54 void saveHighscores(std::ofstream *file); 48 55 49 56 std::map<std::string, std::string> m_settings; 50 57 HighscoreList m_highscores; 58 59 std::string m_file; 51 60 }; 52 61 … … 56 65 std::string date; 57 66 }; 67 68 } 58 69 59 70
Note: See TracChangeset
for help on using the changeset viewer.
