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

@@ -19,7 +19,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
#include "KissCount.h"
KissCount::KissCount() : _user(NULL)
KissCount::KissCount(const char* bdd_filename) : _user(NULL)
{
_wxUI = new wxUI(this, wxT("KissCount"), wxPoint(50, 50), wxSize(1024, 768));
@@ -31,7 +31,7 @@ KissCount::KissCount() : _user(NULL)
try
{
_db = new Database();
_db = new Database(bdd_filename);
}
catch (std::string s)
{

View File

@@ -33,7 +33,7 @@ class wxUI;
class KissCount
{
public:
KissCount();
KissCount(const char* bdd_filename);
~KissCount();
std::list<wxString> GetUsers();

View File

@@ -25,7 +25,10 @@ class MyApp: public wxApp
{
try
{
new KissCount();
if (argc == 2)
new KissCount(wxString(argv[1]).mb_str());
else
new KissCount(NULL);
}
catch (std::string s)
{
@@ -38,28 +41,3 @@ class MyApp: public wxApp
};
IMPLEMENT_APP(MyApp);
// bool MyApp::OnInit()
// {
// Main app;
// MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50), wxSize(1024, 768) );
// AccountPanel* f = new AccountPanel(frame);
// frame->Show(true);
// SetTopWindow(frame);
// frame->Centre();
// frame->Disable();
// try
// {
// app.Init();
// }
// catch (std::string s)
// {
// std::cout << "Error " << s << "\n";
// frame->Close(true);
// }
// frame->Enable();
// return true;
// }

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);