Skip to content

Commit

Permalink
Improve Win32Handle::IsValid
Browse files Browse the repository at this point in the history
- Try making the intent more clearer by making Win32Handle::IsValid virtual and override where applicable
- Also check the HANDLE in Win32File, not just the OVL
  • Loading branch information
visuve committed Feb 5, 2024
1 parent 35ca8cf commit f726ee5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 12 additions & 1 deletion HackLib/Win32File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ Win32File::Win32File(const std::filesystem::path& path, DWORD access) :
_size = size.LowPart;
}

Win32File::~Win32File()
HANDLE Win32File::Value() const
{
return _handle;
}

size_t Win32File::Size() const
{
return _size;
}

bool Win32File::IsValid() const
{
return Win32Handle::IsValid() && _ovl.Offset <= _size;
}

size_t Win32File::Read(void* buffer, size_t size)
Expand Down
18 changes: 3 additions & 15 deletions HackLib/Win32File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@ class Win32File : public Win32Handle
{
public:
explicit Win32File(const std::filesystem::path& path, DWORD access = GENERIC_READ);
virtual ~Win32File();

NonCopyable(Win32File);

inline HANDLE Value() const
{
return _handle;
}

inline size_t Size() const
{
return _size;
}

inline operator bool() const
{
return _ovl.Offset <= _size;
}
HANDLE Value() const;
size_t Size() const;
bool IsValid() const override;

size_t Read(void* buffer, size_t size);
size_t ReadAt(void* buffer, size_t size, size_t offset);
Expand Down
2 changes: 1 addition & 1 deletion HackLib/Win32Handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Win32Handle
Win32Handle& operator = (const Win32Handle& other) = delete;
Win32Handle& operator = (Win32Handle&& other);

bool IsValid() const;
virtual bool IsValid() const;
operator bool() const;

void Reset(HANDLE handle = nullptr);
Expand Down

0 comments on commit f726ee5

Please sign in to comment.