android: Convert GpuDriverMetadata to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-11 00:38:01 -05:00 committed by bunnei
parent d2f9cf133d
commit a05c6deb66
2 changed files with 44 additions and 45 deletions

View File

@ -1,45 +0,0 @@
package org.yuzu.yuzu_emu.utils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GpuDriverMetadata {
public String name;
public String description;
public String author;
public String vendor;
public String driverVersion;
public int minApi;
public String libraryName;
public GpuDriverMetadata(String metadataFilePath) {
try {
JSONObject json = new JSONObject(getStringFromFile(metadataFilePath));
name = json.getString("name");
description = json.getString("description");
author = json.getString("author");
vendor = json.getString("vendor");
driverVersion = json.getString("driverVersion");
minApi = json.getInt("minApi");
libraryName = json.getString("libraryName");
} catch (JSONException e) {
// JSON is malformed, ignore and treat as unsupported metadata.
} catch (IOException e) {
// File is inaccessible, ignore and treat as unsupported metadata.
}
}
private static String getStringFromFile(String filePath) throws IOException {
Path path = Paths.get(filePath);
byte[] bytes = Files.readAllBytes(path);
return new String(bytes, StandardCharsets.UTF_8);
}
}

View File

@ -0,0 +1,44 @@
package org.yuzu.yuzu_emu.utils
import org.json.JSONException
import org.json.JSONObject
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
class GpuDriverMetadata(metadataFilePath: String) {
var name: String? = null
var description: String? = null
var author: String? = null
var vendor: String? = null
var driverVersion: String? = null
var minApi = 0
var libraryName: String? = null
init {
try {
val json = JSONObject(getStringFromFile(metadataFilePath))
name = json.getString("name")
description = json.getString("description")
author = json.getString("author")
vendor = json.getString("vendor")
driverVersion = json.getString("driverVersion")
minApi = json.getInt("minApi")
libraryName = json.getString("libraryName")
} catch (e: JSONException) {
// JSON is malformed, ignore and treat as unsupported metadata.
} catch (e: IOException) {
// File is inaccessible, ignore and treat as unsupported metadata.
}
}
companion object {
@Throws(IOException::class)
private fun getStringFromFile(filePath: String): String {
val path = Paths.get(filePath)
val bytes = Files.readAllBytes(path)
return String(bytes, StandardCharsets.UTF_8)
}
}
}