This repository was archived by the owner on Jul 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMetalink.cpp
More file actions
87 lines (75 loc) · 1.77 KB
/
Metalink.cpp
File metadata and controls
87 lines (75 loc) · 1.77 KB
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
#include "Metalink.hpp"
#include "Metalink4Writer.hpp"
#include "Metalink3Writer.hpp"
#include "Metalink4Reader.hpp"
#include "Metalink3Reader.hpp"
#include <wx/filename.h>
int Metalink::num_files() const
{
return files_.size();
}
bool Metalink::is_empty() const
{
return files_.empty();
}
void Metalink::add_file(const MetalinkFile& file)
{
files_.push_back(file);
}
void Metalink::remove_file(int index)
{
if(index >= files_.size()) return;
files_.erase(files_.begin() + index);
}
void Metalink::set_file(int index, const MetalinkFile& file)
{
files_.at(index) = file;
}
const MetalinkFile& Metalink::get_file(int index) const
{
return files_.at(index);
}
const std::vector<MetalinkFile>& Metalink::get_files() const
{
return files_;
}
void Metalink::clear()
{
files_.clear();
}
void Metalink::save(const wxString& filename)
{
if(wxFileName(filename).GetExt() == wxT("metalink")) {
Metalink3Writer writer(*this);
writer.save(filename);
} else {
Metalink4Writer writer(*this);
writer.save(filename);
}
}
Metalink Metalink::load(const wxString& filename)
{
Metalink ml;
bool loaded = load_metalink4(filename, &ml);
if(!loaded) {
loaded = load_metalink3(filename, &ml);
}
if(!loaded) {
throw MetalinkLoadError("Unrecognized file format!");
}
return ml;
}
bool Metalink::load_metalink4(const wxString& filename, Metalink* metalink)
{
Metalink4Reader reader;
reader.load(filename);
*metalink = reader.get_metalink();
return reader.is_recognized();
}
bool Metalink::load_metalink3(const wxString& filename, Metalink* metalink)
{
Metalink3Reader reader;
reader.load(filename);
*metalink = reader.get_metalink();
return reader.is_recognized();
}