1 #include "recentfiles.hpp"
14 path::path(const std::string
& p
)
19 std::string
path::serialize() const
24 path
path::deserialize(const std::string
& s
)
30 std::string
path::get_path() const
35 bool path::check() const
40 return zip::file_exists(pth
);
47 std::string
path::display() const
52 bool path::operator==(const path
& p
) const
62 std::string
multirom::serialize() const
65 JSON::node
output(JSON::object
);
67 output
["pack"] = JSON::string(packfile
);
68 } else if(singlefile
!= "") {
69 output
["file"] = JSON::string(singlefile
);
70 if(core
!= "") output
["core"] = JSON::string(core
);
71 if(system
!= "") output
["system"] = JSON::string(system
);
72 if(region
!= "") output
["region"] = JSON::string(region
);
74 output
["files"] = JSON::array();
75 JSON::node
& f
= output
["files"];
77 f
.append(JSON::string(i
));
81 if(core
!= "") output
["core"] = JSON::string(core
);
82 if(system
!= "") output
["system"] = JSON::string(system
);
83 if(region
!= "") output
["region"] = JSON::string(region
);
85 if(packfile
!= "" || singlefile
!= "" || core
!= "" || system
!= "" || region
!= "") any
= true;
87 return output
.serialize();
90 multirom
multirom::deserialize(const std::string
& s
)
93 if(s
.length() > 0 && s
[0] == '{') {
97 if(d
.field_exists("pack")) r
.packfile
= d
["pack"].as_string8();
98 if(d
.field_exists("file")) r
.singlefile
= d
["file"].as_string8();
99 if(d
.field_exists("core")) r
.core
= d
["core"].as_string8();
100 if(d
.field_exists("system")) r
.system
= d
["system"].as_string8();
101 if(d
.field_exists("region")) r
.region
= d
["region"].as_string8();
102 if(d
.field_exists("files")) {
103 size_t cnt
= d
["files"].index_count();
105 for(unsigned i
= 0; i
< cnt
; i
++)
106 r
.files
[i
] = d
["files"].index(i
).as_string8();
123 bool multirom::check() const
125 if(packfile
== "" && singlefile
== "" && core
== "" && system
== "" && region
== "" && files
.empty())
127 if(packfile
!= "" && !zip::file_exists(packfile
))
129 if(singlefile
!= "" && !zip::file_exists(singlefile
))
132 if(i
!= "" && !zip::file_exists(i
))
137 std::string
multirom::display() const
141 if(singlefile
!= "") {
142 return singlefile
+ " <" + core
+ "/" + system
+ ">";
144 if(files
.size() > 1 && files
[1] != "")
145 return (stringfmt() << files
[1] << " (+" << files
.size() << ")").str();
146 else if(files
.size() > 0)
147 return (stringfmt() << files
[0] << " (+" << files
.size() << ")").str();
149 return "(blank) <" + core
+ "/" + system
+ ">";
153 bool multirom::operator==(const multirom
& p
) const
155 if(packfile
!= p
.packfile
)
157 if(singlefile
!= p
.singlefile
)
161 if(system
!= p
.system
)
163 if(region
!= p
.region
)
165 if(files
.size() != p
.files
.size())
167 for(unsigned i
= 0; i
< files
.size(); i
++)
168 if(files
[i
] != p
.files
[i
])
173 template<class T
> set
<T
>::set(const std::string
& _cfgfile
, size_t _maxcount
)
176 maxcount
= _maxcount
;
179 template<class T
> void set
<T
>::add(const T
& file
)
184 std::ifstream
in(cfgfile
);
190 g
= T::deserialize(f
);
198 //Search for matches. If found, move to front, otherwise push to first.
199 auto itr
= ents
.begin();
200 for(; itr
!= ents
.end(); itr
++)
203 if(itr
!= ents
.end())
205 ents
.push_front(file
);
206 //Write up to maxcount entries.
209 std::ofstream
out(cfgfile
);
210 for(itr
= ents
.begin(); itr
!= ents
.end() && i
< maxcount
; itr
++, i
++)
211 out
<< itr
->serialize() << std::endl
;
217 template<class T
> void set
<T
>::add_hook(hook
& h
)
222 template<class T
> void set
<T
>::remove_hook(hook
& h
)
224 for(auto itr
= hooks
.begin(); itr
!= hooks
.end(); itr
++)
231 template<class T
> std::list
<T
> set
<T
>::get()
237 std::ifstream
in(cfgfile
);
243 g
= T::deserialize(f
);
247 if(c
< maxcount
&& g
.check()) {
260 void _dummy_63263632747434353545()
263 eat_argument(&set
<path
>::add
);
264 eat_argument(&set
<path
>::add_hook
);
265 eat_argument(&set
<path
>::remove_hook
);
266 eat_argument(&set
<path
>::get
);
267 set
<multirom
> y("", 0);
268 eat_argument(&set
<multirom
>::add
);
269 eat_argument(&set
<multirom
>::add_hook
);
270 eat_argument(&set
<multirom
>::remove_hook
);
271 eat_argument(&set
<multirom
>::get
);