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.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -113,6 +114,41 @@ public class FileManager
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()
{
//Rename existing covers and screens and game file if needed
@ -433,7 +469,7 @@ public class FileManager
Path outDirPath = targetDir.toPath();
Path filePath = outDirPath.resolve(fileName);
filePath.toFile().createNewFile();
FileWriter fw = new FileWriter(filePath.toFile());
FileWriter fw = new FileWriter(filePath.toFile(), StandardCharsets.UTF_8);
if (!fileLoader)
{
@ -932,17 +968,16 @@ public class FileManager
public static void deleteAllFolderContent()
{
deleteDirContent(new File(COVERS), false);
deleteDirContent(new File(SCREENS), false);
deleteDirContent(new File(GAMES), false);
deleteDirContent(new File(COVERS));
deleteDirContent(new File(SCREENS));
deleteDirContent(new File(GAMES));
}
private static void deleteDirContent(File dir, boolean deleteAll)
private static void deleteDirContent(File dir)
{
for (File file : dir.listFiles())
{
if (!file.isDirectory() &&
(deleteAll || !(file.getName().contains("THEC64") || file.getName().contains("VIC20"))))
if (!file.isDirectory())
{
file.delete();
}
@ -1007,7 +1042,7 @@ public class FileManager
try
{
File coversDir = new File(COVERS);
deleteDirContent(coversDir, true);
deleteDirContent(coversDir);
copyDirectory(backupFolder.toPath().resolve("covers").toString(), coversDir.toPath().toString());
}
catch (IOException e)
@ -1022,7 +1057,7 @@ public class FileManager
try
{
File screensDir = new File(SCREENS);
deleteDirContent(screensDir, true);
deleteDirContent(screensDir);
copyDirectory(backupFolder.toPath().resolve("screens").toString(), screensDir.toPath().toString());
}
catch (IOException e)
@ -1037,7 +1072,7 @@ public class FileManager
try
{
File gamesDir = new File(GAMES);
deleteDirContent(gamesDir, true);
deleteDirContent(gamesDir);
copyDirectory(backupFolder.toPath().resolve("games").toString(), gamesDir.toPath().toString());
}
catch (IOException e)