File tree Expand file tree Collapse file tree 4 files changed +55
-11
lines changed Expand file tree Collapse file tree 4 files changed +55
-11
lines changed Original file line number Diff line number Diff line change
1
+ #pragma once
2
+ #include < iostream>
3
+ #include < vector>
4
+ #include < fstream>
5
+ #include < filesystem>
6
+ #include < optional>
7
+ #include " xor.hpp"
8
+
9
+ namespace commons ::file
10
+ {
11
+ inline std::optional<std::vector<char >> ReadFile (const std::filesystem::path& fullFilePath)
12
+ {
13
+ if (!exists (fullFilePath))
14
+ {
15
+ std::wcerr << XORW (L" Cannot open file: " ) << fullFilePath << ' \n ' ;
16
+ return std::nullopt ;
17
+ }
18
+
19
+ std::ifstream file (fullFilePath, std::ios::binary | std::ios::ate);
20
+
21
+ if (!file)
22
+ {
23
+ std::wcerr << XORW (L" Failed to open file: " ) << fullFilePath << ' \n ' ;
24
+ return std::nullopt ;
25
+ }
26
+
27
+ const std::streampos size = file.tellg ();
28
+ std::vector<char > buffer (static_cast <size_t >(size));
29
+ file.seekg (0 , std::ios::beg);
30
+ file.read (buffer.data (), size);
31
+
32
+ return buffer;
33
+ }
34
+ }
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
#include < string>
3
3
4
- #ifndef NDEBUG
5
- template <typename ... Args>
6
- void LOG (const std::wstring& fmt, Args&&... args)
4
+ namespace commons ::logger
7
5
{
8
- wprintf (fmt.c_str (), std::forward<Args>(args)...);
9
- }
6
+ #ifndef NDEBUG
7
+ template <typename ... Args>
8
+ void LOG (const std::wstring& fmt, Args&&... args)
9
+ {
10
+ wprintf (fmt.c_str (), std::forward<Args>(args)...);
11
+ }
10
12
11
- template <typename ... Args>
12
- void LOG (const std::string& fmt, Args&&... args)
13
- {
14
- printf (fmt.c_str (), std::forward<Args>(args)...);
15
- }
13
+ template <typename ... Args>
14
+ void LOG (const std::string& fmt, Args&&... args)
15
+ {
16
+ printf (fmt.c_str (), std::forward<Args>(args)...);
17
+ }
16
18
#else
17
- #define LOG (...)
19
+ template <typename ... Args>
20
+ void LOG (const std::wstring& fmt, Args&&... args)
21
+ {
22
+ }
18
23
#endif
24
+ }
Original file line number Diff line number Diff line change 147
147
</ItemGroup >
148
148
<ItemGroup >
149
149
<ClInclude Include =" include\console.hpp" />
150
+ <ClInclude Include =" include\file.hpp" />
150
151
<ClInclude Include =" include\keyboard.hpp" />
151
152
<ClInclude Include =" include\memory.hpp" />
152
153
<ClInclude Include =" include\process.hpp" />
Original file line number Diff line number Diff line change 41
41
<ClInclude Include =" include\logger.hpp" >
42
42
<Filter >Header Files</Filter >
43
43
</ClInclude >
44
+ <ClInclude Include =" include\file.hpp" >
45
+ <Filter >Header Files</Filter >
46
+ </ClInclude >
44
47
</ItemGroup >
45
48
</Project >
You can’t perform that action at this time.
0 commit comments