fix: Always use UTF-8 as char encoding for generated tsg files

This commit is contained in:
lantzelot-swe 2021-12-29 08:41:46 +01:00
parent 0b67128885
commit d2b957f32c
1 changed files with 51 additions and 16 deletions

View File

@ -13,6 +13,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -113,6 +114,41 @@ public class FileManager
return FileManager.class.getResourceAsStream("/se/lantz/MissingGame-Vic20.vsf.gz"); return FileManager.class.getResourceAsStream("/se/lantz/MissingGame-Vic20.vsf.gz");
} }
public static BufferedImage getInfoSlotCoverImage()
{
BufferedImage coverImage = null;
try
{
coverImage = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotCover.png"));
}
catch (IOException e)
{
ExceptionHandler.handleException(e, "Could not read cover image.");
}
return coverImage;
}
public static BufferedImage getInfoSlotScreenImage(boolean first)
{
BufferedImage coverImage = null;
try
{
if (first)
{
coverImage = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotScreen1.png"));
}
else
{
coverImage = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotScreen2.png"));
}
}
catch (IOException e)
{
ExceptionHandler.handleException(e, "Could not read info slot screen image.");
}
return coverImage;
}
public void saveFiles() public void saveFiles()
{ {
//Rename existing covers and screens and game file if needed //Rename existing covers and screens and game file if needed
@ -433,7 +469,7 @@ public class FileManager
Path outDirPath = targetDir.toPath(); Path outDirPath = targetDir.toPath();
Path filePath = outDirPath.resolve(fileName); Path filePath = outDirPath.resolve(fileName);
filePath.toFile().createNewFile(); filePath.toFile().createNewFile();
FileWriter fw = new FileWriter(filePath.toFile()); FileWriter fw = new FileWriter(filePath.toFile(), StandardCharsets.UTF_8);
if (!fileLoader) if (!fileLoader)
{ {
@ -932,17 +968,16 @@ public class FileManager
public static void deleteAllFolderContent() public static void deleteAllFolderContent()
{ {
deleteDirContent(new File(COVERS), false); deleteDirContent(new File(COVERS));
deleteDirContent(new File(SCREENS), false); deleteDirContent(new File(SCREENS));
deleteDirContent(new File(GAMES), false); deleteDirContent(new File(GAMES));
} }
private static void deleteDirContent(File dir, boolean deleteAll) private static void deleteDirContent(File dir)
{ {
for (File file : dir.listFiles()) for (File file : dir.listFiles())
{ {
if (!file.isDirectory() && if (!file.isDirectory())
(deleteAll || !(file.getName().contains("THEC64") || file.getName().contains("VIC20"))))
{ {
file.delete(); file.delete();
} }
@ -1007,7 +1042,7 @@ public class FileManager
try try
{ {
File coversDir = new File(COVERS); File coversDir = new File(COVERS);
deleteDirContent(coversDir, true); deleteDirContent(coversDir);
copyDirectory(backupFolder.toPath().resolve("covers").toString(), coversDir.toPath().toString()); copyDirectory(backupFolder.toPath().resolve("covers").toString(), coversDir.toPath().toString());
} }
catch (IOException e) catch (IOException e)
@ -1022,7 +1057,7 @@ public class FileManager
try try
{ {
File screensDir = new File(SCREENS); File screensDir = new File(SCREENS);
deleteDirContent(screensDir, true); deleteDirContent(screensDir);
copyDirectory(backupFolder.toPath().resolve("screens").toString(), screensDir.toPath().toString()); copyDirectory(backupFolder.toPath().resolve("screens").toString(), screensDir.toPath().toString());
} }
catch (IOException e) catch (IOException e)
@ -1037,7 +1072,7 @@ public class FileManager
try try
{ {
File gamesDir = new File(GAMES); File gamesDir = new File(GAMES);
deleteDirContent(gamesDir, true); deleteDirContent(gamesDir);
copyDirectory(backupFolder.toPath().resolve("games").toString(), gamesDir.toPath().toString()); copyDirectory(backupFolder.toPath().resolve("games").toString(), gamesDir.toPath().toString());
} }
catch (IOException e) catch (IOException e)
@ -1477,7 +1512,7 @@ public class FileManager
return convertedScreensList; return convertedScreensList;
} }
public static List<String> checkAllFilesForDbValidation(List<GameValidationDetails> gameList) public static List<String> checkAllFilesForDbValidation(List<GameValidationDetails> gameList)
{ {
List<String> fixedGamesList = new ArrayList<>(); List<String> fixedGamesList = new ArrayList<>();
@ -1496,7 +1531,7 @@ public class FileManager
fixScreenImages(gameData.isVic20(), screens1File, screens2File); fixScreenImages(gameData.isVic20(), screens1File, screens2File);
fixedGamesList.add("screenshot files for " + gameData.getTitle()); fixedGamesList.add("screenshot files for " + gameData.getTitle());
} }
//Check game file also //Check game file also
File gameFile = Paths.get(GAMES + gameData.getGame()).toFile(); File gameFile = Paths.get(GAMES + gameData.getGame()).toFile();
if (!gameFile.exists()) if (!gameFile.exists())
@ -1507,7 +1542,7 @@ public class FileManager
} }
return fixedGamesList; return fixedGamesList;
} }
private static void saveEmptyCoverImage(boolean vic20, File coverFile) private static void saveEmptyCoverImage(boolean vic20, File coverFile)
{ {
BufferedImage imageToSave = vic20 ? emptyVic20Cover : emptyC64Cover; BufferedImage imageToSave = vic20 ? emptyVic20Cover : emptyC64Cover;
@ -1521,7 +1556,7 @@ public class FileManager
ExceptionHandler.handleException(e, "Could not store cover"); ExceptionHandler.handleException(e, "Could not store cover");
} }
} }
private static void fixScreenImages(boolean vic20, File screen1File, File screen2File) private static void fixScreenImages(boolean vic20, File screen1File, File screen2File)
{ {
BufferedImage emptyImage = vic20 ? emptyVic20Screenshot : emptyC64Screenshot; BufferedImage emptyImage = vic20 ? emptyVic20Screenshot : emptyC64Screenshot;
@ -1543,14 +1578,14 @@ public class FileManager
//Both are missing, write empty to both //Both are missing, write empty to both
ImageIO.write(emptyImage, "png", screen1File); ImageIO.write(emptyImage, "png", screen1File);
ImageIO.write(emptyImage, "png", screen2File); ImageIO.write(emptyImage, "png", screen2File);
} }
} }
catch (IOException e) catch (IOException e)
{ {
ExceptionHandler.handleException(e, "Could not store screens"); ExceptionHandler.handleException(e, "Could not store screens");
} }
} }
private static void copyMissingGameFile(boolean vic20, File gameFile) private static void copyMissingGameFile(boolean vic20, File gameFile)
{ {
try try