2018-03-10 12:22:10 +01:00
|
|
|
/****************************************************************************
|
2019-04-10 20:13:38 +02:00
|
|
|
* Copyright (C) 2016-2019 Maschell
|
2018-03-10 12:22:10 +01:00
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2017-05-17 19:20:42 +02:00
|
|
|
package de.mas.wiiu.jnus;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-04-18 11:18:32 +02:00
|
|
|
import java.text.ParseException;
|
2017-05-17 19:20:42 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-04-18 11:18:32 +02:00
|
|
|
import java.util.Optional;
|
2019-02-28 21:34:41 +01:00
|
|
|
import java.util.stream.Stream;
|
2017-05-17 19:20:42 +02:00
|
|
|
|
|
|
|
import de.mas.wiiu.jnus.entities.TMD;
|
|
|
|
import de.mas.wiiu.jnus.entities.Ticket;
|
|
|
|
import de.mas.wiiu.jnus.entities.fst.FST;
|
|
|
|
import de.mas.wiiu.jnus.entities.fst.FSTEntry;
|
2019-04-10 18:55:40 +02:00
|
|
|
import de.mas.wiiu.jnus.interfaces.NUSDataProvider;
|
2019-04-26 09:55:52 +02:00
|
|
|
import de.mas.wiiu.jnus.utils.FSTUtils;
|
2017-05-17 19:20:42 +02:00
|
|
|
import lombok.Getter;
|
2019-04-18 11:18:32 +02:00
|
|
|
import lombok.NonNull;
|
2017-05-17 19:20:42 +02:00
|
|
|
import lombok.Setter;
|
|
|
|
|
|
|
|
public class NUSTitle {
|
2019-04-18 11:18:32 +02:00
|
|
|
@Getter @Setter private Optional<FST> FST = Optional.empty();
|
|
|
|
@Getter @Setter private Optional<Ticket> ticket;
|
|
|
|
|
|
|
|
@Getter private final TMD TMD;
|
2017-05-17 19:20:42 +02:00
|
|
|
|
2019-04-18 11:18:32 +02:00
|
|
|
@Getter private final NUSDataProvider dataProvider;
|
|
|
|
|
|
|
|
public NUSTitle(@NonNull NUSDataProvider dataProvider) throws ParseException, IOException {
|
|
|
|
byte[] tmdData = dataProvider.getRawTMD().orElseThrow(() -> new ParseException("No TMD data found", 0));
|
|
|
|
this.TMD = de.mas.wiiu.jnus.entities.TMD.parseTMD(tmdData);
|
|
|
|
this.dataProvider = dataProvider;
|
2017-05-17 19:20:42 +02:00
|
|
|
}
|
|
|
|
|
2019-02-28 21:34:41 +01:00
|
|
|
public Stream<FSTEntry> getAllFSTEntriesAsStream() {
|
2019-04-18 11:18:32 +02:00
|
|
|
if (!FST.isPresent()) {
|
|
|
|
return Stream.empty();
|
|
|
|
}
|
2019-04-26 09:55:52 +02:00
|
|
|
return FSTUtils.getAllFSTEntryChildrenAsStream(FST.get().getRoot());
|
2019-02-28 21:34:41 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 19:20:42 +02:00
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {
|
2019-04-26 09:55:52 +02:00
|
|
|
return getFSTEntriesByRegEx(regEx, true);
|
2019-02-28 22:13:52 +01:00
|
|
|
}
|
2018-03-10 12:22:10 +01:00
|
|
|
|
2019-02-28 22:13:52 +01:00
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, boolean onlyInPackage) {
|
2019-04-18 11:18:32 +02:00
|
|
|
if (!FST.isPresent()) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
2019-04-26 09:55:52 +02:00
|
|
|
return FSTUtils.getFSTEntriesByRegEx(FST.get().getRoot(), regEx, onlyInPackage);
|
2017-05-17 19:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cleanup() throws IOException {
|
|
|
|
if (getDataProvider() != null) {
|
|
|
|
getDataProvider().cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "NUSTitle [dataProvider=" + dataProvider + "]";
|
|
|
|
}
|
|
|
|
}
|