Skip to content

Commit

Permalink
hide more data
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenegriffin committed Dec 20, 2020
1 parent 88c3055 commit 37c98eb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
18 changes: 5 additions & 13 deletions UI/Dialogs/Editors/RestrictEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,15 @@ namespace dialog::editor
const auto res = lpData->cast<sortlistdata::resData>();
if (!res) return false;

const auto lpSourceRes = res->m_lpNewRes ? res->m_lpNewRes : res->m_lpOldRes;
const auto lpSourceRes = res->getCurrentRes();

CRestrictEditor MyResEditor(this, m_lpAllocParent,
lpSourceRes); // pass source res into editor
if (!MyResEditor.DisplayDialog()) return false;
// Since lpData->data.Res.lpNewRes was owned by an m_lpAllocParent, we don't free it directly
res->m_lpNewRes = MyResEditor.DetachModifiedSRestriction();
SetListString(ulListNum, iItem, 1, property::RestrictionToString(res->m_lpNewRes, nullptr));
const auto newRes = MyResEditor.DetachModifiedSRestriction();
res->setCurrentRes(newRes);
SetListString(ulListNum, iItem, 1, property::RestrictionToString(newRes, nullptr));
return true;
}

Expand All @@ -565,16 +566,7 @@ namespace dialog::editor
const auto res = lpData->cast<sortlistdata::resData>();
if (res)
{
if (res->m_lpNewRes)
{
memcpy(&lpNewResArray[paneID], res->m_lpNewRes, sizeof(SRestriction));
memset(res->m_lpNewRes, 0, sizeof(SRestriction));
}
else
{
EC_H_S(mapi::HrCopyRestrictionArray(
res->m_lpOldRes, m_lpAllocParent, 1, &lpNewResArray[paneID]));
}
lpNewResArray[paneID] = res->detachRes(m_lpAllocParent);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/sortlistdata/binaryData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace sortlistdata
{
if (m_NewBin.lpb)
{
return &m_OldBin;
return &m_NewBin;
}
else
{
return &m_NewBin;
return &m_OldBin;
}
}
void setCurrentBin(_In_ const SBinary& bin) { m_NewBin = bin; }
Expand Down
19 changes: 19 additions & 0 deletions core/sortlistdata/resData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <core/stdafx.h>
#include <core/sortlistdata/resData.h>
#include <core/sortlistdata/sortListData.h>
#include <core/utility/error.h>

namespace sortlistdata
{
Expand All @@ -12,4 +13,22 @@ namespace sortlistdata
}

resData::resData(_In_opt_ const _SRestriction* lpOldRes) noexcept : m_lpOldRes(lpOldRes) {}

_Check_return_ _SRestriction resData::detachRes(_In_opt_ const VOID* parent)
{
auto ret = _SRestriction{};
if (m_lpNewRes)
{
memcpy(&ret, m_lpNewRes, sizeof(SRestriction));
// clear out members so we don't double free
memset(m_lpNewRes, 0, sizeof(SRestriction));
}
else
{
EC_H_S(mapi::HrCopyRestrictionArray(m_lpOldRes, parent, 1, &ret));
}

return ret;
}

} // namespace sortlistdata
15 changes: 15 additions & 0 deletions core/sortlistdata/resData.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ namespace sortlistdata

resData(_In_opt_ const _SRestriction* lpOldRes) noexcept;

_Check_return_ const _SRestriction* getCurrentRes()
{
if (m_lpNewRes)
{
return m_lpNewRes;
}
else
{
return m_lpOldRes;
}
}
void setCurrentRes(_In_ _SRestriction* res) { m_lpNewRes = res; }
_Check_return_ _SRestriction detachRes(_In_opt_ const VOID* parent);

private:
const _SRestriction* m_lpOldRes{}; // not allocated - just a pointer
LPSRestriction m_lpNewRes{}; // Owned by an alloc parent - do not free
};
Expand Down

0 comments on commit 37c98eb

Please sign in to comment.