-
Notifications
You must be signed in to change notification settings - Fork 21
/
hash.ixx
106 lines (81 loc) · 2.71 KB
/
hash.ixx
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module;
#include <filesystem>
#include <fstream>
#include <list>
#include <vector>
#include "throw_line.hh"
export module hash;
import cd.cd;
import dump;
import options;
import rom_entry;
import utils.animation;
import utils.logger;
import utils.misc;
namespace gpsxre
{
void progress_output(uint64_t byte, uint64_t bytes_count)
{
char animation = byte == bytes_count ? '*' : spinner_animation();
LOGC_RF("{} [{:3}%] hashing", animation, byte * 100 / bytes_count);
}
export void redumper_hash(Context &ctx, Options &options)
{
if(!ctx.dat)
{
image_check_empty(options);
auto image_prefix = (std::filesystem::path(options.image_path) / options.image_name).string();
std::vector<std::filesystem::path> files;
if(std::filesystem::exists(image_prefix + ".cue"))
{
for(auto const &t : cue_get_entries(image_prefix + ".cue"))
files.push_back(std::filesystem::path(options.image_path) / t.first);
}
else if(std::filesystem::exists(image_prefix + ".iso"))
{
files.push_back(image_prefix + ".iso");
}
else
throw_line("image file not found");
if(!files.empty())
{
uint64_t byte = 0;
uint64_t bytes_count = 0;
for(auto f : files)
bytes_count += std::filesystem::file_size(f);
std::vector<std::string> dat;
std::vector<uint8_t> sector(CD_DATA_SIZE);
for(auto f : files)
{
std::fstream fs(f, std::fstream::in | std::fstream::binary);
if(!fs.is_open())
throw_line("unable to open file ({})", f.filename().string());
ROMEntry rom_entry(f.filename().string());
std::vector<uint8_t> data(1024 * 1024); // 1Mb chunk
batch_process_range<uint64_t>(std::pair(0, std::filesystem::file_size(f)), data.size(),
[&](uint64_t offset, uint64_t size) -> bool
{
progress_output(byte, bytes_count);
fs.read((char *)data.data(), size);
if(fs.fail())
throw_line("read failed ({})", f.filename().string());
rom_entry.update(data.data(), size);
byte += size;
return false;
});
dat.push_back(rom_entry.xmlLine());
}
ctx.dat = dat;
progress_output(bytes_count, bytes_count);
LOG("");
LOG("");
}
}
if(ctx.dat)
{
LOG("dat:");
for(auto l : *ctx.dat)
LOG("{}", l);
}
}
}