mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 10:51:50 -05:00
android: Convert GpuDriverMetadata to Kotlin
This commit is contained in:
parent
d2f9cf133d
commit
a05c6deb66
2 changed files with 44 additions and 45 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue