From bf79e4641181f6395cae6b1bcfafd03f4bcfdb85 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 4 Jul 2023 22:59:57 +0200 Subject: [PATCH] add a GetUTF8File(...) method with a pt::WTextStream & content to the misc --- winixd/core/misc.cpp | 34 +++++++++++++++++++++++++++++++++- winixd/core/misc.h | 6 +++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/winixd/core/misc.cpp b/winixd/core/misc.cpp index 343cc26..f913d19 100644 --- a/winixd/core/misc.cpp +++ b/winixd/core/misc.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2021, Tomasz Sowa + * Copyright (c) 2008-2023, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1162,6 +1162,38 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl } +bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content) +{ +char file[WINIX_OS_PATH_SIZE]; +std::ifstream get_file_content; + + if( clear_content ) + content.clear(); + + if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) ) + return false; + + get_file_content.open(file, std::ios_base::in | std::ios_base::binary); + + if( !get_file_content ) + return false; + + /* + * we don't report any errors when converting from UTF8 to wide characters here + */ + pt::utf8_to_wide(get_file_content, content); + get_file_content.close(); + +return true; +} + + +bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content) +{ + return GetUTF8File(file_path.c_str(), content, clear_content); +} + + bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content) { diff --git a/winixd/core/misc.h b/winixd/core/misc.h index 4da91e7..d0f7246 100644 --- a/winixd/core/misc.h +++ b/winixd/core/misc.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2021, Tomasz Sowa + * Copyright (c) 2008-2023, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -664,6 +664,10 @@ bool RenameFile(const std::wstring & from, const std::wstring & to); bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true); bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true); +bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content = true); +bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content = true); + + bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content = true); bool GetBinaryFile(const std::wstring & file_path, BinaryPage & content, bool clear_content = true);