diff --git a/ZRColaCompile/dbsource.cpp b/ZRColaCompile/dbsource.cpp index a850611..f7cbf71 100644 --- a/ZRColaCompile/dbsource.cpp +++ b/ZRColaCompile/dbsource.cpp @@ -262,7 +262,7 @@ bool ZRCola::DBSource::SelectKeySequences(ATL::CComPtr &rs) const wxCHECK(SUCCEEDED(::CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_ALL, IID_IADORecordset, (LPVOID*)&rs)), false); // Open it. - if (FAILED(rs->Open(ATL::CComVariant(L"SELECT [Znak], [tipka] FROM [wrd_KeyCodes]"), ATL::CComVariant(m_db), adOpenStatic, adLockReadOnly, adCmdText))) { + if (FAILED(rs->Open(ATL::CComVariant(L"SELECT DISTINCT [Znak], [tipka] FROM [wrd_KeyCodes]"), ATL::CComVariant(m_db), adOpenStatic, adLockReadOnly, adCmdText))) { _ftprintf(stderr, wxT("%s: error ZCC0050: Error loading key sequences from database. Please make sure the file is ZRCola.zrc compatible.\n"), m_filename.c_str()); LogErrors(); return false; diff --git a/ZRColaCompile/main.cpp b/ZRColaCompile/main.cpp index 068f68c..5cce0ee 100644 --- a/ZRColaCompile/main.cpp +++ b/ZRColaCompile/main.cpp @@ -464,6 +464,19 @@ int _tmain(int argc, _TCHAR *argv[]) qsort_s(db.idxChr.data(), count, sizeof(unsigned __int32), CompareKeySequenceChar, db.data.data()); qsort_s(db.idxKey.data(), count, sizeof(unsigned __int32), CompareKeySequenceKey , db.data.data()); + // Check key sequences. + for (std::vector::size_type i = 1, n = db.idxKey.size(); i < n; i++) { + const ZRCola::keyseq_db::keyseq + &ks1 = (const ZRCola::keyseq_db::keyseq&)db.data[db.idxKey[i - 1]], + &ks2 = (const ZRCola::keyseq_db::keyseq&)db.data[db.idxKey[i ]]; + + if (CompareSequence(ks1.seq, ks1.seq_len, ks2.seq, ks2.seq_len) == 0) { + std::wstring seq_str; + ZRCola::keyseq_db::GetSequenceAsText(ks1.seq, ks1.seq_len, seq_str); + _ftprintf(stderr, wxT("%s: warning ZCC0007: Duplicate key sequence (%ls => %04X or %04X). The keyboard behaviour will be unpredictable.\n"), (LPCTSTR)filenameIn.c_str(), seq_str.c_str(), ks1.chr, ks2.chr); + } + } + // Write translations to file. dst << ZRCola::keyseq_rec(db); } else { @@ -479,7 +492,7 @@ int _tmain(int argc, _TCHAR *argv[]) stdex::idrec::close(dst, dst_start); if (dst.fail()) { - _ftprintf(stderr, wxT("%s: error ZCC0007: Writing to output file failed.\n"), (LPCTSTR)filenameOut.c_str()); + _ftprintf(stderr, wxT("%s: error ZCC1000: Writing to output file failed.\n"), (LPCTSTR)filenameOut.c_str()); has_errors = true; } diff --git a/lib/libZRColaUI/include/zrcolaui/keyboard.h b/lib/libZRColaUI/include/zrcolaui/keyboard.h index 13a24f4..7e73891 100644 --- a/lib/libZRColaUI/include/zrcolaui/keyboard.h +++ b/lib/libZRColaUI/include/zrcolaui/keyboard.h @@ -63,6 +63,31 @@ namespace ZRCola { std::vector idxChr; ///< Character index std::vector idxKey; ///< Key index std::vector data; ///< Key sequences data + + public: + /// + /// Get text representation of a given key sequence + /// + /// \param[in] seq Key sequence + /// \param[in] seq_len Number of elements in \p seq + /// \param[out] str Text representation of a \p seq key sequence + /// + static void GetSequenceAsText(_In_count_(seq_len) const keyseq::key_t *seq, _In_ size_t seq_len, _Out_ std::wstring& str); + + /// + /// Get text representation of a given key sequence + /// + /// \param[in] seq Key sequence + /// \param[in] seq_len Number of elements in \p seq + /// + /// \returns Text representation of a \p seq key sequence + /// + static inline std::wstring GetSequenceAsText(_In_count_(seq_len) const keyseq::key_t *seq, _In_ size_t seq_len) + { + std::wstring str; + GetSequenceAsText(seq, seq_len, str); + return str; + } }; diff --git a/lib/libZRColaUI/src/keyboard.cpp b/lib/libZRColaUI/src/keyboard.cpp index ac111f1..b5b41cf 100644 --- a/lib/libZRColaUI/src/keyboard.cpp +++ b/lib/libZRColaUI/src/keyboard.cpp @@ -18,3 +18,18 @@ */ #include "stdafx.h" + + +void ZRCola::keyseq_db::GetSequenceAsText(_In_count_(seq_len) const ZRCola::keyseq_db::keyseq::key_t *seq, _In_ size_t seq_len, _Out_ std::wstring& str) +{ + assert(seq || !seq_len); + + str.clear(); + for (size_t i = 0; i < seq_len; i++) { + if (i) str += L", "; + if (seq[i].modifiers & keyseq::CTRL ) str += L"Ctrl+"; + if (seq[i].modifiers & keyseq::ALT ) str += L"Alt+"; + if (seq[i].modifiers & keyseq::SHIFT) str += L"Shift+"; + str += seq[i].key; + } +} diff --git a/lib/libZRColaUI/src/stdafx.h b/lib/libZRColaUI/src/stdafx.h index d4f84ec..171035c 100644 --- a/lib/libZRColaUI/src/stdafx.h +++ b/lib/libZRColaUI/src/stdafx.h @@ -21,3 +21,5 @@ #include "../../../include/zrcola.h" #include "../include/zrcolaui/keyboard.h" + +#include diff --git a/output/data/ZRCola.zrcdb b/output/data/ZRCola.zrcdb index 14c5484..d39f33a 100644 Binary files a/output/data/ZRCola.zrcdb and b/output/data/ZRCola.zrcdb differ