aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-08-29 12:40:04 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-08-29 12:40:04 -0400
commitcf77acfa0fab7b3dd42781b483835a85b12308f2 (patch)
treea57e7a1f0ae8a11f9a83963025344f3aa5f1c4c1 /tests
parentd6663fe7b71db340b3c7a1d069c473f725caa3a8 (diff)
downloaddeduper-cf77acfa0fab7b3dd42781b483835a85b12308f2.tar.xz
Rewrite file header peeking.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/testdrive.cpp23
2 files changed, 16 insertions, 10 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2190875..5990374 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -29,3 +29,6 @@ target_link_libraries(testdrive
${CMAKE_THREAD_LIBS_INIT}
xsig
)
+if(WIN32)
+ target_link_libraries(testdrive shell32 kernel32)
+endif()
diff --git a/tests/testdrive.cpp b/tests/testdrive.cpp
index 2d8b0eb..b6d7436 100644
--- a/tests/testdrive.cpp
+++ b/tests/testdrive.cpp
@@ -2,6 +2,7 @@
#include <cstring>
#include <filesystem>
+#include <fstream>
#include <string>
#include <unordered_map>
#include <utility>
@@ -16,6 +17,8 @@
#ifdef _WIN32 //for the superior operating system
#include <cwchar>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#include <processenv.h>
#include <shellapi.h>
#endif
@@ -168,18 +171,18 @@ void build_file_list(fs::path path, bool recursive, std::vector<fs::path> &out)
auto dirit = fs::recursive_directory_iterator(path);
for (auto &p : dirit)
{
- FILE* fp = fopen(p.path().c_str(),"r");
+ std::fstream st(p.path(), std::ios::binary | std::ios::in);
char c[8];
- size_t sz = fread((void*)c,1,6,fp);
- if (sz < 6) continue;
- if(!memcmp(c,"\x89PNG\r\n",6)||!memcmp(c,"\xff\xd8\xff",3))
+ st.read(c, 6);
+ if (st.gcount() < 6) continue;
+ if(!memcmp(c,"\x89PNG\r\n", 6) || !memcmp(c,"\xff\xd8\xff", 3))
{
out.push_back(p.path().string());
#if DEBUG > 0
printf("%ld, %s\n", out.size() - 1, out.back().c_str());
#endif
}
- fclose(fp);
+ st.close();
}
}
else
@@ -187,18 +190,18 @@ void build_file_list(fs::path path, bool recursive, std::vector<fs::path> &out)
auto dirit = fs::directory_iterator(path);
for(auto &p : dirit)
{
- FILE* fp = fopen(p.path().c_str(),"r");
+ std::fstream st(p.path(), std::ios::binary | std::ios::in);
char c[8];
- size_t sz = fread((void*)c,1,6,fp);
- if (sz < 6) continue;
- if(!memcmp(c,"\x89PNG\r\n",6)||!memcmp(c,"\xff\xd8\xff",3))
+ st.read(c, 6);
+ if (st.gcount() < 6) continue;
+ if(!memcmp(c,"\x89PNG\r\n", 6) || !memcmp(c,"\xff\xd8\xff", 3))
{
out.push_back(p.path().string());
#if DEBUG > 0
printf("%ld, %s\n", out.size() - 1, out.back().c_str());
#endif
}
- fclose(fp);
+ st.close();
}
}
}