-
Notifications
You must be signed in to change notification settings - Fork 2
/
ziprom.h
129 lines (102 loc) · 4.23 KB
/
ziprom.h
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
/*
* This file is part of the Advance project.
*
* Copyright (C) 1998, 1999, 2000, 2001, 2002 Andrea Mazzoleni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ZIPROM_H
#define __ZIPROM_H
#include "zip.h"
#include "rom.h"
enum zip_type {
zip_own, // roms part of the set
zip_import, // roms of other sets used for importing
zip_unknown // roms unknown
};
class ziprom : public zip {
zip_type type;
bool readonly;
void move(const std::string& zipintname_src, ziprom& dst, const std::string& zipintname_dst);
ziprom();
public:
ziprom(const std::string& Apath, zip_type Atype, bool Areadonly);
ziprom(const ziprom& A);
~ziprom();
bool is_readonly() const { return readonly; }
zip_type type_get() const { return type; }
void open();
ziprom::iterator find(const std::string& name);
void load();
void unload();
void save();
void crc(const std::string& zipintname, crc_t& crc);
void remove(const std::string& zipintname);
void remove(const std::string& zipintname, ziprom& reject);
void add(const ziprom::const_iterator& entry_src, const std::string& zipintname_dst);
void add(const ziprom::const_iterator& entry_src, const std::string& zipintname_dst, ziprom& reject);
void add(const std::string& zipintname_src, const std::string& zipintname_dst);
void add(const std::string& zipintname_src, const std::string& zipintname_dst, ziprom& reject);
void rename(const std::string& zipintname_src, const std::string& zipintname_dst, ziprom& reject);
void swap(const std::string& zipintname, ziprom& reject, ziprom::iterator& reject_entry);
};
struct ziprom_by_file_less : std::binary_function<ziprom, ziprom, bool> {
bool operator()(const ziprom& A, const ziprom& B) const {
// don't use file_compare, do exact compare
return A.file_get() < B.file_get();
}
};
typedef std::list<ziprom> zipromcontainer;
class ziparchive_crcsize {
crc_t crc;
unsigned size;
public:
ziparchive_crcsize();
ziparchive_crcsize(const ziparchive_crcsize& A);
ziparchive_crcsize(unsigned size, crc_t crc);
~ziparchive_crcsize();
bool operator==(const ziparchive_crcsize& A) const { return crc==A.crc && size==A.size; }
bool operator<(const ziparchive_crcsize& A) const { return crc<A.crc || (crc==A.crc && size<A.size); }
};
typedef std::set<ziparchive_crcsize> ziparchive_crcsizeset;
class ziparchive {
public:
typedef zipromcontainer::const_iterator const_iterator;
typedef zipromcontainer::iterator iterator;
private:
zipromcontainer data; // list of zip
mutable ziparchive_crcsizeset index; // fast exist test in data
ziparchive(const ziparchive&);
const_iterator find_iter(unsigned size, crc_t crc, ziprom::const_iterator& k) const;
const_iterator find_iter(unsigned size, crc_t crc, zip_type type, ziprom::const_iterator& k) const;
const_iterator find_exclude_iter(const ziprom& exclude, unsigned size, crc_t crc, ziprom::const_iterator& k) const;
public:
ziparchive();
~ziparchive();
unsigned size() const { return data.size(); }
iterator open_and_insert(const ziprom& A);
void update(const ziprom& A);
void erase(iterator A);
iterator begin() { return data.begin(); }
iterator end() { return data.end(); }
const_iterator begin() const { return data.begin(); }
const_iterator end() const { return data.end(); }
const_iterator find(const std::string& zipfile) const;
iterator find(const std::string& zipfile);
const_iterator find(unsigned size, crc_t crc, ziprom::const_iterator& k) const;
const_iterator find(unsigned size, crc_t crc, zip_type type, ziprom::const_iterator& k) const;
const_iterator find_exclude(const ziprom& exclude, unsigned size, crc_t crc, ziprom::const_iterator& k) const;
};
#endif