Possibility pass bdd file to load at startup

This commit is contained in:
2010-08-22 16:35:12 +02:00
parent 9f7d858bc3
commit fb1007bfcb
10 changed files with 80 additions and 51 deletions

View File

@@ -71,19 +71,47 @@ static inline wxString DoubleToString(double d)
return res;
}
Database::Database()
Database::Database(const char* filename)
{
std::ifstream bdd_file;
bdd_file.open(BDD_FILE);
if (!bdd_file)
if (filename)
{
CreateDatabase();
bdd_file.open(filename, std::ifstream::in);
if (!bdd_file.good())
{
wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK );
throw std::string("Unable to open ") + filename;
}
_db.Open(wxString(filename, wxConvUTF8));
if (!_db.IsOpen())
{
wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK );
throw std::string("Unable to open ") + filename;
}
}
else
_db.Open(wxT(BDD_FILE));
{
// If default BDD file, assume this can be the first load
bdd_file.open(BDD_FILE, std::ifstream::in);
if (!bdd_file.good())
{
CreateDatabase();
}
else
{
_db.Open(wxT(BDD_FILE));
if (!_db.IsOpen())
{
wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK );
throw std::string("Unable to open ") + BDD_FILE;
}
}
}
bdd_file.close();
}
@@ -105,6 +133,12 @@ void Database::CreateDatabase()
_db.Open(wxT(BDD_FILE));
if (!_db.IsOpen())
{
wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK );
throw std::string("Unable to open ") + BDD_FILE;
}
do
{
getline(init_script, line);

View File

@@ -35,7 +35,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
class Database
{
public:
Database();
Database(const char* filename);
std::list<wxString> GetUsers();
bool IsValidUser(const wxString& user, const wxString& password);