diff --git a/ZRCola/zrcolaapp.cpp b/ZRCola/zrcolaapp.cpp index 28d56c2..db8b7fe 100644 --- a/ZRCola/zrcolaapp.cpp +++ b/ZRCola/zrcolaapp.cpp @@ -62,6 +62,38 @@ bool ZRColaApp::OnInit() wxVERIFY(m_locale.AddCatalog(wxT("ZRCola"))); } + std::fstream dat((LPCTSTR)GetDatabasePath(), std::ios_base::in | std::ios_base::binary); + if (dat.good()) { + if (stdex::idrec::find(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) { + ZRCola::recordsize_t size; + dat.read((char*)&size, sizeof(ZRCola::recordsize_t)); + if (dat.good()) { + bool has_translation_data = false; + + for (;;) { + ZRCola::recordid_t id; + if (!stdex::idrec::read_id(dat, id, size)) break; + + if (id == ZRCola::translation_rec::id) { + dat >> ZRCola::translation_rec(m_t_db); + if (dat.good()) { + has_translation_data = true; + } else { + wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); + m_t_db.idxComp .clear(); + m_t_db.idxDecomp.clear(); + m_t_db.data .clear(); + } + } + } + + if (!has_translation_data) + wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data.")); + } + } else + wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database.")); + } + wxZRColaFrame* mainFrame = new wxZRColaFrame(); wxPersistentRegisterAndRestore(mainFrame); mainFrame->Show(); diff --git a/ZRCola/zrcolaapp.h b/ZRCola/zrcolaapp.h index 26d15e1..75962a6 100644 --- a/ZRCola/zrcolaapp.h +++ b/ZRCola/zrcolaapp.h @@ -28,6 +28,7 @@ class ZRColaApp; #include #include #include +#include /// @@ -54,6 +55,9 @@ public: inline wxString GetDatabasePath() const; +public: + ZRCola::translation_db m_t_db; ///< Translation database + protected: wxLocale m_locale; ///< Current locale }; diff --git a/ZRCola/zrcolacomppnl.cpp b/ZRCola/zrcolacomppnl.cpp index 3dcd52c..f78f58e 100644 --- a/ZRCola/zrcolacomppnl.cpp +++ b/ZRCola/zrcolacomppnl.cpp @@ -30,28 +30,6 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) : m_selComposed(0, 0), wxZRColaComposerPanelBase(parent) { - std::fstream dat((LPCTSTR)((ZRColaApp*)wxTheApp)->GetDatabasePath(), std::ios_base::in | std::ios_base::binary); - if (dat.good()) { - if (stdex::idrec::find(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) { - ZRCola::recordsize_t size; - dat.read((char*)&size, sizeof(ZRCola::recordsize_t)); - if (dat.good()) { - ZRCola::translation_rec rec(m_t_db); - if (rec.find(dat, size)) { - dat >> rec; - if (!dat.good()) { - wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); - m_t_db.idxComp .clear(); - m_t_db.idxDecomp.clear(); - m_t_db.data .clear(); - } - } else - wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data.")); - } - } else - wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database.")); - } - m_decomposed->PushEventHandler(&m_keyhandler); } @@ -94,7 +72,7 @@ void wxZRColaComposerPanel::OnDecomposedText(wxCommandEvent& event) #endif std::wstring dst; - m_t_db.Compose(src.data(), src.size(), dst, &m_mapping); + ((ZRColaApp*)wxTheApp)->m_t_db.Compose(src.data(), src.size(), dst, &m_mapping); long from, to; m_decomposed->GetSelection(&from, &to); @@ -141,7 +119,7 @@ void wxZRColaComposerPanel::OnComposedText(wxCommandEvent& event) #endif std::wstring dst; - m_t_db.Decompose(src.data(), src.size(), dst, &m_mapping); + ((ZRColaApp*)wxTheApp)->m_t_db.Decompose(src.data(), src.size(), dst, &m_mapping); long from, to; m_composed->GetSelection(&from, &to); diff --git a/ZRCola/zrcolacomppnl.h b/ZRCola/zrcolacomppnl.h index 626cfd0..3760f95 100644 --- a/ZRCola/zrcolacomppnl.h +++ b/ZRCola/zrcolacomppnl.h @@ -27,7 +27,6 @@ class wxZRColaComposerPanel; #include "zrcolagui.h" #include "zrcolakeyhndlr.h" -#include #include @@ -49,7 +48,6 @@ protected: virtual void OnComposedText(wxCommandEvent& event); protected: - ZRCola::translation_db m_t_db; ///< Translation database bool m_progress; ///< Boolean flag to avoid recursive updates of composed and decomposed text controls ZRCola::mapping_vector m_mapping; ///< Character index mapping vector between composed and decomposed text std::pair