mirror of
				https://github.com/packwiz/packwiz-installer.git
				synced 2025-11-04 12:34:31 +01:00 
			
		
		
		
	Always use UTF-8 for reading TOML files (fixes #22)
This commit is contained in:
		@@ -22,10 +22,7 @@ import link.infra.packwiz.installer.ui.data.InstallProgress
 | 
			
		||||
import link.infra.packwiz.installer.util.Log
 | 
			
		||||
import link.infra.packwiz.installer.util.ifletOrErr
 | 
			
		||||
import okio.buffer
 | 
			
		||||
import java.io.FileNotFoundException
 | 
			
		||||
import java.io.FileReader
 | 
			
		||||
import java.io.FileWriter
 | 
			
		||||
import java.io.IOException
 | 
			
		||||
import java.io.*
 | 
			
		||||
import java.nio.file.Files
 | 
			
		||||
import java.nio.file.Paths
 | 
			
		||||
import java.util.concurrent.CompletionService
 | 
			
		||||
@@ -88,7 +85,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
			
		||||
		}
 | 
			
		||||
		val pf = packFileSource.buffer().use {
 | 
			
		||||
			try {
 | 
			
		||||
				Toml().read(it.inputStream()).to(PackFile::class.java)
 | 
			
		||||
				Toml().read(InputStreamReader(it.inputStream(), "UTF-8")).to(PackFile::class.java)
 | 
			
		||||
			} catch (e: IllegalStateException) {
 | 
			
		||||
				ui.showErrorAndExit("Failed to parse pack.toml", e)
 | 
			
		||||
			}
 | 
			
		||||
@@ -201,7 +198,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		val indexFile = try {
 | 
			
		||||
			Toml().read(indexFileSource.buffer().inputStream()).to(IndexFile::class.java)
 | 
			
		||||
			Toml().read(InputStreamReader(indexFileSource.buffer().inputStream(), "UTF-8")).to(IndexFile::class.java)
 | 
			
		||||
		} catch (e: IllegalStateException) {
 | 
			
		||||
			ui.showErrorAndExit("Failed to parse index file", e)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import link.infra.packwiz.installer.request.HandlerManager.getFileSource
 | 
			
		||||
import link.infra.packwiz.installer.request.HandlerManager.getNewLoc
 | 
			
		||||
import okio.Source
 | 
			
		||||
import okio.buffer
 | 
			
		||||
import java.io.InputStreamReader
 | 
			
		||||
import java.nio.file.Paths
 | 
			
		||||
 | 
			
		||||
class IndexFile {
 | 
			
		||||
@@ -43,7 +44,7 @@ class IndexFile {
 | 
			
		||||
			linkedFileURI = getNewLoc(indexUri, file)
 | 
			
		||||
			val src = getFileSource(linkedFileURI!!)
 | 
			
		||||
			val fileStream = getHasher(hashFormat!!).getHashingSource(src)
 | 
			
		||||
			linkedFile = Toml().read(fileStream.buffer().inputStream()).to(ModFile::class.java)
 | 
			
		||||
			linkedFile = Toml().read(InputStreamReader(fileStream.buffer().inputStream(), "UTF-8")).to(ModFile::class.java)
 | 
			
		||||
			if (!fileStream.hashIsEqual(fileHash)) {
 | 
			
		||||
				throw Exception("Invalid mod file hash")
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import link.infra.packwiz.installer.task.CacheKey
 | 
			
		||||
import link.infra.packwiz.installer.task.Task
 | 
			
		||||
import link.infra.packwiz.installer.task.TaskCombinedResult
 | 
			
		||||
import link.infra.packwiz.installer.task.TaskContext
 | 
			
		||||
import java.io.InputStreamReader
 | 
			
		||||
 | 
			
		||||
class PackwizV1PackTomlTask(ctx: TaskContext, val path: PackwizPath): Task<PackwizV1PackFile>(ctx) {
 | 
			
		||||
	// TODO: make hierarchically defined by caller? - then changing the pack format type doesn't leave junk in the cache
 | 
			
		||||
@@ -30,7 +31,7 @@ class PackwizV1PackTomlTask(ctx: TaskContext, val path: PackwizPath): Task<Packw
 | 
			
		||||
 | 
			
		||||
	private val internalResult by lazy {
 | 
			
		||||
		// TODO: query, parse JSON
 | 
			
		||||
		val packFile = Toml().read(path.source(ctx.clients).inputStream()).to(PackFile::class.java)
 | 
			
		||||
		val packFile = Toml().read(InputStreamReader(path.source(ctx.clients).inputStream(), "UTF-8")).to(PackFile::class.java)
 | 
			
		||||
 | 
			
		||||
		val resolved = PackwizV1PackFile(packFile.name ?: throw RuntimeException("Name required"), // TODO: better exception handling
 | 
			
		||||
			path.resolve(packFile.index?.file ?: throw RuntimeException("File required")),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user