Add version information about rom

Review:
Co-authored-by: Niccolò Betto <niccolo.betto@gmail.com>
This commit is contained in:
KikiManjaro 2022-08-07 03:52:14 +02:00 committed by Niccolò Betto
parent 3407f6d530
commit 8fb4e62c28
11 changed files with 98 additions and 8 deletions

View File

@ -53,6 +53,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn
jfieldID applicationNameField{env->GetFieldID(clazz, "applicationName", "Ljava/lang/String;")}; jfieldID applicationNameField{env->GetFieldID(clazz, "applicationName", "Ljava/lang/String;")};
jfieldID applicationAuthorField{env->GetFieldID(clazz, "applicationAuthor", "Ljava/lang/String;")}; jfieldID applicationAuthorField{env->GetFieldID(clazz, "applicationAuthor", "Ljava/lang/String;")};
jfieldID rawIconField{env->GetFieldID(clazz, "rawIcon", "[B")}; jfieldID rawIconField{env->GetFieldID(clazz, "rawIcon", "[B")};
jfieldID applicationVersionField{env->GetFieldID(clazz, "applicationVersion", "Ljava/lang/String;")};
if (loader->nacp) { if (loader->nacp) {
auto language{skyline::language::GetApplicationLanguage(static_cast<skyline::language::SystemLanguage>(systemLanguage))}; auto language{skyline::language::GetApplicationLanguage(static_cast<skyline::language::SystemLanguage>(systemLanguage))};
@ -61,6 +62,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn
env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str())); env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str()));
env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str())); env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str()));
env->SetObjectField(thiz, applicationVersionField, env->NewStringUTF(loader->nacp->GetApplicationVersion().c_str()));
auto icon{loader->GetIcon(language)}; auto icon{loader->GetIcon(language)};
jbyteArray iconByteArray{env->NewByteArray(static_cast<jsize>(icon.size()))}; jbyteArray iconByteArray{env->NewByteArray(static_cast<jsize>(icon.size()))};

View File

@ -33,4 +33,9 @@ namespace skyline::vfs {
auto applicationPublisher{span(nacpContents.titleEntries.at(static_cast<size_t>(language)).applicationPublisher)}; auto applicationPublisher{span(nacpContents.titleEntries.at(static_cast<size_t>(language)).applicationPublisher)};
return std::string(applicationPublisher.as_string(true)); return std::string(applicationPublisher.as_string(true));
} }
std::string NACP::GetApplicationVersion() {
auto applicationPublisher{span(nacpContents.displayVersion)};
return std::string(applicationPublisher.as_string(true));
}
} }

View File

@ -48,5 +48,7 @@ namespace skyline::vfs {
std::string GetApplicationName(language::ApplicationLanguage language); std::string GetApplicationName(language::ApplicationLanguage language);
std::string GetApplicationPublisher(language::ApplicationLanguage language); std::string GetApplicationPublisher(language::ApplicationLanguage language);
std::string GetApplicationVersion();
}; };
} }

View File

@ -77,6 +77,7 @@ class AppDialog : BottomSheetDialogFragment() {
binding.gameIcon.setImageBitmap(item.icon ?: missingIcon) binding.gameIcon.setImageBitmap(item.icon ?: missingIcon)
binding.gameTitle.text = item.title binding.gameTitle.text = item.title
binding.gameSubtitle.text = item.subTitle ?: item.loaderResultString(requireContext()) binding.gameSubtitle.text = item.subTitle ?: item.loaderResultString(requireContext())
binding.gameVersion.text = item.version ?: item.loaderResultString(requireContext())
binding.gamePlay.isEnabled = item.loaderResult == LoaderResult.Success binding.gamePlay.isEnabled = item.loaderResult == LoaderResult.Success
binding.gamePlay.setOnClickListener { binding.gamePlay.setOnClickListener {

View File

@ -46,6 +46,8 @@ interface LayoutBinding<V : ViewBinding> : ViewBinding {
val textSubtitle : TextView val textSubtitle : TextView
val textVersion : TextView
val icon : ImageView val icon : ImageView
} }
@ -56,6 +58,8 @@ class ListBinding(parent : ViewGroup) : LayoutBinding<AppItemLinearBinding> {
override val textSubtitle = binding.textSubtitle override val textSubtitle = binding.textSubtitle
override val textVersion = binding.textVersion
override val icon = binding.icon override val icon = binding.icon
} }
@ -66,6 +70,8 @@ class GridBinding(parent : ViewGroup) : LayoutBinding<AppItemGridBinding> {
override val textSubtitle = binding.textSubtitle override val textSubtitle = binding.textSubtitle
override val textVersion = binding.textVersion
override val icon = binding.icon override val icon = binding.icon
} }
@ -76,6 +82,8 @@ class GridCompatBinding(parent : ViewGroup) : LayoutBinding<AppItemGridCompactBi
override val textSubtitle = binding.textSubtitle override val textSubtitle = binding.textSubtitle
override val textVersion = binding.textVersion
override val icon = binding.icon override val icon = binding.icon
} }
@ -88,6 +96,7 @@ class AppViewItem(var layoutType : LayoutType, private val item : AppItem, priva
val binding = holder.binding val binding = holder.binding
binding.textTitle.text = item.title binding.textTitle.text = item.title
binding.textSubtitle.text = item.subTitle ?: item.loaderResultString(binding.root.context) binding.textSubtitle.text = item.subTitle ?: item.loaderResultString(binding.root.context)
binding.textVersion.text = item.version ?: item.loaderResultString(binding.root.context)
binding.icon.setImageBitmap(item.icon ?: missingIcon) binding.icon.setImageBitmap(item.icon ?: missingIcon)

View File

@ -39,6 +39,11 @@ data class AppItem(private val meta : AppEntry) : DataItem() {
*/ */
val uri get() = meta.uri val uri get() = meta.uri
/**
* The application version
*/
val version get() = meta.version
val loaderResult get() = meta.loaderResult val loaderResult get() = meta.loaderResult
fun loaderResultString(context : Context) = context.getString(when (meta.loaderResult) { fun loaderResultString(context : Context) = context.getString(when (meta.loaderResult) {

View File

@ -63,12 +63,12 @@ enum class LoaderResult(val value : Int) {
/** /**
* This class is used to hold an application's metadata in a serializable way * This class is used to hold an application's metadata in a serializable way
*/ */
data class AppEntry(var name : String, var author : String?, var icon : Bitmap?, var format : RomFormat, var uri : Uri, var loaderResult : LoaderResult) : Serializable { data class AppEntry(var name : String, var author : String?, var icon : Bitmap?, var version : String?, var format : RomFormat, var uri : Uri, var loaderResult : LoaderResult) : Serializable {
constructor(context : Context, format : RomFormat, uri : Uri, loaderResult : LoaderResult) : this(context.contentResolver.query(uri, null, null, null, null)?.use { cursor -> constructor(context : Context, format : RomFormat, uri : Uri, loaderResult : LoaderResult) : this(context.contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val nameIndex : Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) val nameIndex : Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
cursor.moveToFirst() cursor.moveToFirst()
cursor.getString(nameIndex) cursor.getString(nameIndex)
}!!.dropLast(format.name.length + 1), null, null, format, uri, loaderResult) }!!.dropLast(format.name.length + 1), null, null, null, format, uri, loaderResult)
private fun writeObject(output : ObjectOutputStream) { private fun writeObject(output : ObjectOutputStream) {
output.writeUTF(name) output.writeUTF(name)
@ -77,6 +77,8 @@ data class AppEntry(var name : String, var author : String?, var icon : Bitmap?,
output.writeBoolean(author != null) output.writeBoolean(author != null)
if (author != null) if (author != null)
output.writeUTF(author) output.writeUTF(author)
if (version != null)
output.writeUTF(version)
output.writeInt(loaderResult.value) output.writeInt(loaderResult.value)
output.writeBoolean(icon != null) output.writeBoolean(icon != null)
icon?.let { icon?.let {
@ -119,6 +121,11 @@ internal class RomFile(context : Context, format : RomFormat, uri : Uri, systemL
*/ */
private var rawIcon : ByteArray? = null private var rawIcon : ByteArray? = null
/**
* @note This field is filled in by native code
*/
private var applicationVersion : String? = null
val appEntry : AppEntry val appEntry : AppEntry
var result = LoaderResult.Success var result = LoaderResult.Success
@ -133,8 +140,10 @@ internal class RomFile(context : Context, format : RomFormat, uri : Uri, systemL
appEntry = applicationName?.let { name -> appEntry = applicationName?.let { name ->
applicationAuthor?.let { author -> applicationAuthor?.let { author ->
applicationVersion?.let { version ->
rawIcon?.let { icon -> rawIcon?.let { icon ->
AppEntry(name, author, BitmapFactory.decodeByteArray(icon, 0, icon.size), format, uri, result) AppEntry(name, author, BitmapFactory.decodeByteArray(icon, 0, icon.size), version, format, uri, result)
}
} }
} }
} ?: AppEntry(context, format, uri, result) } ?: AppEntry(context, format, uri, result)

View File

@ -45,11 +45,23 @@
app:layout_constraintTop_toBottomOf="@id/game_title" app:layout_constraintTop_toBottomOf="@id/game_title"
tools:text="Nintendo" /> tools:text="Nintendo" />
<TextView
android:id="@+id/game_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="@android:color/tertiary_text_light"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/game_subtitle"
app:layout_constraintTop_toBottomOf="@id/game_subtitle"
tools:layout_editor_absoluteY="64dp"
tools:text="Version" />
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start" android:layout_gravity="start"
android:layout_marginTop="12dp" android:layout_marginTop="28dp"
app:flexWrap="wrap" app:flexWrap="wrap"
app:layout_constraintStart_toStartOf="@id/game_title" app:layout_constraintStart_toStartOf="@id/game_title"
app:layout_constraintTop_toBottomOf="@id/game_subtitle"> app:layout_constraintTop_toBottomOf="@id/game_subtitle">

View File

@ -45,10 +45,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:ellipsize="marquee" android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true" android:singleLine="true"
android:textSize="12sp" android:textSize="12sp"
tools:text="Subtitle" /> tools:text="Subtitle" />
<TextView
android:id="@+id/text_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textSize="12sp"
tools:text="Version" />
</LinearLayout> </LinearLayout>

View File

@ -49,6 +49,25 @@
android:id="@+id/text_subtitle" android:id="@+id/text_subtitle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:alpha="242.25"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@id/text_version"
app:layout_constraintEnd_toEndOf="@id/icon"
app:layout_constraintStart_toStartOf="@id/icon"
tools:text="Subtitle" />
<TextView
android:id="@+id/text_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:alpha="242.25" android:alpha="242.25"
android:ellipsize="marquee" android:ellipsize="marquee"
@ -63,6 +82,6 @@
app:layout_constraintBottom_toBottomOf="@id/icon" app:layout_constraintBottom_toBottomOf="@id/icon"
app:layout_constraintEnd_toEndOf="@id/icon" app:layout_constraintEnd_toEndOf="@id/icon"
app:layout_constraintStart_toStartOf="@id/icon" app:layout_constraintStart_toStartOf="@id/icon"
tools:text="Subtitle" /> tools:text="Version" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>

View File

@ -44,10 +44,24 @@
android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="@android:color/tertiary_text_light" android:textColor="@android:color/tertiary_text_light"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0" app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/icon" app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintTop_toBottomOf="@+id/text_title" app:layout_constraintTop_toBottomOf="@+id/text_title"
tools:text="SubTitle" /> tools:text="SubTitle" />
<TextView
android:id="@+id/text_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="@android:color/tertiary_text_light"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintTop_toBottomOf="@+id/text_subtitle"
tools:text="Version" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>