forked from superg/redumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.ixx
129 lines (105 loc) · 2.82 KB
/
info.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
module;
#include <filesystem>
#include <fstream>
#include <list>
#include <string>
#include <utility>
#include <sstream>
#include "throw_line.hh"
export module info;
import cd.cdrom;
import dump;
import filesystem.iso9660;
import options;
import readers.sector_reader;
import readers.form1_reader;
import readers.image_bin_form1_reader;
import readers.image_iso_form1_reader;
import readers.image_raw_reader;
import readers.raw_reader;
import systems.system;
import systems.systems;
import utils.hex_bin;
import utils.logger;
import utils.misc;
import utils.strings;
namespace gpsxre
{
enum class TrackType
{
DATA,
AUDIO,
ISO
};
std::list<std::pair<std::string, bool>> cue_get_entries(const std::filesystem::path &cue_path)
{
std::list<std::pair<std::string, bool>> entries;
std::fstream fs(cue_path, std::fstream::in);
if(!fs.is_open())
throw_line("unable to open file ({})", cue_path.filename().string());
std::pair<std::string, bool> entry;
std::string line;
while(std::getline(fs, line))
{
auto tokens(tokenize(line, " \t", "\"\""));
if(tokens.size() == 3)
{
if(tokens[0] == "FILE")
entry.first = tokens[1];
else if(tokens[0] == "TRACK" && !entry.first.empty())
{
entry.second = tokens[2] != "AUDIO";
entries.push_back(entry);
entry.first.clear();
}
}
}
return entries;
}
export void redumper_info(Options &options)
{
if(options.image_name.empty())
throw_line("image name is not provided");
auto image_prefix = (std::filesystem::path(options.image_path) / options.image_name).string();
std::list<std::pair<std::filesystem::path, TrackType>> tracks;
if(std::filesystem::exists(image_prefix + ".cue"))
{
for(auto const &t : cue_get_entries(image_prefix + ".cue"))
tracks.emplace_back(std::filesystem::path(options.image_path) / t.first, t.second ? TrackType::DATA : TrackType::AUDIO);
}
else if(std::filesystem::exists(image_prefix + ".iso"))
{
tracks.emplace_back(image_prefix + ".iso", TrackType::ISO);
}
bool separate_nl = false;
for(auto const &t : tracks)
{
std::shared_ptr<SectorReader> raw_reader;
std::shared_ptr<SectorReader> form1_reader;
if(t.second == TrackType::ISO)
form1_reader = std::make_shared<Image_ISO_Form1Reader>(t.first);
else if(t.second == TrackType::DATA)
{
raw_reader = std::make_shared<Image_RawReader>(t.first);
form1_reader = std::make_shared<Image_BIN_Form1Reader>(t.first);
}
for(auto const &s : Systems::get())
{
auto system = s();
auto reader = system->getType() == System::Type::ISO ? form1_reader : raw_reader;
if(!reader)
continue;
std::stringstream ss;
system->printInfo(ss, reader.get(), t.first);
if(ss.rdbuf()->in_avail())
{
if(separate_nl)
LOG("");
separate_nl = true;
LOG("{} [{}]:", system->getName(), t.first.filename().string());
LOG_F("{}", ss.str());
}
}
}
}
}