Possibility pass bdd file to load at startup
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ class wxUI;
|
||||
class KissCount
|
||||
{
|
||||
public:
|
||||
KissCount();
|
||||
KissCount(const char* bdd_filename);
|
||||
~KissCount();
|
||||
|
||||
std::list<wxString> GetUsers();
|
||||
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -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;
|
||||
// }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user