From a05c6deb666bdaa06a025c4b7c28e5d0e767fe43 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 11 Mar 2023 00:38:01 -0500 Subject: android: Convert GpuDriverMetadata to Kotlin --- .../org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java | 45 ---------------------- .../org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt | 44 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 45 deletions(-) delete mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt (limited to 'src') diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java deleted file mode 100644 index d2bb2dd23..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java +++ /dev/null @@ -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); - } - -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt new file mode 100644 index 000000000..732be3f63 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt @@ -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) + } + } +} -- cgit v1.2.3