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;
|
|
|
|
|
2018-12-16 13:19:26 +01:00
|
|
|
import java.io.File;
|
2017-05-17 19:20:42 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.regex.Pattern;
|
2019-02-28 21:17:18 +01:00
|
|
|
import java.util.stream.Collectors;
|
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.content.Content;
|
|
|
|
import de.mas.wiiu.jnus.entities.content.ContentFSTInfo;
|
|
|
|
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;
|
2017-05-17 19:20:42 +02:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
|
|
|
|
|
|
|
public class NUSTitle {
|
|
|
|
@Getter @Setter private FST FST;
|
|
|
|
@Getter @Setter private TMD TMD;
|
|
|
|
@Getter @Setter private Ticket ticket;
|
|
|
|
|
|
|
|
@Getter @Setter private boolean skipExistingFiles = true;
|
|
|
|
@Getter @Setter private NUSDataProvider dataProvider = null;
|
|
|
|
|
|
|
|
public List<FSTEntry> getAllFSTEntriesFlatByContentID(short ID) {
|
|
|
|
return getFSTEntriesFlatByContent(getTMD().getContentByID((int) ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<FSTEntry> getFSTEntriesFlatByContentIndex(int index) {
|
|
|
|
return getFSTEntriesFlatByContent(getTMD().getContentByIndex(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<FSTEntry> getFSTEntriesFlatByContent(Content content) {
|
|
|
|
return getFSTEntriesFlatByContents(new ArrayList<Content>(Arrays.asList(content)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<FSTEntry> getFSTEntriesFlatByContents(List<Content> list) {
|
2019-02-28 21:17:18 +01:00
|
|
|
return list.stream().flatMap(c -> c.getEntries().stream()).collect(Collectors.toList());
|
2017-05-17 19:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<FSTEntry> getAllFSTEntriesFlat() {
|
|
|
|
return getFSTEntriesFlatByContents(new ArrayList<Content>(getTMD().getAllContents().values()));
|
|
|
|
}
|
|
|
|
|
2019-02-28 21:34:41 +01:00
|
|
|
public Stream<FSTEntry> getAllFSTEntriesAsStream() {
|
|
|
|
return getAllFSTEntryChildrenAsStream(FST.getRoot());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Stream<FSTEntry> getAllFSTEntryChildrenAsStream(FSTEntry cur) {
|
|
|
|
return getAllFSTEntryChildrenAsStream(cur, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Stream<FSTEntry> getAllFSTEntryChildrenAsStream(FSTEntry cur, boolean allowNotInPackage) {
|
|
|
|
return cur.getChildren().stream() //
|
|
|
|
.filter(e -> allowNotInPackage || !e.isNotInPackage()) //
|
|
|
|
.flatMap(e -> {
|
|
|
|
if (!e.isDir()) {
|
2019-02-28 21:53:09 +01:00
|
|
|
return Stream.of(e);
|
2019-02-28 21:34:41 +01:00
|
|
|
}
|
|
|
|
return getAllFSTEntryChildrenAsStream(e, allowNotInPackage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-17 19:20:42 +02:00
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {
|
2019-02-28 22:13:52 +01:00
|
|
|
return getFSTEntriesByRegEx(regEx, FST.getRoot());
|
|
|
|
}
|
2018-03-10 12:22:10 +01:00
|
|
|
|
2019-02-28 22:13:52 +01:00
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, FSTEntry entry) {
|
|
|
|
return getFSTEntriesByRegEx(regEx, entry, true);
|
|
|
|
}
|
2018-03-10 12:22:10 +01:00
|
|
|
|
2019-02-28 22:13:52 +01:00
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, boolean onlyInPackage) {
|
|
|
|
return getFSTEntriesByRegEx(regEx, FST.getRoot(), onlyInPackage);
|
2017-05-17 19:20:42 +02:00
|
|
|
}
|
2019-02-28 22:13:52 +01:00
|
|
|
|
|
|
|
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, FSTEntry entry, boolean allowNotInPackage) {
|
|
|
|
Pattern p = Pattern.compile(regEx);
|
|
|
|
return getFSTEntriesByRegExStream(p, entry, allowNotInPackage).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
private Stream<FSTEntry> getFSTEntriesByRegExStream(Pattern p, FSTEntry entry, boolean allowNotInPackage) {
|
|
|
|
return entry.getChildren().stream()//
|
|
|
|
.filter(e -> allowNotInPackage || !e.isNotInPackage()) //
|
|
|
|
.flatMap(e -> {
|
|
|
|
if (!e.isDir()) {
|
2019-04-04 10:21:43 +02:00
|
|
|
if (p.matcher(e.getFullPath().replace("/", File.separator)).matches()) {
|
2019-04-04 10:23:04 +02:00
|
|
|
return Stream.of(e);
|
2019-02-28 22:13:52 +01:00
|
|
|
} else {
|
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return getFSTEntriesByRegExStream(p, e, allowNotInPackage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-17 19:20:42 +02:00
|
|
|
public void printFiles() {
|
|
|
|
getFST().getRoot().printRecursive(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void printContentFSTInfos() {
|
|
|
|
for (Entry<Integer, ContentFSTInfo> e : getFST().getContentFSTInfos().entrySet()) {
|
|
|
|
System.out.println(String.format("%08X", e.getKey()) + ": " + e.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void printContentInfos() {
|
|
|
|
for (Entry<Integer, Content> e : getTMD().getAllContents().entrySet()) {
|
|
|
|
|
|
|
|
System.out.println(String.format("%08X", e.getKey()) + ": " + e.getValue());
|
|
|
|
System.out.println(e.getValue().getContentFSTInfo());
|
|
|
|
for (FSTEntry entry : e.getValue().getEntries()) {
|
|
|
|
System.out.println(entry.getFullPath() + String.format(" size: %016X", entry.getFileSize())
|
|
|
|
+ String.format(" offset: %016X", entry.getFileOffset()) + String.format(" flags: %04X", entry.getFlags()));
|
|
|
|
}
|
|
|
|
System.out.println("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cleanup() throws IOException {
|
|
|
|
if (getDataProvider() != null) {
|
|
|
|
getDataProvider().cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void printDetailedData() {
|
|
|
|
printFiles();
|
|
|
|
printContentFSTInfos();
|
|
|
|
printContentInfos();
|
|
|
|
|
|
|
|
System.out.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "NUSTitle [dataProvider=" + dataProvider + "]";
|
|
|
|
}
|
|
|
|
}
|