-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathScanner.cpp
71 lines (71 loc) · 2.15 KB
/
Scanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "Scanner.hpp"
#include "Platforms/Platform.hpp"
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using DirIter = fs::directory_iterator;
std::vector<Data> scanData(const fs::path& dataPath) {
if(!fs::exists(dataPath))
return {};
std::map<fs::path, fs::path> in, out;
std::vector<Data> res;
for(auto it : DirIter(dataPath)) {
it.refresh();
if(!it.is_regular_file())
continue;
auto cp = it.path(), name = cp.stem(),
ext = cp.extension();
if(!cp.has_extension() || ext == ".in") {
if(out.count(name))
res.push_back(Data(cp, out[name]));
else
in[name] = cp;
} else if(ext == ".out" || ext == ".a" ||
ext == ".ans") {
if(in.count(name))
res.push_back(Data(in[name], cp));
else
out[name] = cp;
}
}
std::sort(res.begin(), res.end());
line("Auto Scan Result");
std::cout << "task count:" << res.size()
<< std::endl;
{
uintmax_t maxInput = 0, maxOutput = 0;
for(auto d : res) {
maxInput = std::max(
maxInput, fs::file_size(d.input));
maxOutput = std::max(
maxOutput, fs::file_size(d.output));
}
std::cout << "maxInput:"
<< maxInput / 1048576.0 << " MB"
<< std::endl;
std::cout << "maxOutput:"
<< maxOutput / 1048576.0 << " MB"
<< std::endl;
}
return res;
}
fs::path scanExec() {
std::set<fs::path> blacklist{ "checker",
"charCounter" };
fs::file_time_type mft;
fs::path res;
for(auto it : DirIter(fs::current_path())) {
it.refresh();
if(!it.is_regular_file())
continue;
auto cp = it.path(), name = cp.stem(),
ext = cp.extension();
if(ext != ".out" || blacklist.count(name))
continue;
auto cft = fs::last_write_time(cp);
if(cft > mft)
mft = cft, res = cp;
}
return fs::relative(res);
}