diff options
| author | 2023-03-11 00:38:01 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:41 -0700 | |
| commit | a05c6deb666bdaa06a025c4b7c28e5d0e767fe43 (patch) | |
| tree | b38d6af31f85f3bb9d3e5a0bb48b8d94aa4a16fa /src/android | |
| parent | android: Convert GpuDriverHelper to Kotlin (diff) | |
| download | yuzu-a05c6deb666bdaa06a025c4b7c28e5d0e767fe43.tar.gz yuzu-a05c6deb666bdaa06a025c4b7c28e5d0e767fe43.tar.xz yuzu-a05c6deb666bdaa06a025c4b7c28e5d0e767fe43.zip | |
android: Convert GpuDriverMetadata to Kotlin
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.java | 45 | ||||
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GpuDriverMetadata.kt | 44 |
2 files changed, 44 insertions, 45 deletions
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.utils; | ||
| 2 | |||
| 3 | import org.json.JSONException; | ||
| 4 | import org.json.JSONObject; | ||
| 5 | |||
| 6 | import java.io.IOException; | ||
| 7 | import java.nio.charset.StandardCharsets; | ||
| 8 | import java.nio.file.Files; | ||
| 9 | import java.nio.file.Path; | ||
| 10 | import java.nio.file.Paths; | ||
| 11 | |||
| 12 | public class GpuDriverMetadata { | ||
| 13 | |||
| 14 | public String name; | ||
| 15 | public String description; | ||
| 16 | public String author; | ||
| 17 | public String vendor; | ||
| 18 | public String driverVersion; | ||
| 19 | public int minApi; | ||
| 20 | public String libraryName; | ||
| 21 | |||
| 22 | public GpuDriverMetadata(String metadataFilePath) { | ||
| 23 | try { | ||
| 24 | JSONObject json = new JSONObject(getStringFromFile(metadataFilePath)); | ||
| 25 | name = json.getString("name"); | ||
| 26 | description = json.getString("description"); | ||
| 27 | author = json.getString("author"); | ||
| 28 | vendor = json.getString("vendor"); | ||
| 29 | driverVersion = json.getString("driverVersion"); | ||
| 30 | minApi = json.getInt("minApi"); | ||
| 31 | libraryName = json.getString("libraryName"); | ||
| 32 | } catch (JSONException e) { | ||
| 33 | // JSON is malformed, ignore and treat as unsupported metadata. | ||
| 34 | } catch (IOException e) { | ||
| 35 | // File is inaccessible, ignore and treat as unsupported metadata. | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | private static String getStringFromFile(String filePath) throws IOException { | ||
| 40 | Path path = Paths.get(filePath); | ||
| 41 | byte[] bytes = Files.readAllBytes(path); | ||
| 42 | return new String(bytes, StandardCharsets.UTF_8); | ||
| 43 | } | ||
| 44 | |||
| 45 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.utils | ||
| 2 | |||
| 3 | import org.json.JSONException | ||
| 4 | import org.json.JSONObject | ||
| 5 | import java.io.IOException | ||
| 6 | import java.nio.charset.StandardCharsets | ||
| 7 | import java.nio.file.Files | ||
| 8 | import java.nio.file.Paths | ||
| 9 | |||
| 10 | class GpuDriverMetadata(metadataFilePath: String) { | ||
| 11 | var name: String? = null | ||
| 12 | var description: String? = null | ||
| 13 | var author: String? = null | ||
| 14 | var vendor: String? = null | ||
| 15 | var driverVersion: String? = null | ||
| 16 | var minApi = 0 | ||
| 17 | var libraryName: String? = null | ||
| 18 | |||
| 19 | init { | ||
| 20 | try { | ||
| 21 | val json = JSONObject(getStringFromFile(metadataFilePath)) | ||
| 22 | name = json.getString("name") | ||
| 23 | description = json.getString("description") | ||
| 24 | author = json.getString("author") | ||
| 25 | vendor = json.getString("vendor") | ||
| 26 | driverVersion = json.getString("driverVersion") | ||
| 27 | minApi = json.getInt("minApi") | ||
| 28 | libraryName = json.getString("libraryName") | ||
| 29 | } catch (e: JSONException) { | ||
| 30 | // JSON is malformed, ignore and treat as unsupported metadata. | ||
| 31 | } catch (e: IOException) { | ||
| 32 | // File is inaccessible, ignore and treat as unsupported metadata. | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | companion object { | ||
| 37 | @Throws(IOException::class) | ||
| 38 | private fun getStringFromFile(filePath: String): String { | ||
| 39 | val path = Paths.get(filePath) | ||
| 40 | val bytes = Files.readAllBytes(path) | ||
| 41 | return String(bytes, StandardCharsets.UTF_8) | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||