fix: Import from a gamebase db handles files in different formats better
-gz files are not zipped again -prg files are not zipped at all since VICE does not handle it -rar files are handled in the same way as zip files (picking the first entry).
This commit is contained in:
parent
cb548a7014
commit
fcb31bde36
5
pom.xml
5
pom.xml
|
@ -67,6 +67,11 @@
|
|||
<artifactId>ucanaccess</artifactId>
|
||||
<version>4.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.junrar</groupId>
|
||||
<artifactId>junrar</artifactId>
|
||||
<version>0.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -567,9 +567,18 @@ public class GamebaseImporter
|
|||
{
|
||||
File selectedFile = FileManager.createTempFileForScraper(new BufferedInputStream(new FileInputStream(gameFile)),
|
||||
gameFile.getName());
|
||||
Path compressedFilePath = selectedFile.toPath().getParent().resolve(selectedFile.getName() + ".gz");
|
||||
FileManager.compressGzip(selectedFile.toPath(), compressedFilePath);
|
||||
return compressedFilePath.toString();
|
||||
//Do not compress prg files: Vice doesn't seem to unzip them properly
|
||||
String lowercaseName = selectedFile.getName().toLowerCase();
|
||||
if (lowercaseName.endsWith(".gz") || lowercaseName.endsWith(".prg") || lowercaseName.endsWith(".p00") )
|
||||
{
|
||||
return selectedFile.toPath().toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Path compressedFilePath = selectedFile.toPath().getParent().resolve(selectedFile.getName() + ".gz");
|
||||
FileManager.compressGzip(selectedFile.toPath(), compressedFilePath);
|
||||
return compressedFilePath.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -240,7 +240,7 @@ public class C64comScraper implements Scraper
|
|||
.execute();
|
||||
|
||||
//create a temp file and fetch the content
|
||||
scrapedFile = FileManager.createTempFileForScraper(response.bodyStream(), "ScrapedFile");
|
||||
scrapedFile = FileManager.createTempFileForScraper(response.bodyStream(), "ScrapedFile.zip");
|
||||
logger.debug("File to include as game: {}", scrapedFile != null ? scrapedFile.getAbsolutePath() : null);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -285,7 +285,7 @@ public class GamebaseScraper implements Scraper
|
|||
URLConnection conn = url.openConnection();
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
//create a temp file and fetch the content
|
||||
scrapedFile = FileManager.createTempFileForScraper(new BufferedInputStream(inputStream), "ScrapedFile");
|
||||
scrapedFile = FileManager.createTempFileForScraper(new BufferedInputStream(inputStream), "ScrapedFile.zip");
|
||||
logger.debug("File to include as game: {}", scrapedFile != null ? scrapedFile.getAbsolutePath() : null);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.io.FileWriter;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
|
@ -20,9 +19,7 @@ import java.nio.file.Paths;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -40,6 +37,9 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.github.junrar.Archive;
|
||||
import com.github.junrar.rarfile.FileHeader;
|
||||
|
||||
import se.lantz.db.DbConnector;
|
||||
import se.lantz.model.InfoModel;
|
||||
import se.lantz.model.MainViewModel;
|
||||
|
@ -1035,6 +1035,7 @@ public class FileManager
|
|||
|
||||
/**
|
||||
* Creates a temporary file from inputStream, just leaving the File as-is.
|
||||
*
|
||||
* @param inputStream The stream to read from
|
||||
* @param gameFilename The name of the file
|
||||
* @return The created temporary file
|
||||
|
@ -1057,9 +1058,10 @@ public class FileManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary file from inputStream, unzips the File and picks the first valid entry in the file.
|
||||
* Since GB64 for example can contain multiple disk images The first one is picked (no support for disk swap in the carousel).
|
||||
* Creates a temporary file from inputStream, unzips the File and picks the first valid entry in the file. Since GB64
|
||||
* for example can contain multiple disk images The first one is picked (no support for disk swap in the carousel).
|
||||
* For some file a .NFO file is the first entry, which will not work when passing it to the carousel.
|
||||
*
|
||||
* @param inputStream The stream to read from
|
||||
* @param gameFilename The name of the file
|
||||
* @return The first entry in the zip file (unzipped) to be included with the game during import.
|
||||
|
@ -1068,7 +1070,7 @@ public class FileManager
|
|||
public static File createTempFileForScraper(BufferedInputStream inputStream, String gameFilename) throws IOException
|
||||
{
|
||||
Files.createDirectories(TEMP_PATH);
|
||||
File file = new File(TEMP_PATH + File.separator + gameFilename + ".zip");
|
||||
File file = new File(TEMP_PATH + File.separator + gameFilename);
|
||||
FileOutputStream fos = new FileOutputStream(file, false);
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
|
@ -1078,6 +1080,10 @@ public class FileManager
|
|||
}
|
||||
inputStream.close();
|
||||
fos.close();
|
||||
if (gameFilename.toLowerCase().endsWith(".rar"))
|
||||
{
|
||||
return unrarAndPickFirstEntry(file);
|
||||
}
|
||||
return unzipAndPickFirstEntry(file);
|
||||
}
|
||||
|
||||
|
@ -1162,6 +1168,30 @@ public class FileManager
|
|||
return filePath != null ? filePath.toFile() : file;
|
||||
}
|
||||
|
||||
public static File unrarAndPickFirstEntry(File file)
|
||||
{
|
||||
Path filePath = null;
|
||||
try (Archive archive = new Archive(file))
|
||||
{
|
||||
archive.getMainHeader().print();
|
||||
FileHeader fh = archive.nextFileHeader();
|
||||
if (fh != null)
|
||||
{
|
||||
File fileEntry = new File(TEMP_PATH + File.separator + fh.getFileNameString().trim());
|
||||
FileOutputStream os = new FileOutputStream(fileEntry);
|
||||
archive.extractFile(fh, os);
|
||||
os.close();
|
||||
fh = archive.nextFileHeader();
|
||||
filePath = fileEntry.toPath();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionHandler.logException(e, "Could not unrar file");
|
||||
}
|
||||
return filePath != null ? filePath.toFile() : file;
|
||||
}
|
||||
|
||||
private static ZipEntry getFirstMatchingZipEntry(ZipArchiveInputStream zis) throws IOException
|
||||
{
|
||||
ZipEntry ze = zis.getNextZipEntry();
|
||||
|
|
Loading…
Reference in New Issue