Index: src/ictranslate/ICTranslateDlg.cpp =================================================================== diff -u -rf6fe924675e9de6120b6c1eac2430fa5b2946251 -re9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14 --- src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision f6fe924675e9de6120b6c1eac2430fa5b2946251) +++ src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision e9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14) @@ -6,6 +6,7 @@ #include "ICTranslateDlg.h" #include #include +#include "../libicpf/exception.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -633,6 +634,12 @@ void CICTranslateDlg::OnFileSaveTranslationAs() { + if(!m_ldCustom.IsValidDescription()) + { + AfxMessageBox(_T("Please fill the Author, Language name and font with correct values before saving.")); + return; + } + CString strFilename = m_ldCustom.GetFilename(false); CString strPath = m_ldCustom.GetFilename(true); @@ -651,13 +658,30 @@ m_ldCustom.SetDirection(bRTL); // store translation with new name - m_ldCustom.WriteTranslation(dlg.GetPathName()); + try + { + m_ldCustom.WriteTranslation(dlg.GetPathName()); + } + catch(icpf::exception& e) + { + CString strInfo; + strInfo.Format(_T("Cannot write translation file.\nReason: %s"), e.get_desc()); + AfxMessageBox(strInfo); + return; + } m_ctlDstFilename.SetWindowText(m_ldCustom.GetFilename(true)); } } void CICTranslateDlg::OnFileSaveTranslation() { + // sanity checks + if(!m_ldCustom.IsValidDescription()) + { + AfxMessageBox(_T("Please fill the Author, Language name and font with correct values before saving.")); + return; + } + CString strPath = m_ldCustom.GetFilename(true); if(strPath.IsEmpty()) { @@ -676,7 +700,17 @@ bool bRTL = (m_ctlDstRTL.GetCheck() == BST_CHECKED); m_ldCustom.SetDirection(bRTL); - m_ldCustom.WriteTranslation(NULL); + try + { + m_ldCustom.WriteTranslation(NULL); + } + catch(icpf::exception& e) + { + CString strInfo; + strInfo.Format(_T("Cannot write translation file.\nReason: %s"), e.get_desc()); + AfxMessageBox(strInfo); + return; + } m_ctlDstFilename.SetWindowText(m_ldCustom.GetFilename(true)); } } Index: src/libictranslate/ResourceManager.cpp =================================================================== diff -u -rf6fe924675e9de6120b6c1eac2430fa5b2946251 -re9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14 --- src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision f6fe924675e9de6120b6c1eac2430fa5b2946251) +++ src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision e9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14) @@ -19,6 +19,7 @@ *************************************************************************/ #include "stdafx.h" #include "ResourceManager.h" +#include "../libicpf/exception.h" #include "../libicpf/cfg.h" #include "../libicpf/crc32.h" #include @@ -97,6 +98,11 @@ m_uiChecksum = 0; } +const tchar_t* CTranslationItem::GetText() const +{ + return m_pszText ? m_pszText : _t(""); +} + void CTranslationItem::SetText(const tchar_t* pszText, bool bUnescapeString) { delete [] m_pszText; @@ -524,6 +530,10 @@ void CLangData::WriteTranslation(PCTSTR pszPath) { + if(!IsValidDescription()) + THROW(_t("Invalid translation information (author, name or point size)"), 0, 0, 0); + + // real writing const int iBufferSize = 256; tchar_t szTemp[iBufferSize]; @@ -693,6 +703,17 @@ m_bModified = true; } +bool CLangData::IsValidDescription() const +{ + // basic sanity checks + if(!m_pszAuthor || m_pszAuthor[0] == _t('\0') || + !m_pszLngName || m_pszLngName[0] == _t('\0') || + !m_pszFontFace || m_pszFontFace[0] == _t('\0') || + m_wPointSize == 0) + return false; + return true; +} + void CLangData::SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc) { if (*ppszDst) Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -rf6fe924675e9de6120b6c1eac2430fa5b2946251 -re9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14 --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision f6fe924675e9de6120b6c1eac2430fa5b2946251) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision e9d0e63fbb826dd00b7c590d2dcda5e5f41b4b14) @@ -60,7 +60,7 @@ void Clear(); void CalculateChecksum(); - const tchar_t* GetText() const { return m_pszText; } + const tchar_t* GetText() const; void SetText(const tchar_t* pszText, bool bUnescapeString); uint_t GetChecksum() const { return m_uiChecksum; } void SetChecksum(uint_t uiChecksum) { m_uiChecksum = uiChecksum; } @@ -127,6 +127,7 @@ bool IsModified() const { return m_bModified; } void SetModified() { m_bModified = true; } + bool IsValidDescription() const; protected: void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); static void EnumAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData);