Compare commits
111 Commits
android-18
...
android-19
Author | SHA1 | Date | |
---|---|---|---|
7e59ea1f58 | |||
2baff34467 | |||
ce1935bf52 | |||
ec55e324f5 | |||
de4ebdc21d | |||
af26858ceb | |||
b4a8e1ef8a | |||
5ea8f05ec6 | |||
10535e0016 | |||
a8c552e261 | |||
932bd98824 | |||
9f376cd901 | |||
a560b9f5a2 | |||
4f04bd3697 | |||
97c8b49444 | |||
3092855d5a | |||
72f803c366 | |||
c87b96435d | |||
6536d29c61 | |||
116f76e4b6 | |||
dff0a7c52a | |||
915efa4236 | |||
4548e5ae1d | |||
46c2435235 | |||
0b0e9ef18d | |||
7f5adf8982 | |||
89d6856090 | |||
2c29c2b8dd | |||
16abda59be | |||
90ab89a0b0 | |||
6531ad56a6 | |||
e8671ed04e | |||
2044ae6b3a | |||
c661b95864 | |||
c683ec2bcb | |||
2e4e33156e | |||
04f4eeaca2 | |||
2e4b32204c | |||
34db13486a | |||
c6c6bb4041 | |||
a2ffb419c9 | |||
0127cec371 | |||
db3a6075f5 | |||
8876a15227 | |||
954eb40237 | |||
d4acdac168 | |||
817c7c445d | |||
da714a362b | |||
7b3941e5d4 | |||
15d8a40529 | |||
cdeaca73c4 | |||
bee22540a1 | |||
76880b84f9 | |||
2f0b57ca13 | |||
f90a022d3a | |||
f2fed21c11 | |||
d940974789 | |||
f7a3c135e2 | |||
fcb0dff67c | |||
b5dac5f525 | |||
a4d90a9a64 | |||
84787a2ada | |||
2a0d707ce1 | |||
aae9eea532 | |||
2044a289f8 | |||
d3ba6b334b | |||
dac8c4ce4d | |||
9e974d4c7e | |||
6bfc3c530c | |||
93239f191a | |||
b17db2b462 | |||
9130366a58 | |||
ad0066a6b6 | |||
78c323c4eb | |||
51ad2d10de | |||
6533dfd7ce | |||
e11a3414ae | |||
4fdc900581 | |||
d99830b59c | |||
23c11e50f9 | |||
5fde5e62a8 | |||
f124461674 | |||
63b835f822 | |||
30743eff56 | |||
4f83b00f6f | |||
ea710e6523 | |||
200b371d13 | |||
ae88ea79b2 | |||
82b58668ed | |||
bd80929ac1 | |||
2a4ac7cfac | |||
ab513c378a | |||
a959fb011f | |||
53085a45e0 | |||
bc2d1262d7 | |||
1220309323 | |||
a972341b5d | |||
87430acff1 | |||
0b4cc6e14c | |||
5105b90017 | |||
3516a2d0bf | |||
f224ef6185 | |||
8e27a485d8 | |||
a36f4d0a9f | |||
b71840bbd2 | |||
71fbc87dbd | |||
37b0870ee3 | |||
3dbe998f9b | |||
edfbf363de | |||
53d4dbacf0 | |||
e5de3d5a77 |
@ -3,38 +3,35 @@
|
|||||||
# SPDX-FileCopyrightText: 2019 yuzu Emulator Project
|
# SPDX-FileCopyrightText: 2019 yuzu Emulator Project
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \
|
shopt -s nullglob globstar
|
||||||
dist/*.svg dist/*.xml; then
|
|
||||||
|
if git grep -nrI '\s$' src **/*.yml **/*.txt **/*.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop dist/*.svg dist/*.xml; then
|
||||||
echo Trailing whitespace found, aborting
|
echo Trailing whitespace found, aborting
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Default clang-format points to default 3.5 version one
|
# Default clang-format points to default 3.5 version one
|
||||||
CLANG_FORMAT=${CLANG_FORMAT:-clang-format-15}
|
CLANG_FORMAT="${CLANG_FORMAT:-clang-format-15}"
|
||||||
$CLANG_FORMAT --version
|
"$CLANG_FORMAT" --version
|
||||||
|
|
||||||
if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
|
|
||||||
# Get list of every file modified in this pull request
|
|
||||||
files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)"
|
|
||||||
else
|
|
||||||
# Check everything for branch pushes
|
|
||||||
files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Turn off tracing for this because it's too verbose
|
# Turn off tracing for this because it's too verbose
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
for f in $files_to_lint; do
|
# Check everything for branch pushes
|
||||||
d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
|
FILES_TO_LINT="$(find src/ -name '*.cpp' -or -name '*.h')"
|
||||||
if ! [ -z "$d" ]; then
|
|
||||||
echo "!!! $f not compliant to coding style, here is the fix:"
|
for f in $FILES_TO_LINT; do
|
||||||
echo "$d"
|
echo "$f"
|
||||||
fail=1
|
"$CLANG_FORMAT" -i "$f"
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
set -x
|
DIFF=$(git -c core.fileMode=false diff)
|
||||||
|
|
||||||
if [ "$fail" = 1 ]; then
|
if [ ! -z "$DIFF" ]; then
|
||||||
|
echo "!!! Not compliant to coding style, here is the fix:"
|
||||||
|
echo "$DIFF"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cd src/android
|
||||||
|
./gradlew ktlintCheck
|
||||||
|
@ -9,7 +9,7 @@ chmod a+x ./.ci/scripts/linux/docker.sh
|
|||||||
sudo chown -R 1027 ./
|
sudo chown -R 1027 ./
|
||||||
|
|
||||||
# The environment variables listed below:
|
# The environment variables listed below:
|
||||||
# AZURECIREPO TITLEBARFORMATIDLE TITLEBARFORMATRUNNING DISPLAYVERSION
|
# AZURECIREPO TITLEBARFORMATIDLE TITLEBARFORMATRUNNING DISPLAYVERSION
|
||||||
# are requested in src/common/CMakeLists.txt and appear to be provided somewhere in Azure DevOps
|
# are requested in src/common/CMakeLists.txt and appear to be provided somewhere in Azure DevOps
|
||||||
|
|
||||||
docker run -e AZURECIREPO -e TITLEBARFORMATIDLE -e TITLEBARFORMATRUNNING -e DISPLAYVERSION -e ENABLE_COMPATIBILITY_REPORTING -e CCACHE_DIR=/yuzu/ccache -v "$(pwd):/yuzu" -w /yuzu yuzuemu/build-environments:linux-fresh /bin/bash /yuzu/.ci/scripts/linux/docker.sh "$1"
|
docker run -e AZURECIREPO -e TITLEBARFORMATIDLE -e TITLEBARFORMATRUNNING -e DISPLAYVERSION -e ENABLE_COMPATIBILITY_REPORTING -e CCACHE_DIR=/yuzu/ccache -v "$(pwd):/yuzu" -w /yuzu yuzuemu/build-environments:linux-fresh /bin/bash /yuzu/.ci/scripts/linux/docker.sh "$1"
|
||||||
|
@ -8,17 +8,7 @@ variables:
|
|||||||
DisplayVersion: $[counter(variables['DisplayPrefix'], 1)]
|
DisplayVersion: $[counter(variables['DisplayPrefix'], 1)]
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- stage: format
|
|
||||||
displayName: 'format'
|
|
||||||
jobs:
|
|
||||||
- job: format
|
|
||||||
displayName: 'clang'
|
|
||||||
pool:
|
|
||||||
vmImage: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- template: ./templates/format-check.yml
|
|
||||||
- stage: build
|
- stage: build
|
||||||
dependsOn: format
|
|
||||||
displayName: 'build'
|
displayName: 'build'
|
||||||
jobs:
|
jobs:
|
||||||
- job: build
|
- job: build
|
||||||
@ -43,7 +33,6 @@ stages:
|
|||||||
cache: 'true'
|
cache: 'true'
|
||||||
version: $(DisplayVersion)
|
version: $(DisplayVersion)
|
||||||
- stage: build_win
|
- stage: build_win
|
||||||
dependsOn: format
|
|
||||||
displayName: 'build-windows'
|
displayName: 'build-windows'
|
||||||
jobs:
|
jobs:
|
||||||
- job: build
|
- job: build
|
||||||
|
8
.github/workflows/verify.yml
vendored
8
.github/workflows/verify.yml
vendored
@ -13,13 +13,15 @@ jobs:
|
|||||||
format:
|
format:
|
||||||
name: 'verify format'
|
name: 'verify format'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
|
||||||
image: yuzuemu/build-environments:linux-clang-format
|
|
||||||
options: -u 1001
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: false
|
submodules: false
|
||||||
|
- name: set up JDK 17
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: '17'
|
||||||
|
distribution: 'temurin'
|
||||||
- name: 'Verify Formatting'
|
- name: 'Verify Formatting'
|
||||||
run: bash -ex ./.ci/scripts/format/script.sh
|
run: bash -ex ./.ci/scripts/format/script.sh
|
||||||
build:
|
build:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) <year> <owner>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>.
|
Copyright (c) <year> <owner>.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ Mozilla Public License Version 2.0
|
|||||||
means any form of the work other than Source Code Form.
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
1.7. "Larger Work"
|
1.7. "Larger Work"
|
||||||
means a work that combines Covered Software with other material, in
|
means a work that combines Covered Software with other material, in
|
||||||
a separate file or files, that is not Covered Software.
|
a separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
1.8. "License"
|
1.8. "License"
|
||||||
|
13
README.md
13
README.md
@ -1,3 +1,16 @@
|
|||||||
|
| Pull Request | Commit | Title | Author | Merged? |
|
||||||
|
|----|----|----|----|----|
|
||||||
|
| [12579](https://github.com/yuzu-emu/yuzu-android//pull/12579) | [`748465f5a`](https://github.com/yuzu-emu/yuzu-android//pull/12579/files) | Core: Implement Device Mapping & GPU SMMU | [FernandoS27](https://github.com/FernandoS27/) | Yes |
|
||||||
|
| [12660](https://github.com/yuzu-emu/yuzu-android//pull/12660) | [`2cacb9d48`](https://github.com/yuzu-emu/yuzu-android//pull/12660/files) | service: hid: Fully implement abstract vibration | [german77](https://github.com/german77/) | Yes |
|
||||||
|
| [12688](https://github.com/yuzu-emu/yuzu-android//pull/12688) | [`e9eb017aa`](https://github.com/yuzu-emu/yuzu-android//pull/12688/files) | renderer_vulkan: recreate swapchain when frame size changes | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
|
| [12701](https://github.com/yuzu-emu/yuzu-android//pull/12701) | [`e4bbb24dc`](https://github.com/yuzu-emu/yuzu-android//pull/12701/files) | vi: check layer state before opening or closing | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
|
| [12715](https://github.com/yuzu-emu/yuzu-android//pull/12715) | [`47058d705`](https://github.com/yuzu-emu/yuzu-android//pull/12715/files) | android: Add uninstall addon button | [t895](https://github.com/t895/) | Yes |
|
||||||
|
|
||||||
|
|
||||||
|
End of merge log. You can find the original README.md below the break.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
2
externals/ffmpeg/CMakeLists.txt
vendored
2
externals/ffmpeg/CMakeLists.txt
vendored
@ -138,7 +138,7 @@ if (NOT WIN32 AND NOT ANDROID)
|
|||||||
--cross-prefix=${TOOLCHAIN}/bin/aarch64-linux-android-
|
--cross-prefix=${TOOLCHAIN}/bin/aarch64-linux-android-
|
||||||
--sysroot=${SYSROOT}
|
--sysroot=${SYSROOT}
|
||||||
--target-os=android
|
--target-os=android
|
||||||
--extra-ldflags="--ld-path=${TOOLCHAIN}/bin/ld.lld"
|
--extra-ldflags="--ld-path=${TOOLCHAIN}/bin/ld.lld"
|
||||||
--extra-ldflags="-nostdlib"
|
--extra-ldflags="-nostdlib"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
2
externals/nx_tzdb/tzdb_to_nx
vendored
2
externals/nx_tzdb/tzdb_to_nx
vendored
Submodule externals/nx_tzdb/tzdb_to_nx updated: f6680093bc...404d390045
@ -188,8 +188,15 @@ tasks.create<Delete>("ktlintReset") {
|
|||||||
delete(File(buildDir.path + File.separator + "intermediates/ktLint"))
|
delete(File(buildDir.path + File.separator + "intermediates/ktLint"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val showFormatHelp = {
|
||||||
|
logger.lifecycle(
|
||||||
|
"If this check fails, please try running \"gradlew ktlintFormat\" for automatic " +
|
||||||
|
"codestyle fixes"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
tasks.getByPath("ktlintKotlinScriptCheck").doFirst { showFormatHelp.invoke() }
|
||||||
|
tasks.getByPath("ktlintMainSourceSetCheck").doFirst { showFormatHelp.invoke() }
|
||||||
tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset")
|
tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset")
|
||||||
tasks.getByPath("preBuild").dependsOn("ktlintCheck")
|
|
||||||
|
|
||||||
ktlint {
|
ktlint {
|
||||||
version.set("0.47.1")
|
version.set("0.47.1")
|
||||||
@ -228,71 +235,33 @@ dependencies {
|
|||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGitVersion(): String {
|
fun runGitCommand(command: List<String>): String {
|
||||||
var versionName = "0.0"
|
return try {
|
||||||
|
ProcessBuilder(command)
|
||||||
try {
|
|
||||||
versionName = ProcessBuilder("git", "describe", "--always", "--long")
|
|
||||||
.directory(project.rootDir)
|
.directory(project.rootDir)
|
||||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
.redirectError(ProcessBuilder.Redirect.PIPE)
|
||||||
.start().inputStream.bufferedReader().use { it.readText() }
|
.start().inputStream.bufferedReader().use { it.readText() }
|
||||||
.trim()
|
.trim()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.error("Cannot find git")
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGitVersion(): String {
|
||||||
|
val versionName = if (System.getenv("GITHUB_ACTIONS") != null) {
|
||||||
|
val gitTag = System.getenv("GIT_TAG_NAME") ?: ""
|
||||||
|
gitTag
|
||||||
|
} else {
|
||||||
|
runGitCommand(listOf("git", "describe", "--always", "--long"))
|
||||||
.replace(Regex("(-0)?-[^-]+$"), "")
|
.replace(Regex("(-0)?-[^-]+$"), "")
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.error("Cannot find git, defaulting to dummy version number")
|
|
||||||
}
|
}
|
||||||
|
return versionName.ifEmpty { "0.0" }
|
||||||
if (System.getenv("GITHUB_ACTIONS") != null) {
|
|
||||||
val gitTag = System.getenv("GIT_TAG_NAME")
|
|
||||||
versionName = gitTag ?: versionName
|
|
||||||
}
|
|
||||||
|
|
||||||
return versionName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGitHash(): String {
|
fun getGitHash(): String =
|
||||||
try {
|
runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" }
|
||||||
val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
|
|
||||||
processBuilder.directory(project.rootDir)
|
|
||||||
val process = processBuilder.start()
|
|
||||||
val inputStream = process.inputStream
|
|
||||||
val errorStream = process.errorStream
|
|
||||||
process.waitFor()
|
|
||||||
|
|
||||||
return if (process.exitValue() == 0) {
|
fun getBranch(): String =
|
||||||
inputStream.bufferedReader()
|
runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" }
|
||||||
.use { it.readText().trim() } // return the value of gitHash
|
|
||||||
} else {
|
|
||||||
val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
|
|
||||||
logger.error("Error running git command: $errorMessage")
|
|
||||||
"dummy-hash" // return a dummy hash value in case of an error
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.error("$e: Cannot find git, defaulting to dummy build hash")
|
|
||||||
return "dummy-hash" // return a dummy hash value in case of an error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBranch(): String {
|
|
||||||
try {
|
|
||||||
val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
|
|
||||||
processBuilder.directory(project.rootDir)
|
|
||||||
val process = processBuilder.start()
|
|
||||||
val inputStream = process.inputStream
|
|
||||||
val errorStream = process.errorStream
|
|
||||||
process.waitFor()
|
|
||||||
|
|
||||||
return if (process.exitValue() == 0) {
|
|
||||||
inputStream.bufferedReader()
|
|
||||||
.use { it.readText().trim() } // return the value of gitHash
|
|
||||||
} else {
|
|
||||||
val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
|
|
||||||
logger.error("Error running git command: $errorMessage")
|
|
||||||
"dummy-hash" // return a dummy hash value in case of an error
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.error("$e: Cannot find git, defaulting to dummy build hash")
|
|
||||||
return "dummy-hash" // return a dummy hash value in case of an error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -31,6 +31,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
android:dataExtractionRules="@xml/data_extraction_rules_api_31"
|
android:dataExtractionRules="@xml/data_extraction_rules_api_31"
|
||||||
android:enableOnBackInvokedCallback="true">
|
android:enableOnBackInvokedCallback="true">
|
||||||
|
|
||||||
|
<meta-data android:name="android.game_mode_config"
|
||||||
|
android:resource="@xml/game_mode_config" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.yuzu.yuzu_emu.ui.main.MainActivity"
|
android:name="org.yuzu.yuzu_emu.ui.main.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
@ -21,6 +21,8 @@ import org.yuzu.yuzu_emu.utils.DocumentsTree
|
|||||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||||
import org.yuzu.yuzu_emu.utils.Log
|
import org.yuzu.yuzu_emu.utils.Log
|
||||||
import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable
|
import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable
|
||||||
|
import org.yuzu.yuzu_emu.model.InstallResult
|
||||||
|
import org.yuzu.yuzu_emu.model.Patch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which contains methods that interact
|
* Class which contains methods that interact
|
||||||
@ -235,9 +237,12 @@ object NativeLibrary {
|
|||||||
/**
|
/**
|
||||||
* Installs a nsp or xci file to nand
|
* Installs a nsp or xci file to nand
|
||||||
* @param filename String representation of file uri
|
* @param filename String representation of file uri
|
||||||
* @param extension Lowercase string representation of file extension without "."
|
* @return int representation of [InstallResult]
|
||||||
*/
|
*/
|
||||||
external fun installFileToNand(filename: String, extension: String): Int
|
external fun installFileToNand(
|
||||||
|
filename: String,
|
||||||
|
callback: (max: Long, progress: Long) -> Boolean
|
||||||
|
): Int
|
||||||
|
|
||||||
external fun doesUpdateMatchProgram(programId: String, updatePath: String): Boolean
|
external fun doesUpdateMatchProgram(programId: String, updatePath: String): Boolean
|
||||||
|
|
||||||
@ -535,9 +540,29 @@ object NativeLibrary {
|
|||||||
*
|
*
|
||||||
* @param path Path to game file. Can be a [Uri].
|
* @param path Path to game file. Can be a [Uri].
|
||||||
* @param programId String representation of a game's program ID
|
* @param programId String representation of a game's program ID
|
||||||
* @return Array of pairs where the first value is the name of an addon and the second is the version
|
* @return Array of available patches
|
||||||
*/
|
*/
|
||||||
external fun getAddonsForFile(path: String, programId: String): Array<Pair<String, String>>?
|
external fun getPatchesForFile(path: String, programId: String): Array<Patch>?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an update for a given [programId]
|
||||||
|
* @param programId String representation of a game's program ID
|
||||||
|
*/
|
||||||
|
external fun removeUpdate(programId: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes DLC by its unique [titleId]
|
||||||
|
* @param titleId String representation of a DLC's title ID
|
||||||
|
*/
|
||||||
|
external fun removeDLC(titleId: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a mod installed for a given [programId]
|
||||||
|
* @param programId String representation of a game's program ID
|
||||||
|
* @param name The name of a mod as given by [getPatchesForFile]. This corresponds with the name
|
||||||
|
* of the mod's directory in a game's load folder.
|
||||||
|
*/
|
||||||
|
external fun removeMod(programId: String, name: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the save location for a specific game
|
* Gets the save location for a specific game
|
||||||
@ -547,6 +572,15 @@ object NativeLibrary {
|
|||||||
*/
|
*/
|
||||||
external fun getSavePath(programId: String): String
|
external fun getSavePath(programId: String): String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the root save directory for the default profile as either
|
||||||
|
* /user/save/account/<user id raw string> or /user/save/000...000/<user id>
|
||||||
|
*
|
||||||
|
* @param future If true, returns the /user/save/account/... directory
|
||||||
|
* @return Save data path that may not exist yet
|
||||||
|
*/
|
||||||
|
external fun getDefaultProfileSaveDataRoot(future: Boolean): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a file to the manual filesystem provider in our EmulationSession instance
|
* Adds a file to the manual filesystem provider in our EmulationSession instance
|
||||||
* @param path Path to the file we're adding. Can be a string representation of a [Uri] or
|
* @param path Path to the file we're adding. Can be a string representation of a [Uri] or
|
||||||
@ -600,15 +634,4 @@ object NativeLibrary {
|
|||||||
const val RELEASED = 0
|
const val RELEASED = 0
|
||||||
const val PRESSED = 1
|
const val PRESSED = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Result from installFileToNand
|
|
||||||
*/
|
|
||||||
object InstallFileToNandResult {
|
|
||||||
const val Success = 0
|
|
||||||
const val SuccessFileOverwritten = 1
|
|
||||||
const val Error = 2
|
|
||||||
const val ErrorBaseGame = 3
|
|
||||||
const val ErrorFilenameExtension = 4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ import org.yuzu.yuzu_emu.utils.ForegroundService
|
|||||||
import org.yuzu.yuzu_emu.utils.InputHandler
|
import org.yuzu.yuzu_emu.utils.InputHandler
|
||||||
import org.yuzu.yuzu_emu.utils.Log
|
import org.yuzu.yuzu_emu.utils.Log
|
||||||
import org.yuzu.yuzu_emu.utils.MemoryUtil
|
import org.yuzu.yuzu_emu.utils.MemoryUtil
|
||||||
import org.yuzu.yuzu_emu.utils.NativeConfig
|
|
||||||
import org.yuzu.yuzu_emu.utils.NfcReader
|
import org.yuzu.yuzu_emu.utils.NfcReader
|
||||||
import org.yuzu.yuzu_emu.utils.ThemeHelper
|
import org.yuzu.yuzu_emu.utils.ThemeHelper
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
@ -171,11 +170,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||||||
stopMotionSensorListener()
|
stopMotionSensorListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
|
||||||
super.onStop()
|
|
||||||
NativeConfig.saveGlobalConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUserLeaveHint() {
|
override fun onUserLeaveHint() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||||
if (BooleanSetting.PICTURE_IN_PICTURE.getBoolean() && !isInPictureInPictureMode) {
|
if (BooleanSetting.PICTURE_IN_PICTURE.getBoolean() && !isInPictureInPictureMode) {
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic adapter that implements an [AsyncDifferConfig] and covers some of the basic boilerplate
|
||||||
|
* code used in every [RecyclerView].
|
||||||
|
* Type assigned to [Model] must inherit from [Object] in order to be compared properly.
|
||||||
|
*/
|
||||||
|
abstract class AbstractDiffAdapter<Model : Any, Holder : AbstractViewHolder<Model>> :
|
||||||
|
ListAdapter<Model, Holder>(AsyncDifferConfig.Builder(DiffCallback<Model>()).build()) {
|
||||||
|
override fun onBindViewHolder(holder: Holder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
|
private class DiffCallback<Model> : DiffUtil.ItemCallback<Model>() {
|
||||||
|
override fun areItemsTheSame(oldItem: Model & Any, newItem: Model & Any): Boolean {
|
||||||
|
return oldItem === newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("DiffUtilEquals")
|
||||||
|
override fun areContentsTheSame(oldItem: Model & Any, newItem: Model & Any): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic list class meant to take care of basic lists
|
||||||
|
* @param currentList The list to show initially
|
||||||
|
*/
|
||||||
|
abstract class AbstractListAdapter<Model : Any, Holder : AbstractViewHolder<Model>>(
|
||||||
|
open var currentList: List<Model>
|
||||||
|
) : RecyclerView.Adapter<Holder>() {
|
||||||
|
override fun onBindViewHolder(holder: Holder, position: Int) =
|
||||||
|
holder.bind(currentList[position])
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = currentList.size
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to [currentList] and notifies the underlying adapter of the change. If no parameter
|
||||||
|
* is passed in for position, [item] is added to the end of the list. Invokes [callback] last.
|
||||||
|
* @param item The item to add to the list
|
||||||
|
* @param position Index where [item] will be added
|
||||||
|
* @param callback Lambda that's called at the end of the list changes and has the added list
|
||||||
|
* position passed in as a parameter
|
||||||
|
*/
|
||||||
|
open fun addItem(item: Model, position: Int = -1, callback: ((position: Int) -> Unit)? = null) {
|
||||||
|
val newList = currentList.toMutableList()
|
||||||
|
val positionToUpdate: Int
|
||||||
|
if (position == -1) {
|
||||||
|
newList.add(item)
|
||||||
|
currentList = newList
|
||||||
|
positionToUpdate = currentList.size - 1
|
||||||
|
} else {
|
||||||
|
newList.add(position, item)
|
||||||
|
currentList = newList
|
||||||
|
positionToUpdate = position
|
||||||
|
}
|
||||||
|
onItemAdded(positionToUpdate, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun onItemAdded(position: Int, callback: ((Int) -> Unit)? = null) {
|
||||||
|
notifyItemInserted(position)
|
||||||
|
callback?.invoke(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces the [item] at [position] in the [currentList] and notifies the underlying adapter
|
||||||
|
* of the change. Invokes [callback] last.
|
||||||
|
* @param item New list item
|
||||||
|
* @param position Index where [item] will replace the existing list item
|
||||||
|
* @param callback Lambda that's called at the end of the list changes and has the changed list
|
||||||
|
* position passed in as a parameter
|
||||||
|
*/
|
||||||
|
fun changeItem(item: Model, position: Int, callback: ((position: Int) -> Unit)? = null) {
|
||||||
|
val newList = currentList.toMutableList()
|
||||||
|
newList[position] = item
|
||||||
|
currentList = newList
|
||||||
|
onItemChanged(position, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun onItemChanged(position: Int, callback: ((Int) -> Unit)? = null) {
|
||||||
|
notifyItemChanged(position)
|
||||||
|
callback?.invoke(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the list item at [position] in [currentList] and notifies the underlying adapter
|
||||||
|
* of the change. Invokes [callback] last.
|
||||||
|
* @param position Index where the list item will be removed
|
||||||
|
* @param callback Lambda that's called at the end of the list changes and has the removed list
|
||||||
|
* position passed in as a parameter
|
||||||
|
*/
|
||||||
|
fun removeItem(position: Int, callback: ((position: Int) -> Unit)? = null) {
|
||||||
|
val newList = currentList.toMutableList()
|
||||||
|
newList.removeAt(position)
|
||||||
|
currentList = newList
|
||||||
|
onItemRemoved(position, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun onItemRemoved(position: Int, callback: ((Int) -> Unit)? = null) {
|
||||||
|
notifyItemRemoved(position)
|
||||||
|
callback?.invoke(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces [currentList] with [newList] and notifies the underlying adapter of the change.
|
||||||
|
* @param newList The new list to replace [currentList]
|
||||||
|
*/
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
|
open fun replaceList(newList: List<Model>) {
|
||||||
|
currentList = newList
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
|
import org.yuzu.yuzu_emu.model.SelectableItem
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic list class meant to take care of single selection UI updates
|
||||||
|
* @param currentList The list to show initially
|
||||||
|
* @param defaultSelection The default selection to use if no list items are selected by
|
||||||
|
* [SelectableItem.selected] or if the currently selected item is removed from the list
|
||||||
|
*/
|
||||||
|
abstract class AbstractSingleSelectionList<
|
||||||
|
Model : SelectableItem,
|
||||||
|
Holder : AbstractViewHolder<Model>
|
||||||
|
>(
|
||||||
|
final override var currentList: List<Model>,
|
||||||
|
private val defaultSelection: DefaultSelection = DefaultSelection.Start
|
||||||
|
) : AbstractListAdapter<Model, Holder>(currentList) {
|
||||||
|
var selectedItem = getDefaultSelection()
|
||||||
|
|
||||||
|
init {
|
||||||
|
findSelectedItem()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the selection state of the [SelectableItem] that was selected and the previously selected
|
||||||
|
* item and notifies the underlying adapter of the change for those items. Invokes [callback] last.
|
||||||
|
* Does nothing if [position] is the same as the currently selected item.
|
||||||
|
* @param position Index of the item that was selected
|
||||||
|
* @param callback Lambda that's called at the end of the list changes and has the selected list
|
||||||
|
* position passed in as a parameter
|
||||||
|
*/
|
||||||
|
fun selectItem(position: Int, callback: ((position: Int) -> Unit)? = null) {
|
||||||
|
if (position == selectedItem) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val previouslySelectedItem = selectedItem
|
||||||
|
selectedItem = position
|
||||||
|
if (currentList.indices.contains(selectedItem)) {
|
||||||
|
currentList[selectedItem].onSelectionStateChanged(true)
|
||||||
|
}
|
||||||
|
if (currentList.indices.contains(previouslySelectedItem)) {
|
||||||
|
currentList[previouslySelectedItem].onSelectionStateChanged(false)
|
||||||
|
}
|
||||||
|
onItemChanged(previouslySelectedItem)
|
||||||
|
onItemChanged(selectedItem)
|
||||||
|
callback?.invoke(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a given item from the list and notifies the underlying adapter of the change. If the
|
||||||
|
* currently selected item was the item that was removed, the item at the position provided
|
||||||
|
* by [defaultSelection] will be made the new selection. Invokes [callback] last.
|
||||||
|
* @param position Index of the item that was removed
|
||||||
|
* @param callback Lambda that's called at the end of the list changes and has the removed and
|
||||||
|
* selected list positions passed in as parameters
|
||||||
|
*/
|
||||||
|
fun removeSelectableItem(
|
||||||
|
position: Int,
|
||||||
|
callback: ((removedPosition: Int, selectedPosition: Int) -> Unit)?
|
||||||
|
) {
|
||||||
|
removeItem(position)
|
||||||
|
if (position == selectedItem) {
|
||||||
|
selectedItem = getDefaultSelection()
|
||||||
|
currentList[selectedItem].onSelectionStateChanged(true)
|
||||||
|
onItemChanged(selectedItem)
|
||||||
|
} else if (position < selectedItem) {
|
||||||
|
selectedItem--
|
||||||
|
}
|
||||||
|
callback?.invoke(position, selectedItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addItem(item: Model, position: Int, callback: ((Int) -> Unit)?) {
|
||||||
|
super.addItem(item, position, callback)
|
||||||
|
if (position <= selectedItem && position != -1) {
|
||||||
|
selectedItem++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun replaceList(newList: List<Model>) {
|
||||||
|
super.replaceList(newList)
|
||||||
|
findSelectedItem()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun findSelectedItem() {
|
||||||
|
for (i in currentList.indices) {
|
||||||
|
if (currentList[i].selected) {
|
||||||
|
selectedItem = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDefaultSelection(): Int =
|
||||||
|
when (defaultSelection) {
|
||||||
|
DefaultSelection.Start -> currentList.indices.first
|
||||||
|
DefaultSelection.End -> currentList.indices.last
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class DefaultSelection { Start, End }
|
||||||
|
}
|
@ -5,48 +5,33 @@ package org.yuzu.yuzu_emu.adapters
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.databinding.ListItemAddonBinding
|
import org.yuzu.yuzu_emu.databinding.ListItemAddonBinding
|
||||||
import org.yuzu.yuzu_emu.model.Addon
|
import org.yuzu.yuzu_emu.model.Patch
|
||||||
|
import org.yuzu.yuzu_emu.model.AddonViewModel
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class AddonAdapter : ListAdapter<Addon, AddonAdapter.AddonViewHolder>(
|
class AddonAdapter(val addonViewModel: AddonViewModel) :
|
||||||
AsyncDifferConfig.Builder(DiffCallback()).build()
|
AbstractDiffAdapter<Patch, AddonAdapter.AddonViewHolder>() {
|
||||||
) {
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddonViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AddonViewHolder {
|
||||||
ListItemAddonBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
ListItemAddonBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
.also { return AddonViewHolder(it) }
|
.also { return AddonViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = currentList.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: AddonViewHolder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
inner class AddonViewHolder(val binding: ListItemAddonBinding) :
|
inner class AddonViewHolder(val binding: ListItemAddonBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<Patch>(binding) {
|
||||||
fun bind(addon: Addon) {
|
override fun bind(model: Patch) {
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
binding.addonSwitch.isChecked = !binding.addonSwitch.isChecked
|
binding.addonCheckbox.isChecked = !binding.addonCheckbox.isChecked
|
||||||
}
|
}
|
||||||
binding.title.text = addon.title
|
binding.title.text = model.name
|
||||||
binding.version.text = addon.version
|
binding.version.text = model.version
|
||||||
binding.addonSwitch.setOnCheckedChangeListener { _, checked ->
|
binding.addonCheckbox.setOnCheckedChangeListener { _, checked ->
|
||||||
addon.enabled = checked
|
model.enabled = checked
|
||||||
|
}
|
||||||
|
binding.addonCheckbox.isChecked = model.enabled
|
||||||
|
binding.buttonDelete.setOnClickListener {
|
||||||
|
addonViewModel.setAddonToDelete(model)
|
||||||
}
|
}
|
||||||
binding.addonSwitch.isChecked = addon.enabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<Addon>() {
|
|
||||||
override fun areItemsTheSame(oldItem: Addon, newItem: Addon): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: Addon, newItem: Addon): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,11 @@
|
|||||||
package org.yuzu.yuzu_emu.adapters
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
@ -19,72 +17,58 @@ import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
|||||||
import org.yuzu.yuzu_emu.model.Applet
|
import org.yuzu.yuzu_emu.model.Applet
|
||||||
import org.yuzu.yuzu_emu.model.AppletInfo
|
import org.yuzu.yuzu_emu.model.AppletInfo
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class AppletAdapter(val activity: FragmentActivity, var applets: List<Applet>) :
|
class AppletAdapter(val activity: FragmentActivity, applets: List<Applet>) :
|
||||||
RecyclerView.Adapter<AppletAdapter.AppletViewHolder>(),
|
AbstractListAdapter<Applet, AppletAdapter.AppletViewHolder>(applets) {
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): AppletAdapter.AppletViewHolder {
|
): AppletAdapter.AppletViewHolder {
|
||||||
CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
.apply { root.setOnClickListener(this@AppletAdapter) }
|
|
||||||
.also { return AppletViewHolder(it) }
|
.also { return AppletViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: AppletViewHolder, position: Int) =
|
|
||||||
holder.bind(applets[position])
|
|
||||||
|
|
||||||
override fun getItemCount(): Int = applets.size
|
|
||||||
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
val applet = (view.tag as AppletViewHolder).applet
|
|
||||||
val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId)
|
|
||||||
if (appletPath.isEmpty()) {
|
|
||||||
Toast.makeText(
|
|
||||||
YuzuApplication.appContext,
|
|
||||||
R.string.applets_error_applet,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (applet.appletInfo == AppletInfo.Cabinet) {
|
|
||||||
view.findNavController()
|
|
||||||
.navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId)
|
|
||||||
val appletGame = Game(
|
|
||||||
title = YuzuApplication.appContext.getString(applet.titleId),
|
|
||||||
path = appletPath
|
|
||||||
)
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
|
||||||
view.findNavController().navigate(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) :
|
inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<Applet>(binding) {
|
||||||
lateinit var applet: Applet
|
override fun bind(model: Applet) {
|
||||||
|
binding.title.setText(model.titleId)
|
||||||
init {
|
binding.description.setText(model.descriptionId)
|
||||||
itemView.tag = this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(applet: Applet) {
|
|
||||||
this.applet = applet
|
|
||||||
|
|
||||||
binding.title.setText(applet.titleId)
|
|
||||||
binding.description.setText(applet.descriptionId)
|
|
||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
binding.icon.context.resources,
|
binding.icon.context.resources,
|
||||||
applet.iconId,
|
model.iconId,
|
||||||
binding.icon.context.theme
|
binding.icon.context.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
binding.root.setOnClickListener { onClick(model) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onClick(applet: Applet) {
|
||||||
|
val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId)
|
||||||
|
if (appletPath.isEmpty()) {
|
||||||
|
Toast.makeText(
|
||||||
|
binding.root.context,
|
||||||
|
R.string.applets_error_applet,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applet.appletInfo == AppletInfo.Cabinet) {
|
||||||
|
binding.root.findNavController()
|
||||||
|
.navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId)
|
||||||
|
val appletGame = Game(
|
||||||
|
title = YuzuApplication.appContext.getString(applet.titleId),
|
||||||
|
path = appletPath
|
||||||
|
)
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
||||||
|
binding.root.findNavController().navigate(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,10 @@
|
|||||||
package org.yuzu.yuzu_emu.adapters
|
package org.yuzu.yuzu_emu.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
@ -19,54 +17,43 @@ import org.yuzu.yuzu_emu.model.CabinetMode
|
|||||||
import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder
|
import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder
|
||||||
import org.yuzu.yuzu_emu.model.AppletInfo
|
import org.yuzu.yuzu_emu.model.AppletInfo
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class CabinetLauncherDialogAdapter(val fragment: Fragment) :
|
class CabinetLauncherDialogAdapter(val fragment: Fragment) :
|
||||||
RecyclerView.Adapter<CabinetModeViewHolder>(),
|
AbstractListAdapter<CabinetMode, CabinetModeViewHolder>(
|
||||||
View.OnClickListener {
|
CabinetMode.values().copyOfRange(1, CabinetMode.entries.size).toList()
|
||||||
private val cabinetModes = CabinetMode.values().copyOfRange(1, CabinetMode.values().size)
|
) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder {
|
||||||
DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
.apply { root.setOnClickListener(this@CabinetLauncherDialogAdapter) }
|
|
||||||
.also { return CabinetModeViewHolder(it) }
|
.also { return CabinetModeViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = cabinetModes.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: CabinetModeViewHolder, position: Int) =
|
|
||||||
holder.bind(cabinetModes[position])
|
|
||||||
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
val mode = (view.tag as CabinetModeViewHolder).cabinetMode
|
|
||||||
val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId)
|
|
||||||
NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId)
|
|
||||||
NativeLibrary.setCabinetMode(mode.id)
|
|
||||||
val appletGame = Game(
|
|
||||||
title = YuzuApplication.appContext.getString(R.string.cabinet_applet),
|
|
||||||
path = appletPath
|
|
||||||
)
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
|
||||||
fragment.findNavController().navigate(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class CabinetModeViewHolder(val binding: DialogListItemBinding) :
|
inner class CabinetModeViewHolder(val binding: DialogListItemBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<CabinetMode>(binding) {
|
||||||
lateinit var cabinetMode: CabinetMode
|
override fun bind(model: CabinetMode) {
|
||||||
|
|
||||||
init {
|
|
||||||
itemView.tag = this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(cabinetMode: CabinetMode) {
|
|
||||||
this.cabinetMode = cabinetMode
|
|
||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
binding.icon.context.resources,
|
binding.icon.context.resources,
|
||||||
cabinetMode.iconId,
|
model.iconId,
|
||||||
binding.icon.context.theme
|
binding.icon.context.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
binding.title.setText(cabinetMode.titleId)
|
binding.title.setText(model.titleId)
|
||||||
|
|
||||||
|
binding.root.setOnClickListener { onClick(model) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onClick(mode: CabinetMode) {
|
||||||
|
val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId)
|
||||||
|
NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId)
|
||||||
|
NativeLibrary.setCabinetMode(mode.id)
|
||||||
|
val appletGame = Game(
|
||||||
|
title = YuzuApplication.appContext.getString(R.string.cabinet_applet),
|
||||||
|
path = appletPath
|
||||||
|
)
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame)
|
||||||
|
fragment.findNavController().navigate(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,65 +7,39 @@ import android.text.TextUtils
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.R
|
|
||||||
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
||||||
|
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
||||||
|
import org.yuzu.yuzu_emu.model.Driver
|
||||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
|
||||||
|
|
||||||
class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
||||||
ListAdapter<Pair<String, GpuDriverMetadata>, DriverAdapter.DriverViewHolder>(
|
AbstractSingleSelectionList<Driver, DriverAdapter.DriverViewHolder>(
|
||||||
AsyncDifferConfig.Builder(DiffCallback()).build()
|
driverViewModel.driverList.value
|
||||||
) {
|
) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DriverViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DriverViewHolder {
|
||||||
val binding =
|
CardDriverOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
CardDriverOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
.also { return DriverViewHolder(it) }
|
||||||
return DriverViewHolder(binding)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemCount(): Int = currentList.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: DriverViewHolder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
private fun onSelectDriver(position: Int) {
|
|
||||||
driverViewModel.setSelectedDriverIndex(position)
|
|
||||||
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
|
||||||
notifyItemChanged(driverViewModel.selectedDriver)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onDeleteDriver(driverData: Pair<String, GpuDriverMetadata>, position: Int) {
|
|
||||||
if (driverViewModel.selectedDriver > position) {
|
|
||||||
driverViewModel.setSelectedDriverIndex(driverViewModel.selectedDriver - 1)
|
|
||||||
}
|
|
||||||
if (GpuDriverHelper.customDriverSettingData == driverData.second) {
|
|
||||||
driverViewModel.setSelectedDriverIndex(0)
|
|
||||||
}
|
|
||||||
driverViewModel.driversToDelete.add(driverData.first)
|
|
||||||
driverViewModel.removeDriver(driverData)
|
|
||||||
notifyItemRemoved(position)
|
|
||||||
notifyItemChanged(driverViewModel.selectedDriver)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class DriverViewHolder(val binding: CardDriverOptionBinding) :
|
inner class DriverViewHolder(val binding: CardDriverOptionBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<Driver>(binding) {
|
||||||
private lateinit var driverData: Pair<String, GpuDriverMetadata>
|
override fun bind(model: Driver) {
|
||||||
|
|
||||||
fun bind(driverData: Pair<String, GpuDriverMetadata>) {
|
|
||||||
this.driverData = driverData
|
|
||||||
val driver = driverData.second
|
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
radioButton.isChecked = driverViewModel.selectedDriver == bindingAdapterPosition
|
radioButton.isChecked = model.selected
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
onSelectDriver(bindingAdapterPosition)
|
selectItem(bindingAdapterPosition) {
|
||||||
|
driverViewModel.onDriverSelected(it)
|
||||||
|
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buttonDelete.setOnClickListener {
|
buttonDelete.setOnClickListener {
|
||||||
onDeleteDriver(driverData, bindingAdapterPosition)
|
removeSelectableItem(
|
||||||
|
bindingAdapterPosition
|
||||||
|
) { removedPosition: Int, selectedPosition: Int ->
|
||||||
|
driverViewModel.onDriverRemoved(removedPosition, selectedPosition)
|
||||||
|
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delay marquee by 3s
|
// Delay marquee by 3s
|
||||||
@ -80,38 +54,19 @@ class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
if (driver.name == null) {
|
title.text = model.title
|
||||||
title.setText(R.string.system_gpu_driver)
|
version.text = model.version
|
||||||
description.text = ""
|
description.text = model.description
|
||||||
version.text = ""
|
if (model.description.isNotEmpty()) {
|
||||||
version.visibility = View.GONE
|
|
||||||
description.visibility = View.GONE
|
|
||||||
buttonDelete.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
title.text = driver.name
|
|
||||||
version.text = driver.version
|
|
||||||
description.text = driver.description
|
|
||||||
version.visibility = View.VISIBLE
|
version.visibility = View.VISIBLE
|
||||||
description.visibility = View.VISIBLE
|
description.visibility = View.VISIBLE
|
||||||
buttonDelete.visibility = View.VISIBLE
|
buttonDelete.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
version.visibility = View.GONE
|
||||||
|
description.visibility = View.GONE
|
||||||
|
buttonDelete.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<Pair<String, GpuDriverMetadata>>() {
|
|
||||||
override fun areItemsTheSame(
|
|
||||||
oldItem: Pair<String, GpuDriverMetadata>,
|
|
||||||
newItem: Pair<String, GpuDriverMetadata>
|
|
||||||
): Boolean {
|
|
||||||
return oldItem.first == newItem.first
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(
|
|
||||||
oldItem: Pair<String, GpuDriverMetadata>,
|
|
||||||
newItem: Pair<String, GpuDriverMetadata>
|
|
||||||
): Boolean {
|
|
||||||
return oldItem.second == newItem.second
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,14 @@ import android.text.TextUtils
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.databinding.CardFolderBinding
|
import org.yuzu.yuzu_emu.databinding.CardFolderBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.GameFolderPropertiesDialogFragment
|
import org.yuzu.yuzu_emu.fragments.GameFolderPropertiesDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.GameDir
|
import org.yuzu.yuzu_emu.model.GameDir
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesViewModel) :
|
class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesViewModel) :
|
||||||
ListAdapter<GameDir, FolderAdapter.FolderViewHolder>(
|
AbstractDiffAdapter<GameDir, FolderAdapter.FolderViewHolder>() {
|
||||||
AsyncDifferConfig.Builder(DiffCallback()).build()
|
|
||||||
) {
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
@ -29,18 +24,11 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
.also { return FolderViewHolder(it) }
|
.also { return FolderViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: FolderAdapter.FolderViewHolder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
inner class FolderViewHolder(val binding: CardFolderBinding) :
|
inner class FolderViewHolder(val binding: CardFolderBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<GameDir>(binding) {
|
||||||
private lateinit var gameDir: GameDir
|
override fun bind(model: GameDir) {
|
||||||
|
|
||||||
fun bind(gameDir: GameDir) {
|
|
||||||
this.gameDir = gameDir
|
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
path.text = Uri.parse(gameDir.uriString).path
|
path.text = Uri.parse(model.uriString).path
|
||||||
path.postDelayed(
|
path.postDelayed(
|
||||||
{
|
{
|
||||||
path.isSelected = true
|
path.isSelected = true
|
||||||
@ -50,7 +38,7 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
)
|
)
|
||||||
|
|
||||||
buttonEdit.setOnClickListener {
|
buttonEdit.setOnClickListener {
|
||||||
GameFolderPropertiesDialogFragment.newInstance(this@FolderViewHolder.gameDir)
|
GameFolderPropertiesDialogFragment.newInstance(model)
|
||||||
.show(
|
.show(
|
||||||
activity.supportFragmentManager,
|
activity.supportFragmentManager,
|
||||||
GameFolderPropertiesDialogFragment.TAG
|
GameFolderPropertiesDialogFragment.TAG
|
||||||
@ -58,19 +46,9 @@ class FolderAdapter(val activity: FragmentActivity, val gamesViewModel: GamesVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonDelete.setOnClickListener {
|
buttonDelete.setOnClickListener {
|
||||||
gamesViewModel.removeFolder(this@FolderViewHolder.gameDir)
|
gamesViewModel.removeFolder(model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<GameDir>() {
|
|
||||||
override fun areItemsTheSame(oldItem: GameDir, newItem: GameDir): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: GameDir, newItem: GameDir): Boolean {
|
|
||||||
return oldItem == newItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.drawable.LayerDrawable
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -25,10 +24,6 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -36,122 +31,26 @@ import org.yuzu.yuzu_emu.HomeNavigationDirections
|
|||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||||
import org.yuzu.yuzu_emu.adapters.GameAdapter.GameViewHolder
|
|
||||||
import org.yuzu.yuzu_emu.databinding.CardGameBinding
|
import org.yuzu.yuzu_emu.databinding.CardGameBinding
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class GameAdapter(private val activity: AppCompatActivity) :
|
class GameAdapter(private val activity: AppCompatActivity) :
|
||||||
ListAdapter<Game, GameViewHolder>(AsyncDifferConfig.Builder(DiffCallback()).build()),
|
AbstractDiffAdapter<Game, GameAdapter.GameViewHolder>() {
|
||||||
View.OnClickListener,
|
|
||||||
View.OnLongClickListener {
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder {
|
||||||
// Create a new view.
|
CardGameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
val binding = CardGameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
.also { return GameViewHolder(it) }
|
||||||
binding.cardGame.setOnClickListener(this)
|
|
||||||
binding.cardGame.setOnLongClickListener(this)
|
|
||||||
|
|
||||||
// Use that view to create a ViewHolder.
|
|
||||||
return GameViewHolder(binding)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: GameViewHolder, position: Int) =
|
|
||||||
holder.bind(currentList[position])
|
|
||||||
|
|
||||||
override fun getItemCount(): Int = currentList.size
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launches the game that was clicked on.
|
|
||||||
*
|
|
||||||
* @param view The card representing the game the user wants to play.
|
|
||||||
*/
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
val holder = view.tag as GameViewHolder
|
|
||||||
|
|
||||||
val gameExists = DocumentFile.fromSingleUri(
|
|
||||||
YuzuApplication.appContext,
|
|
||||||
Uri.parse(holder.game.path)
|
|
||||||
)?.exists() == true
|
|
||||||
if (!gameExists) {
|
|
||||||
Toast.makeText(
|
|
||||||
YuzuApplication.appContext,
|
|
||||||
R.string.loader_error_file_not_found,
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
|
|
||||||
ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
|
||||||
preferences.edit()
|
|
||||||
.putLong(
|
|
||||||
holder.game.keyLastPlayedTime,
|
|
||||||
System.currentTimeMillis()
|
|
||||||
)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
val openIntent = Intent(YuzuApplication.appContext, EmulationActivity::class.java).apply {
|
|
||||||
action = Intent.ACTION_VIEW
|
|
||||||
data = Uri.parse(holder.game.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.lifecycleScope.launch {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val layerDrawable = ResourcesCompat.getDrawable(
|
|
||||||
YuzuApplication.appContext.resources,
|
|
||||||
R.drawable.shortcut,
|
|
||||||
null
|
|
||||||
) as LayerDrawable
|
|
||||||
layerDrawable.setDrawableByLayerId(
|
|
||||||
R.id.shortcut_foreground,
|
|
||||||
GameIconUtils.getGameIcon(activity, holder.game)
|
|
||||||
.toDrawable(YuzuApplication.appContext.resources)
|
|
||||||
)
|
|
||||||
val inset = YuzuApplication.appContext.resources
|
|
||||||
.getDimensionPixelSize(R.dimen.icon_inset)
|
|
||||||
layerDrawable.setLayerInset(1, inset, inset, inset, inset)
|
|
||||||
val shortcut =
|
|
||||||
ShortcutInfoCompat.Builder(YuzuApplication.appContext, holder.game.path)
|
|
||||||
.setShortLabel(holder.game.title)
|
|
||||||
.setIcon(
|
|
||||||
IconCompat.createWithAdaptiveBitmap(
|
|
||||||
layerDrawable.toBitmap(config = Bitmap.Config.ARGB_8888)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setIntent(openIntent)
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(YuzuApplication.appContext, shortcut)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val action = HomeNavigationDirections.actionGlobalEmulationActivity(holder.game, true)
|
|
||||||
view.findNavController().navigate(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLongClick(view: View): Boolean {
|
|
||||||
val holder = view.tag as GameViewHolder
|
|
||||||
val action = HomeNavigationDirections.actionGlobalPerGamePropertiesFragment(holder.game)
|
|
||||||
view.findNavController().navigate(action)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class GameViewHolder(val binding: CardGameBinding) :
|
inner class GameViewHolder(val binding: CardGameBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<Game>(binding) {
|
||||||
lateinit var game: Game
|
override fun bind(model: Game) {
|
||||||
|
|
||||||
init {
|
|
||||||
binding.cardGame.tag = this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(game: Game) {
|
|
||||||
this.game = game
|
|
||||||
|
|
||||||
binding.imageGameScreen.scaleType = ImageView.ScaleType.CENTER_CROP
|
binding.imageGameScreen.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
GameIconUtils.loadGameIcon(game, binding.imageGameScreen)
|
GameIconUtils.loadGameIcon(model, binding.imageGameScreen)
|
||||||
|
|
||||||
binding.textGameTitle.text = game.title.replace("[\\t\\n\\r]+".toRegex(), " ")
|
binding.textGameTitle.text = model.title.replace("[\\t\\n\\r]+".toRegex(), " ")
|
||||||
|
|
||||||
binding.textGameTitle.postDelayed(
|
binding.textGameTitle.postDelayed(
|
||||||
{
|
{
|
||||||
@ -160,16 +59,79 @@ class GameAdapter(private val activity: AppCompatActivity) :
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<Game>() {
|
binding.cardGame.setOnClickListener { onClick(model) }
|
||||||
override fun areItemsTheSame(oldItem: Game, newItem: Game): Boolean {
|
binding.cardGame.setOnLongClickListener { onLongClick(model) }
|
||||||
return oldItem == newItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: Game, newItem: Game): Boolean {
|
fun onClick(game: Game) {
|
||||||
return oldItem == newItem
|
val gameExists = DocumentFile.fromSingleUri(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
Uri.parse(game.path)
|
||||||
|
)?.exists() == true
|
||||||
|
if (!gameExists) {
|
||||||
|
Toast.makeText(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
R.string.loader_error_file_not_found,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
|
||||||
|
ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val preferences =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||||
|
preferences.edit()
|
||||||
|
.putLong(
|
||||||
|
game.keyLastPlayedTime,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
val openIntent =
|
||||||
|
Intent(YuzuApplication.appContext, EmulationActivity::class.java).apply {
|
||||||
|
action = Intent.ACTION_VIEW
|
||||||
|
data = Uri.parse(game.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val layerDrawable = ResourcesCompat.getDrawable(
|
||||||
|
YuzuApplication.appContext.resources,
|
||||||
|
R.drawable.shortcut,
|
||||||
|
null
|
||||||
|
) as LayerDrawable
|
||||||
|
layerDrawable.setDrawableByLayerId(
|
||||||
|
R.id.shortcut_foreground,
|
||||||
|
GameIconUtils.getGameIcon(activity, game)
|
||||||
|
.toDrawable(YuzuApplication.appContext.resources)
|
||||||
|
)
|
||||||
|
val inset = YuzuApplication.appContext.resources
|
||||||
|
.getDimensionPixelSize(R.dimen.icon_inset)
|
||||||
|
layerDrawable.setLayerInset(1, inset, inset, inset, inset)
|
||||||
|
val shortcut =
|
||||||
|
ShortcutInfoCompat.Builder(YuzuApplication.appContext, game.path)
|
||||||
|
.setShortLabel(game.title)
|
||||||
|
.setIcon(
|
||||||
|
IconCompat.createWithAdaptiveBitmap(
|
||||||
|
layerDrawable.toBitmap(config = Bitmap.Config.ARGB_8888)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setIntent(openIntent)
|
||||||
|
.build()
|
||||||
|
ShortcutManagerCompat.pushDynamicShortcut(YuzuApplication.appContext, shortcut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val action = HomeNavigationDirections.actionGlobalEmulationActivity(game, true)
|
||||||
|
binding.root.findNavController().navigate(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onLongClick(game: Game): Boolean {
|
||||||
|
val action = HomeNavigationDirections.actionGlobalPerGamePropertiesFragment(game)
|
||||||
|
binding.root.findNavController().navigate(action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,23 +12,22 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding
|
import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding
|
||||||
import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding
|
||||||
import org.yuzu.yuzu_emu.model.GameProperty
|
import org.yuzu.yuzu_emu.model.GameProperty
|
||||||
import org.yuzu.yuzu_emu.model.InstallableProperty
|
import org.yuzu.yuzu_emu.model.InstallableProperty
|
||||||
import org.yuzu.yuzu_emu.model.SubmenuProperty
|
import org.yuzu.yuzu_emu.model.SubmenuProperty
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class GamePropertiesAdapter(
|
class GamePropertiesAdapter(
|
||||||
private val viewLifecycle: LifecycleOwner,
|
private val viewLifecycle: LifecycleOwner,
|
||||||
private var properties: List<GameProperty>
|
private var properties: List<GameProperty>
|
||||||
) :
|
) : AbstractListAdapter<GameProperty, AbstractViewHolder<GameProperty>>(properties) {
|
||||||
RecyclerView.Adapter<GamePropertiesAdapter.GamePropertyViewHolder>() {
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): GamePropertyViewHolder {
|
): AbstractViewHolder<GameProperty> {
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
PropertyType.Submenu.ordinal -> {
|
PropertyType.Submenu.ordinal -> {
|
||||||
@ -51,11 +50,6 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = properties.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: GamePropertyViewHolder, position: Int) =
|
|
||||||
holder.bind(properties[position])
|
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return when (properties[position]) {
|
return when (properties[position]) {
|
||||||
is SubmenuProperty -> PropertyType.Submenu.ordinal
|
is SubmenuProperty -> PropertyType.Submenu.ordinal
|
||||||
@ -63,14 +57,10 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class GamePropertyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|
||||||
abstract fun bind(property: GameProperty)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) :
|
inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) :
|
||||||
GamePropertyViewHolder(binding.root) {
|
AbstractViewHolder<GameProperty>(binding) {
|
||||||
override fun bind(property: GameProperty) {
|
override fun bind(model: GameProperty) {
|
||||||
val submenuProperty = property as SubmenuProperty
|
val submenuProperty = model as SubmenuProperty
|
||||||
|
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
submenuProperty.action.invoke()
|
submenuProperty.action.invoke()
|
||||||
@ -108,9 +98,9 @@ class GamePropertiesAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) :
|
inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) :
|
||||||
GamePropertyViewHolder(binding.root) {
|
AbstractViewHolder<GameProperty>(binding) {
|
||||||
override fun bind(property: GameProperty) {
|
override fun bind(model: GameProperty) {
|
||||||
val installableProperty = property as InstallableProperty
|
val installableProperty = model as InstallableProperty
|
||||||
|
|
||||||
binding.title.setText(installableProperty.titleId)
|
binding.title.setText(installableProperty.titleId)
|
||||||
binding.description.setText(installableProperty.descriptionId)
|
binding.description.setText(installableProperty.descriptionId)
|
||||||
|
@ -14,69 +14,37 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.HomeSetting
|
import org.yuzu.yuzu_emu.model.HomeSetting
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class HomeSettingAdapter(
|
class HomeSettingAdapter(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
private val viewLifecycle: LifecycleOwner,
|
private val viewLifecycle: LifecycleOwner,
|
||||||
var options: List<HomeSetting>
|
options: List<HomeSetting>
|
||||||
) :
|
) : AbstractListAdapter<HomeSetting, HomeSettingAdapter.HomeOptionViewHolder>(options) {
|
||||||
RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(),
|
|
||||||
View.OnClickListener {
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
||||||
val binding =
|
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
.also { return HomeOptionViewHolder(it) }
|
||||||
binding.root.setOnClickListener(this)
|
|
||||||
return HomeOptionViewHolder(binding)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
|
||||||
return options.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) {
|
|
||||||
holder.bind(options[position])
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
val holder = view.tag as HomeOptionViewHolder
|
|
||||||
if (holder.option.isEnabled.invoke()) {
|
|
||||||
holder.option.onClick.invoke()
|
|
||||||
} else {
|
|
||||||
MessageDialogFragment.newInstance(
|
|
||||||
activity,
|
|
||||||
titleId = holder.option.disabledTitleId,
|
|
||||||
descriptionId = holder.option.disabledMessageId
|
|
||||||
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<HomeSetting>(binding) {
|
||||||
lateinit var option: HomeSetting
|
override fun bind(model: HomeSetting) {
|
||||||
|
binding.optionTitle.text = activity.resources.getString(model.titleId)
|
||||||
init {
|
binding.optionDescription.text = activity.resources.getString(model.descriptionId)
|
||||||
itemView.tag = this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(option: HomeSetting) {
|
|
||||||
this.option = option
|
|
||||||
binding.optionTitle.text = activity.resources.getString(option.titleId)
|
|
||||||
binding.optionDescription.text = activity.resources.getString(option.descriptionId)
|
|
||||||
binding.optionIcon.setImageDrawable(
|
binding.optionIcon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
option.iconId,
|
model.iconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
when (option.titleId) {
|
when (model.titleId) {
|
||||||
R.string.get_early_access ->
|
R.string.get_early_access ->
|
||||||
binding.optionLayout.background =
|
binding.optionLayout.background =
|
||||||
ContextCompat.getDrawable(
|
ContextCompat.getDrawable(
|
||||||
@ -85,7 +53,7 @@ class HomeSettingAdapter(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option.isEnabled.invoke()) {
|
if (!model.isEnabled.invoke()) {
|
||||||
binding.optionTitle.alpha = 0.5f
|
binding.optionTitle.alpha = 0.5f
|
||||||
binding.optionDescription.alpha = 0.5f
|
binding.optionDescription.alpha = 0.5f
|
||||||
binding.optionIcon.alpha = 0.5f
|
binding.optionIcon.alpha = 0.5f
|
||||||
@ -93,7 +61,7 @@ class HomeSettingAdapter(
|
|||||||
|
|
||||||
viewLifecycle.lifecycleScope.launch {
|
viewLifecycle.lifecycleScope.launch {
|
||||||
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
option.details.collect { updateOptionDetails(it) }
|
model.details.collect { updateOptionDetails(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.optionDetail.postDelayed(
|
binding.optionDetail.postDelayed(
|
||||||
@ -103,6 +71,20 @@ class HomeSettingAdapter(
|
|||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
binding.root.setOnClickListener { onClick(model) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onClick(model: HomeSetting) {
|
||||||
|
if (model.isEnabled.invoke()) {
|
||||||
|
model.onClick.invoke()
|
||||||
|
} else {
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
activity,
|
||||||
|
titleId = model.disabledTitleId,
|
||||||
|
descriptionId = model.disabledMessageId
|
||||||
|
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateOptionDetails(detailString: String) {
|
private fun updateOptionDetails(detailString: String) {
|
||||||
|
@ -6,43 +6,33 @@ package org.yuzu.yuzu_emu.adapters
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.yuzu.yuzu_emu.databinding.CardInstallableBinding
|
import org.yuzu.yuzu_emu.databinding.CardInstallableBinding
|
||||||
import org.yuzu.yuzu_emu.model.Installable
|
import org.yuzu.yuzu_emu.model.Installable
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class InstallableAdapter(private val installables: List<Installable>) :
|
class InstallableAdapter(installables: List<Installable>) :
|
||||||
RecyclerView.Adapter<InstallableAdapter.InstallableViewHolder>() {
|
AbstractListAdapter<Installable, InstallableAdapter.InstallableViewHolder>(installables) {
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int
|
||||||
): InstallableAdapter.InstallableViewHolder {
|
): InstallableAdapter.InstallableViewHolder {
|
||||||
val binding =
|
CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
.also { return InstallableViewHolder(it) }
|
||||||
return InstallableViewHolder(binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = installables.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: InstallableAdapter.InstallableViewHolder, position: Int) =
|
|
||||||
holder.bind(installables[position])
|
|
||||||
|
|
||||||
inner class InstallableViewHolder(val binding: CardInstallableBinding) :
|
inner class InstallableViewHolder(val binding: CardInstallableBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
AbstractViewHolder<Installable>(binding) {
|
||||||
lateinit var installable: Installable
|
override fun bind(model: Installable) {
|
||||||
|
binding.title.setText(model.titleId)
|
||||||
|
binding.description.setText(model.descriptionId)
|
||||||
|
|
||||||
fun bind(installable: Installable) {
|
if (model.install != null) {
|
||||||
this.installable = installable
|
|
||||||
|
|
||||||
binding.title.setText(installable.titleId)
|
|
||||||
binding.description.setText(installable.descriptionId)
|
|
||||||
|
|
||||||
if (installable.install != null) {
|
|
||||||
binding.buttonInstall.visibility = View.VISIBLE
|
binding.buttonInstall.visibility = View.VISIBLE
|
||||||
binding.buttonInstall.setOnClickListener { installable.install.invoke() }
|
binding.buttonInstall.setOnClickListener { model.install.invoke() }
|
||||||
}
|
}
|
||||||
if (installable.export != null) {
|
if (model.export != null) {
|
||||||
binding.buttonExport.visibility = View.VISIBLE
|
binding.buttonExport.visibility = View.VISIBLE
|
||||||
binding.buttonExport.setOnClickListener { installable.export.invoke() }
|
binding.buttonExport.setOnClickListener { model.export.invoke() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,49 +7,33 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
|
||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
|
||||||
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
|
import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding
|
||||||
import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment
|
import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.License
|
import org.yuzu.yuzu_emu.model.License
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class LicenseAdapter(private val activity: AppCompatActivity, var licenses: List<License>) :
|
class LicenseAdapter(private val activity: AppCompatActivity, licenses: List<License>) :
|
||||||
RecyclerView.Adapter<LicenseAdapter.LicenseViewHolder>(),
|
AbstractListAdapter<License, LicenseAdapter.LicenseViewHolder>(licenses) {
|
||||||
View.OnClickListener {
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder {
|
||||||
val binding =
|
ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
.also { return LicenseViewHolder(it) }
|
||||||
binding.root.setOnClickListener(this)
|
|
||||||
return LicenseViewHolder(binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = licenses.size
|
inner class LicenseViewHolder(val binding: ListItemSettingBinding) :
|
||||||
|
AbstractViewHolder<License>(binding) {
|
||||||
|
override fun bind(model: License) {
|
||||||
|
binding.apply {
|
||||||
|
textSettingName.text = root.context.getString(model.titleId)
|
||||||
|
textSettingDescription.text = root.context.getString(model.descriptionId)
|
||||||
|
textSettingValue.visibility = View.GONE
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: LicenseViewHolder, position: Int) {
|
root.setOnClickListener { onClick(model) }
|
||||||
holder.bind(licenses[position])
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
val license = (view.tag as LicenseViewHolder).license
|
|
||||||
LicenseBottomSheetDialogFragment.newInstance(license)
|
|
||||||
.show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG)
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class LicenseViewHolder(val binding: ListItemSettingBinding) : ViewHolder(binding.root) {
|
|
||||||
lateinit var license: License
|
|
||||||
|
|
||||||
init {
|
|
||||||
itemView.tag = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bind(license: License) {
|
private fun onClick(license: License) {
|
||||||
this.license = license
|
LicenseBottomSheetDialogFragment.newInstance(license)
|
||||||
|
.show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG)
|
||||||
val context = YuzuApplication.appContext
|
|
||||||
binding.textSettingName.text = context.getString(license.titleId)
|
|
||||||
binding.textSettingDescription.text = context.getString(license.descriptionId)
|
|
||||||
binding.textSettingValue.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import android.view.ViewGroup
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import org.yuzu.yuzu_emu.databinding.PageSetupBinding
|
import org.yuzu.yuzu_emu.databinding.PageSetupBinding
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
@ -18,31 +17,19 @@ import org.yuzu.yuzu_emu.model.SetupCallback
|
|||||||
import org.yuzu.yuzu_emu.model.SetupPage
|
import org.yuzu.yuzu_emu.model.SetupPage
|
||||||
import org.yuzu.yuzu_emu.model.StepState
|
import org.yuzu.yuzu_emu.model.StepState
|
||||||
import org.yuzu.yuzu_emu.utils.ViewUtils
|
import org.yuzu.yuzu_emu.utils.ViewUtils
|
||||||
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
||||||
|
|
||||||
class SetupAdapter(val activity: AppCompatActivity, val pages: List<SetupPage>) :
|
class SetupAdapter(val activity: AppCompatActivity, pages: List<SetupPage>) :
|
||||||
RecyclerView.Adapter<SetupAdapter.SetupPageViewHolder>() {
|
AbstractListAdapter<SetupPage, SetupAdapter.SetupPageViewHolder>(pages) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder {
|
||||||
val binding = PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return SetupPageViewHolder(binding)
|
.also { return SetupPageViewHolder(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = pages.size
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: SetupPageViewHolder, position: Int) =
|
|
||||||
holder.bind(pages[position])
|
|
||||||
|
|
||||||
inner class SetupPageViewHolder(val binding: PageSetupBinding) :
|
inner class SetupPageViewHolder(val binding: PageSetupBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root), SetupCallback {
|
AbstractViewHolder<SetupPage>(binding), SetupCallback {
|
||||||
lateinit var page: SetupPage
|
override fun bind(model: SetupPage) {
|
||||||
|
if (model.stepCompleted.invoke() == StepState.COMPLETE) {
|
||||||
init {
|
|
||||||
itemView.tag = this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(page: SetupPage) {
|
|
||||||
this.page = page
|
|
||||||
|
|
||||||
if (page.stepCompleted.invoke() == StepState.COMPLETE) {
|
|
||||||
binding.buttonAction.visibility = View.INVISIBLE
|
binding.buttonAction.visibility = View.INVISIBLE
|
||||||
binding.textConfirmation.visibility = View.VISIBLE
|
binding.textConfirmation.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
@ -50,31 +37,31 @@ class SetupAdapter(val activity: AppCompatActivity, val pages: List<SetupPage>)
|
|||||||
binding.icon.setImageDrawable(
|
binding.icon.setImageDrawable(
|
||||||
ResourcesCompat.getDrawable(
|
ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
page.iconId,
|
model.iconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
binding.textTitle.text = activity.resources.getString(page.titleId)
|
binding.textTitle.text = activity.resources.getString(model.titleId)
|
||||||
binding.textDescription.text =
|
binding.textDescription.text =
|
||||||
Html.fromHtml(activity.resources.getString(page.descriptionId), 0)
|
Html.fromHtml(activity.resources.getString(model.descriptionId), 0)
|
||||||
|
|
||||||
binding.buttonAction.apply {
|
binding.buttonAction.apply {
|
||||||
text = activity.resources.getString(page.buttonTextId)
|
text = activity.resources.getString(model.buttonTextId)
|
||||||
if (page.buttonIconId != 0) {
|
if (model.buttonIconId != 0) {
|
||||||
icon = ResourcesCompat.getDrawable(
|
icon = ResourcesCompat.getDrawable(
|
||||||
activity.resources,
|
activity.resources,
|
||||||
page.buttonIconId,
|
model.buttonIconId,
|
||||||
activity.theme
|
activity.theme
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
iconGravity =
|
iconGravity =
|
||||||
if (page.leftAlignedIcon) {
|
if (model.leftAlignedIcon) {
|
||||||
MaterialButton.ICON_GRAVITY_START
|
MaterialButton.ICON_GRAVITY_START
|
||||||
} else {
|
} else {
|
||||||
MaterialButton.ICON_GRAVITY_END
|
MaterialButton.ICON_GRAVITY_END
|
||||||
}
|
}
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
page.buttonAction.invoke(this@SetupPageViewHolder)
|
model.buttonAction.invoke(this@SetupPageViewHolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ class AboutFragment : Fragment() {
|
|||||||
binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment)
|
binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.textBuildHash.text = BuildConfig.GIT_HASH
|
binding.textVersionName.text = BuildConfig.VERSION_NAME
|
||||||
binding.buttonBuildHash.setOnClickListener {
|
binding.textVersionName.setOnClickListener {
|
||||||
val clipBoard =
|
val clipBoard =
|
||||||
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH)
|
val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH)
|
||||||
|
@ -74,7 +74,7 @@ class AddonsFragment : Fragment() {
|
|||||||
|
|
||||||
binding.listAddons.apply {
|
binding.listAddons.apply {
|
||||||
layoutManager = LinearLayoutManager(requireContext())
|
layoutManager = LinearLayoutManager(requireContext())
|
||||||
adapter = AddonAdapter()
|
adapter = AddonAdapter(addonViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.apply {
|
viewLifecycleOwner.lifecycleScope.apply {
|
||||||
@ -110,6 +110,21 @@ class AddonsFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
addonViewModel.addonToDelete.collect {
|
||||||
|
if (it != null) {
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
titleId = R.string.confirm_uninstall,
|
||||||
|
descriptionId = R.string.confirm_uninstall_description,
|
||||||
|
positiveAction = { addonViewModel.onDeleteAddon(it) }
|
||||||
|
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
addonViewModel.setAddonToDelete(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonInstall.setOnClickListener {
|
binding.buttonInstall.setOnClickListener {
|
||||||
@ -156,22 +171,22 @@ class AddonsFragment : Fragment() {
|
|||||||
descriptionId = R.string.invalid_directory_description
|
descriptionId = R.string.invalid_directory_description
|
||||||
)
|
)
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
R.string.installing_game_content,
|
R.string.installing_game_content,
|
||||||
false
|
false
|
||||||
) {
|
) { progressCallback, _ ->
|
||||||
val parentDirectoryName = externalAddonDirectory.name
|
val parentDirectoryName = externalAddonDirectory.name
|
||||||
val internalAddonDirectory =
|
val internalAddonDirectory =
|
||||||
File(args.game.addonDir + parentDirectoryName)
|
File(args.game.addonDir + parentDirectoryName)
|
||||||
try {
|
try {
|
||||||
externalAddonDirectory.copyFilesTo(internalAddonDirectory)
|
externalAddonDirectory.copyFilesTo(internalAddonDirectory, progressCallback)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
return@newInstance errorMessage
|
return@newInstance errorMessage
|
||||||
}
|
}
|
||||||
addonViewModel.refreshAddons()
|
addonViewModel.refreshAddons()
|
||||||
return@newInstance getString(R.string.addon_installed_successfully)
|
return@newInstance getString(R.string.addon_installed_successfully)
|
||||||
}.show(parentFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(parentFragmentManager, ProgressDialogFragment.TAG)
|
||||||
} else {
|
} else {
|
||||||
errorMessage.show(parentFragmentManager, MessageDialogFragment.TAG)
|
errorMessage.show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
package org.yuzu.yuzu_emu.fragments
|
package org.yuzu.yuzu_emu.fragments
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -13,20 +14,26 @@ import androidx.core.view.WindowInsetsCompat
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.google.android.material.transition.MaterialSharedAxis
|
import com.google.android.material.transition.MaterialSharedAxis
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.adapters.DriverAdapter
|
import org.yuzu.yuzu_emu.adapters.DriverAdapter
|
||||||
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
|
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
|
||||||
|
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
||||||
|
import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver
|
||||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
|
import org.yuzu.yuzu_emu.utils.NativeConfig
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@ -55,12 +62,43 @@ class DriverManagerFragment : Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is using the correct scope, lint is just acting up
|
||||||
|
@SuppressLint("UnsafeRepeatOnLifecycleDetector")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
||||||
homeViewModel.setStatusBarShadeVisibility(visible = false)
|
homeViewModel.setStatusBarShadeVisibility(visible = false)
|
||||||
|
|
||||||
driverViewModel.onOpenDriverManager(args.game)
|
driverViewModel.onOpenDriverManager(args.game)
|
||||||
|
if (NativeConfig.isPerGameConfigLoaded()) {
|
||||||
|
binding.toolbarDrivers.inflateMenu(R.menu.menu_driver_manager)
|
||||||
|
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
||||||
|
binding.toolbarDrivers.setOnMenuItemClickListener {
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.menu_driver_clear -> {
|
||||||
|
StringSetting.DRIVER_PATH.global = true
|
||||||
|
driverViewModel.updateDriverList()
|
||||||
|
(binding.listDrivers.adapter as DriverAdapter)
|
||||||
|
.replaceList(driverViewModel.driverList.value)
|
||||||
|
driverViewModel.showClearButton(false)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewLifecycleOwner.lifecycleScope.apply {
|
||||||
|
launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
driverViewModel.showClearButton.collect {
|
||||||
|
binding.toolbarDrivers.menu
|
||||||
|
.findItem(R.id.menu_driver_clear).isVisible = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!driverViewModel.isInteractionAllowed.value) {
|
if (!driverViewModel.isInteractionAllowed.value) {
|
||||||
DriversLoadingDialogFragment().show(
|
DriversLoadingDialogFragment().show(
|
||||||
@ -85,25 +123,6 @@ class DriverManagerFragment : Fragment() {
|
|||||||
adapter = DriverAdapter(driverViewModel)
|
adapter = DriverAdapter(driverViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.apply {
|
|
||||||
launch {
|
|
||||||
driverViewModel.driverList.collectLatest {
|
|
||||||
(binding.listDrivers.adapter as DriverAdapter).submitList(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
launch {
|
|
||||||
driverViewModel.newDriverInstalled.collect {
|
|
||||||
if (_binding != null && it) {
|
|
||||||
(binding.listDrivers.adapter as DriverAdapter).apply {
|
|
||||||
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
|
||||||
notifyItemChanged(driverViewModel.selectedDriver)
|
|
||||||
driverViewModel.setNewDriverInstalled(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setInsets()
|
setInsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +173,13 @@ class DriverManagerFragment : Fragment() {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
R.string.installing_driver,
|
R.string.installing_driver,
|
||||||
false
|
false
|
||||||
) {
|
) { _, _ ->
|
||||||
val driverPath =
|
val driverPath =
|
||||||
"${GpuDriverHelper.driverStoragePath}/${FileUtil.getFilename(result)}"
|
"${GpuDriverHelper.driverStoragePath}${FileUtil.getFilename(result)}"
|
||||||
val driverFile = File(driverPath)
|
val driverFile = File(driverPath)
|
||||||
|
|
||||||
// Ignore file exceptions when a user selects an invalid zip
|
// Ignore file exceptions when a user selects an invalid zip
|
||||||
@ -177,14 +196,23 @@ class DriverManagerFragment : Fragment() {
|
|||||||
|
|
||||||
val driverData = GpuDriverHelper.getMetadataFromZip(driverFile)
|
val driverData = GpuDriverHelper.getMetadataFromZip(driverFile)
|
||||||
val driverInList =
|
val driverInList =
|
||||||
driverViewModel.driverList.value.firstOrNull { it.second == driverData }
|
driverViewModel.driverData.firstOrNull { it.second == driverData }
|
||||||
if (driverInList != null) {
|
if (driverInList != null) {
|
||||||
return@newInstance getString(R.string.driver_already_installed)
|
return@newInstance getString(R.string.driver_already_installed)
|
||||||
} else {
|
} else {
|
||||||
driverViewModel.addDriver(Pair(driverPath, driverData))
|
driverViewModel.onDriverAdded(Pair(driverPath, driverData))
|
||||||
driverViewModel.setNewDriverInstalled(true)
|
withContext(Dispatchers.Main) {
|
||||||
|
if (_binding != null) {
|
||||||
|
val adapter = binding.listDrivers.adapter as DriverAdapter
|
||||||
|
adapter.addItem(driverData.toDriver())
|
||||||
|
adapter.selectItem(adapter.currentList.indices.last)
|
||||||
|
driverViewModel.showClearButton(!StringSetting.DRIVER_PATH.global)
|
||||||
|
binding.listDrivers
|
||||||
|
.smoothScrollToPosition(adapter.currentList.indices.last)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return@newInstance Any()
|
return@newInstance Any()
|
||||||
}.show(childFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(childFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,6 +554,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
findItem(R.id.menu_touchscreen).isChecked = BooleanSetting.TOUCHSCREEN.getBoolean()
|
findItem(R.id.menu_touchscreen).isChecked = BooleanSetting.TOUCHSCREEN.getBoolean()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
popup.setOnDismissListener { NativeConfig.saveGlobalConfig() }
|
||||||
popup.setOnMenuItemClickListener {
|
popup.setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.menu_toggle_fps -> {
|
R.id.menu_toggle_fps -> {
|
||||||
@ -720,7 +721,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.emulation_control_adjust)
|
.setTitle(R.string.emulation_control_adjust)
|
||||||
.setView(adjustBinding.root)
|
.setView(adjustBinding.root)
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
|
||||||
|
NativeConfig.saveGlobalConfig()
|
||||||
|
}
|
||||||
.setNeutralButton(R.string.slider_default) { _: DialogInterface?, _: Int ->
|
.setNeutralButton(R.string.slider_default) { _: DialogInterface?, _: Int ->
|
||||||
setControlScale(50)
|
setControlScale(50)
|
||||||
setControlOpacity(100)
|
setControlOpacity(100)
|
||||||
|
@ -44,7 +44,6 @@ import org.yuzu.yuzu_emu.utils.FileUtil
|
|||||||
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
import org.yuzu.yuzu_emu.utils.GameIconUtils
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
import org.yuzu.yuzu_emu.utils.MemoryUtil
|
import org.yuzu.yuzu_emu.utils.MemoryUtil
|
||||||
import java.io.BufferedInputStream
|
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -357,27 +356,17 @@ class GamePropertiesFragment : Fragment() {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
val inputZip = requireContext().contentResolver.openInputStream(result)
|
|
||||||
val savesFolder = File(args.game.saveDir)
|
val savesFolder = File(args.game.saveDir)
|
||||||
val cacheSaveDir = File("${requireContext().cacheDir.path}/saves/")
|
val cacheSaveDir = File("${requireContext().cacheDir.path}/saves/")
|
||||||
cacheSaveDir.mkdir()
|
cacheSaveDir.mkdir()
|
||||||
|
|
||||||
if (inputZip == null) {
|
ProgressDialogFragment.newInstance(
|
||||||
Toast.makeText(
|
|
||||||
YuzuApplication.appContext,
|
|
||||||
getString(R.string.fatal_error),
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
return@registerForActivityResult
|
|
||||||
}
|
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
R.string.save_files_importing,
|
R.string.save_files_importing,
|
||||||
false
|
false
|
||||||
) {
|
) { _, _ ->
|
||||||
try {
|
try {
|
||||||
FileUtil.unzipToInternalStorage(BufferedInputStream(inputZip), cacheSaveDir)
|
FileUtil.unzipToInternalStorage(result.toString(), cacheSaveDir)
|
||||||
val files = cacheSaveDir.listFiles()
|
val files = cacheSaveDir.listFiles()
|
||||||
var savesFolderFile: File? = null
|
var savesFolderFile: File? = null
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
@ -422,7 +411,7 @@ class GamePropertiesFragment : Fragment() {
|
|||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}.show(parentFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(parentFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -436,11 +425,11 @@ class GamePropertiesFragment : Fragment() {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
R.string.save_files_exporting,
|
R.string.save_files_exporting,
|
||||||
false
|
false
|
||||||
) {
|
) { _, _ ->
|
||||||
val saveLocation = args.game.saveDir
|
val saveLocation = args.game.saveDir
|
||||||
val zipResult = FileUtil.zipFromInternalStorage(
|
val zipResult = FileUtil.zipFromInternalStorage(
|
||||||
File(saveLocation),
|
File(saveLocation),
|
||||||
@ -452,6 +441,6 @@ class GamePropertiesFragment : Fragment() {
|
|||||||
TaskState.Completed -> getString(R.string.export_success)
|
TaskState.Completed -> getString(R.string.export_success)
|
||||||
TaskState.Cancelled, TaskState.Failed -> getString(R.string.export_failed)
|
TaskState.Cancelled, TaskState.Failed -> getString(R.string.export_failed)
|
||||||
}
|
}
|
||||||
}.show(parentFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(parentFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,38 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.google.android.material.transition.MaterialSharedAxis
|
import com.google.android.material.transition.MaterialSharedAxis
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.adapters.InstallableAdapter
|
import org.yuzu.yuzu_emu.adapters.InstallableAdapter
|
||||||
import org.yuzu.yuzu_emu.databinding.FragmentInstallablesBinding
|
import org.yuzu.yuzu_emu.databinding.FragmentInstallablesBinding
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
import org.yuzu.yuzu_emu.model.Installable
|
import org.yuzu.yuzu_emu.model.Installable
|
||||||
|
import org.yuzu.yuzu_emu.model.TaskState
|
||||||
import org.yuzu.yuzu_emu.ui.main.MainActivity
|
import org.yuzu.yuzu_emu.ui.main.MainActivity
|
||||||
|
import org.yuzu.yuzu_emu.utils.DirectoryInitialization
|
||||||
|
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||||
|
import java.io.BufferedOutputStream
|
||||||
|
import java.io.File
|
||||||
|
import java.math.BigInteger
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
class InstallableFragment : Fragment() {
|
class InstallableFragment : Fragment() {
|
||||||
private var _binding: FragmentInstallablesBinding? = null
|
private var _binding: FragmentInstallablesBinding? = null
|
||||||
@ -56,6 +74,17 @@ class InstallableFragment : Fragment() {
|
|||||||
binding.root.findNavController().popBackStack()
|
binding.root.findNavController().popBackStack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
homeViewModel.openImportSaves.collect {
|
||||||
|
if (it) {
|
||||||
|
importSaves.launch(arrayOf("application/zip"))
|
||||||
|
homeViewModel.setOpenImportSaves(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val installables = listOf(
|
val installables = listOf(
|
||||||
Installable(
|
Installable(
|
||||||
R.string.user_data,
|
R.string.user_data,
|
||||||
@ -63,6 +92,43 @@ class InstallableFragment : Fragment() {
|
|||||||
install = { mainActivity.importUserData.launch(arrayOf("application/zip")) },
|
install = { mainActivity.importUserData.launch(arrayOf("application/zip")) },
|
||||||
export = { mainActivity.exportUserData.launch("export.zip") }
|
export = { mainActivity.exportUserData.launch("export.zip") }
|
||||||
),
|
),
|
||||||
|
Installable(
|
||||||
|
R.string.manage_save_data,
|
||||||
|
R.string.manage_save_data_description,
|
||||||
|
install = {
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
titleId = R.string.import_save_warning,
|
||||||
|
descriptionId = R.string.import_save_warning_description,
|
||||||
|
positiveAction = { homeViewModel.setOpenImportSaves(true) }
|
||||||
|
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
},
|
||||||
|
export = {
|
||||||
|
val oldSaveDataFolder = File(
|
||||||
|
"${DirectoryInitialization.userDirectory}/nand" +
|
||||||
|
NativeLibrary.getDefaultProfileSaveDataRoot(false)
|
||||||
|
)
|
||||||
|
val futureSaveDataFolder = File(
|
||||||
|
"${DirectoryInitialization.userDirectory}/nand" +
|
||||||
|
NativeLibrary.getDefaultProfileSaveDataRoot(true)
|
||||||
|
)
|
||||||
|
if (!oldSaveDataFolder.exists() && !futureSaveDataFolder.exists()) {
|
||||||
|
Toast.makeText(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
R.string.no_save_data_found,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return@Installable
|
||||||
|
} else {
|
||||||
|
exportSaves.launch(
|
||||||
|
"${getString(R.string.save_data)} " +
|
||||||
|
LocalDateTime.now().format(
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
Installable(
|
Installable(
|
||||||
R.string.install_game_content,
|
R.string.install_game_content,
|
||||||
R.string.install_game_content_description,
|
R.string.install_game_content_description,
|
||||||
@ -121,4 +187,150 @@ class InstallableFragment : Fragment() {
|
|||||||
|
|
||||||
windowInsets
|
windowInsets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val importSaves =
|
||||||
|
registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
||||||
|
if (result == null) {
|
||||||
|
return@registerForActivityResult
|
||||||
|
}
|
||||||
|
|
||||||
|
val cacheSaveDir = File("${requireContext().cacheDir.path}/saves/")
|
||||||
|
cacheSaveDir.mkdir()
|
||||||
|
|
||||||
|
ProgressDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
R.string.save_files_importing,
|
||||||
|
false
|
||||||
|
) { progressCallback, _ ->
|
||||||
|
try {
|
||||||
|
FileUtil.unzipToInternalStorage(
|
||||||
|
result.toString(),
|
||||||
|
cacheSaveDir,
|
||||||
|
progressCallback
|
||||||
|
)
|
||||||
|
val files = cacheSaveDir.listFiles()
|
||||||
|
var successfulImports = 0
|
||||||
|
var failedImports = 0
|
||||||
|
if (files != null) {
|
||||||
|
for (file in files) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
val baseSaveDir =
|
||||||
|
NativeLibrary.getSavePath(BigInteger(file.name, 16).toString())
|
||||||
|
if (baseSaveDir.isEmpty()) {
|
||||||
|
failedImports++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val internalSaveFolder = File(
|
||||||
|
"${DirectoryInitialization.userDirectory}/nand$baseSaveDir"
|
||||||
|
)
|
||||||
|
internalSaveFolder.deleteRecursively()
|
||||||
|
internalSaveFolder.mkdir()
|
||||||
|
file.copyRecursively(target = internalSaveFolder, overwrite = true)
|
||||||
|
successfulImports++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (successfulImports == 0) {
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
titleId = R.string.save_file_invalid_zip_structure,
|
||||||
|
descriptionId = R.string.save_file_invalid_zip_structure_description
|
||||||
|
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
return@withContext
|
||||||
|
}
|
||||||
|
val successString = if (failedImports > 0) {
|
||||||
|
"""
|
||||||
|
${
|
||||||
|
requireContext().resources.getQuantityString(
|
||||||
|
R.plurals.saves_import_success,
|
||||||
|
successfulImports,
|
||||||
|
successfulImports
|
||||||
|
)
|
||||||
|
}
|
||||||
|
${
|
||||||
|
requireContext().resources.getQuantityString(
|
||||||
|
R.plurals.saves_import_failed,
|
||||||
|
failedImports,
|
||||||
|
failedImports
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
} else {
|
||||||
|
requireContext().resources.getQuantityString(
|
||||||
|
R.plurals.saves_import_success,
|
||||||
|
successfulImports,
|
||||||
|
successfulImports
|
||||||
|
)
|
||||||
|
}
|
||||||
|
MessageDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
titleId = R.string.import_complete,
|
||||||
|
descriptionString = successString
|
||||||
|
).show(parentFragmentManager, MessageDialogFragment.TAG)
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheSaveDir.deleteRecursively()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(
|
||||||
|
YuzuApplication.appContext,
|
||||||
|
getString(R.string.fatal_error),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}.show(parentFragmentManager, ProgressDialogFragment.TAG)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val exportSaves = registerForActivityResult(
|
||||||
|
ActivityResultContracts.CreateDocument("application/zip")
|
||||||
|
) { result ->
|
||||||
|
if (result == null) {
|
||||||
|
return@registerForActivityResult
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressDialogFragment.newInstance(
|
||||||
|
requireActivity(),
|
||||||
|
R.string.save_files_exporting,
|
||||||
|
false
|
||||||
|
) { _, _ ->
|
||||||
|
val cacheSaveDir = File("${requireContext().cacheDir.path}/saves/")
|
||||||
|
cacheSaveDir.mkdir()
|
||||||
|
|
||||||
|
val oldSaveDataFolder = File(
|
||||||
|
"${DirectoryInitialization.userDirectory}/nand" +
|
||||||
|
NativeLibrary.getDefaultProfileSaveDataRoot(false)
|
||||||
|
)
|
||||||
|
if (oldSaveDataFolder.exists()) {
|
||||||
|
oldSaveDataFolder.copyRecursively(cacheSaveDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
val futureSaveDataFolder = File(
|
||||||
|
"${DirectoryInitialization.userDirectory}/nand" +
|
||||||
|
NativeLibrary.getDefaultProfileSaveDataRoot(true)
|
||||||
|
)
|
||||||
|
if (futureSaveDataFolder.exists()) {
|
||||||
|
futureSaveDataFolder.copyRecursively(cacheSaveDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
val saveFilesTotal = cacheSaveDir.listFiles()?.size ?: 0
|
||||||
|
if (saveFilesTotal == 0) {
|
||||||
|
cacheSaveDir.deleteRecursively()
|
||||||
|
return@newInstance getString(R.string.no_save_data_found)
|
||||||
|
}
|
||||||
|
|
||||||
|
val zipResult = FileUtil.zipFromInternalStorage(
|
||||||
|
cacheSaveDir,
|
||||||
|
cacheSaveDir.path,
|
||||||
|
BufferedOutputStream(requireContext().contentResolver.openOutputStream(result))
|
||||||
|
)
|
||||||
|
cacheSaveDir.deleteRecursively()
|
||||||
|
|
||||||
|
return@newInstance when (zipResult) {
|
||||||
|
TaskState.Completed -> getString(R.string.export_success)
|
||||||
|
TaskState.Cancelled, TaskState.Failed -> getString(R.string.export_failed)
|
||||||
|
}
|
||||||
|
}.show(parentFragmentManager, ProgressDialogFragment.TAG)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,13 @@ import org.yuzu.yuzu_emu.R
|
|||||||
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
||||||
import org.yuzu.yuzu_emu.model.TaskViewModel
|
import org.yuzu.yuzu_emu.model.TaskViewModel
|
||||||
|
|
||||||
class IndeterminateProgressDialogFragment : DialogFragment() {
|
class ProgressDialogFragment : DialogFragment() {
|
||||||
private val taskViewModel: TaskViewModel by activityViewModels()
|
private val taskViewModel: TaskViewModel by activityViewModels()
|
||||||
|
|
||||||
private lateinit var binding: DialogProgressBarBinding
|
private lateinit var binding: DialogProgressBarBinding
|
||||||
|
|
||||||
|
private val PROGRESS_BAR_RESOLUTION = 1000
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val titleId = requireArguments().getInt(TITLE)
|
val titleId = requireArguments().getInt(TITLE)
|
||||||
val cancellable = requireArguments().getBoolean(CANCELLABLE)
|
val cancellable = requireArguments().getBoolean(CANCELLABLE)
|
||||||
@ -61,6 +63,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
binding.message.isSelected = true
|
||||||
viewLifecycleOwner.lifecycleScope.apply {
|
viewLifecycleOwner.lifecycleScope.apply {
|
||||||
launch {
|
launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
@ -97,6 +100,35 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
taskViewModel.progress.collect {
|
||||||
|
if (it != 0.0) {
|
||||||
|
binding.progressBar.apply {
|
||||||
|
isIndeterminate = false
|
||||||
|
progress = (
|
||||||
|
(it / taskViewModel.maxProgress.value) *
|
||||||
|
PROGRESS_BAR_RESOLUTION
|
||||||
|
).toInt()
|
||||||
|
min = 0
|
||||||
|
max = PROGRESS_BAR_RESOLUTION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
taskViewModel.message.collect {
|
||||||
|
if (it.isEmpty()) {
|
||||||
|
binding.message.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.message.visibility = View.VISIBLE
|
||||||
|
binding.message.text = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +140,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
|||||||
val negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE)
|
val negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE)
|
||||||
negativeButton.setOnClickListener {
|
negativeButton.setOnClickListener {
|
||||||
alertDialog.setTitle(getString(R.string.cancelling))
|
alertDialog.setTitle(getString(R.string.cancelling))
|
||||||
|
binding.progressBar.isIndeterminate = true
|
||||||
taskViewModel.setCancelled(true)
|
taskViewModel.setCancelled(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,9 +155,12 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
|||||||
activity: FragmentActivity,
|
activity: FragmentActivity,
|
||||||
titleId: Int,
|
titleId: Int,
|
||||||
cancellable: Boolean = false,
|
cancellable: Boolean = false,
|
||||||
task: suspend () -> Any
|
task: suspend (
|
||||||
): IndeterminateProgressDialogFragment {
|
progressCallback: (max: Long, progress: Long) -> Boolean,
|
||||||
val dialog = IndeterminateProgressDialogFragment()
|
messageCallback: (message: String) -> Unit
|
||||||
|
) -> Any
|
||||||
|
): ProgressDialogFragment {
|
||||||
|
val dialog = ProgressDialogFragment()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
ViewModelProvider(activity)[TaskViewModel::class.java].task = task
|
ViewModelProvider(activity)[TaskViewModel::class.java].task = task
|
||||||
args.putInt(TITLE, titleId)
|
args.putInt(TITLE, titleId)
|
@ -1,10 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.yuzu.yuzu_emu.model
|
|
||||||
|
|
||||||
data class Addon(
|
|
||||||
var enabled: Boolean,
|
|
||||||
val title: String,
|
|
||||||
val version: String
|
|
||||||
)
|
|
@ -15,8 +15,8 @@ import org.yuzu.yuzu_emu.utils.NativeConfig
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class AddonViewModel : ViewModel() {
|
class AddonViewModel : ViewModel() {
|
||||||
private val _addonList = MutableStateFlow(mutableListOf<Addon>())
|
private val _patchList = MutableStateFlow(mutableListOf<Patch>())
|
||||||
val addonList get() = _addonList.asStateFlow()
|
val addonList get() = _patchList.asStateFlow()
|
||||||
|
|
||||||
private val _showModInstallPicker = MutableStateFlow(false)
|
private val _showModInstallPicker = MutableStateFlow(false)
|
||||||
val showModInstallPicker get() = _showModInstallPicker.asStateFlow()
|
val showModInstallPicker get() = _showModInstallPicker.asStateFlow()
|
||||||
@ -24,6 +24,9 @@ class AddonViewModel : ViewModel() {
|
|||||||
private val _showModNoticeDialog = MutableStateFlow(false)
|
private val _showModNoticeDialog = MutableStateFlow(false)
|
||||||
val showModNoticeDialog get() = _showModNoticeDialog.asStateFlow()
|
val showModNoticeDialog get() = _showModNoticeDialog.asStateFlow()
|
||||||
|
|
||||||
|
private val _addonToDelete = MutableStateFlow<Patch?>(null)
|
||||||
|
val addonToDelete = _addonToDelete.asStateFlow()
|
||||||
|
|
||||||
var game: Game? = null
|
var game: Game? = null
|
||||||
|
|
||||||
private val isRefreshing = AtomicBoolean(false)
|
private val isRefreshing = AtomicBoolean(false)
|
||||||
@ -40,36 +43,47 @@ class AddonViewModel : ViewModel() {
|
|||||||
isRefreshing.set(true)
|
isRefreshing.set(true)
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val addonList = mutableListOf<Addon>()
|
val patchList = (
|
||||||
val disabledAddons = NativeConfig.getDisabledAddons(game!!.programId)
|
NativeLibrary.getPatchesForFile(game!!.path, game!!.programId)
|
||||||
NativeLibrary.getAddonsForFile(game!!.path, game!!.programId)?.forEach {
|
?: emptyArray()
|
||||||
val name = it.first.replace("[D] ", "")
|
).toMutableList()
|
||||||
addonList.add(Addon(!disabledAddons.contains(name), name, it.second))
|
patchList.sortBy { it.name }
|
||||||
}
|
_patchList.value = patchList
|
||||||
addonList.sortBy { it.title }
|
|
||||||
_addonList.value = addonList
|
|
||||||
isRefreshing.set(false)
|
isRefreshing.set(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setAddonToDelete(patch: Patch?) {
|
||||||
|
_addonToDelete.value = patch
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDeleteAddon(patch: Patch) {
|
||||||
|
when (PatchType.from(patch.type)) {
|
||||||
|
PatchType.Update -> NativeLibrary.removeUpdate(patch.programId)
|
||||||
|
PatchType.DLC -> NativeLibrary.removeDLC(patch.titleId)
|
||||||
|
PatchType.Mod -> NativeLibrary.removeMod(patch.programId, patch.name)
|
||||||
|
}
|
||||||
|
refreshAddons()
|
||||||
|
}
|
||||||
|
|
||||||
fun onCloseAddons() {
|
fun onCloseAddons() {
|
||||||
if (_addonList.value.isEmpty()) {
|
if (_patchList.value.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeConfig.setDisabledAddons(
|
NativeConfig.setDisabledAddons(
|
||||||
game!!.programId,
|
game!!.programId,
|
||||||
_addonList.value.mapNotNull {
|
_patchList.value.mapNotNull {
|
||||||
if (it.enabled) {
|
if (it.enabled) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
it.title
|
it.name
|
||||||
}
|
}
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
)
|
)
|
||||||
NativeConfig.saveGlobalConfig()
|
NativeConfig.saveGlobalConfig()
|
||||||
_addonList.value.clear()
|
_patchList.value.clear()
|
||||||
game = null
|
game = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.model
|
||||||
|
|
||||||
|
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||||
|
|
||||||
|
data class Driver(
|
||||||
|
override var selected: Boolean,
|
||||||
|
val title: String,
|
||||||
|
val version: String = "",
|
||||||
|
val description: String = ""
|
||||||
|
) : SelectableItem {
|
||||||
|
override fun onSelectionStateChanged(selected: Boolean) {
|
||||||
|
this.selected = selected
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun GpuDriverMetadata.toDriver(selected: Boolean = false): Driver =
|
||||||
|
Driver(
|
||||||
|
selected,
|
||||||
|
this.name ?: "",
|
||||||
|
this.version ?: "",
|
||||||
|
this.description ?: ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -17,11 +18,10 @@ import org.yuzu.yuzu_emu.R
|
|||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
||||||
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
||||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||||
import org.yuzu.yuzu_emu.utils.NativeConfig
|
import org.yuzu.yuzu_emu.utils.NativeConfig
|
||||||
import java.io.BufferedOutputStream
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class DriverViewModel : ViewModel() {
|
class DriverViewModel : ViewModel() {
|
||||||
@ -38,97 +38,81 @@ class DriverViewModel : ViewModel() {
|
|||||||
!loading && ready && !deleting
|
!loading && ready && !deleting
|
||||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialValue = false)
|
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), initialValue = false)
|
||||||
|
|
||||||
private val _driverList = MutableStateFlow(GpuDriverHelper.getDrivers())
|
var driverData = GpuDriverHelper.getDrivers()
|
||||||
val driverList: StateFlow<MutableList<Pair<String, GpuDriverMetadata>>> get() = _driverList
|
|
||||||
|
|
||||||
var previouslySelectedDriver = 0
|
private val _driverList = MutableStateFlow(emptyList<Driver>())
|
||||||
var selectedDriver = -1
|
val driverList: StateFlow<List<Driver>> get() = _driverList
|
||||||
|
|
||||||
// Used for showing which driver is currently installed within the driver manager card
|
// Used for showing which driver is currently installed within the driver manager card
|
||||||
private val _selectedDriverTitle = MutableStateFlow("")
|
private val _selectedDriverTitle = MutableStateFlow("")
|
||||||
val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle
|
val selectedDriverTitle: StateFlow<String> get() = _selectedDriverTitle
|
||||||
|
|
||||||
private val _newDriverInstalled = MutableStateFlow(false)
|
private val _showClearButton = MutableStateFlow(false)
|
||||||
val newDriverInstalled: StateFlow<Boolean> get() = _newDriverInstalled
|
val showClearButton = _showClearButton.asStateFlow()
|
||||||
|
|
||||||
val driversToDelete = mutableListOf<String>()
|
private val driversToDelete = mutableListOf<String>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val currentDriverMetadata = GpuDriverHelper.installedCustomDriverData
|
updateDriverList()
|
||||||
findSelectedDriver(currentDriverMetadata)
|
|
||||||
|
|
||||||
// If a user had installed a driver before the manager was implemented, this zips
|
|
||||||
// the installed driver to UserData/gpu_drivers/CustomDriver.zip so that it can
|
|
||||||
// be indexed and exported as expected.
|
|
||||||
if (selectedDriver == -1) {
|
|
||||||
val driverToSave =
|
|
||||||
File(GpuDriverHelper.driverStoragePath, "CustomDriver.zip")
|
|
||||||
driverToSave.createNewFile()
|
|
||||||
FileUtil.zipFromInternalStorage(
|
|
||||||
File(GpuDriverHelper.driverInstallationPath!!),
|
|
||||||
GpuDriverHelper.driverInstallationPath!!,
|
|
||||||
BufferedOutputStream(driverToSave.outputStream())
|
|
||||||
)
|
|
||||||
_driverList.value.add(Pair(driverToSave.path, currentDriverMetadata))
|
|
||||||
setSelectedDriverIndex(_driverList.value.size - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a user had installed a driver before the config was reworked to be multiplatform,
|
|
||||||
// we have save the path of the previously selected driver to the new setting.
|
|
||||||
if (StringSetting.DRIVER_PATH.getString(true).isEmpty() && selectedDriver > 0 &&
|
|
||||||
StringSetting.DRIVER_PATH.global
|
|
||||||
) {
|
|
||||||
StringSetting.DRIVER_PATH.setString(_driverList.value[selectedDriver].first)
|
|
||||||
NativeConfig.saveGlobalConfig()
|
|
||||||
} else {
|
|
||||||
findSelectedDriver(GpuDriverHelper.customDriverSettingData)
|
|
||||||
}
|
|
||||||
updateDriverNameForGame(null)
|
updateDriverNameForGame(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSelectedDriverIndex(value: Int) {
|
fun reloadDriverData() {
|
||||||
if (selectedDriver != -1) {
|
_areDriversLoading.value = true
|
||||||
previouslySelectedDriver = selectedDriver
|
driverData = GpuDriverHelper.getDrivers()
|
||||||
|
updateDriverList()
|
||||||
|
_areDriversLoading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateDriverList() {
|
||||||
|
val selectedDriver = GpuDriverHelper.customDriverSettingData
|
||||||
|
val newDriverList = mutableListOf(
|
||||||
|
Driver(
|
||||||
|
selectedDriver == GpuDriverMetadata(),
|
||||||
|
YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
driverData.forEach {
|
||||||
|
newDriverList.add(it.second.toDriver(it.second == selectedDriver))
|
||||||
}
|
}
|
||||||
selectedDriver = value
|
_driverList.value = newDriverList
|
||||||
}
|
|
||||||
|
|
||||||
fun setNewDriverInstalled(value: Boolean) {
|
|
||||||
_newDriverInstalled.value = value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
|
||||||
val driverIndex = _driverList.value.indexOfFirst { it == driverData }
|
|
||||||
if (driverIndex == -1) {
|
|
||||||
_driverList.value.add(driverData)
|
|
||||||
setSelectedDriverIndex(_driverList.value.size - 1)
|
|
||||||
_selectedDriverTitle.value = driverData.second.name
|
|
||||||
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
|
||||||
} else {
|
|
||||||
setSelectedDriverIndex(driverIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
|
||||||
_driverList.value.remove(driverData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenDriverManager(game: Game?) {
|
fun onOpenDriverManager(game: Game?) {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
SettingsFile.loadCustomConfig(game)
|
SettingsFile.loadCustomConfig(game)
|
||||||
}
|
}
|
||||||
|
updateDriverList()
|
||||||
|
}
|
||||||
|
|
||||||
val driverPath = StringSetting.DRIVER_PATH.getString()
|
fun showClearButton(value: Boolean) {
|
||||||
if (driverPath.isEmpty()) {
|
_showClearButton.value = value
|
||||||
setSelectedDriverIndex(0)
|
}
|
||||||
|
|
||||||
|
fun onDriverSelected(position: Int) {
|
||||||
|
if (position == 0) {
|
||||||
|
StringSetting.DRIVER_PATH.setString("")
|
||||||
} else {
|
} else {
|
||||||
findSelectedDriver(GpuDriverHelper.getMetadataFromZip(File(driverPath)))
|
StringSetting.DRIVER_PATH.setString(driverData[position - 1].first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onDriverRemoved(removedPosition: Int, selectedPosition: Int) {
|
||||||
|
driversToDelete.add(driverData[removedPosition - 1].first)
|
||||||
|
driverData.removeAt(removedPosition - 1)
|
||||||
|
onDriverSelected(selectedPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDriverAdded(driver: Pair<String, GpuDriverMetadata>) {
|
||||||
|
if (driversToDelete.contains(driver.first)) {
|
||||||
|
driversToDelete.remove(driver.first)
|
||||||
|
}
|
||||||
|
driverData.add(driver)
|
||||||
|
onDriverSelected(driverData.size)
|
||||||
|
}
|
||||||
|
|
||||||
fun onCloseDriverManager(game: Game?) {
|
fun onCloseDriverManager(game: Game?) {
|
||||||
_isDeletingDrivers.value = true
|
_isDeletingDrivers.value = true
|
||||||
StringSetting.DRIVER_PATH.setString(driverList.value[selectedDriver].first)
|
|
||||||
updateDriverNameForGame(game)
|
updateDriverNameForGame(game)
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
NativeConfig.saveGlobalConfig()
|
NativeConfig.saveGlobalConfig()
|
||||||
@ -181,20 +165,6 @@ class DriverViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findSelectedDriver(currentDriverMetadata: GpuDriverMetadata) {
|
|
||||||
if (driverList.value.size == 1) {
|
|
||||||
setSelectedDriverIndex(0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
driverList.value.forEachIndexed { i: Int, driver: Pair<String, GpuDriverMetadata> ->
|
|
||||||
if (driver.second == currentDriverMetadata) {
|
|
||||||
setSelectedDriverIndex(i)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateDriverNameForGame(game: Game?) {
|
fun updateDriverNameForGame(game: Game?) {
|
||||||
if (!GpuDriverHelper.supportsCustomDriverLoading()) {
|
if (!GpuDriverHelper.supportsCustomDriverLoading()) {
|
||||||
return
|
return
|
||||||
@ -217,7 +187,6 @@ class DriverViewModel : ViewModel() {
|
|||||||
|
|
||||||
private fun setDriverReady() {
|
private fun setDriverReady() {
|
||||||
_isDriverReady.value = true
|
_isDriverReady.value = true
|
||||||
_selectedDriverTitle.value = GpuDriverHelper.customDriverSettingData.name
|
updateName()
|
||||||
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.model
|
||||||
|
|
||||||
|
enum class InstallResult(val int: Int) {
|
||||||
|
Success(0),
|
||||||
|
Overwrite(1),
|
||||||
|
Failure(2),
|
||||||
|
BaseInstallAttempted(3);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(int: Int): InstallResult = entries.firstOrNull { it.int == int } ?: Success
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.model
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
data class Patch(
|
||||||
|
var enabled: Boolean,
|
||||||
|
val name: String,
|
||||||
|
val version: String,
|
||||||
|
val type: Int,
|
||||||
|
val programId: String,
|
||||||
|
val titleId: String
|
||||||
|
)
|
@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.model
|
||||||
|
|
||||||
|
enum class PatchType(val int: Int) {
|
||||||
|
Update(0),
|
||||||
|
DLC(1),
|
||||||
|
Mod(2);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(int: Int): PatchType = entries.firstOrNull { it.int == int } ?: Update
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.model
|
||||||
|
|
||||||
|
interface SelectableItem {
|
||||||
|
var selected: Boolean
|
||||||
|
fun onSelectionStateChanged(selected: Boolean)
|
||||||
|
}
|
@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class TaskViewModel : ViewModel() {
|
class TaskViewModel : ViewModel() {
|
||||||
@ -23,13 +24,28 @@ class TaskViewModel : ViewModel() {
|
|||||||
val cancelled: StateFlow<Boolean> get() = _cancelled
|
val cancelled: StateFlow<Boolean> get() = _cancelled
|
||||||
private val _cancelled = MutableStateFlow(false)
|
private val _cancelled = MutableStateFlow(false)
|
||||||
|
|
||||||
lateinit var task: suspend () -> Any
|
private val _progress = MutableStateFlow(0.0)
|
||||||
|
val progress = _progress.asStateFlow()
|
||||||
|
|
||||||
|
private val _maxProgress = MutableStateFlow(0.0)
|
||||||
|
val maxProgress = _maxProgress.asStateFlow()
|
||||||
|
|
||||||
|
private val _message = MutableStateFlow("")
|
||||||
|
val message = _message.asStateFlow()
|
||||||
|
|
||||||
|
lateinit var task: suspend (
|
||||||
|
progressCallback: (max: Long, progress: Long) -> Boolean,
|
||||||
|
messageCallback: (message: String) -> Unit
|
||||||
|
) -> Any
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
_result.value = Any()
|
_result.value = Any()
|
||||||
_isComplete.value = false
|
_isComplete.value = false
|
||||||
_isRunning.value = false
|
_isRunning.value = false
|
||||||
_cancelled.value = false
|
_cancelled.value = false
|
||||||
|
_progress.value = 0.0
|
||||||
|
_maxProgress.value = 0.0
|
||||||
|
_message.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCancelled(value: Boolean) {
|
fun setCancelled(value: Boolean) {
|
||||||
@ -43,7 +59,16 @@ class TaskViewModel : ViewModel() {
|
|||||||
_isRunning.value = true
|
_isRunning.value = true
|
||||||
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val res = task()
|
val res = task(
|
||||||
|
{ max, progress ->
|
||||||
|
_maxProgress.value = max.toDouble()
|
||||||
|
_progress.value = progress.toDouble()
|
||||||
|
return@task cancelled.value
|
||||||
|
},
|
||||||
|
{ message ->
|
||||||
|
_message.value = message
|
||||||
|
}
|
||||||
|
)
|
||||||
_result.value = res
|
_result.value = res
|
||||||
_isComplete.value = true
|
_isComplete.value = true
|
||||||
_isRunning.value = false
|
_isRunning.value = false
|
||||||
|
@ -38,11 +38,13 @@ import org.yuzu.yuzu_emu.activities.EmulationActivity
|
|||||||
import org.yuzu.yuzu_emu.databinding.ActivityMainBinding
|
import org.yuzu.yuzu_emu.databinding.ActivityMainBinding
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
||||||
import org.yuzu.yuzu_emu.fragments.AddGameFolderDialogFragment
|
import org.yuzu.yuzu_emu.fragments.AddGameFolderDialogFragment
|
||||||
import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment
|
import org.yuzu.yuzu_emu.fragments.ProgressDialogFragment
|
||||||
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
||||||
import org.yuzu.yuzu_emu.model.AddonViewModel
|
import org.yuzu.yuzu_emu.model.AddonViewModel
|
||||||
|
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
|
import org.yuzu.yuzu_emu.model.InstallResult
|
||||||
import org.yuzu.yuzu_emu.model.TaskState
|
import org.yuzu.yuzu_emu.model.TaskState
|
||||||
import org.yuzu.yuzu_emu.model.TaskViewModel
|
import org.yuzu.yuzu_emu.model.TaskViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.*
|
import org.yuzu.yuzu_emu.utils.*
|
||||||
@ -58,6 +60,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
private val gamesViewModel: GamesViewModel by viewModels()
|
private val gamesViewModel: GamesViewModel by viewModels()
|
||||||
private val taskViewModel: TaskViewModel by viewModels()
|
private val taskViewModel: TaskViewModel by viewModels()
|
||||||
private val addonViewModel: AddonViewModel by viewModels()
|
private val addonViewModel: AddonViewModel by viewModels()
|
||||||
|
private val driverViewModel: DriverViewModel by viewModels()
|
||||||
|
|
||||||
override var themeId: Int = 0
|
override var themeId: Int = 0
|
||||||
|
|
||||||
@ -367,26 +370,23 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
val inputZip = contentResolver.openInputStream(result)
|
|
||||||
if (inputZip == null) {
|
|
||||||
Toast.makeText(
|
|
||||||
applicationContext,
|
|
||||||
getString(R.string.fatal_error),
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
return@registerForActivityResult
|
|
||||||
}
|
|
||||||
|
|
||||||
val filterNCA = FilenameFilter { _, dirName -> dirName.endsWith(".nca") }
|
val filterNCA = FilenameFilter { _, dirName -> dirName.endsWith(".nca") }
|
||||||
|
|
||||||
val firmwarePath =
|
val firmwarePath =
|
||||||
File(DirectoryInitialization.userDirectory + "/nand/system/Contents/registered/")
|
File(DirectoryInitialization.userDirectory + "/nand/system/Contents/registered/")
|
||||||
val cacheFirmwareDir = File("${cacheDir.path}/registered/")
|
val cacheFirmwareDir = File("${cacheDir.path}/registered/")
|
||||||
|
|
||||||
val task: () -> Any = {
|
ProgressDialogFragment.newInstance(
|
||||||
|
this,
|
||||||
|
R.string.firmware_installing
|
||||||
|
) { progressCallback, _ ->
|
||||||
var messageToShow: Any
|
var messageToShow: Any
|
||||||
try {
|
try {
|
||||||
FileUtil.unzipToInternalStorage(BufferedInputStream(inputZip), cacheFirmwareDir)
|
FileUtil.unzipToInternalStorage(
|
||||||
|
result.toString(),
|
||||||
|
cacheFirmwareDir,
|
||||||
|
progressCallback
|
||||||
|
)
|
||||||
val unfilteredNumOfFiles = cacheFirmwareDir.list()?.size ?: -1
|
val unfilteredNumOfFiles = cacheFirmwareDir.list()?.size ?: -1
|
||||||
val filteredNumOfFiles = cacheFirmwareDir.list(filterNCA)?.size ?: -2
|
val filteredNumOfFiles = cacheFirmwareDir.list(filterNCA)?.size ?: -2
|
||||||
messageToShow = if (unfilteredNumOfFiles != filteredNumOfFiles) {
|
messageToShow = if (unfilteredNumOfFiles != filteredNumOfFiles) {
|
||||||
@ -402,18 +402,13 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
getString(R.string.save_file_imported_success)
|
getString(R.string.save_file_imported_success)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.error("[MainActivity] Firmware install failed - ${e.message}")
|
||||||
messageToShow = getString(R.string.fatal_error)
|
messageToShow = getString(R.string.fatal_error)
|
||||||
} finally {
|
} finally {
|
||||||
cacheFirmwareDir.deleteRecursively()
|
cacheFirmwareDir.deleteRecursively()
|
||||||
}
|
}
|
||||||
messageToShow
|
messageToShow
|
||||||
}
|
}.show(supportFragmentManager, ProgressDialogFragment.TAG)
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
|
||||||
this,
|
|
||||||
R.string.firmware_installing,
|
|
||||||
task = task
|
|
||||||
).show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAmiiboKey =
|
val getAmiiboKey =
|
||||||
@ -472,11 +467,11 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
this@MainActivity,
|
this@MainActivity,
|
||||||
R.string.verifying_content,
|
R.string.verifying_content,
|
||||||
false
|
false
|
||||||
) {
|
) { _, _ ->
|
||||||
var updatesMatchProgram = true
|
var updatesMatchProgram = true
|
||||||
for (document in documents) {
|
for (document in documents) {
|
||||||
val valid = NativeLibrary.doesUpdateMatchProgram(
|
val valid = NativeLibrary.doesUpdateMatchProgram(
|
||||||
@ -499,44 +494,42 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
positiveAction = { homeViewModel.setContentToInstall(documents) }
|
positiveAction = { homeViewModel.setContentToInstall(documents) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun installContent(documents: List<Uri>) {
|
private fun installContent(documents: List<Uri>) {
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
this@MainActivity,
|
this@MainActivity,
|
||||||
R.string.installing_game_content
|
R.string.installing_game_content
|
||||||
) {
|
) { progressCallback, messageCallback ->
|
||||||
var installSuccess = 0
|
var installSuccess = 0
|
||||||
var installOverwrite = 0
|
var installOverwrite = 0
|
||||||
var errorBaseGame = 0
|
var errorBaseGame = 0
|
||||||
var errorExtension = 0
|
var error = 0
|
||||||
var errorOther = 0
|
|
||||||
documents.forEach {
|
documents.forEach {
|
||||||
|
messageCallback.invoke(FileUtil.getFilename(it))
|
||||||
when (
|
when (
|
||||||
NativeLibrary.installFileToNand(
|
InstallResult.from(
|
||||||
it.toString(),
|
NativeLibrary.installFileToNand(
|
||||||
FileUtil.getExtension(it)
|
it.toString(),
|
||||||
|
progressCallback
|
||||||
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
NativeLibrary.InstallFileToNandResult.Success -> {
|
InstallResult.Success -> {
|
||||||
installSuccess += 1
|
installSuccess += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.SuccessFileOverwritten -> {
|
InstallResult.Overwrite -> {
|
||||||
installOverwrite += 1
|
installOverwrite += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.ErrorBaseGame -> {
|
InstallResult.BaseInstallAttempted -> {
|
||||||
errorBaseGame += 1
|
errorBaseGame += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.ErrorFilenameExtension -> {
|
InstallResult.Failure -> {
|
||||||
errorExtension += 1
|
error += 1
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
errorOther += 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -563,7 +556,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
)
|
)
|
||||||
installResult.append(separator)
|
installResult.append(separator)
|
||||||
}
|
}
|
||||||
val errorTotal: Int = errorBaseGame + errorExtension + errorOther
|
val errorTotal: Int = errorBaseGame + error
|
||||||
if (errorTotal > 0) {
|
if (errorTotal > 0) {
|
||||||
installResult.append(separator)
|
installResult.append(separator)
|
||||||
installResult.append(
|
installResult.append(
|
||||||
@ -580,14 +573,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
)
|
)
|
||||||
installResult.append(separator)
|
installResult.append(separator)
|
||||||
}
|
}
|
||||||
if (errorExtension > 0) {
|
if (error > 0) {
|
||||||
installResult.append(separator)
|
|
||||||
installResult.append(
|
|
||||||
getString(R.string.install_game_content_failure_file_extension)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
|
||||||
if (errorOther > 0) {
|
|
||||||
installResult.append(
|
installResult.append(
|
||||||
getString(R.string.install_game_content_failure_description)
|
getString(R.string.install_game_content_failure_description)
|
||||||
)
|
)
|
||||||
@ -606,7 +592,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
descriptionString = installResult.toString().trim()
|
descriptionString = installResult.toString().trim()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
val exportUserData = registerForActivityResult(
|
val exportUserData = registerForActivityResult(
|
||||||
@ -616,16 +602,16 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
this,
|
this,
|
||||||
R.string.exporting_user_data,
|
R.string.exporting_user_data,
|
||||||
true
|
true
|
||||||
) {
|
) { progressCallback, _ ->
|
||||||
val zipResult = FileUtil.zipFromInternalStorage(
|
val zipResult = FileUtil.zipFromInternalStorage(
|
||||||
File(DirectoryInitialization.userDirectory!!),
|
File(DirectoryInitialization.userDirectory!!),
|
||||||
DirectoryInitialization.userDirectory!!,
|
DirectoryInitialization.userDirectory!!,
|
||||||
BufferedOutputStream(contentResolver.openOutputStream(result)),
|
BufferedOutputStream(contentResolver.openOutputStream(result)),
|
||||||
taskViewModel.cancelled,
|
progressCallback,
|
||||||
compression = false
|
compression = false
|
||||||
)
|
)
|
||||||
return@newInstance when (zipResult) {
|
return@newInstance when (zipResult) {
|
||||||
@ -633,7 +619,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
TaskState.Failed -> R.string.export_failed
|
TaskState.Failed -> R.string.export_failed
|
||||||
TaskState.Cancelled -> R.string.user_data_export_cancelled
|
TaskState.Cancelled -> R.string.user_data_export_cancelled
|
||||||
}
|
}
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
val importUserData =
|
val importUserData =
|
||||||
@ -642,10 +628,10 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
IndeterminateProgressDialogFragment.newInstance(
|
ProgressDialogFragment.newInstance(
|
||||||
this,
|
this,
|
||||||
R.string.importing_user_data
|
R.string.importing_user_data
|
||||||
) {
|
) { progressCallback, _ ->
|
||||||
val checkStream =
|
val checkStream =
|
||||||
ZipInputStream(BufferedInputStream(contentResolver.openInputStream(result)))
|
ZipInputStream(BufferedInputStream(contentResolver.openInputStream(result)))
|
||||||
var isYuzuBackup = false
|
var isYuzuBackup = false
|
||||||
@ -674,8 +660,9 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
// Copy archive to internal storage
|
// Copy archive to internal storage
|
||||||
try {
|
try {
|
||||||
FileUtil.unzipToInternalStorage(
|
FileUtil.unzipToInternalStorage(
|
||||||
BufferedInputStream(contentResolver.openInputStream(result)),
|
result.toString(),
|
||||||
File(DirectoryInitialization.userDirectory!!)
|
File(DirectoryInitialization.userDirectory!!),
|
||||||
|
progressCallback
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return@newInstance MessageDialogFragment.newInstance(
|
return@newInstance MessageDialogFragment.newInstance(
|
||||||
@ -689,8 +676,9 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
NativeLibrary.initializeSystem(true)
|
NativeLibrary.initializeSystem(true)
|
||||||
NativeConfig.initializeGlobalConfig()
|
NativeConfig.initializeGlobalConfig()
|
||||||
gamesViewModel.reloadGames(false)
|
gamesViewModel.reloadGames(false)
|
||||||
|
driverViewModel.reloadDriverData()
|
||||||
|
|
||||||
return@newInstance getString(R.string.user_data_import_success)
|
return@newInstance getString(R.string.user_data_import_success)
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, ProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import android.database.Cursor
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -19,6 +18,7 @@ import org.yuzu.yuzu_emu.YuzuApplication
|
|||||||
import org.yuzu.yuzu_emu.model.MinimalDocumentFile
|
import org.yuzu.yuzu_emu.model.MinimalDocumentFile
|
||||||
import org.yuzu.yuzu_emu.model.TaskState
|
import org.yuzu.yuzu_emu.model.TaskState
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.lang.NullPointerException
|
import java.lang.NullPointerException
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.zip.Deflater
|
import java.util.zip.Deflater
|
||||||
@ -104,7 +104,7 @@ object FileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference: https://stackoverflow.com/questions/42186820/documentfile-is-very-slow
|
* Reference: https://stackoverflow.com/questions/42186820/documentfile-is-very-slow
|
||||||
* This function will be faster than DoucmentFile.listFiles
|
* This function will be faster than DocumentFile.listFiles
|
||||||
* @param uri Directory uri.
|
* @param uri Directory uri.
|
||||||
* @return CheapDocument lists.
|
* @return CheapDocument lists.
|
||||||
*/
|
*/
|
||||||
@ -283,12 +283,34 @@ object FileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the given zip file into the given directory.
|
* Extracts the given zip file into the given directory.
|
||||||
|
* @param path String representation of a [Uri] or a typical path delimited by '/'
|
||||||
|
* @param destDir Location to unzip the contents of [path] into
|
||||||
|
* @param progressCallback Lambda that is called with the total number of files and the current
|
||||||
|
* progress through the process. Stops execution as soon as possible if this returns true.
|
||||||
*/
|
*/
|
||||||
@Throws(SecurityException::class)
|
@Throws(SecurityException::class)
|
||||||
fun unzipToInternalStorage(zipStream: BufferedInputStream, destDir: File) {
|
fun unzipToInternalStorage(
|
||||||
ZipInputStream(zipStream).use { zis ->
|
path: String,
|
||||||
|
destDir: File,
|
||||||
|
progressCallback: (max: Long, progress: Long) -> Boolean = { _, _ -> false }
|
||||||
|
) {
|
||||||
|
var totalEntries = 0L
|
||||||
|
ZipInputStream(getInputStream(path)).use { zis ->
|
||||||
|
var tempEntry = zis.nextEntry
|
||||||
|
while (tempEntry != null) {
|
||||||
|
tempEntry = zis.nextEntry
|
||||||
|
totalEntries++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var progress = 0L
|
||||||
|
ZipInputStream(getInputStream(path)).use { zis ->
|
||||||
var entry: ZipEntry? = zis.nextEntry
|
var entry: ZipEntry? = zis.nextEntry
|
||||||
while (entry != null) {
|
while (entry != null) {
|
||||||
|
if (progressCallback.invoke(totalEntries, progress)) {
|
||||||
|
return@use
|
||||||
|
}
|
||||||
|
|
||||||
val newFile = File(destDir, entry.name)
|
val newFile = File(destDir, entry.name)
|
||||||
val destinationDirectory = if (entry.isDirectory) newFile else newFile.parentFile
|
val destinationDirectory = if (entry.isDirectory) newFile else newFile.parentFile
|
||||||
|
|
||||||
@ -304,6 +326,7 @@ object FileUtil {
|
|||||||
newFile.outputStream().use { fos -> zis.copyTo(fos) }
|
newFile.outputStream().use { fos -> zis.copyTo(fos) }
|
||||||
}
|
}
|
||||||
entry = zis.nextEntry
|
entry = zis.nextEntry
|
||||||
|
progress++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,14 +336,15 @@ object FileUtil {
|
|||||||
* @param inputFile File representation of the item that will be zipped
|
* @param inputFile File representation of the item that will be zipped
|
||||||
* @param rootDir Directory containing the inputFile
|
* @param rootDir Directory containing the inputFile
|
||||||
* @param outputStream Stream where the zip file will be output
|
* @param outputStream Stream where the zip file will be output
|
||||||
* @param cancelled [StateFlow] that reports whether this process has been cancelled
|
* @param progressCallback Lambda that is called with the total number of files and the current
|
||||||
|
* progress through the process. Stops execution as soon as possible if this returns true.
|
||||||
* @param compression Disables compression if true
|
* @param compression Disables compression if true
|
||||||
*/
|
*/
|
||||||
fun zipFromInternalStorage(
|
fun zipFromInternalStorage(
|
||||||
inputFile: File,
|
inputFile: File,
|
||||||
rootDir: String,
|
rootDir: String,
|
||||||
outputStream: BufferedOutputStream,
|
outputStream: BufferedOutputStream,
|
||||||
cancelled: StateFlow<Boolean>? = null,
|
progressCallback: (max: Long, progress: Long) -> Boolean = { _, _ -> false },
|
||||||
compression: Boolean = true
|
compression: Boolean = true
|
||||||
): TaskState {
|
): TaskState {
|
||||||
try {
|
try {
|
||||||
@ -330,8 +354,10 @@ object FileUtil {
|
|||||||
zos.setLevel(Deflater.NO_COMPRESSION)
|
zos.setLevel(Deflater.NO_COMPRESSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var count = 0L
|
||||||
|
val totalFiles = inputFile.walkTopDown().count().toLong()
|
||||||
inputFile.walkTopDown().forEach { file ->
|
inputFile.walkTopDown().forEach { file ->
|
||||||
if (cancelled?.value == true) {
|
if (progressCallback.invoke(totalFiles, count)) {
|
||||||
return TaskState.Cancelled
|
return TaskState.Cancelled
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,6 +369,7 @@ object FileUtil {
|
|||||||
if (file.isFile) {
|
if (file.isFile) {
|
||||||
file.inputStream().use { fis -> fis.copyTo(zos) }
|
file.inputStream().use { fis -> fis.copyTo(zos) }
|
||||||
}
|
}
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,9 +383,14 @@ object FileUtil {
|
|||||||
/**
|
/**
|
||||||
* Helper function that copies the contents of a DocumentFile folder into a [File]
|
* Helper function that copies the contents of a DocumentFile folder into a [File]
|
||||||
* @param file [File] representation of the folder to copy into
|
* @param file [File] representation of the folder to copy into
|
||||||
|
* @param progressCallback Lambda that is called with the total number of files and the current
|
||||||
|
* progress through the process. Stops execution as soon as possible if this returns true.
|
||||||
* @throws IllegalStateException Fails when trying to copy a folder into a file and vice versa
|
* @throws IllegalStateException Fails when trying to copy a folder into a file and vice versa
|
||||||
*/
|
*/
|
||||||
fun DocumentFile.copyFilesTo(file: File) {
|
fun DocumentFile.copyFilesTo(
|
||||||
|
file: File,
|
||||||
|
progressCallback: (max: Long, progress: Long) -> Boolean = { _, _ -> false }
|
||||||
|
) {
|
||||||
file.mkdirs()
|
file.mkdirs()
|
||||||
if (!this.isDirectory || !file.isDirectory) {
|
if (!this.isDirectory || !file.isDirectory) {
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(
|
||||||
@ -366,7 +398,13 @@ object FileUtil {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var count = 0L
|
||||||
|
val totalFiles = this.listFiles().size.toLong()
|
||||||
this.listFiles().forEach {
|
this.listFiles().forEach {
|
||||||
|
if (progressCallback.invoke(totalFiles, count)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val newFile = File(file, it.name!!)
|
val newFile = File(file, it.name!!)
|
||||||
if (it.isDirectory) {
|
if (it.isDirectory) {
|
||||||
newFile.mkdirs()
|
newFile.mkdirs()
|
||||||
@ -381,6 +419,7 @@ object FileUtil {
|
|||||||
newFile.outputStream().use { os -> bos.copyTo(os) }
|
newFile.outputStream().use { os -> bos.copyTo(os) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,6 +466,18 @@ object FileUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getInputStream(path: String) = if (path.contains("content://")) {
|
||||||
|
Uri.parse(path).inputStream()
|
||||||
|
} else {
|
||||||
|
File(path).inputStream()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOutputStream(path: String) = if (path.contains("content://")) {
|
||||||
|
Uri.parse(path).outputStream()
|
||||||
|
} else {
|
||||||
|
File(path).outputStream()
|
||||||
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun getStringFromFile(file: File): String =
|
fun getStringFromFile(file: File): String =
|
||||||
String(file.readBytes(), StandardCharsets.UTF_8)
|
String(file.readBytes(), StandardCharsets.UTF_8)
|
||||||
@ -434,4 +485,19 @@ object FileUtil {
|
|||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun getStringFromInputStream(stream: InputStream): String =
|
fun getStringFromInputStream(stream: InputStream): String =
|
||||||
String(stream.readBytes(), StandardCharsets.UTF_8)
|
String(stream.readBytes(), StandardCharsets.UTF_8)
|
||||||
|
|
||||||
|
fun DocumentFile.inputStream(): InputStream =
|
||||||
|
YuzuApplication.appContext.contentResolver.openInputStream(uri)!!
|
||||||
|
|
||||||
|
fun DocumentFile.outputStream(): OutputStream =
|
||||||
|
YuzuApplication.appContext.contentResolver.openOutputStream(uri)!!
|
||||||
|
|
||||||
|
fun Uri.inputStream(): InputStream =
|
||||||
|
YuzuApplication.appContext.contentResolver.openInputStream(this)!!
|
||||||
|
|
||||||
|
fun Uri.outputStream(): OutputStream =
|
||||||
|
YuzuApplication.appContext.contentResolver.openOutputStream(this)!!
|
||||||
|
|
||||||
|
fun Uri.asDocumentFile(): DocumentFile? =
|
||||||
|
DocumentFile.fromSingleUri(YuzuApplication.appContext, this)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ package org.yuzu.yuzu_emu.utils
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import java.io.BufferedInputStream
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
@ -62,9 +61,6 @@ object GpuDriverHelper {
|
|||||||
?.sortedByDescending { it: Pair<String, GpuDriverMetadata> -> it.second.name }
|
?.sortedByDescending { it: Pair<String, GpuDriverMetadata> -> it.second.name }
|
||||||
?.distinct()
|
?.distinct()
|
||||||
?.toMutableList() ?: mutableListOf()
|
?.toMutableList() ?: mutableListOf()
|
||||||
|
|
||||||
// TODO: Get system driver information
|
|
||||||
drivers.add(0, Pair("", GpuDriverMetadata()))
|
|
||||||
return drivers
|
return drivers
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +122,7 @@ object GpuDriverHelper {
|
|||||||
// Unzip the driver.
|
// Unzip the driver.
|
||||||
try {
|
try {
|
||||||
FileUtil.unzipToInternalStorage(
|
FileUtil.unzipToInternalStorage(
|
||||||
BufferedInputStream(copiedFile.inputStream()),
|
copiedFile.path,
|
||||||
File(driverInstallationPath!!)
|
File(driverInstallationPath!!)
|
||||||
)
|
)
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
@ -159,7 +155,7 @@ object GpuDriverHelper {
|
|||||||
// Unzip the driver to the private installation directory
|
// Unzip the driver to the private installation directory
|
||||||
try {
|
try {
|
||||||
FileUtil.unzipToInternalStorage(
|
FileUtil.unzipToInternalStorage(
|
||||||
BufferedInputStream(driver.inputStream()),
|
driver.path,
|
||||||
File(driverInstallationPath!!)
|
File(driverInstallationPath!!)
|
||||||
)
|
)
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.yuzu.yuzu_emu.viewholder
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.viewbinding.ViewBinding
|
||||||
|
import org.yuzu.yuzu_emu.adapters.AbstractDiffAdapter
|
||||||
|
import org.yuzu.yuzu_emu.adapters.AbstractListAdapter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [RecyclerView.ViewHolder] meant to work together with a [AbstractDiffAdapter] or a
|
||||||
|
* [AbstractListAdapter] so we can run [bind] on each list item without needing a manual hookup.
|
||||||
|
*/
|
||||||
|
abstract class AbstractViewHolder<Model>(binding: ViewBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
abstract fun bind(model: Model)
|
||||||
|
}
|
@ -42,3 +42,19 @@ double GetJDouble(JNIEnv* env, jobject jdouble) {
|
|||||||
jobject ToJDouble(JNIEnv* env, double value) {
|
jobject ToJDouble(JNIEnv* env, double value) {
|
||||||
return env->NewObject(IDCache::GetDoubleClass(), IDCache::GetDoubleConstructor(), value);
|
return env->NewObject(IDCache::GetDoubleClass(), IDCache::GetDoubleConstructor(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 GetJInteger(JNIEnv* env, jobject jinteger) {
|
||||||
|
return env->GetIntField(jinteger, IDCache::GetIntegerValueField());
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject ToJInteger(JNIEnv* env, s32 value) {
|
||||||
|
return env->NewObject(IDCache::GetIntegerClass(), IDCache::GetIntegerConstructor(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetJBoolean(JNIEnv* env, jobject jboolean) {
|
||||||
|
return env->GetBooleanField(jboolean, IDCache::GetBooleanValueField());
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject ToJBoolean(JNIEnv* env, bool value) {
|
||||||
|
return env->NewObject(IDCache::GetBooleanClass(), IDCache::GetBooleanConstructor(), value);
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
std::string GetJString(JNIEnv* env, jstring jstr);
|
std::string GetJString(JNIEnv* env, jstring jstr);
|
||||||
jstring ToJString(JNIEnv* env, std::string_view str);
|
jstring ToJString(JNIEnv* env, std::string_view str);
|
||||||
@ -13,3 +14,9 @@ jstring ToJString(JNIEnv* env, std::u16string_view str);
|
|||||||
|
|
||||||
double GetJDouble(JNIEnv* env, jobject jdouble);
|
double GetJDouble(JNIEnv* env, jobject jdouble);
|
||||||
jobject ToJDouble(JNIEnv* env, double value);
|
jobject ToJDouble(JNIEnv* env, double value);
|
||||||
|
|
||||||
|
s32 GetJInteger(JNIEnv* env, jobject jinteger);
|
||||||
|
jobject ToJInteger(JNIEnv* env, s32 value);
|
||||||
|
|
||||||
|
bool GetJBoolean(JNIEnv* env, jobject jboolean);
|
||||||
|
jobject ToJBoolean(JNIEnv* env, bool value);
|
||||||
|
@ -21,7 +21,7 @@ void AndroidConfig::ReloadAllValues() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AndroidConfig::SaveAllValues() {
|
void AndroidConfig::SaveAllValues() {
|
||||||
Save();
|
SaveValues();
|
||||||
SaveAndroidValues();
|
SaveAndroidValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +43,27 @@ static jfieldID s_overlay_control_data_landscape_position_field;
|
|||||||
static jfieldID s_overlay_control_data_portrait_position_field;
|
static jfieldID s_overlay_control_data_portrait_position_field;
|
||||||
static jfieldID s_overlay_control_data_foldable_position_field;
|
static jfieldID s_overlay_control_data_foldable_position_field;
|
||||||
|
|
||||||
|
static jclass s_patch_class;
|
||||||
|
static jmethodID s_patch_constructor;
|
||||||
|
static jfieldID s_patch_enabled_field;
|
||||||
|
static jfieldID s_patch_name_field;
|
||||||
|
static jfieldID s_patch_version_field;
|
||||||
|
static jfieldID s_patch_type_field;
|
||||||
|
static jfieldID s_patch_program_id_field;
|
||||||
|
static jfieldID s_patch_title_id_field;
|
||||||
|
|
||||||
static jclass s_double_class;
|
static jclass s_double_class;
|
||||||
static jmethodID s_double_constructor;
|
static jmethodID s_double_constructor;
|
||||||
static jfieldID s_double_value_field;
|
static jfieldID s_double_value_field;
|
||||||
|
|
||||||
|
static jclass s_integer_class;
|
||||||
|
static jmethodID s_integer_constructor;
|
||||||
|
static jfieldID s_integer_value_field;
|
||||||
|
|
||||||
|
static jclass s_boolean_class;
|
||||||
|
static jmethodID s_boolean_constructor;
|
||||||
|
static jfieldID s_boolean_value_field;
|
||||||
|
|
||||||
static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
|
static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
|
||||||
|
|
||||||
namespace IDCache {
|
namespace IDCache {
|
||||||
@ -186,6 +203,38 @@ jfieldID GetOverlayControlDataFoldablePositionField() {
|
|||||||
return s_overlay_control_data_foldable_position_field;
|
return s_overlay_control_data_foldable_position_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jclass GetPatchClass() {
|
||||||
|
return s_patch_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
jmethodID GetPatchConstructor() {
|
||||||
|
return s_patch_constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchEnabledField() {
|
||||||
|
return s_patch_enabled_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchNameField() {
|
||||||
|
return s_patch_name_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchVersionField() {
|
||||||
|
return s_patch_version_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchTypeField() {
|
||||||
|
return s_patch_type_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchProgramIdField() {
|
||||||
|
return s_patch_program_id_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetPatchTitleIdField() {
|
||||||
|
return s_patch_title_id_field;
|
||||||
|
}
|
||||||
|
|
||||||
jclass GetDoubleClass() {
|
jclass GetDoubleClass() {
|
||||||
return s_double_class;
|
return s_double_class;
|
||||||
}
|
}
|
||||||
@ -198,6 +247,30 @@ jfieldID GetDoubleValueField() {
|
|||||||
return s_double_value_field;
|
return s_double_value_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jclass GetIntegerClass() {
|
||||||
|
return s_integer_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
jmethodID GetIntegerConstructor() {
|
||||||
|
return s_integer_constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetIntegerValueField() {
|
||||||
|
return s_integer_value_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
jclass GetBooleanClass() {
|
||||||
|
return s_boolean_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
jmethodID GetBooleanConstructor() {
|
||||||
|
return s_boolean_constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
jfieldID GetBooleanValueField() {
|
||||||
|
return s_boolean_value_field;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace IDCache
|
} // namespace IDCache
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -278,12 +351,37 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|||||||
env->GetFieldID(overlay_control_data_class, "foldablePosition", "Lkotlin/Pair;");
|
env->GetFieldID(overlay_control_data_class, "foldablePosition", "Lkotlin/Pair;");
|
||||||
env->DeleteLocalRef(overlay_control_data_class);
|
env->DeleteLocalRef(overlay_control_data_class);
|
||||||
|
|
||||||
|
const jclass patch_class = env->FindClass("org/yuzu/yuzu_emu/model/Patch");
|
||||||
|
s_patch_class = reinterpret_cast<jclass>(env->NewGlobalRef(patch_class));
|
||||||
|
s_patch_constructor = env->GetMethodID(
|
||||||
|
patch_class, "<init>",
|
||||||
|
"(ZLjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V");
|
||||||
|
s_patch_enabled_field = env->GetFieldID(patch_class, "enabled", "Z");
|
||||||
|
s_patch_name_field = env->GetFieldID(patch_class, "name", "Ljava/lang/String;");
|
||||||
|
s_patch_version_field = env->GetFieldID(patch_class, "version", "Ljava/lang/String;");
|
||||||
|
s_patch_type_field = env->GetFieldID(patch_class, "type", "I");
|
||||||
|
s_patch_program_id_field = env->GetFieldID(patch_class, "programId", "Ljava/lang/String;");
|
||||||
|
s_patch_title_id_field = env->GetFieldID(patch_class, "titleId", "Ljava/lang/String;");
|
||||||
|
env->DeleteLocalRef(patch_class);
|
||||||
|
|
||||||
const jclass double_class = env->FindClass("java/lang/Double");
|
const jclass double_class = env->FindClass("java/lang/Double");
|
||||||
s_double_class = reinterpret_cast<jclass>(env->NewGlobalRef(double_class));
|
s_double_class = reinterpret_cast<jclass>(env->NewGlobalRef(double_class));
|
||||||
s_double_constructor = env->GetMethodID(double_class, "<init>", "(D)V");
|
s_double_constructor = env->GetMethodID(double_class, "<init>", "(D)V");
|
||||||
s_double_value_field = env->GetFieldID(double_class, "value", "D");
|
s_double_value_field = env->GetFieldID(double_class, "value", "D");
|
||||||
env->DeleteLocalRef(double_class);
|
env->DeleteLocalRef(double_class);
|
||||||
|
|
||||||
|
const jclass int_class = env->FindClass("java/lang/Integer");
|
||||||
|
s_integer_class = reinterpret_cast<jclass>(env->NewGlobalRef(int_class));
|
||||||
|
s_integer_constructor = env->GetMethodID(int_class, "<init>", "(I)V");
|
||||||
|
s_integer_value_field = env->GetFieldID(int_class, "value", "I");
|
||||||
|
env->DeleteLocalRef(int_class);
|
||||||
|
|
||||||
|
const jclass boolean_class = env->FindClass("java/lang/Boolean");
|
||||||
|
s_boolean_class = reinterpret_cast<jclass>(env->NewGlobalRef(boolean_class));
|
||||||
|
s_boolean_constructor = env->GetMethodID(boolean_class, "<init>", "(Z)V");
|
||||||
|
s_boolean_value_field = env->GetFieldID(boolean_class, "value", "Z");
|
||||||
|
env->DeleteLocalRef(boolean_class);
|
||||||
|
|
||||||
// Initialize Android Storage
|
// Initialize Android Storage
|
||||||
Common::FS::Android::RegisterCallbacks(env, s_native_library_class);
|
Common::FS::Android::RegisterCallbacks(env, s_native_library_class);
|
||||||
|
|
||||||
@ -309,7 +407,10 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
|
|||||||
env->DeleteGlobalRef(s_string_class);
|
env->DeleteGlobalRef(s_string_class);
|
||||||
env->DeleteGlobalRef(s_pair_class);
|
env->DeleteGlobalRef(s_pair_class);
|
||||||
env->DeleteGlobalRef(s_overlay_control_data_class);
|
env->DeleteGlobalRef(s_overlay_control_data_class);
|
||||||
|
env->DeleteGlobalRef(s_patch_class);
|
||||||
env->DeleteGlobalRef(s_double_class);
|
env->DeleteGlobalRef(s_double_class);
|
||||||
|
env->DeleteGlobalRef(s_integer_class);
|
||||||
|
env->DeleteGlobalRef(s_boolean_class);
|
||||||
|
|
||||||
// UnInitialize applets
|
// UnInitialize applets
|
||||||
SoftwareKeyboard::CleanupJNI(env);
|
SoftwareKeyboard::CleanupJNI(env);
|
||||||
|
@ -43,8 +43,25 @@ jfieldID GetOverlayControlDataLandscapePositionField();
|
|||||||
jfieldID GetOverlayControlDataPortraitPositionField();
|
jfieldID GetOverlayControlDataPortraitPositionField();
|
||||||
jfieldID GetOverlayControlDataFoldablePositionField();
|
jfieldID GetOverlayControlDataFoldablePositionField();
|
||||||
|
|
||||||
|
jclass GetPatchClass();
|
||||||
|
jmethodID GetPatchConstructor();
|
||||||
|
jfieldID GetPatchEnabledField();
|
||||||
|
jfieldID GetPatchNameField();
|
||||||
|
jfieldID GetPatchVersionField();
|
||||||
|
jfieldID GetPatchTypeField();
|
||||||
|
jfieldID GetPatchProgramIdField();
|
||||||
|
jfieldID GetPatchTitleIdField();
|
||||||
|
|
||||||
jclass GetDoubleClass();
|
jclass GetDoubleClass();
|
||||||
jmethodID GetDoubleConstructor();
|
jmethodID GetDoubleConstructor();
|
||||||
jfieldID GetDoubleValueField();
|
jfieldID GetDoubleValueField();
|
||||||
|
|
||||||
|
jclass GetIntegerClass();
|
||||||
|
jmethodID GetIntegerConstructor();
|
||||||
|
jfieldID GetIntegerValueField();
|
||||||
|
|
||||||
|
jclass GetBooleanClass();
|
||||||
|
jmethodID GetBooleanConstructor();
|
||||||
|
jfieldID GetBooleanValueField();
|
||||||
|
|
||||||
} // namespace IDCache
|
} // namespace IDCache
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <core/file_sys/patch_manager.h>
|
#include <core/file_sys/patch_manager.h>
|
||||||
#include <core/file_sys/savedata_factory.h>
|
#include <core/file_sys/savedata_factory.h>
|
||||||
#include <core/loader/nro.h>
|
#include <core/loader/nro.h>
|
||||||
|
#include <frontend_common/content_manager.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "common/detached_tasks.h"
|
#include "common/detached_tasks.h"
|
||||||
@ -100,67 +101,6 @@ void EmulationSession::SetNativeWindow(ANativeWindow* native_window) {
|
|||||||
m_native_window = native_window;
|
m_native_window = native_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmulationSession::InstallFileToNand(std::string filename, std::string file_extension) {
|
|
||||||
jconst copy_func = [](const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest,
|
|
||||||
std::size_t block_size) {
|
|
||||||
if (src == nullptr || dest == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!dest->Resize(src->GetSize())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace Common::Literals;
|
|
||||||
[[maybe_unused]] std::vector<u8> buffer(1_MiB);
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
|
|
||||||
jconst read = src->Read(buffer.data(), buffer.size(), i);
|
|
||||||
dest->Write(buffer.data(), read, i);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum InstallResult {
|
|
||||||
Success = 0,
|
|
||||||
SuccessFileOverwritten = 1,
|
|
||||||
InstallError = 2,
|
|
||||||
ErrorBaseGame = 3,
|
|
||||||
ErrorFilenameExtension = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
[[maybe_unused]] std::shared_ptr<FileSys::NSP> nsp;
|
|
||||||
if (file_extension == "nsp") {
|
|
||||||
nsp = std::make_shared<FileSys::NSP>(m_vfs->OpenFile(filename, FileSys::Mode::Read));
|
|
||||||
if (nsp->IsExtractedType()) {
|
|
||||||
return InstallError;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ErrorFilenameExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nsp) {
|
|
||||||
return InstallError;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsp->GetStatus() != Loader::ResultStatus::Success) {
|
|
||||||
return InstallError;
|
|
||||||
}
|
|
||||||
|
|
||||||
jconst res = m_system.GetFileSystemController().GetUserNANDContents()->InstallEntry(*nsp, true,
|
|
||||||
copy_func);
|
|
||||||
|
|
||||||
switch (res) {
|
|
||||||
case FileSys::InstallResult::Success:
|
|
||||||
return Success;
|
|
||||||
case FileSys::InstallResult::OverwriteExisting:
|
|
||||||
return SuccessFileOverwritten;
|
|
||||||
case FileSys::InstallResult::ErrorBaseInstall:
|
|
||||||
return ErrorBaseGame;
|
|
||||||
default:
|
|
||||||
return InstallError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmulationSession::InitializeGpuDriver(const std::string& hook_lib_dir,
|
void EmulationSession::InitializeGpuDriver(const std::string& hook_lib_dir,
|
||||||
const std::string& custom_driver_dir,
|
const std::string& custom_driver_dir,
|
||||||
const std::string& custom_driver_name,
|
const std::string& custom_driver_name,
|
||||||
@ -410,8 +350,8 @@ void EmulationSession::OnGamepadConnectEvent([[maybe_unused]] int index) {
|
|||||||
jauto handheld = m_system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
jauto handheld = m_system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
||||||
|
|
||||||
if (controller->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::Handheld) {
|
if (controller->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::Handheld) {
|
||||||
handheld->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
|
handheld->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
|
||||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
|
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
|
||||||
handheld->Disconnect();
|
handheld->Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,10 +452,20 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env, jobject
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Java_org_yuzu_yuzu_1emu_NativeLibrary_installFileToNand(JNIEnv* env, jobject instance,
|
int Java_org_yuzu_yuzu_1emu_NativeLibrary_installFileToNand(JNIEnv* env, jobject instance,
|
||||||
jstring j_file,
|
jstring j_file, jobject jcallback) {
|
||||||
jstring j_file_extension) {
|
auto jlambdaClass = env->GetObjectClass(jcallback);
|
||||||
return EmulationSession::GetInstance().InstallFileToNand(GetJString(env, j_file),
|
auto jlambdaInvokeMethod = env->GetMethodID(
|
||||||
GetJString(env, j_file_extension));
|
jlambdaClass, "invoke", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||||
|
const auto callback = [env, jcallback, jlambdaInvokeMethod](size_t max, size_t progress) {
|
||||||
|
auto jwasCancelled = env->CallObjectMethod(jcallback, jlambdaInvokeMethod,
|
||||||
|
ToJDouble(env, max), ToJDouble(env, progress));
|
||||||
|
return GetJBoolean(env, jwasCancelled);
|
||||||
|
};
|
||||||
|
|
||||||
|
return static_cast<int>(
|
||||||
|
ContentManager::InstallNSP(&EmulationSession::GetInstance().System(),
|
||||||
|
EmulationSession::GetInstance().System().GetFilesystem().get(),
|
||||||
|
GetJString(env, j_file), callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_doesUpdateMatchProgram(JNIEnv* env, jobject jobj,
|
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_doesUpdateMatchProgram(JNIEnv* env, jobject jobj,
|
||||||
@ -770,8 +720,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv*
|
|||||||
ASSERT(user_id);
|
ASSERT(user_id);
|
||||||
|
|
||||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||||
EmulationSession::GetInstance().System(), vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser,
|
{}, vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, 1,
|
||||||
FileSys::SaveDataType::SaveData, 1, user_id->AsU128(), 0);
|
user_id->AsU128(), 0);
|
||||||
|
|
||||||
const auto full_path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
|
const auto full_path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
|
||||||
if (!Common::FS::CreateParentDirs(full_path)) {
|
if (!Common::FS::CreateParentDirs(full_path)) {
|
||||||
@ -824,9 +774,9 @@ jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isFirmwareAvailable(JNIEnv* env,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getAddonsForFile(JNIEnv* env, jobject jobj,
|
jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getPatchesForFile(JNIEnv* env, jobject jobj,
|
||||||
jstring jpath,
|
jstring jpath,
|
||||||
jstring jprogramId) {
|
jstring jprogramId) {
|
||||||
const auto path = GetJString(env, jpath);
|
const auto path = GetJString(env, jpath);
|
||||||
const auto vFile =
|
const auto vFile =
|
||||||
Core::GetGameFileFromPath(EmulationSession::GetInstance().System().GetFilesystem(), path);
|
Core::GetGameFileFromPath(EmulationSession::GetInstance().System().GetFilesystem(), path);
|
||||||
@ -843,25 +793,48 @@ jobjectArray Java_org_yuzu_yuzu_1emu_NativeLibrary_getAddonsForFile(JNIEnv* env,
|
|||||||
FileSys::VirtualFile update_raw;
|
FileSys::VirtualFile update_raw;
|
||||||
loader->ReadUpdateRaw(update_raw);
|
loader->ReadUpdateRaw(update_raw);
|
||||||
|
|
||||||
auto addons = pm.GetPatchVersionNames(update_raw);
|
auto patches = pm.GetPatches(update_raw);
|
||||||
auto jemptyString = ToJString(env, "");
|
jobjectArray jpatchArray =
|
||||||
auto jemptyStringPair = env->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
|
env->NewObjectArray(patches.size(), IDCache::GetPatchClass(), nullptr);
|
||||||
jemptyString, jemptyString);
|
|
||||||
jobjectArray jaddonsArray =
|
|
||||||
env->NewObjectArray(addons.size(), IDCache::GetPairClass(), jemptyStringPair);
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const auto& addon : addons) {
|
for (const auto& patch : patches) {
|
||||||
jobject jaddon = env->NewObject(IDCache::GetPairClass(), IDCache::GetPairConstructor(),
|
jobject jpatch = env->NewObject(
|
||||||
ToJString(env, addon.first), ToJString(env, addon.second));
|
IDCache::GetPatchClass(), IDCache::GetPatchConstructor(), patch.enabled,
|
||||||
env->SetObjectArrayElement(jaddonsArray, i, jaddon);
|
ToJString(env, patch.name), ToJString(env, patch.version),
|
||||||
|
static_cast<jint>(patch.type), ToJString(env, std::to_string(patch.program_id)),
|
||||||
|
ToJString(env, std::to_string(patch.title_id)));
|
||||||
|
env->SetObjectArrayElement(jpatchArray, i, jpatch);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
return jaddonsArray;
|
return jpatchArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_removeUpdate(JNIEnv* env, jobject jobj,
|
||||||
|
jstring jprogramId) {
|
||||||
|
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||||
|
ContentManager::RemoveUpdate(EmulationSession::GetInstance().System().GetFileSystemController(),
|
||||||
|
program_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_removeDLC(JNIEnv* env, jobject jobj, jstring jtitleId) {
|
||||||
|
auto title_id = EmulationSession::GetProgramId(env, jtitleId);
|
||||||
|
ContentManager::RemoveDLC(EmulationSession::GetInstance().System().GetFileSystemController(),
|
||||||
|
title_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_removeMod(JNIEnv* env, jobject jobj, jstring jprogramId,
|
||||||
|
jstring jname) {
|
||||||
|
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||||
|
ContentManager::RemoveMod(EmulationSession::GetInstance().System().GetFileSystemController(),
|
||||||
|
program_id, GetJString(env, jname));
|
||||||
}
|
}
|
||||||
|
|
||||||
jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject jobj,
|
jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject jobj,
|
||||||
jstring jprogramId) {
|
jstring jprogramId) {
|
||||||
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
auto program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||||
|
if (program_id == 0) {
|
||||||
|
return ToJString(env, "");
|
||||||
|
}
|
||||||
|
|
||||||
auto& system = EmulationSession::GetInstance().System();
|
auto& system = EmulationSession::GetInstance().System();
|
||||||
|
|
||||||
@ -875,11 +848,24 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getSavePath(JNIEnv* env, jobject j
|
|||||||
FileSys::Mode::Read);
|
FileSys::Mode::Read);
|
||||||
|
|
||||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||||
system, vfsNandDir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
{}, vfsNandDir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
||||||
program_id, user_id->AsU128(), 0);
|
program_id, user_id->AsU128(), 0);
|
||||||
return ToJString(env, user_save_data_path);
|
return ToJString(env, user_save_data_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getDefaultProfileSaveDataRoot(JNIEnv* env,
|
||||||
|
jobject jobj,
|
||||||
|
jboolean jfuture) {
|
||||||
|
Service::Account::ProfileManager manager;
|
||||||
|
// TODO: Pass in a selected user once we get the relevant UI working
|
||||||
|
const auto user_id = manager.GetUser(static_cast<std::size_t>(0));
|
||||||
|
ASSERT(user_id);
|
||||||
|
|
||||||
|
const auto user_save_data_root =
|
||||||
|
FileSys::SaveDataFactory::GetUserGameSaveDataRoot(user_id->AsU128(), jfuture);
|
||||||
|
return ToJString(env, user_save_data_root);
|
||||||
|
}
|
||||||
|
|
||||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_addFileToFilesystemProvider(JNIEnv* env, jobject jobj,
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_addFileToFilesystemProvider(JNIEnv* env, jobject jobj,
|
||||||
jstring jpath) {
|
jstring jpath) {
|
||||||
EmulationSession::GetInstance().ConfigureFilesystemProvider(GetJString(env, jpath));
|
EmulationSession::GetInstance().ConfigureFilesystemProvider(GetJString(env, jpath));
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "core/file_sys/registered_cache.h"
|
#include "core/file_sys/registered_cache.h"
|
||||||
#include "core/hle/service/acc/profile_manager.h"
|
#include "core/hle/service/acc/profile_manager.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
|
#include "frontend_common/content_manager.h"
|
||||||
#include "jni/applets/software_keyboard.h"
|
#include "jni/applets/software_keyboard.h"
|
||||||
#include "jni/emu_window/emu_window.h"
|
#include "jni/emu_window/emu_window.h"
|
||||||
#include "video_core/rasterizer_interface.h"
|
#include "video_core/rasterizer_interface.h"
|
||||||
@ -29,7 +30,6 @@ public:
|
|||||||
void SetNativeWindow(ANativeWindow* native_window);
|
void SetNativeWindow(ANativeWindow* native_window);
|
||||||
void SurfaceChanged();
|
void SurfaceChanged();
|
||||||
|
|
||||||
int InstallFileToNand(std::string filename, std::string file_extension);
|
|
||||||
void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir,
|
void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir,
|
||||||
const std::string& custom_driver_name,
|
const std::string& custom_driver_name,
|
||||||
const std::string& file_redirect_dir);
|
const std::string& file_redirect_dir);
|
||||||
|
@ -205,7 +205,7 @@ jboolean Java_org_yuzu_yuzu_1emu_utils_NativeConfig_getIsRuntimeModifiable(JNIEn
|
|||||||
jstring jkey) {
|
jstring jkey) {
|
||||||
auto setting = getSetting<std::string>(env, jkey);
|
auto setting = getSetting<std::string>(env, jkey);
|
||||||
if (setting != nullptr) {
|
if (setting != nullptr) {
|
||||||
return setting->RuntimeModfiable();
|
return setting->RuntimeModifiable();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@
|
|||||||
android:layout_marginHorizontal="20dp" />
|
android:layout_marginHorizontal="20dp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/button_build_hash"
|
android:id="@+id/button_version_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
@ -164,7 +164,7 @@
|
|||||||
android:textAlignment="viewStart" />
|
android:textAlignment="viewStart" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/text_build_hash"
|
android:id="@+id/text_version_name"
|
||||||
style="@style/TextAppearance.Material3.BodyMedium"
|
style="@style/TextAppearance.Material3.BodyMedium"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -1,8 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.google.android.material.progressindicator.LinearProgressIndicator xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/progress_bar"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="24dp"
|
android:orientation="vertical">
|
||||||
app:trackCornerRadius="4dp" />
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/message"
|
||||||
|
style="@style/TextAppearance.Material3.BodyMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginBottom="6dp"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:requiresFadingEdge="horizontal"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
|
android:id="@+id/progress_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="24dp"
|
||||||
|
app:trackCornerRadius="4dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
@ -148,7 +148,7 @@
|
|||||||
android:layout_marginHorizontal="20dp" />
|
android:layout_marginHorizontal="20dp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/button_build_hash"
|
android:id="@+id/button_version_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingVertical="16dp"
|
android:paddingVertical="16dp"
|
||||||
@ -165,7 +165,7 @@
|
|||||||
android:text="@string/build" />
|
android:text="@string/build" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/text_build_hash"
|
android:id="@+id/text_version_name"
|
||||||
style="@style/TextAppearance.Material3.BodyMedium"
|
style="@style/TextAppearance.Material3.BodyMedium"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -14,12 +14,11 @@
|
|||||||
android:id="@+id/text_container"
|
android:id="@+id/text_container"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/addon_switch"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/addon_switch"
|
app:layout_constraintEnd_toStartOf="@+id/addon_checkbox"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/addon_switch">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
@ -42,16 +41,29 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.materialswitch.MaterialSwitch
|
<com.google.android.material.checkbox.MaterialCheckBox
|
||||||
android:id="@+id/addon_switch"
|
android:id="@+id/addon_checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:nextFocusLeft="@id/addon_container"
|
android:layout_marginEnd="8dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintTop_toTopOf="@+id/text_container"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/text_container"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/button_delete" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_delete"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:contentDescription="@string/delete"
|
||||||
|
android:tooltipText="@string/delete"
|
||||||
|
app:icon="@drawable/ic_delete"
|
||||||
|
app:iconTint="?attr/colorControlNormal"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@id/text_container"
|
app:layout_constraintTop_toTopOf="@+id/addon_checkbox"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintBottom_toBottomOf="@+id/addon_checkbox" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
11
src/android/app/src/main/res/menu/menu_driver_manager.xml
Normal file
11
src/android/app/src/main/res/menu/menu_driver_manager.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_driver_clear"
|
||||||
|
android:icon="@drawable/ic_clear"
|
||||||
|
android:title="@string/clear"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
@ -29,7 +29,7 @@
|
|||||||
<item>@string/language_dutch</item>
|
<item>@string/language_dutch</item>
|
||||||
<item>@string/language_english</item>
|
<item>@string/language_english</item>
|
||||||
<item>@string/language_french</item>
|
<item>@string/language_french</item>
|
||||||
<item>@string/langauge_german</item>
|
<item>@string/language_german</item>
|
||||||
<item>@string/language_italian</item>
|
<item>@string/language_italian</item>
|
||||||
<item>@string/language_japanese</item>
|
<item>@string/language_japanese</item>
|
||||||
<item>@string/language_korean</item>
|
<item>@string/language_korean</item>
|
||||||
@ -228,10 +228,10 @@
|
|||||||
<item>R</item>
|
<item>R</item>
|
||||||
<item>ZL</item>
|
<item>ZL</item>
|
||||||
<item>ZR</item>
|
<item>ZR</item>
|
||||||
<item>@string/gamepad_left_stick</item>
|
|
||||||
<item>@string/gamepad_right_stick</item>
|
|
||||||
<item>L3</item>
|
<item>L3</item>
|
||||||
<item>R3</item>
|
<item>R3</item>
|
||||||
|
<item>@string/gamepad_left_stick</item>
|
||||||
|
<item>@string/gamepad_right_stick</item>
|
||||||
<item>@string/gamepad_d_pad</item>
|
<item>@string/gamepad_d_pad</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
@ -133,6 +133,15 @@
|
|||||||
<string name="add_game_folder">Add game folder</string>
|
<string name="add_game_folder">Add game folder</string>
|
||||||
<string name="folder_already_added">This folder was already added!</string>
|
<string name="folder_already_added">This folder was already added!</string>
|
||||||
<string name="game_folder_properties">Game folder properties</string>
|
<string name="game_folder_properties">Game folder properties</string>
|
||||||
|
<plurals name="saves_import_failed">
|
||||||
|
<item quantity="one">Failed to import %d save</item>
|
||||||
|
<item quantity="other">Failed to import %d saves</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="saves_import_success">
|
||||||
|
<item quantity="one">Successfully imported %d save</item>
|
||||||
|
<item quantity="other">Successfully imported %d saves</item>
|
||||||
|
</plurals>
|
||||||
|
<string name="no_save_data_found">No save data found</string>
|
||||||
|
|
||||||
<!-- Applet launcher strings -->
|
<!-- Applet launcher strings -->
|
||||||
<string name="applets">Applet launcher</string>
|
<string name="applets">Applet launcher</string>
|
||||||
@ -276,6 +285,8 @@
|
|||||||
<string name="global">Global</string>
|
<string name="global">Global</string>
|
||||||
<string name="custom">Custom</string>
|
<string name="custom">Custom</string>
|
||||||
<string name="notice">Notice</string>
|
<string name="notice">Notice</string>
|
||||||
|
<string name="import_complete">Import complete</string>
|
||||||
|
<string name="more_options">More options</string>
|
||||||
|
|
||||||
<!-- GPU driver installation -->
|
<!-- GPU driver installation -->
|
||||||
<string name="select_gpu_driver">Select GPU driver</string>
|
<string name="select_gpu_driver">Select GPU driver</string>
|
||||||
@ -338,6 +349,8 @@
|
|||||||
<string name="verifying_content">Verifying content…</string>
|
<string name="verifying_content">Verifying content…</string>
|
||||||
<string name="content_install_notice">Content install notice</string>
|
<string name="content_install_notice">Content install notice</string>
|
||||||
<string name="content_install_notice_description">The content that you selected does not match this game.\nInstall anyway?</string>
|
<string name="content_install_notice_description">The content that you selected does not match this game.\nInstall anyway?</string>
|
||||||
|
<string name="confirm_uninstall">Confirm uninstall</string>
|
||||||
|
<string name="confirm_uninstall_description">Are you sure you want to uninstall this addon?</string>
|
||||||
|
|
||||||
<!-- ROM loading errors -->
|
<!-- ROM loading errors -->
|
||||||
<string name="loader_error_encrypted">Your ROM is encrypted</string>
|
<string name="loader_error_encrypted">Your ROM is encrypted</string>
|
||||||
@ -400,7 +413,7 @@
|
|||||||
<string name="language_japanese" translatable="false">日本語</string>
|
<string name="language_japanese" translatable="false">日本語</string>
|
||||||
<string name="language_english" translatable="false">English</string>
|
<string name="language_english" translatable="false">English</string>
|
||||||
<string name="language_french" translatable="false">Français</string>
|
<string name="language_french" translatable="false">Français</string>
|
||||||
<string name="langauge_german" translatable="false">Deutsch</string>
|
<string name="language_german" translatable="false">Deutsch</string>
|
||||||
<string name="language_italian" translatable="false">Italiano</string>
|
<string name="language_italian" translatable="false">Italiano</string>
|
||||||
<string name="language_spanish" translatable="false">Español</string>
|
<string name="language_spanish" translatable="false">Español</string>
|
||||||
<string name="language_chinese" translatable="false">简体中文</string>
|
<string name="language_chinese" translatable="false">简体中文</string>
|
||||||
|
7
src/android/app/src/main/res/xml/game_mode_config.xml
Normal file
7
src/android/app/src/main/res/xml/game_mode_config.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<game-mode-config
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:supportsBatteryGameMode="true"
|
||||||
|
android:supportsPerformanceGameMode="true"
|
||||||
|
android:allowGameDownscaling="false"
|
||||||
|
android:allowGameFpsOverride="false"/>
|
@ -11,7 +11,7 @@ ADSP::ADSP(Core::System& system, Sink::Sink& sink) {
|
|||||||
opus_decoder = std::make_unique<OpusDecoder::OpusDecoder>(system);
|
opus_decoder = std::make_unique<OpusDecoder::OpusDecoder>(system);
|
||||||
opus_decoder->Send(Direction::DSP, OpusDecoder::Message::Start);
|
opus_decoder->Send(Direction::DSP, OpusDecoder::Message::Start);
|
||||||
if (opus_decoder->Receive(Direction::Host) != OpusDecoder::Message::StartOK) {
|
if (opus_decoder->Receive(Direction::Host) != OpusDecoder::Message::StartOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDeocder failed to initialize.");
|
LOG_ERROR(Service_Audio, "OpusDecoder failed to initialize.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,11 @@
|
|||||||
#include "audio_core/sink/sink_stream.h"
|
#include "audio_core/sink/sink_stream.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/guest_memory.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
@ -25,7 +28,7 @@ DeviceSession::~DeviceSession() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_,
|
Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_,
|
||||||
u16 channel_count_, size_t session_id_, u32 handle_,
|
u16 channel_count_, size_t session_id_, Kernel::KProcess* handle_,
|
||||||
u64 applet_resource_user_id_, Sink::StreamType type_) {
|
u64 applet_resource_user_id_, Sink::StreamType type_) {
|
||||||
if (stream) {
|
if (stream) {
|
||||||
Finalize();
|
Finalize();
|
||||||
@ -36,6 +39,7 @@ Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_for
|
|||||||
channel_count = channel_count_;
|
channel_count = channel_count_;
|
||||||
session_id = session_id_;
|
session_id = session_id_;
|
||||||
handle = handle_;
|
handle = handle_;
|
||||||
|
handle->Open();
|
||||||
applet_resource_user_id = applet_resource_user_id_;
|
applet_resource_user_id = applet_resource_user_id_;
|
||||||
|
|
||||||
if (type == Sink::StreamType::In) {
|
if (type == Sink::StreamType::In) {
|
||||||
@ -54,6 +58,11 @@ void DeviceSession::Finalize() {
|
|||||||
sink->CloseStream(stream);
|
sink->CloseStream(stream);
|
||||||
stream = nullptr;
|
stream = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handle) {
|
||||||
|
handle->Close();
|
||||||
|
handle = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceSession::Start() {
|
void DeviceSession::Start() {
|
||||||
@ -91,7 +100,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
|
|||||||
stream->AppendBuffer(new_buffer, tmp_samples);
|
stream->AppendBuffer(new_buffer, tmp_samples);
|
||||||
} else {
|
} else {
|
||||||
Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples(
|
Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples(
|
||||||
system.ApplicationMemory(), buffer.samples, buffer.size / sizeof(s16));
|
handle->GetMemory(), buffer.samples, buffer.size / sizeof(s16));
|
||||||
stream->AppendBuffer(new_buffer, samples);
|
stream->AppendBuffer(new_buffer, samples);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +109,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
|
|||||||
void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const {
|
void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const {
|
||||||
if (type == Sink::StreamType::In) {
|
if (type == Sink::StreamType::In) {
|
||||||
auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))};
|
auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))};
|
||||||
system.ApplicationMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
handle->GetMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ struct EventType;
|
|||||||
} // namespace Timing
|
} // namespace Timing
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KProcess;
|
||||||
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
namespace Sink {
|
namespace Sink {
|
||||||
@ -44,13 +48,13 @@ public:
|
|||||||
* @param sample_format - Sample format for this device's output.
|
* @param sample_format - Sample format for this device's output.
|
||||||
* @param channel_count - Number of channels for this device (2 or 6).
|
* @param channel_count - Number of channels for this device (2 or 6).
|
||||||
* @param session_id - This session's id.
|
* @param session_id - This session's id.
|
||||||
* @param handle - Handle for this device session (unused).
|
* @param handle - Process handle for this device session.
|
||||||
* @param applet_resource_user_id - Applet resource user id for this device session (unused).
|
* @param applet_resource_user_id - Applet resource user id for this device session (unused).
|
||||||
* @param type - Type of this stream (Render, In, Out).
|
* @param type - Type of this stream (Render, In, Out).
|
||||||
* @return Result code for this call.
|
* @return Result code for this call.
|
||||||
*/
|
*/
|
||||||
Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count,
|
Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count,
|
||||||
size_t session_id, u32 handle, u64 applet_resource_user_id,
|
size_t session_id, Kernel::KProcess* handle, u64 applet_resource_user_id,
|
||||||
Sink::StreamType type);
|
Sink::StreamType type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,8 +141,8 @@ private:
|
|||||||
u16 channel_count{};
|
u16 channel_count{};
|
||||||
/// Session id of this device session
|
/// Session id of this device session
|
||||||
size_t session_id{};
|
size_t session_id{};
|
||||||
/// Handle of this device session
|
/// Process handle of device memory owner
|
||||||
u32 handle{};
|
Kernel::KProcess* handle{};
|
||||||
/// Applet resource user id of this device session
|
/// Applet resource user id of this device session
|
||||||
u64 applet_resource_user_id{};
|
u64 applet_resource_user_id{};
|
||||||
/// Total number of samples played by this device session
|
/// Total number of samples played by this device session
|
||||||
|
@ -57,7 +57,7 @@ Result System::IsConfigValid(const std::string_view device_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result System::Initialize(std::string device_name, const AudioInParameter& in_params,
|
Result System::Initialize(std::string device_name, const AudioInParameter& in_params,
|
||||||
const u32 handle_, const u64 applet_resource_user_id_) {
|
Kernel::KProcess* handle_, const u64 applet_resource_user_id_) {
|
||||||
auto result{IsConfigValid(device_name, in_params)};
|
auto result{IsConfigValid(device_name, in_params)};
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -19,7 +19,8 @@ class System;
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KEvent;
|
class KEvent;
|
||||||
}
|
class KProcess;
|
||||||
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace AudioCore::AudioIn {
|
namespace AudioCore::AudioIn {
|
||||||
|
|
||||||
@ -93,12 +94,12 @@ public:
|
|||||||
*
|
*
|
||||||
* @param device_name - The name of the requested input device.
|
* @param device_name - The name of the requested input device.
|
||||||
* @param in_params - Input parameters, see AudioInParameter.
|
* @param in_params - Input parameters, see AudioInParameter.
|
||||||
* @param handle - Unused.
|
* @param handle - Process handle.
|
||||||
* @param applet_resource_user_id - Unused.
|
* @param applet_resource_user_id - Unused.
|
||||||
* @return Result code.
|
* @return Result code.
|
||||||
*/
|
*/
|
||||||
Result Initialize(std::string device_name, const AudioInParameter& in_params, u32 handle,
|
Result Initialize(std::string device_name, const AudioInParameter& in_params,
|
||||||
u64 applet_resource_user_id);
|
Kernel::KProcess* handle, u64 applet_resource_user_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start this system.
|
* Start this system.
|
||||||
@ -244,8 +245,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
/// Core system
|
/// Core system
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
/// (Unused)
|
/// Process handle
|
||||||
u32 handle{};
|
Kernel::KProcess* handle{};
|
||||||
/// (Unused)
|
/// (Unused)
|
||||||
u64 applet_resource_user_id{};
|
u64 applet_resource_user_id{};
|
||||||
/// Buffer event, signalled when a buffer is ready
|
/// Buffer event, signalled when a buffer is ready
|
||||||
|
@ -48,8 +48,8 @@ Result System::IsConfigValid(std::string_view device_name,
|
|||||||
return Service::Audio::ResultInvalidChannelCount;
|
return Service::Audio::ResultInvalidChannelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result System::Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle_,
|
Result System::Initialize(std::string device_name, const AudioOutParameter& in_params,
|
||||||
u64 applet_resource_user_id_) {
|
Kernel::KProcess* handle_, u64 applet_resource_user_id_) {
|
||||||
auto result = IsConfigValid(device_name, in_params);
|
auto result = IsConfigValid(device_name, in_params);
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -19,7 +19,8 @@ class System;
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KEvent;
|
class KEvent;
|
||||||
}
|
class KProcess;
|
||||||
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace AudioCore::AudioOut {
|
namespace AudioCore::AudioOut {
|
||||||
|
|
||||||
@ -84,12 +85,12 @@ public:
|
|||||||
*
|
*
|
||||||
* @param device_name - The name of the requested output device.
|
* @param device_name - The name of the requested output device.
|
||||||
* @param in_params - Input parameters, see AudioOutParameter.
|
* @param in_params - Input parameters, see AudioOutParameter.
|
||||||
* @param handle - Unused.
|
* @param handle - Process handle.
|
||||||
* @param applet_resource_user_id - Unused.
|
* @param applet_resource_user_id - Unused.
|
||||||
* @return Result code.
|
* @return Result code.
|
||||||
*/
|
*/
|
||||||
Result Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle,
|
Result Initialize(std::string device_name, const AudioOutParameter& in_params,
|
||||||
u64 applet_resource_user_id);
|
Kernel::KProcess* handle, u64 applet_resource_user_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start this system.
|
* Start this system.
|
||||||
@ -228,8 +229,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
/// Core system
|
/// Core system
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
/// (Unused)
|
/// Process handle
|
||||||
u32 handle{};
|
Kernel::KProcess* handle{};
|
||||||
/// (Unused)
|
/// (Unused)
|
||||||
u64 applet_resource_user_id{};
|
u64 applet_resource_user_id{};
|
||||||
/// Buffer event, signalled when a buffer is ready
|
/// Buffer event, signalled when a buffer is ready
|
||||||
|
@ -41,7 +41,7 @@ void CommandGenerator::GenerateDataSourceCommand(VoiceInfo& voice_info,
|
|||||||
const VoiceState& voice_state, const s8 channel) {
|
const VoiceState& voice_state, const s8 channel) {
|
||||||
if (voice_info.mix_id == UnusedMixId) {
|
if (voice_info.mix_id == UnusedMixId) {
|
||||||
if (voice_info.splitter_id != UnusedSplitterId) {
|
if (voice_info.splitter_id != UnusedSplitterId) {
|
||||||
auto destination{splitter_context.GetDesintationData(voice_info.splitter_id, 0)};
|
auto destination{splitter_context.GetDestinationData(voice_info.splitter_id, 0)};
|
||||||
u32 dest_id{0};
|
u32 dest_id{0};
|
||||||
while (destination != nullptr) {
|
while (destination != nullptr) {
|
||||||
if (destination->IsConfigured()) {
|
if (destination->IsConfigured()) {
|
||||||
@ -55,7 +55,7 @@ void CommandGenerator::GenerateDataSourceCommand(VoiceInfo& voice_info,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dest_id++;
|
dest_id++;
|
||||||
destination = splitter_context.GetDesintationData(voice_info.splitter_id, dest_id);
|
destination = splitter_context.GetDestinationData(voice_info.splitter_id, dest_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -234,7 +234,7 @@ void CommandGenerator::GenerateVoiceCommand(VoiceInfo& voice_info) {
|
|||||||
if (voice_info.mix_id == UnusedMixId) {
|
if (voice_info.mix_id == UnusedMixId) {
|
||||||
if (voice_info.splitter_id != UnusedSplitterId) {
|
if (voice_info.splitter_id != UnusedSplitterId) {
|
||||||
auto i{channel};
|
auto i{channel};
|
||||||
auto destination{splitter_context.GetDesintationData(voice_info.splitter_id, i)};
|
auto destination{splitter_context.GetDestinationData(voice_info.splitter_id, i)};
|
||||||
while (destination != nullptr) {
|
while (destination != nullptr) {
|
||||||
if (destination->IsConfigured()) {
|
if (destination->IsConfigured()) {
|
||||||
const auto mix_id{destination->GetMixId()};
|
const auto mix_id{destination->GetMixId()};
|
||||||
@ -249,7 +249,7 @@ void CommandGenerator::GenerateVoiceCommand(VoiceInfo& voice_info) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += voice_info.channel_count;
|
i += voice_info.channel_count;
|
||||||
destination = splitter_context.GetDesintationData(voice_info.splitter_id, i);
|
destination = splitter_context.GetDestinationData(voice_info.splitter_id, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -591,7 +591,7 @@ void CommandGenerator::GenerateMixCommands(MixInfo& mix_info) {
|
|||||||
if (mix_info.dst_splitter_id != UnusedSplitterId) {
|
if (mix_info.dst_splitter_id != UnusedSplitterId) {
|
||||||
s16 dest_id{0};
|
s16 dest_id{0};
|
||||||
auto destination{
|
auto destination{
|
||||||
splitter_context.GetDesintationData(mix_info.dst_splitter_id, dest_id)};
|
splitter_context.GetDestinationData(mix_info.dst_splitter_id, dest_id)};
|
||||||
while (destination != nullptr) {
|
while (destination != nullptr) {
|
||||||
if (destination->IsConfigured()) {
|
if (destination->IsConfigured()) {
|
||||||
auto splitter_mix_id{destination->GetMixId()};
|
auto splitter_mix_id{destination->GetMixId()};
|
||||||
@ -612,7 +612,7 @@ void CommandGenerator::GenerateMixCommands(MixInfo& mix_info) {
|
|||||||
}
|
}
|
||||||
dest_id++;
|
dest_id++;
|
||||||
destination =
|
destination =
|
||||||
splitter_context.GetDesintationData(mix_info.dst_splitter_id, dest_id);
|
splitter_context.GetDestinationData(mix_info.dst_splitter_id, dest_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "common/fixed_point.h"
|
#include "common/fixed_point.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scratch_buffer.h"
|
#include "common/scratch_buffer.h"
|
||||||
|
#include "core/guest_memory.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace AudioCore::Renderer {
|
namespace AudioCore::Renderer {
|
||||||
|
@ -93,7 +93,7 @@ bool MixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const InParameter& in_pa
|
|||||||
|
|
||||||
for (u32 i = 0; i < destination_count; i++) {
|
for (u32 i = 0; i < destination_count; i++) {
|
||||||
auto destination{
|
auto destination{
|
||||||
splitter_context.GetDesintationData(in_params.dest_splitter_id, i)};
|
splitter_context.GetDestinationData(in_params.dest_splitter_id, i)};
|
||||||
|
|
||||||
if (destination) {
|
if (destination) {
|
||||||
const auto destination_id{destination->GetMixId()};
|
const auto destination_id{destination->GetMixId()};
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace AudioCore::Renderer {
|
namespace AudioCore::Renderer {
|
||||||
|
|
||||||
SplitterDestinationData* SplitterContext::GetDesintationData(const s32 splitter_id,
|
SplitterDestinationData* SplitterContext::GetDestinationData(const s32 splitter_id,
|
||||||
const s32 destination_id) {
|
const s32 destination_id) {
|
||||||
return splitter_infos[splitter_id].GetData(destination_id);
|
return splitter_infos[splitter_id].GetData(destination_id);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
* @param destination_id - Destination index within the splitter.
|
* @param destination_id - Destination index within the splitter.
|
||||||
* @return Pointer to the found destination. May be nullptr.
|
* @return Pointer to the found destination. May be nullptr.
|
||||||
*/
|
*/
|
||||||
SplitterDestinationData* GetDesintationData(s32 splitter_id, s32 destination_id);
|
SplitterDestinationData* GetDestinationData(s32 splitter_id, s32 destination_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a splitter from the given index.
|
* Get a splitter from the given index.
|
||||||
|
@ -45,6 +45,7 @@ using f32 = float; ///< 32-bit floating point
|
|||||||
using f64 = double; ///< 64-bit floating point
|
using f64 = double; ///< 64-bit floating point
|
||||||
|
|
||||||
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
|
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
|
||||||
|
using DAddr = u64; ///< Represents a pointer in the device specific virtual address space.
|
||||||
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
|
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
|
||||||
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
|
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "common/page_table.h"
|
#include "common/page_table.h"
|
||||||
|
#include "common/scope_exit.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
@ -11,29 +12,10 @@ PageTable::~PageTable() noexcept = default;
|
|||||||
|
|
||||||
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
|
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
|
||||||
Common::ProcessAddress address) const {
|
Common::ProcessAddress address) const {
|
||||||
// Setup invalid defaults.
|
out_context->next_offset = GetInteger(address);
|
||||||
out_entry->phys_addr = 0;
|
out_context->next_page = address / page_size;
|
||||||
out_entry->block_size = page_size;
|
|
||||||
out_context->next_page = 0;
|
|
||||||
|
|
||||||
// Validate that we can read the actual entry.
|
return this->ContinueTraversal(out_entry, out_context);
|
||||||
const auto page = address / page_size;
|
|
||||||
if (page >= backing_addr.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate that the entry is mapped.
|
|
||||||
const auto phys_addr = backing_addr[page];
|
|
||||||
if (phys_addr == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate the results.
|
|
||||||
out_entry->phys_addr = phys_addr + GetInteger(address);
|
|
||||||
out_context->next_page = page + 1;
|
|
||||||
out_context->next_offset = GetInteger(address) + page_size;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
|
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
|
||||||
@ -41,6 +23,12 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
|
|||||||
out_entry->phys_addr = 0;
|
out_entry->phys_addr = 0;
|
||||||
out_entry->block_size = page_size;
|
out_entry->block_size = page_size;
|
||||||
|
|
||||||
|
// Regardless of whether the page was mapped, advance on exit.
|
||||||
|
SCOPE_EXIT({
|
||||||
|
context->next_page += 1;
|
||||||
|
context->next_offset += page_size;
|
||||||
|
});
|
||||||
|
|
||||||
// Validate that we can read the actual entry.
|
// Validate that we can read the actual entry.
|
||||||
const auto page = context->next_page;
|
const auto page = context->next_page;
|
||||||
if (page >= backing_addr.size()) {
|
if (page >= backing_addr.size()) {
|
||||||
@ -55,8 +43,6 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
|
|||||||
|
|
||||||
// Populate the results.
|
// Populate the results.
|
||||||
out_entry->phys_addr = phys_addr + context->next_offset;
|
out_entry->phys_addr = phys_addr + context->next_offset;
|
||||||
context->next_page = page + 1;
|
|
||||||
context->next_offset += page_size;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ bool BasicSetting::Save() const {
|
|||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BasicSetting::RuntimeModfiable() const {
|
bool BasicSetting::RuntimeModifiable() const {
|
||||||
return runtime_modifiable;
|
return runtime_modifiable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @returns true if the current setting can be changed while the guest is running.
|
* @returns true if the current setting can be changed while the guest is running.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool RuntimeModfiable() const;
|
[[nodiscard]] bool RuntimeModifiable() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns A unique number corresponding to the setting.
|
* @returns A unique number corresponding to the setting.
|
||||||
|
@ -37,6 +37,8 @@ add_library(core STATIC
|
|||||||
debugger/gdbstub_arch.h
|
debugger/gdbstub_arch.h
|
||||||
debugger/gdbstub.cpp
|
debugger/gdbstub.cpp
|
||||||
debugger/gdbstub.h
|
debugger/gdbstub.h
|
||||||
|
device_memory_manager.h
|
||||||
|
device_memory_manager.inc
|
||||||
device_memory.cpp
|
device_memory.cpp
|
||||||
device_memory.h
|
device_memory.h
|
||||||
file_sys/fssystem/fs_i_storage.h
|
file_sys/fssystem/fs_i_storage.h
|
||||||
@ -490,6 +492,10 @@ add_library(core STATIC
|
|||||||
hle/service/filesystem/fsp_pr.h
|
hle/service/filesystem/fsp_pr.h
|
||||||
hle/service/filesystem/fsp_srv.cpp
|
hle/service/filesystem/fsp_srv.cpp
|
||||||
hle/service/filesystem/fsp_srv.h
|
hle/service/filesystem/fsp_srv.h
|
||||||
|
hle/service/filesystem/romfs_controller.cpp
|
||||||
|
hle/service/filesystem/romfs_controller.h
|
||||||
|
hle/service/filesystem/save_data_controller.cpp
|
||||||
|
hle/service/filesystem/save_data_controller.h
|
||||||
hle/service/fgm/fgm.cpp
|
hle/service/fgm/fgm.cpp
|
||||||
hle/service/fgm/fgm.h
|
hle/service/fgm/fgm.h
|
||||||
hle/service/friend/friend.cpp
|
hle/service/friend/friend.cpp
|
||||||
@ -605,6 +611,8 @@ add_library(core STATIC
|
|||||||
hle/service/ns/pdm_qry.h
|
hle/service/ns/pdm_qry.h
|
||||||
hle/service/nvdrv/core/container.cpp
|
hle/service/nvdrv/core/container.cpp
|
||||||
hle/service/nvdrv/core/container.h
|
hle/service/nvdrv/core/container.h
|
||||||
|
hle/service/nvdrv/core/heap_mapper.cpp
|
||||||
|
hle/service/nvdrv/core/heap_mapper.h
|
||||||
hle/service/nvdrv/core/nvmap.cpp
|
hle/service/nvdrv/core/nvmap.cpp
|
||||||
hle/service/nvdrv/core/nvmap.h
|
hle/service/nvdrv/core/nvmap.h
|
||||||
hle/service/nvdrv/core/syncpoint_manager.cpp
|
hle/service/nvdrv/core/syncpoint_manager.cpp
|
||||||
@ -708,24 +716,25 @@ add_library(core STATIC
|
|||||||
hle/service/server_manager.h
|
hle/service/server_manager.h
|
||||||
hle/service/service.cpp
|
hle/service/service.cpp
|
||||||
hle/service/service.h
|
hle/service/service.h
|
||||||
hle/service/set/set.cpp
|
hle/service/set/setting_formats/appln_settings.cpp
|
||||||
hle/service/set/set.h
|
hle/service/set/setting_formats/appln_settings.h
|
||||||
hle/service/set/appln_settings.cpp
|
hle/service/set/setting_formats/device_settings.cpp
|
||||||
hle/service/set/appln_settings.h
|
hle/service/set/setting_formats/device_settings.h
|
||||||
hle/service/set/device_settings.cpp
|
hle/service/set/setting_formats/system_settings.cpp
|
||||||
hle/service/set/device_settings.h
|
hle/service/set/setting_formats/system_settings.h
|
||||||
hle/service/set/private_settings.cpp
|
hle/service/set/setting_formats/private_settings.cpp
|
||||||
hle/service/set/private_settings.h
|
hle/service/set/setting_formats/private_settings.h
|
||||||
hle/service/set/set_cal.cpp
|
hle/service/set/factory_settings_server.cpp
|
||||||
hle/service/set/set_cal.h
|
hle/service/set/factory_settings_server.h
|
||||||
hle/service/set/set_fd.cpp
|
hle/service/set/firmware_debug_settings_server.cpp
|
||||||
hle/service/set/set_fd.h
|
hle/service/set/firmware_debug_settings_server.h
|
||||||
hle/service/set/set_sys.cpp
|
|
||||||
hle/service/set/set_sys.h
|
|
||||||
hle/service/set/settings.cpp
|
hle/service/set/settings.cpp
|
||||||
hle/service/set/settings.h
|
hle/service/set/settings.h
|
||||||
hle/service/set/system_settings.cpp
|
hle/service/set/settings_server.cpp
|
||||||
hle/service/set/system_settings.h
|
hle/service/set/settings_server.h
|
||||||
|
hle/service/set/settings_types.h
|
||||||
|
hle/service/set/system_settings_server.cpp
|
||||||
|
hle/service/set/system_settings_server.h
|
||||||
hle/service/sm/sm.cpp
|
hle/service/sm/sm.cpp
|
||||||
hle/service/sm/sm.h
|
hle/service/sm/sm.h
|
||||||
hle/service/sm/sm_controller.cpp
|
hle/service/sm/sm_controller.cpp
|
||||||
|
@ -22,14 +22,10 @@ using NativeExecutionParameters = Kernel::KThread::NativeExecutionParameters;
|
|||||||
constexpr size_t MaxRelativeBranch = 128_MiB;
|
constexpr size_t MaxRelativeBranch = 128_MiB;
|
||||||
constexpr u32 ModuleCodeIndex = 0x24 / sizeof(u32);
|
constexpr u32 ModuleCodeIndex = 0x24 / sizeof(u32);
|
||||||
|
|
||||||
Patcher::Patcher() : c(m_patch_instructions) {}
|
Patcher::Patcher() : c(m_patch_instructions) {
|
||||||
|
// The first word of the patch section is always a branch to the first instruction of the
|
||||||
Patcher::~Patcher() = default;
|
// module.
|
||||||
|
c.dw(0);
|
||||||
void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
|
|
||||||
const Kernel::CodeSet::Segment& code) {
|
|
||||||
// Branch to the first instruction of the module.
|
|
||||||
this->BranchToModule(0);
|
|
||||||
|
|
||||||
// Write save context helper function.
|
// Write save context helper function.
|
||||||
c.l(m_save_context);
|
c.l(m_save_context);
|
||||||
@ -38,6 +34,25 @@ void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
|
|||||||
// Write load context helper function.
|
// Write load context helper function.
|
||||||
c.l(m_load_context);
|
c.l(m_load_context);
|
||||||
WriteLoadContext();
|
WriteLoadContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
Patcher::~Patcher() = default;
|
||||||
|
|
||||||
|
bool Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
|
||||||
|
const Kernel::CodeSet::Segment& code) {
|
||||||
|
// If we have patched modules but cannot reach the new module, then it needs its own patcher.
|
||||||
|
const size_t image_size = program_image.size();
|
||||||
|
if (total_program_size + image_size > MaxRelativeBranch && total_program_size > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new module patch to our list
|
||||||
|
modules.emplace_back();
|
||||||
|
curr_patch = &modules.back();
|
||||||
|
|
||||||
|
// The first word of the patch section is always a branch to the first instruction of the
|
||||||
|
// module.
|
||||||
|
curr_patch->m_branch_to_module_relocations.push_back({0, 0});
|
||||||
|
|
||||||
// Retrieve text segment data.
|
// Retrieve text segment data.
|
||||||
const auto text = std::span{program_image}.subspan(code.offset, code.size);
|
const auto text = std::span{program_image}.subspan(code.offset, code.size);
|
||||||
@ -94,16 +109,17 @@ void Patcher::PatchText(const Kernel::PhysicalMemory& program_image,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto exclusive = Exclusive{inst}; exclusive.Verify()) {
|
if (auto exclusive = Exclusive{inst}; exclusive.Verify()) {
|
||||||
m_exclusives.push_back(i);
|
curr_patch->m_exclusives.push_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine patching mode for the final relocation step
|
// Determine patching mode for the final relocation step
|
||||||
const size_t image_size = program_image.size();
|
total_program_size += image_size;
|
||||||
this->mode = image_size > MaxRelativeBranch ? PatchMode::PreText : PatchMode::PostData;
|
this->mode = image_size > MaxRelativeBranch ? PatchMode::PreText : PatchMode::PostData;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
bool Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
||||||
const Kernel::CodeSet::Segment& code,
|
const Kernel::CodeSet::Segment& code,
|
||||||
Kernel::PhysicalMemory& program_image,
|
Kernel::PhysicalMemory& program_image,
|
||||||
EntryTrampolines* out_trampolines) {
|
EntryTrampolines* out_trampolines) {
|
||||||
@ -120,7 +136,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
|||||||
if (mode == PatchMode::PreText) {
|
if (mode == PatchMode::PreText) {
|
||||||
rc.B(rel.patch_offset - patch_size - rel.module_offset);
|
rc.B(rel.patch_offset - patch_size - rel.module_offset);
|
||||||
} else {
|
} else {
|
||||||
rc.B(image_size - rel.module_offset + rel.patch_offset);
|
rc.B(total_program_size - rel.module_offset + rel.patch_offset);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,7 +145,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
|||||||
if (mode == PatchMode::PreText) {
|
if (mode == PatchMode::PreText) {
|
||||||
rc.B(patch_size - rel.patch_offset + rel.module_offset);
|
rc.B(patch_size - rel.patch_offset + rel.module_offset);
|
||||||
} else {
|
} else {
|
||||||
rc.B(rel.module_offset - image_size - rel.patch_offset);
|
rc.B(rel.module_offset - total_program_size - rel.patch_offset);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -137,7 +153,7 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
|||||||
if (mode == PatchMode::PreText) {
|
if (mode == PatchMode::PreText) {
|
||||||
return GetInteger(load_base) + patch_offset;
|
return GetInteger(load_base) + patch_offset;
|
||||||
} else {
|
} else {
|
||||||
return GetInteger(load_base) + image_size + patch_offset;
|
return GetInteger(load_base) + total_program_size + patch_offset;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -150,39 +166,50 @@ void Patcher::RelocateAndCopy(Common::ProcessAddress load_base,
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We are now ready to relocate!
|
// We are now ready to relocate!
|
||||||
for (const Relocation& rel : m_branch_to_patch_relocations) {
|
auto& patch = modules[m_relocate_module_index++];
|
||||||
|
for (const Relocation& rel : patch.m_branch_to_patch_relocations) {
|
||||||
ApplyBranchToPatchRelocation(text_words.data() + rel.module_offset / sizeof(u32), rel);
|
ApplyBranchToPatchRelocation(text_words.data() + rel.module_offset / sizeof(u32), rel);
|
||||||
}
|
}
|
||||||
for (const Relocation& rel : m_branch_to_module_relocations) {
|
for (const Relocation& rel : patch.m_branch_to_module_relocations) {
|
||||||
ApplyBranchToModuleRelocation(m_patch_instructions.data() + rel.patch_offset / sizeof(u32),
|
ApplyBranchToModuleRelocation(m_patch_instructions.data() + rel.patch_offset / sizeof(u32),
|
||||||
rel);
|
rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite PC constants and record post trampolines
|
// Rewrite PC constants and record post trampolines
|
||||||
for (const Relocation& rel : m_write_module_pc_relocations) {
|
for (const Relocation& rel : patch.m_write_module_pc_relocations) {
|
||||||
oaknut::CodeGenerator rc{m_patch_instructions.data() + rel.patch_offset / sizeof(u32)};
|
oaknut::CodeGenerator rc{m_patch_instructions.data() + rel.patch_offset / sizeof(u32)};
|
||||||
rc.dx(RebasePc(rel.module_offset));
|
rc.dx(RebasePc(rel.module_offset));
|
||||||
}
|
}
|
||||||
for (const Trampoline& rel : m_trampolines) {
|
for (const Trampoline& rel : patch.m_trampolines) {
|
||||||
out_trampolines->insert({RebasePc(rel.module_offset), RebasePatch(rel.patch_offset)});
|
out_trampolines->insert({RebasePc(rel.module_offset), RebasePatch(rel.patch_offset)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cortex-A57 seems to treat all exclusives as ordered, but newer processors do not.
|
// Cortex-A57 seems to treat all exclusives as ordered, but newer processors do not.
|
||||||
// Convert to ordered to preserve this assumption.
|
// Convert to ordered to preserve this assumption.
|
||||||
for (const ModuleTextAddress i : m_exclusives) {
|
for (const ModuleTextAddress i : patch.m_exclusives) {
|
||||||
auto exclusive = Exclusive{text_words[i]};
|
auto exclusive = Exclusive{text_words[i]};
|
||||||
text_words[i] = exclusive.AsOrdered();
|
text_words[i] = exclusive.AsOrdered();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy to program image
|
// Remove the patched module size from the total. This is done so total_program_size
|
||||||
if (this->mode == PatchMode::PreText) {
|
// always represents the distance from the currently patched module to the patch section.
|
||||||
std::memcpy(program_image.data(), m_patch_instructions.data(),
|
total_program_size -= image_size;
|
||||||
m_patch_instructions.size() * sizeof(u32));
|
|
||||||
} else {
|
// Only copy to the program image of the last module
|
||||||
program_image.resize(image_size + patch_size);
|
if (m_relocate_module_index == modules.size()) {
|
||||||
std::memcpy(program_image.data() + image_size, m_patch_instructions.data(),
|
if (this->mode == PatchMode::PreText) {
|
||||||
m_patch_instructions.size() * sizeof(u32));
|
ASSERT(image_size == total_program_size);
|
||||||
|
std::memcpy(program_image.data(), m_patch_instructions.data(),
|
||||||
|
m_patch_instructions.size() * sizeof(u32));
|
||||||
|
} else {
|
||||||
|
program_image.resize(image_size + patch_size);
|
||||||
|
std::memcpy(program_image.data() + image_size, m_patch_instructions.data(),
|
||||||
|
m_patch_instructions.size() * sizeof(u32));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Patcher::GetSectionSize() const noexcept {
|
size_t Patcher::GetSectionSize() const noexcept {
|
||||||
@ -322,7 +349,7 @@ void Patcher::WriteSvcTrampoline(ModuleDestLabel module_dest, u32 svc_id) {
|
|||||||
|
|
||||||
// Write the post-SVC trampoline address, which will jump back to the guest after restoring its
|
// Write the post-SVC trampoline address, which will jump back to the guest after restoring its
|
||||||
// state.
|
// state.
|
||||||
m_trampolines.push_back({c.offset(), module_dest});
|
curr_patch->m_trampolines.push_back({c.offset(), module_dest});
|
||||||
|
|
||||||
// Host called this location. Save the return address so we can
|
// Host called this location. Save the return address so we can
|
||||||
// unwind the stack properly when jumping back.
|
// unwind the stack properly when jumping back.
|
||||||
|
@ -31,9 +31,9 @@ public:
|
|||||||
explicit Patcher();
|
explicit Patcher();
|
||||||
~Patcher();
|
~Patcher();
|
||||||
|
|
||||||
void PatchText(const Kernel::PhysicalMemory& program_image,
|
bool PatchText(const Kernel::PhysicalMemory& program_image,
|
||||||
const Kernel::CodeSet::Segment& code);
|
const Kernel::CodeSet::Segment& code);
|
||||||
void RelocateAndCopy(Common::ProcessAddress load_base, const Kernel::CodeSet::Segment& code,
|
bool RelocateAndCopy(Common::ProcessAddress load_base, const Kernel::CodeSet::Segment& code,
|
||||||
Kernel::PhysicalMemory& program_image, EntryTrampolines* out_trampolines);
|
Kernel::PhysicalMemory& program_image, EntryTrampolines* out_trampolines);
|
||||||
size_t GetSectionSize() const noexcept;
|
size_t GetSectionSize() const noexcept;
|
||||||
|
|
||||||
@ -61,16 +61,16 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void BranchToPatch(uintptr_t module_dest) {
|
void BranchToPatch(uintptr_t module_dest) {
|
||||||
m_branch_to_patch_relocations.push_back({c.offset(), module_dest});
|
curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), module_dest});
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchToModule(uintptr_t module_dest) {
|
void BranchToModule(uintptr_t module_dest) {
|
||||||
m_branch_to_module_relocations.push_back({c.offset(), module_dest});
|
curr_patch->m_branch_to_module_relocations.push_back({c.offset(), module_dest});
|
||||||
c.dw(0);
|
c.dw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteModulePc(uintptr_t module_dest) {
|
void WriteModulePc(uintptr_t module_dest) {
|
||||||
m_write_module_pc_relocations.push_back({c.offset(), module_dest});
|
curr_patch->m_write_module_pc_relocations.push_back({c.offset(), module_dest});
|
||||||
c.dx(0);
|
c.dx(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,15 +84,22 @@ private:
|
|||||||
uintptr_t module_offset; ///< Offset in bytes from the start of the text section.
|
uintptr_t module_offset; ///< Offset in bytes from the start of the text section.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ModulePatch {
|
||||||
|
std::vector<Trampoline> m_trampolines;
|
||||||
|
std::vector<Relocation> m_branch_to_patch_relocations{};
|
||||||
|
std::vector<Relocation> m_branch_to_module_relocations{};
|
||||||
|
std::vector<Relocation> m_write_module_pc_relocations{};
|
||||||
|
std::vector<ModuleTextAddress> m_exclusives{};
|
||||||
|
};
|
||||||
|
|
||||||
oaknut::VectorCodeGenerator c;
|
oaknut::VectorCodeGenerator c;
|
||||||
std::vector<Trampoline> m_trampolines;
|
|
||||||
std::vector<Relocation> m_branch_to_patch_relocations{};
|
|
||||||
std::vector<Relocation> m_branch_to_module_relocations{};
|
|
||||||
std::vector<Relocation> m_write_module_pc_relocations{};
|
|
||||||
std::vector<ModuleTextAddress> m_exclusives{};
|
|
||||||
oaknut::Label m_save_context{};
|
oaknut::Label m_save_context{};
|
||||||
oaknut::Label m_load_context{};
|
oaknut::Label m_load_context{};
|
||||||
PatchMode mode{PatchMode::None};
|
PatchMode mode{PatchMode::None};
|
||||||
|
size_t total_program_size{};
|
||||||
|
size_t m_relocate_module_index{};
|
||||||
|
std::vector<ModulePatch> modules;
|
||||||
|
ModulePatch* curr_patch;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core::NCE
|
} // namespace Core::NCE
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "core/file_sys/savedata_factory.h"
|
#include "core/file_sys/savedata_factory.h"
|
||||||
#include "core/file_sys/vfs_concat.h"
|
#include "core/file_sys/vfs_concat.h"
|
||||||
#include "core/file_sys/vfs_real.h"
|
#include "core/file_sys/vfs_real.h"
|
||||||
|
#include "core/gpu_dirty_memory_manager.h"
|
||||||
#include "core/hle/kernel/k_memory_manager.h"
|
#include "core/hle/kernel/k_memory_manager.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_resource_limit.h"
|
#include "core/hle/kernel/k_resource_limit.h"
|
||||||
@ -413,6 +414,7 @@ struct System::Impl {
|
|||||||
kernel.ShutdownCores();
|
kernel.ShutdownCores();
|
||||||
services.reset();
|
services.reset();
|
||||||
service_manager.reset();
|
service_manager.reset();
|
||||||
|
fs_controller.Reset();
|
||||||
cheat_engine.reset();
|
cheat_engine.reset();
|
||||||
telemetry_session.reset();
|
telemetry_session.reset();
|
||||||
time_manager.Shutdown();
|
time_manager.Shutdown();
|
||||||
@ -564,6 +566,9 @@ struct System::Impl {
|
|||||||
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
|
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
|
||||||
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};
|
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};
|
||||||
|
|
||||||
|
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES>
|
||||||
|
gpu_dirty_memory_managers;
|
||||||
|
|
||||||
std::deque<std::vector<u8>> user_channel;
|
std::deque<std::vector<u8>> user_channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -650,8 +655,14 @@ size_t System::GetCurrentHostThreadID() const {
|
|||||||
return impl->kernel.GetCurrentHostThreadID();
|
return impl->kernel.GetCurrentHostThreadID();
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) {
|
std::span<GPUDirtyMemoryManager> System::GetGPUDirtyMemoryManager() {
|
||||||
return this->ApplicationProcess()->GatherGPUDirtyMemory(callback);
|
return impl->gpu_dirty_memory_managers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void System::GatherGPUDirtyMemory(std::function<void(PAddr, size_t)>& callback) {
|
||||||
|
for (auto& manager : impl->gpu_dirty_memory_managers) {
|
||||||
|
manager.Gather(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfStatsResults System::GetAndResetPerfStats() {
|
PerfStatsResults System::GetAndResetPerfStats() {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -116,6 +117,7 @@ class CpuManager;
|
|||||||
class Debugger;
|
class Debugger;
|
||||||
class DeviceMemory;
|
class DeviceMemory;
|
||||||
class ExclusiveMonitor;
|
class ExclusiveMonitor;
|
||||||
|
class GPUDirtyMemoryManager;
|
||||||
class PerfStats;
|
class PerfStats;
|
||||||
class Reporter;
|
class Reporter;
|
||||||
class SpeedLimiter;
|
class SpeedLimiter;
|
||||||
@ -224,7 +226,9 @@ public:
|
|||||||
/// Prepare the core emulation for a reschedule
|
/// Prepare the core emulation for a reschedule
|
||||||
void PrepareReschedule(u32 core_index);
|
void PrepareReschedule(u32 core_index);
|
||||||
|
|
||||||
void GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback);
|
std::span<GPUDirtyMemoryManager> GetGPUDirtyMemoryManager();
|
||||||
|
|
||||||
|
void GatherGPUDirtyMemory(std::function<void(PAddr, size_t)>& callback);
|
||||||
|
|
||||||
[[nodiscard]] size_t GetCurrentHostThreadID() const;
|
[[nodiscard]] size_t GetCurrentHostThreadID() const;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
return [this] { ShutdownThreadFunction(); };
|
return [this] { ShutdownThreadFunction(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreemptSingleCore(bool from_running_enviroment = true);
|
void PreemptSingleCore(bool from_running_environment = true);
|
||||||
|
|
||||||
std::size_t CurrentCore() const {
|
std::size_t CurrentCore() const {
|
||||||
return current_core.load();
|
return current_core.load();
|
||||||
|
@ -114,7 +114,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KThread* GetActiveThread() override {
|
Kernel::KThread* GetActiveThread() override {
|
||||||
return state->active_thread;
|
return state->active_thread.GetPointerUnsafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -147,11 +147,14 @@ private:
|
|||||||
|
|
||||||
std::scoped_lock lk{connection_lock};
|
std::scoped_lock lk{connection_lock};
|
||||||
|
|
||||||
|
// Find the process we are going to debug.
|
||||||
|
SetDebugProcess();
|
||||||
|
|
||||||
// Ensure everything is stopped.
|
// Ensure everything is stopped.
|
||||||
PauseEmulation();
|
PauseEmulation();
|
||||||
|
|
||||||
// Set up the new frontend.
|
// Set up the new frontend.
|
||||||
frontend = std::make_unique<GDBStub>(*this, system);
|
frontend = std::make_unique<GDBStub>(*this, system, debug_process.GetPointerUnsafe());
|
||||||
|
|
||||||
// Set the new state. This will tear down any existing state.
|
// Set the new state. This will tear down any existing state.
|
||||||
state = ConnectionState{
|
state = ConnectionState{
|
||||||
@ -194,15 +197,20 @@ private:
|
|||||||
UpdateActiveThread();
|
UpdateActiveThread();
|
||||||
|
|
||||||
if (state->info.type == SignalType::Watchpoint) {
|
if (state->info.type == SignalType::Watchpoint) {
|
||||||
frontend->Watchpoint(state->active_thread, *state->info.watchpoint);
|
frontend->Watchpoint(std::addressof(*state->active_thread),
|
||||||
|
*state->info.watchpoint);
|
||||||
} else {
|
} else {
|
||||||
frontend->Stopped(state->active_thread);
|
frontend->Stopped(std::addressof(*state->active_thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SignalType::ShuttingDown:
|
case SignalType::ShuttingDown:
|
||||||
frontend->ShuttingDown();
|
frontend->ShuttingDown();
|
||||||
|
|
||||||
|
// Release members.
|
||||||
|
state->active_thread.Reset(nullptr);
|
||||||
|
debug_process.Reset(nullptr);
|
||||||
|
|
||||||
// Wait for emulation to shut down gracefully now.
|
// Wait for emulation to shut down gracefully now.
|
||||||
state->signal_pipe.close();
|
state->signal_pipe.close();
|
||||||
state->client_socket.shutdown(boost::asio::socket_base::shutdown_both);
|
state->client_socket.shutdown(boost::asio::socket_base::shutdown_both);
|
||||||
@ -222,7 +230,7 @@ private:
|
|||||||
stopped = true;
|
stopped = true;
|
||||||
PauseEmulation();
|
PauseEmulation();
|
||||||
UpdateActiveThread();
|
UpdateActiveThread();
|
||||||
frontend->Stopped(state->active_thread);
|
frontend->Stopped(state->active_thread.GetPointerUnsafe());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DebuggerAction::Continue:
|
case DebuggerAction::Continue:
|
||||||
@ -232,7 +240,7 @@ private:
|
|||||||
MarkResumed([&] {
|
MarkResumed([&] {
|
||||||
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
||||||
state->active_thread->Resume(Kernel::SuspendType::Debug);
|
state->active_thread->Resume(Kernel::SuspendType::Debug);
|
||||||
ResumeEmulation(state->active_thread);
|
ResumeEmulation(state->active_thread.GetPointerUnsafe());
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case DebuggerAction::StepThreadLocked: {
|
case DebuggerAction::StepThreadLocked: {
|
||||||
@ -255,6 +263,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PauseEmulation() {
|
void PauseEmulation() {
|
||||||
|
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
||||||
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
||||||
|
|
||||||
// Put all threads to sleep on next scheduler round.
|
// Put all threads to sleep on next scheduler round.
|
||||||
@ -264,6 +273,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ResumeEmulation(Kernel::KThread* except = nullptr) {
|
void ResumeEmulation(Kernel::KThread* except = nullptr) {
|
||||||
|
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
||||||
|
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
||||||
|
|
||||||
// Wake up all threads.
|
// Wake up all threads.
|
||||||
for (auto& thread : ThreadList()) {
|
for (auto& thread : ThreadList()) {
|
||||||
if (std::addressof(thread) == except) {
|
if (std::addressof(thread) == except) {
|
||||||
@ -277,15 +289,16 @@ private:
|
|||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void MarkResumed(Callback&& cb) {
|
void MarkResumed(Callback&& cb) {
|
||||||
Kernel::KScopedSchedulerLock sl{system.Kernel()};
|
|
||||||
stopped = false;
|
stopped = false;
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateActiveThread() {
|
void UpdateActiveThread() {
|
||||||
|
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
|
||||||
|
|
||||||
auto& threads{ThreadList()};
|
auto& threads{ThreadList()};
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
if (std::addressof(thread) == state->active_thread) {
|
if (std::addressof(thread) == state->active_thread.GetPointerUnsafe()) {
|
||||||
// Thread is still alive, no need to update.
|
// Thread is still alive, no need to update.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -293,12 +306,18 @@ private:
|
|||||||
state->active_thread = std::addressof(threads.front());
|
state->active_thread = std::addressof(threads.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetDebugProcess() {
|
||||||
|
debug_process = std::move(system.Kernel().GetProcessList().back());
|
||||||
|
}
|
||||||
|
|
||||||
Kernel::KProcess::ThreadList& ThreadList() {
|
Kernel::KProcess::ThreadList& ThreadList() {
|
||||||
return system.ApplicationProcess()->GetThreadList();
|
return debug_process->GetThreadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
System& system;
|
System& system;
|
||||||
|
Kernel::KScopedAutoObject<Kernel::KProcess> debug_process;
|
||||||
std::unique_ptr<DebuggerFrontend> frontend;
|
std::unique_ptr<DebuggerFrontend> frontend;
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
@ -310,7 +329,7 @@ private:
|
|||||||
boost::process::async_pipe signal_pipe;
|
boost::process::async_pipe signal_pipe;
|
||||||
|
|
||||||
SignalInfo info;
|
SignalInfo info;
|
||||||
Kernel::KThread* active_thread;
|
Kernel::KScopedAutoObject<Kernel::KThread> active_thread;
|
||||||
std::array<u8, 4096> client_data;
|
std::array<u8, 4096> client_data;
|
||||||
bool pipe_data;
|
bool pipe_data;
|
||||||
};
|
};
|
||||||
|
@ -108,9 +108,9 @@ static std::string EscapeXML(std::string_view data) {
|
|||||||
return escaped;
|
return escaped;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDBStub::GDBStub(DebuggerBackend& backend_, Core::System& system_)
|
GDBStub::GDBStub(DebuggerBackend& backend_, Core::System& system_, Kernel::KProcess* debug_process_)
|
||||||
: DebuggerFrontend(backend_), system{system_} {
|
: DebuggerFrontend(backend_), system{system_}, debug_process{debug_process_} {
|
||||||
if (system.ApplicationProcess()->Is64Bit()) {
|
if (GetProcess()->Is64Bit()) {
|
||||||
arch = std::make_unique<GDBStubA64>();
|
arch = std::make_unique<GDBStubA64>();
|
||||||
} else {
|
} else {
|
||||||
arch = std::make_unique<GDBStubA32>();
|
arch = std::make_unique<GDBStubA32>();
|
||||||
@ -276,7 +276,7 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
|
||||||
|
|
||||||
std::vector<u8> mem(size);
|
std::vector<u8> mem(size);
|
||||||
if (system.ApplicationMemory().ReadBlock(addr, mem.data(), size)) {
|
if (GetMemory().ReadBlock(addr, mem.data(), size)) {
|
||||||
// Restore any bytes belonging to replaced instructions.
|
// Restore any bytes belonging to replaced instructions.
|
||||||
auto it = replaced_instructions.lower_bound(addr);
|
auto it = replaced_instructions.lower_bound(addr);
|
||||||
for (; it != replaced_instructions.end() && it->first < addr + size; it++) {
|
for (; it != replaced_instructions.end() && it->first < addr + size; it++) {
|
||||||
@ -310,8 +310,8 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||||||
const auto mem_substr{std::string_view(command).substr(mem_sep)};
|
const auto mem_substr{std::string_view(command).substr(mem_sep)};
|
||||||
const auto mem{Common::HexStringToVector(mem_substr, false)};
|
const auto mem{Common::HexStringToVector(mem_substr, false)};
|
||||||
|
|
||||||
if (system.ApplicationMemory().WriteBlock(addr, mem.data(), size)) {
|
if (GetMemory().WriteBlock(addr, mem.data(), size)) {
|
||||||
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, size);
|
Core::InvalidateInstructionCacheRange(GetProcess(), addr, size);
|
||||||
SendReply(GDB_STUB_REPLY_OK);
|
SendReply(GDB_STUB_REPLY_OK);
|
||||||
} else {
|
} else {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
@ -353,7 +353,7 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||||||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||||
|
|
||||||
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
if (!GetMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -362,22 +362,20 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BreakpointType::Software:
|
case BreakpointType::Software:
|
||||||
replaced_instructions[addr] = system.ApplicationMemory().Read32(addr);
|
replaced_instructions[addr] = GetMemory().Read32(addr);
|
||||||
system.ApplicationMemory().Write32(addr, arch->BreakpointInstruction());
|
GetMemory().Write32(addr, arch->BreakpointInstruction());
|
||||||
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, sizeof(u32));
|
Core::InvalidateInstructionCacheRange(GetProcess(), addr, sizeof(u32));
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
success = GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
||||||
Kernel::DebugWatchpointType::Write);
|
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
success = GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
||||||
Kernel::DebugWatchpointType::Read);
|
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success = system.ApplicationProcess()->InsertWatchpoint(
|
success =
|
||||||
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
GetProcess()->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
@ -400,7 +398,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||||||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||||
|
|
||||||
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
if (!GetMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||||
SendReply(GDB_STUB_REPLY_ERR);
|
SendReply(GDB_STUB_REPLY_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -411,24 +409,22 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||||||
case BreakpointType::Software: {
|
case BreakpointType::Software: {
|
||||||
const auto orig_insn{replaced_instructions.find(addr)};
|
const auto orig_insn{replaced_instructions.find(addr)};
|
||||||
if (orig_insn != replaced_instructions.end()) {
|
if (orig_insn != replaced_instructions.end()) {
|
||||||
system.ApplicationMemory().Write32(addr, orig_insn->second);
|
GetMemory().Write32(addr, orig_insn->second);
|
||||||
Core::InvalidateInstructionCacheRange(system.ApplicationProcess(), addr, sizeof(u32));
|
Core::InvalidateInstructionCacheRange(GetProcess(), addr, sizeof(u32));
|
||||||
replaced_instructions.erase(addr);
|
replaced_instructions.erase(addr);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
success = GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
||||||
Kernel::DebugWatchpointType::Write);
|
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
success = GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
||||||
Kernel::DebugWatchpointType::Read);
|
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success = system.ApplicationProcess()->RemoveWatchpoint(
|
success =
|
||||||
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
GetProcess()->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
@ -466,10 +462,10 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
const auto target_xml{arch->GetTargetXML()};
|
const auto target_xml{arch->GetTargetXML()};
|
||||||
SendReply(PaginateBuffer(target_xml, command.substr(30)));
|
SendReply(PaginateBuffer(target_xml, command.substr(30)));
|
||||||
} else if (command.starts_with("Offsets")) {
|
} else if (command.starts_with("Offsets")) {
|
||||||
const auto main_offset = Core::FindMainModuleEntrypoint(system.ApplicationProcess());
|
const auto main_offset = Core::FindMainModuleEntrypoint(GetProcess());
|
||||||
SendReply(fmt::format("TextSeg={:x}", GetInteger(main_offset)));
|
SendReply(fmt::format("TextSeg={:x}", GetInteger(main_offset)));
|
||||||
} else if (command.starts_with("Xfer:libraries:read::")) {
|
} else if (command.starts_with("Xfer:libraries:read::")) {
|
||||||
auto modules = Core::FindModules(system.ApplicationProcess());
|
auto modules = Core::FindModules(GetProcess());
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer += R"(<?xml version="1.0"?>)";
|
buffer += R"(<?xml version="1.0"?>)";
|
||||||
@ -483,7 +479,7 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
SendReply(PaginateBuffer(buffer, command.substr(21)));
|
SendReply(PaginateBuffer(buffer, command.substr(21)));
|
||||||
} else if (command.starts_with("fThreadInfo")) {
|
} else if (command.starts_with("fThreadInfo")) {
|
||||||
// beginning of list
|
// beginning of list
|
||||||
const auto& threads = system.ApplicationProcess()->GetThreadList();
|
const auto& threads = GetProcess()->GetThreadList();
|
||||||
std::vector<std::string> thread_ids;
|
std::vector<std::string> thread_ids;
|
||||||
for (const auto& thread : threads) {
|
for (const auto& thread : threads) {
|
||||||
thread_ids.push_back(fmt::format("{:x}", thread.GetThreadId()));
|
thread_ids.push_back(fmt::format("{:x}", thread.GetThreadId()));
|
||||||
@ -497,7 +493,7 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||||||
buffer += R"(<?xml version="1.0"?>)";
|
buffer += R"(<?xml version="1.0"?>)";
|
||||||
buffer += "<threads>";
|
buffer += "<threads>";
|
||||||
|
|
||||||
const auto& threads = system.ApplicationProcess()->GetThreadList();
|
const auto& threads = GetProcess()->GetThreadList();
|
||||||
for (const auto& thread : threads) {
|
for (const auto& thread : threads) {
|
||||||
auto thread_name{Core::GetThreadName(&thread)};
|
auto thread_name{Core::GetThreadName(&thread)};
|
||||||
if (!thread_name) {
|
if (!thread_name) {
|
||||||
@ -559,28 +555,28 @@ void GDBStub::HandleVCont(std::string_view command, std::vector<DebuggerAction>&
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr std::array<std::pair<const char*, Kernel::Svc::MemoryState>, 22> MemoryStateNames{{
|
constexpr std::array<std::pair<const char*, Kernel::Svc::MemoryState>, 22> MemoryStateNames{{
|
||||||
{"----- Free -----", Kernel::Svc::MemoryState::Free},
|
{"----- Free ------", Kernel::Svc::MemoryState::Free},
|
||||||
{"Io ", Kernel::Svc::MemoryState::Io},
|
{"Io ", Kernel::Svc::MemoryState::Io},
|
||||||
{"Static ", Kernel::Svc::MemoryState::Static},
|
{"Static ", Kernel::Svc::MemoryState::Static},
|
||||||
{"Code ", Kernel::Svc::MemoryState::Code},
|
{"Code ", Kernel::Svc::MemoryState::Code},
|
||||||
{"CodeData ", Kernel::Svc::MemoryState::CodeData},
|
{"CodeData ", Kernel::Svc::MemoryState::CodeData},
|
||||||
{"Normal ", Kernel::Svc::MemoryState::Normal},
|
{"Normal ", Kernel::Svc::MemoryState::Normal},
|
||||||
{"Shared ", Kernel::Svc::MemoryState::Shared},
|
{"Shared ", Kernel::Svc::MemoryState::Shared},
|
||||||
{"AliasCode ", Kernel::Svc::MemoryState::AliasCode},
|
{"AliasCode ", Kernel::Svc::MemoryState::AliasCode},
|
||||||
{"AliasCodeData ", Kernel::Svc::MemoryState::AliasCodeData},
|
{"AliasCodeData ", Kernel::Svc::MemoryState::AliasCodeData},
|
||||||
{"Ipc ", Kernel::Svc::MemoryState::Ipc},
|
{"Ipc ", Kernel::Svc::MemoryState::Ipc},
|
||||||
{"Stack ", Kernel::Svc::MemoryState::Stack},
|
{"Stack ", Kernel::Svc::MemoryState::Stack},
|
||||||
{"ThreadLocal ", Kernel::Svc::MemoryState::ThreadLocal},
|
{"ThreadLocal ", Kernel::Svc::MemoryState::ThreadLocal},
|
||||||
{"Transfered ", Kernel::Svc::MemoryState::Transfered},
|
{"Transferred ", Kernel::Svc::MemoryState::Transferred},
|
||||||
{"SharedTransfered", Kernel::Svc::MemoryState::SharedTransfered},
|
{"SharedTransferred", Kernel::Svc::MemoryState::SharedTransferred},
|
||||||
{"SharedCode ", Kernel::Svc::MemoryState::SharedCode},
|
{"SharedCode ", Kernel::Svc::MemoryState::SharedCode},
|
||||||
{"Inaccessible ", Kernel::Svc::MemoryState::Inaccessible},
|
{"Inaccessible ", Kernel::Svc::MemoryState::Inaccessible},
|
||||||
{"NonSecureIpc ", Kernel::Svc::MemoryState::NonSecureIpc},
|
{"NonSecureIpc ", Kernel::Svc::MemoryState::NonSecureIpc},
|
||||||
{"NonDeviceIpc ", Kernel::Svc::MemoryState::NonDeviceIpc},
|
{"NonDeviceIpc ", Kernel::Svc::MemoryState::NonDeviceIpc},
|
||||||
{"Kernel ", Kernel::Svc::MemoryState::Kernel},
|
{"Kernel ", Kernel::Svc::MemoryState::Kernel},
|
||||||
{"GeneratedCode ", Kernel::Svc::MemoryState::GeneratedCode},
|
{"GeneratedCode ", Kernel::Svc::MemoryState::GeneratedCode},
|
||||||
{"CodeOut ", Kernel::Svc::MemoryState::CodeOut},
|
{"CodeOut ", Kernel::Svc::MemoryState::CodeOut},
|
||||||
{"Coverage ", Kernel::Svc::MemoryState::Coverage},
|
{"Coverage ", Kernel::Svc::MemoryState::Coverage},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static constexpr const char* GetMemoryStateName(Kernel::Svc::MemoryState state) {
|
static constexpr const char* GetMemoryStateName(Kernel::Svc::MemoryState state) {
|
||||||
@ -613,7 +609,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
|
|||||||
std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
|
std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
|
||||||
std::string reply;
|
std::string reply;
|
||||||
|
|
||||||
auto* process = system.ApplicationProcess();
|
auto* process = GetProcess();
|
||||||
auto& page_table = process->GetPageTable();
|
auto& page_table = process->GetPageTable();
|
||||||
|
|
||||||
const char* commands = "Commands:\n"
|
const char* commands = "Commands:\n"
|
||||||
@ -714,7 +710,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
|
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
|
||||||
auto& threads{system.ApplicationProcess()->GetThreadList()};
|
auto& threads{GetProcess()->GetThreadList()};
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
if (thread.GetThreadId() == thread_id) {
|
if (thread.GetThreadId() == thread_id) {
|
||||||
return std::addressof(thread);
|
return std::addressof(thread);
|
||||||
@ -783,4 +779,12 @@ void GDBStub::SendStatus(char status) {
|
|||||||
backend.WriteToClient(buf);
|
backend.WriteToClient(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KProcess* GDBStub::GetProcess() {
|
||||||
|
return debug_process;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Memory::Memory& GDBStub::GetMemory() {
|
||||||
|
return GetProcess()->GetMemory();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -12,13 +12,22 @@
|
|||||||
#include "core/debugger/debugger_interface.h"
|
#include "core/debugger/debugger_interface.h"
|
||||||
#include "core/debugger/gdbstub_arch.h"
|
#include "core/debugger/gdbstub_arch.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Core::Memory {
|
||||||
|
class Memory;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class System;
|
class System;
|
||||||
|
|
||||||
class GDBStub : public DebuggerFrontend {
|
class GDBStub : public DebuggerFrontend {
|
||||||
public:
|
public:
|
||||||
explicit GDBStub(DebuggerBackend& backend, Core::System& system);
|
explicit GDBStub(DebuggerBackend& backend, Core::System& system,
|
||||||
|
Kernel::KProcess* debug_process);
|
||||||
~GDBStub() override;
|
~GDBStub() override;
|
||||||
|
|
||||||
void Connected() override;
|
void Connected() override;
|
||||||
@ -42,8 +51,12 @@ private:
|
|||||||
void SendReply(std::string_view data);
|
void SendReply(std::string_view data);
|
||||||
void SendStatus(char status);
|
void SendStatus(char status);
|
||||||
|
|
||||||
|
Kernel::KProcess* GetProcess();
|
||||||
|
Core::Memory::Memory& GetMemory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
|
Kernel::KProcess* debug_process;
|
||||||
std::unique_ptr<GDBStubArch> arch;
|
std::unique_ptr<GDBStubArch> arch;
|
||||||
std::vector<char> current_command;
|
std::vector<char> current_command;
|
||||||
std::map<VAddr, u32> replaced_instructions;
|
std::map<VAddr, u32> replaced_instructions;
|
||||||
|
@ -31,6 +31,12 @@ public:
|
|||||||
DramMemoryMap::Base;
|
DramMemoryMap::Base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
PAddr GetRawPhysicalAddr(const T* ptr) const {
|
||||||
|
return static_cast<PAddr>(reinterpret_cast<uintptr_t>(ptr) -
|
||||||
|
reinterpret_cast<uintptr_t>(buffer.BackingBasePointer()));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* GetPointer(Common::PhysicalAddress addr) {
|
T* GetPointer(Common::PhysicalAddress addr) {
|
||||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
||||||
@ -43,6 +49,16 @@ public:
|
|||||||
(GetInteger(addr) - DramMemoryMap::Base));
|
(GetInteger(addr) - DramMemoryMap::Base));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T* GetPointerFromRaw(PAddr addr) {
|
||||||
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() + addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const T* GetPointerFromRaw(PAddr addr) const {
|
||||||
|
return reinterpret_cast<T*>(buffer.BackingBasePointer() + addr);
|
||||||
|
}
|
||||||
|
|
||||||
Common::HostMemory buffer;
|
Common::HostMemory buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
211
src/core/device_memory_manager.h
Normal file
211
src/core/device_memory_manager.h
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
|
#include <deque>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "common/scratch_buffer.h"
|
||||||
|
#include "common/virtual_buffer.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
|
||||||
|
constexpr size_t DEVICE_PAGEBITS = 12ULL;
|
||||||
|
constexpr size_t DEVICE_PAGESIZE = 1ULL << DEVICE_PAGEBITS;
|
||||||
|
constexpr size_t DEVICE_PAGEMASK = DEVICE_PAGESIZE - 1ULL;
|
||||||
|
|
||||||
|
class DeviceMemory;
|
||||||
|
|
||||||
|
namespace Memory {
|
||||||
|
class Memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename DTraits>
|
||||||
|
struct DeviceMemoryManagerAllocator;
|
||||||
|
|
||||||
|
struct Asid {
|
||||||
|
size_t id;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
class DeviceMemoryManager {
|
||||||
|
using DeviceInterface = typename Traits::DeviceInterface;
|
||||||
|
using DeviceMethods = typename Traits::DeviceMethods;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DeviceMemoryManager(const DeviceMemory& device_memory);
|
||||||
|
~DeviceMemoryManager();
|
||||||
|
|
||||||
|
void BindInterface(DeviceInterface* device_inter);
|
||||||
|
|
||||||
|
DAddr Allocate(size_t size);
|
||||||
|
void AllocateFixed(DAddr start, size_t size);
|
||||||
|
void Free(DAddr start, size_t size);
|
||||||
|
|
||||||
|
void Map(DAddr address, VAddr virtual_address, size_t size, Asid asid, bool track = false);
|
||||||
|
|
||||||
|
void Unmap(DAddr address, size_t size);
|
||||||
|
|
||||||
|
void TrackContinuityImpl(DAddr address, VAddr virtual_address, size_t size, Asid asid);
|
||||||
|
void TrackContinuity(DAddr address, VAddr virtual_address, size_t size, Asid asid) {
|
||||||
|
std::scoped_lock lk(mapping_guard);
|
||||||
|
TrackContinuityImpl(address, virtual_address, size, asid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write / Read
|
||||||
|
template <typename T>
|
||||||
|
T* GetPointer(DAddr address);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const T* GetPointer(DAddr address) const;
|
||||||
|
|
||||||
|
template <typename Func>
|
||||||
|
void ApplyOpOnPAddr(PAddr address, Common::ScratchBuffer<u32>& buffer, Func&& operation) {
|
||||||
|
DAddr subbits = static_cast<DAddr>(address & page_mask);
|
||||||
|
const u32 base = compressed_device_addr[(address >> page_bits)];
|
||||||
|
if ((base >> MULTI_FLAG_BITS) == 0) [[likely]] {
|
||||||
|
const DAddr d_address = (static_cast<DAddr>(base) << page_bits) + subbits;
|
||||||
|
operation(d_address);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InnerGatherDeviceAddresses(buffer, address);
|
||||||
|
for (u32 value : buffer) {
|
||||||
|
operation((static_cast<DAddr>(value) << page_bits) + subbits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Func>
|
||||||
|
void ApplyOpOnPointer(const u8* p, Common::ScratchBuffer<u32>& buffer, Func&& operation) {
|
||||||
|
PAddr address = GetRawPhysicalAddr<u8>(p);
|
||||||
|
ApplyOpOnPAddr(address, buffer, operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
PAddr GetPhysicalRawAddressFromDAddr(DAddr address) const {
|
||||||
|
PAddr subbits = static_cast<PAddr>(address & page_mask);
|
||||||
|
auto paddr = compressed_physical_ptr[(address >> page_bits)];
|
||||||
|
if (paddr == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (static_cast<PAddr>(paddr - 1) << page_bits) + subbits;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Write(DAddr address, T value);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T Read(DAddr address) const;
|
||||||
|
|
||||||
|
u8* GetSpan(const DAddr src_addr, const std::size_t size);
|
||||||
|
const u8* GetSpan(const DAddr src_addr, const std::size_t size) const;
|
||||||
|
|
||||||
|
void ReadBlock(DAddr address, void* dest_pointer, size_t size);
|
||||||
|
void ReadBlockUnsafe(DAddr address, void* dest_pointer, size_t size);
|
||||||
|
void WriteBlock(DAddr address, const void* src_pointer, size_t size);
|
||||||
|
void WriteBlockUnsafe(DAddr address, const void* src_pointer, size_t size);
|
||||||
|
|
||||||
|
Asid RegisterProcess(Memory::Memory* memory);
|
||||||
|
void UnregisterProcess(Asid id);
|
||||||
|
|
||||||
|
void UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta);
|
||||||
|
|
||||||
|
static constexpr size_t AS_BITS = Traits::device_virtual_bits;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr size_t device_virtual_bits = Traits::device_virtual_bits;
|
||||||
|
static constexpr size_t device_as_size = 1ULL << device_virtual_bits;
|
||||||
|
static constexpr size_t physical_min_bits = 32;
|
||||||
|
static constexpr size_t physical_max_bits = 33;
|
||||||
|
static constexpr size_t page_bits = 12;
|
||||||
|
static constexpr size_t page_size = 1ULL << page_bits;
|
||||||
|
static constexpr size_t page_mask = page_size - 1ULL;
|
||||||
|
static constexpr u32 physical_address_base = 1U << page_bits;
|
||||||
|
static constexpr u32 MULTI_FLAG_BITS = 31;
|
||||||
|
static constexpr u32 MULTI_FLAG = 1U << MULTI_FLAG_BITS;
|
||||||
|
static constexpr u32 MULTI_MASK = ~MULTI_FLAG;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T* GetPointerFromRaw(PAddr addr) {
|
||||||
|
return reinterpret_cast<T*>(physical_base + addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const T* GetPointerFromRaw(PAddr addr) const {
|
||||||
|
return reinterpret_cast<T*>(physical_base + addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
PAddr GetRawPhysicalAddr(const T* ptr) const {
|
||||||
|
return static_cast<PAddr>(reinterpret_cast<uintptr_t>(ptr) - physical_base);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WalkBlock(const DAddr addr, const std::size_t size, auto on_unmapped, auto on_memory,
|
||||||
|
auto increment);
|
||||||
|
|
||||||
|
void InnerGatherDeviceAddresses(Common::ScratchBuffer<u32>& buffer, PAddr address);
|
||||||
|
|
||||||
|
std::unique_ptr<DeviceMemoryManagerAllocator<Traits>> impl;
|
||||||
|
|
||||||
|
const uintptr_t physical_base;
|
||||||
|
DeviceInterface* device_inter;
|
||||||
|
Common::VirtualBuffer<u32> compressed_physical_ptr;
|
||||||
|
Common::VirtualBuffer<u32> compressed_device_addr;
|
||||||
|
Common::VirtualBuffer<u32> continuity_tracker;
|
||||||
|
|
||||||
|
// Process memory interfaces
|
||||||
|
|
||||||
|
std::deque<size_t> id_pool;
|
||||||
|
std::deque<Memory::Memory*> registered_processes;
|
||||||
|
|
||||||
|
// Memory protection management
|
||||||
|
|
||||||
|
static constexpr size_t guest_max_as_bits = 39;
|
||||||
|
static constexpr size_t guest_as_size = 1ULL << guest_max_as_bits;
|
||||||
|
static constexpr size_t guest_mask = guest_as_size - 1ULL;
|
||||||
|
static constexpr size_t asid_start_bit = guest_max_as_bits;
|
||||||
|
|
||||||
|
std::pair<Asid, VAddr> ExtractCPUBacking(size_t page_index) {
|
||||||
|
auto content = cpu_backing_address[page_index];
|
||||||
|
const VAddr address = content & guest_mask;
|
||||||
|
const Asid asid{static_cast<size_t>(content >> asid_start_bit)};
|
||||||
|
return std::make_pair(asid, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InsertCPUBacking(size_t page_index, VAddr address, Asid asid) {
|
||||||
|
cpu_backing_address[page_index] = address | (asid.id << asid_start_bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
Common::VirtualBuffer<VAddr> cpu_backing_address;
|
||||||
|
static constexpr size_t subentries = 8 / sizeof(u8);
|
||||||
|
static constexpr size_t subentries_mask = subentries - 1;
|
||||||
|
class CounterEntry final {
|
||||||
|
public:
|
||||||
|
CounterEntry() = default;
|
||||||
|
|
||||||
|
std::atomic_uint8_t& Count(std::size_t page) {
|
||||||
|
return values[page & subentries_mask];
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::atomic_uint8_t& Count(std::size_t page) const {
|
||||||
|
return values[page & subentries_mask];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<std::atomic_uint8_t, subentries> values{};
|
||||||
|
};
|
||||||
|
static_assert(sizeof(CounterEntry) == subentries * sizeof(u8),
|
||||||
|
"CounterEntry should be 8 bytes!");
|
||||||
|
|
||||||
|
static constexpr size_t num_counter_entries =
|
||||||
|
(1ULL << (device_virtual_bits - page_bits)) / subentries;
|
||||||
|
using CachedPages = std::array<CounterEntry, num_counter_entries>;
|
||||||
|
std::unique_ptr<CachedPages> cached_pages;
|
||||||
|
std::mutex counter_guard;
|
||||||
|
std::mutex mapping_guard;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
582
src/core/device_memory_manager.inc
Normal file
582
src/core/device_memory_manager.inc
Normal file
@ -0,0 +1,582 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "common/address_space.h"
|
||||||
|
#include "common/address_space.inc"
|
||||||
|
#include "common/alignment.h"
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/div_ceil.h"
|
||||||
|
#include "common/scope_exit.h"
|
||||||
|
#include "common/settings.h"
|
||||||
|
#include "core/device_memory.h"
|
||||||
|
#include "core/device_memory_manager.h"
|
||||||
|
#include "core/memory.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class MultiAddressContainer {
|
||||||
|
public:
|
||||||
|
MultiAddressContainer() = default;
|
||||||
|
~MultiAddressContainer() = default;
|
||||||
|
|
||||||
|
void GatherValues(u32 start_entry, Common::ScratchBuffer<u32>& buffer) {
|
||||||
|
buffer.resize(8);
|
||||||
|
buffer.resize(0);
|
||||||
|
size_t index = 0;
|
||||||
|
const auto add_value = [&](u32 value) {
|
||||||
|
buffer[index] = value;
|
||||||
|
index++;
|
||||||
|
buffer.resize(index);
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 iter_entry = start_entry;
|
||||||
|
Entry* current = &storage[iter_entry - 1];
|
||||||
|
add_value(current->value);
|
||||||
|
while (current->next_entry != 0) {
|
||||||
|
iter_entry = current->next_entry;
|
||||||
|
current = &storage[iter_entry - 1];
|
||||||
|
add_value(current->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 Register(u32 value) {
|
||||||
|
return RegisterImplementation(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Register(u32 value, u32 start_entry) {
|
||||||
|
auto entry_id = RegisterImplementation(value);
|
||||||
|
u32 iter_entry = start_entry;
|
||||||
|
Entry* current = &storage[iter_entry - 1];
|
||||||
|
while (current->next_entry != 0) {
|
||||||
|
iter_entry = current->next_entry;
|
||||||
|
current = &storage[iter_entry - 1];
|
||||||
|
}
|
||||||
|
current->next_entry = entry_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<bool, u32> Unregister(u32 value, u32 start_entry) {
|
||||||
|
u32 iter_entry = start_entry;
|
||||||
|
Entry* previous{};
|
||||||
|
Entry* current = &storage[iter_entry - 1];
|
||||||
|
Entry* next{};
|
||||||
|
bool more_than_one_remaining = false;
|
||||||
|
u32 result_start{start_entry};
|
||||||
|
size_t count = 0;
|
||||||
|
while (current->value != value) {
|
||||||
|
count++;
|
||||||
|
previous = current;
|
||||||
|
iter_entry = current->next_entry;
|
||||||
|
current = &storage[iter_entry - 1];
|
||||||
|
}
|
||||||
|
// Find next
|
||||||
|
u32 next_entry = current->next_entry;
|
||||||
|
if (next_entry != 0) {
|
||||||
|
next = &storage[next_entry - 1];
|
||||||
|
more_than_one_remaining = next->next_entry != 0 || previous != nullptr;
|
||||||
|
}
|
||||||
|
if (previous) {
|
||||||
|
previous->next_entry = next_entry;
|
||||||
|
} else {
|
||||||
|
result_start = next_entry;
|
||||||
|
}
|
||||||
|
free_entries.emplace_back(iter_entry);
|
||||||
|
return std::make_pair(more_than_one_remaining || count > 1, result_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 ReleaseEntry(u32 start_entry) {
|
||||||
|
Entry* current = &storage[start_entry - 1];
|
||||||
|
free_entries.emplace_back(start_entry);
|
||||||
|
return current->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
u32 RegisterImplementation(u32 value) {
|
||||||
|
auto entry_id = GetNewEntry();
|
||||||
|
auto& entry = storage[entry_id - 1];
|
||||||
|
entry.next_entry = 0;
|
||||||
|
entry.value = value;
|
||||||
|
return entry_id;
|
||||||
|
}
|
||||||
|
u32 GetNewEntry() {
|
||||||
|
if (!free_entries.empty()) {
|
||||||
|
u32 result = free_entries.front();
|
||||||
|
free_entries.pop_front();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
storage.emplace_back();
|
||||||
|
u32 new_entry = static_cast<u32>(storage.size());
|
||||||
|
return new_entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Entry {
|
||||||
|
u32 next_entry{};
|
||||||
|
u32 value{};
|
||||||
|
};
|
||||||
|
|
||||||
|
std::deque<Entry> storage;
|
||||||
|
std::deque<u32> free_entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EmptyAllocator {
|
||||||
|
EmptyAllocator([[maybe_unused]] DAddr address) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
template <typename DTraits>
|
||||||
|
struct DeviceMemoryManagerAllocator {
|
||||||
|
static constexpr size_t device_virtual_bits = DTraits::device_virtual_bits;
|
||||||
|
static constexpr DAddr first_address = 1ULL << Memory::YUZU_PAGEBITS;
|
||||||
|
static constexpr DAddr max_device_area = 1ULL << device_virtual_bits;
|
||||||
|
|
||||||
|
DeviceMemoryManagerAllocator() : main_allocator(first_address) {}
|
||||||
|
|
||||||
|
Common::FlatAllocator<DAddr, 0, device_virtual_bits> main_allocator;
|
||||||
|
MultiAddressContainer multi_dev_address;
|
||||||
|
|
||||||
|
/// Returns true when vaddr -> vaddr+size is fully contained in the buffer
|
||||||
|
template <bool pin_area>
|
||||||
|
[[nodiscard]] bool IsInBounds(VAddr addr, u64 size) const noexcept {
|
||||||
|
return addr >= 0 && addr + size <= max_device_area;
|
||||||
|
}
|
||||||
|
|
||||||
|
DAddr Allocate(size_t size) {
|
||||||
|
return main_allocator.Allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AllocateFixed(DAddr b_address, size_t b_size) {
|
||||||
|
main_allocator.AllocateFixed(b_address, b_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Free(DAddr b_address, size_t b_size) {
|
||||||
|
main_allocator.Free(b_address, b_size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
DeviceMemoryManager<Traits>::DeviceMemoryManager(const DeviceMemory& device_memory_)
|
||||||
|
: physical_base{reinterpret_cast<const uintptr_t>(device_memory_.buffer.BackingBasePointer())},
|
||||||
|
device_inter{nullptr}, compressed_physical_ptr(device_as_size >> Memory::YUZU_PAGEBITS),
|
||||||
|
compressed_device_addr(1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
|
||||||
|
Settings::MemoryLayout::Memory_4Gb
|
||||||
|
? physical_min_bits
|
||||||
|
: physical_max_bits) -
|
||||||
|
Memory::YUZU_PAGEBITS)),
|
||||||
|
continuity_tracker(device_as_size >> Memory::YUZU_PAGEBITS),
|
||||||
|
cpu_backing_address(device_as_size >> Memory::YUZU_PAGEBITS) {
|
||||||
|
impl = std::make_unique<DeviceMemoryManagerAllocator<Traits>>();
|
||||||
|
cached_pages = std::make_unique<CachedPages>();
|
||||||
|
|
||||||
|
const size_t total_virtual = device_as_size >> Memory::YUZU_PAGEBITS;
|
||||||
|
for (size_t i = 0; i < total_virtual; i++) {
|
||||||
|
compressed_physical_ptr[i] = 0;
|
||||||
|
continuity_tracker[i] = 1;
|
||||||
|
cpu_backing_address[i] = 0;
|
||||||
|
}
|
||||||
|
const size_t total_phys = 1ULL << ((Settings::values.memory_layout_mode.GetValue() ==
|
||||||
|
Settings::MemoryLayout::Memory_4Gb
|
||||||
|
? physical_min_bits
|
||||||
|
: physical_max_bits) -
|
||||||
|
Memory::YUZU_PAGEBITS);
|
||||||
|
for (size_t i = 0; i < total_phys; i++) {
|
||||||
|
compressed_device_addr[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
DeviceMemoryManager<Traits>::~DeviceMemoryManager() = default;
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::BindInterface(DeviceInterface* device_inter_) {
|
||||||
|
device_inter = device_inter_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
DAddr DeviceMemoryManager<Traits>::Allocate(size_t size) {
|
||||||
|
return impl->Allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::AllocateFixed(DAddr start, size_t size) {
|
||||||
|
return impl->AllocateFixed(start, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::Free(DAddr start, size_t size) {
|
||||||
|
impl->Free(start, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::Map(DAddr address, VAddr virtual_address, size_t size,
|
||||||
|
Asid asid, bool track) {
|
||||||
|
Core::Memory::Memory* process_memory = registered_processes[asid.id];
|
||||||
|
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
||||||
|
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
||||||
|
std::scoped_lock lk(mapping_guard);
|
||||||
|
for (size_t i = 0; i < num_pages; i++) {
|
||||||
|
const VAddr new_vaddress = virtual_address + i * Memory::YUZU_PAGESIZE;
|
||||||
|
auto* ptr = process_memory->GetPointerSilent(Common::ProcessAddress(new_vaddress));
|
||||||
|
if (ptr == nullptr) [[unlikely]] {
|
||||||
|
compressed_physical_ptr[start_page_d + i] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto phys_addr = static_cast<u32>(GetRawPhysicalAddr(ptr) >> Memory::YUZU_PAGEBITS) + 1U;
|
||||||
|
compressed_physical_ptr[start_page_d + i] = phys_addr;
|
||||||
|
InsertCPUBacking(start_page_d + i, new_vaddress, asid);
|
||||||
|
const u32 base_dev = compressed_device_addr[phys_addr - 1U];
|
||||||
|
const u32 new_dev = static_cast<u32>(start_page_d + i);
|
||||||
|
if (base_dev == 0) [[likely]] {
|
||||||
|
compressed_device_addr[phys_addr - 1U] = new_dev;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
u32 start_id = base_dev & MULTI_MASK;
|
||||||
|
if ((base_dev >> MULTI_FLAG_BITS) == 0) {
|
||||||
|
start_id = impl->multi_dev_address.Register(base_dev);
|
||||||
|
compressed_device_addr[phys_addr - 1U] = MULTI_FLAG | start_id;
|
||||||
|
}
|
||||||
|
impl->multi_dev_address.Register(new_dev, start_id);
|
||||||
|
}
|
||||||
|
if (track) {
|
||||||
|
TrackContinuityImpl(address, virtual_address, size, asid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::Unmap(DAddr address, size_t size) {
|
||||||
|
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
||||||
|
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
||||||
|
device_inter->InvalidateRegion(address, size);
|
||||||
|
std::scoped_lock lk(mapping_guard);
|
||||||
|
for (size_t i = 0; i < num_pages; i++) {
|
||||||
|
auto phys_addr = compressed_physical_ptr[start_page_d + i];
|
||||||
|
compressed_physical_ptr[start_page_d + i] = 0;
|
||||||
|
cpu_backing_address[start_page_d + i] = 0;
|
||||||
|
if (phys_addr != 0) [[likely]] {
|
||||||
|
const u32 base_dev = compressed_device_addr[phys_addr - 1U];
|
||||||
|
if ((base_dev >> MULTI_FLAG_BITS) == 0) [[likely]] {
|
||||||
|
compressed_device_addr[phys_addr - 1] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto [more_entries, new_start] = impl->multi_dev_address.Unregister(
|
||||||
|
static_cast<u32>(start_page_d + i), base_dev & MULTI_MASK);
|
||||||
|
if (!more_entries) {
|
||||||
|
compressed_device_addr[phys_addr - 1] =
|
||||||
|
impl->multi_dev_address.ReleaseEntry(new_start);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
compressed_device_addr[phys_addr - 1] = new_start | MULTI_FLAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::TrackContinuityImpl(DAddr address, VAddr virtual_address,
|
||||||
|
size_t size, Asid asid) {
|
||||||
|
Core::Memory::Memory* process_memory = registered_processes[asid.id];
|
||||||
|
size_t start_page_d = address >> Memory::YUZU_PAGEBITS;
|
||||||
|
size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS;
|
||||||
|
uintptr_t last_ptr = 0;
|
||||||
|
size_t page_count = 1;
|
||||||
|
for (size_t i = num_pages; i > 0; i--) {
|
||||||
|
size_t index = i - 1;
|
||||||
|
const VAddr new_vaddress = virtual_address + index * Memory::YUZU_PAGESIZE;
|
||||||
|
const uintptr_t new_ptr = reinterpret_cast<uintptr_t>(
|
||||||
|
process_memory->GetPointerSilent(Common::ProcessAddress(new_vaddress)));
|
||||||
|
if (new_ptr + page_size == last_ptr) {
|
||||||
|
page_count++;
|
||||||
|
} else {
|
||||||
|
page_count = 1;
|
||||||
|
}
|
||||||
|
last_ptr = new_ptr;
|
||||||
|
continuity_tracker[start_page_d + index] = static_cast<u32>(page_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template <typename Traits>
|
||||||
|
u8* DeviceMemoryManager<Traits>::GetSpan(const DAddr src_addr, const std::size_t size) {
|
||||||
|
size_t page_index = src_addr >> page_bits;
|
||||||
|
size_t subbits = src_addr & page_mask;
|
||||||
|
if ((static_cast<size_t>(continuity_tracker[page_index]) << page_bits) >= size + subbits) {
|
||||||
|
return GetPointer<u8>(src_addr);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
const u8* DeviceMemoryManager<Traits>::GetSpan(const DAddr src_addr, const std::size_t size) const {
|
||||||
|
size_t page_index = src_addr >> page_bits;
|
||||||
|
size_t subbits = src_addr & page_mask;
|
||||||
|
if ((static_cast<size_t>(continuity_tracker[page_index]) << page_bits) >= size + subbits) {
|
||||||
|
return GetPointer<u8>(src_addr);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::InnerGatherDeviceAddresses(Common::ScratchBuffer<u32>& buffer,
|
||||||
|
PAddr address) {
|
||||||
|
size_t phys_addr = address >> page_bits;
|
||||||
|
std::scoped_lock lk(mapping_guard);
|
||||||
|
u32 backing = compressed_device_addr[phys_addr];
|
||||||
|
if ((backing >> MULTI_FLAG_BITS) != 0) {
|
||||||
|
impl->multi_dev_address.GatherValues(backing & MULTI_MASK, buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buffer.resize(1);
|
||||||
|
buffer[0] = backing;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
template <typename T>
|
||||||
|
T* DeviceMemoryManager<Traits>::GetPointer(DAddr address) {
|
||||||
|
const size_t index = address >> Memory::YUZU_PAGEBITS;
|
||||||
|
const size_t offset = address & Memory::YUZU_PAGEMASK;
|
||||||
|
auto phys_addr = compressed_physical_ptr[index];
|
||||||
|
if (phys_addr == 0) [[unlikely]] {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return GetPointerFromRaw<T>((static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) +
|
||||||
|
offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
template <typename T>
|
||||||
|
const T* DeviceMemoryManager<Traits>::GetPointer(DAddr address) const {
|
||||||
|
const size_t index = address >> Memory::YUZU_PAGEBITS;
|
||||||
|
const size_t offset = address & Memory::YUZU_PAGEMASK;
|
||||||
|
auto phys_addr = compressed_physical_ptr[index];
|
||||||
|
if (phys_addr == 0) [[unlikely]] {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return GetPointerFromRaw<T>((static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) +
|
||||||
|
offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
template <typename T>
|
||||||
|
void DeviceMemoryManager<Traits>::Write(DAddr address, T value) {
|
||||||
|
T* ptr = GetPointer<T>(address);
|
||||||
|
if (!ptr) [[unlikely]] {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::memcpy(ptr, &value, sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
template <typename T>
|
||||||
|
T DeviceMemoryManager<Traits>::Read(DAddr address) const {
|
||||||
|
const T* ptr = GetPointer<T>(address);
|
||||||
|
T result{};
|
||||||
|
if (!ptr) [[unlikely]] {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
std::memcpy(&result, ptr, sizeof(T));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::WalkBlock(DAddr addr, std::size_t size, auto on_unmapped,
|
||||||
|
auto on_memory, auto increment) {
|
||||||
|
std::size_t remaining_size = size;
|
||||||
|
std::size_t page_index = addr >> Memory::YUZU_PAGEBITS;
|
||||||
|
std::size_t page_offset = addr & Memory::YUZU_PAGEMASK;
|
||||||
|
|
||||||
|
while (remaining_size) {
|
||||||
|
const size_t next_pages = static_cast<std::size_t>(continuity_tracker[page_index]);
|
||||||
|
const std::size_t copy_amount =
|
||||||
|
std::min((next_pages << Memory::YUZU_PAGEBITS) - page_offset, remaining_size);
|
||||||
|
const auto current_vaddr =
|
||||||
|
static_cast<u64>((page_index << Memory::YUZU_PAGEBITS) + page_offset);
|
||||||
|
SCOPE_EXIT({
|
||||||
|
page_index += next_pages;
|
||||||
|
page_offset = 0;
|
||||||
|
increment(copy_amount);
|
||||||
|
remaining_size -= copy_amount;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto phys_addr = compressed_physical_ptr[page_index];
|
||||||
|
if (phys_addr == 0) {
|
||||||
|
on_unmapped(copy_amount, current_vaddr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto* mem_ptr = GetPointerFromRaw<u8>(
|
||||||
|
(static_cast<PAddr>(phys_addr - 1) << Memory::YUZU_PAGEBITS) + page_offset);
|
||||||
|
on_memory(copy_amount, mem_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::ReadBlock(DAddr address, void* dest_pointer, size_t size) {
|
||||||
|
device_inter->FlushRegion(address, size);
|
||||||
|
WalkBlock(
|
||||||
|
address, size,
|
||||||
|
[&](size_t copy_amount, DAddr current_vaddr) {
|
||||||
|
LOG_ERROR(
|
||||||
|
HW_Memory,
|
||||||
|
"Unmapped Device ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
||||||
|
current_vaddr, address, size);
|
||||||
|
std::memset(dest_pointer, 0, copy_amount);
|
||||||
|
},
|
||||||
|
[&](size_t copy_amount, const u8* const src_ptr) {
|
||||||
|
std::memcpy(dest_pointer, src_ptr, copy_amount);
|
||||||
|
},
|
||||||
|
[&](const std::size_t copy_amount) {
|
||||||
|
dest_pointer = static_cast<u8*>(dest_pointer) + copy_amount;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::WriteBlock(DAddr address, const void* src_pointer, size_t size) {
|
||||||
|
WalkBlock(
|
||||||
|
address, size,
|
||||||
|
[&](size_t copy_amount, DAddr current_vaddr) {
|
||||||
|
LOG_ERROR(
|
||||||
|
HW_Memory,
|
||||||
|
"Unmapped Device WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
||||||
|
current_vaddr, address, size);
|
||||||
|
},
|
||||||
|
[&](size_t copy_amount, u8* const dst_ptr) {
|
||||||
|
std::memcpy(dst_ptr, src_pointer, copy_amount);
|
||||||
|
},
|
||||||
|
[&](const std::size_t copy_amount) {
|
||||||
|
src_pointer = static_cast<const u8*>(src_pointer) + copy_amount;
|
||||||
|
});
|
||||||
|
device_inter->InvalidateRegion(address, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::ReadBlockUnsafe(DAddr address, void* dest_pointer, size_t size) {
|
||||||
|
WalkBlock(
|
||||||
|
address, size,
|
||||||
|
[&](size_t copy_amount, DAddr current_vaddr) {
|
||||||
|
LOG_ERROR(
|
||||||
|
HW_Memory,
|
||||||
|
"Unmapped Device ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
||||||
|
current_vaddr, address, size);
|
||||||
|
std::memset(dest_pointer, 0, copy_amount);
|
||||||
|
},
|
||||||
|
[&](size_t copy_amount, const u8* const src_ptr) {
|
||||||
|
std::memcpy(dest_pointer, src_ptr, copy_amount);
|
||||||
|
},
|
||||||
|
[&](const std::size_t copy_amount) {
|
||||||
|
dest_pointer = static_cast<u8*>(dest_pointer) + copy_amount;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::WriteBlockUnsafe(DAddr address, const void* src_pointer,
|
||||||
|
size_t size) {
|
||||||
|
WalkBlock(
|
||||||
|
address, size,
|
||||||
|
[&](size_t copy_amount, DAddr current_vaddr) {
|
||||||
|
LOG_ERROR(
|
||||||
|
HW_Memory,
|
||||||
|
"Unmapped Device WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
|
||||||
|
current_vaddr, address, size);
|
||||||
|
},
|
||||||
|
[&](size_t copy_amount, u8* const dst_ptr) {
|
||||||
|
std::memcpy(dst_ptr, src_pointer, copy_amount);
|
||||||
|
},
|
||||||
|
[&](const std::size_t copy_amount) {
|
||||||
|
src_pointer = static_cast<const u8*>(src_pointer) + copy_amount;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
Asid DeviceMemoryManager<Traits>::RegisterProcess(Memory::Memory* memory_device_inter) {
|
||||||
|
size_t new_id{};
|
||||||
|
if (!id_pool.empty()) {
|
||||||
|
new_id = id_pool.front();
|
||||||
|
id_pool.pop_front();
|
||||||
|
registered_processes[new_id] = memory_device_inter;
|
||||||
|
} else {
|
||||||
|
registered_processes.emplace_back(memory_device_inter);
|
||||||
|
new_id = registered_processes.size() - 1U;
|
||||||
|
}
|
||||||
|
return Asid{new_id};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::UnregisterProcess(Asid asid) {
|
||||||
|
registered_processes[asid.id] = nullptr;
|
||||||
|
id_pool.push_front(asid.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Traits>
|
||||||
|
void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta) {
|
||||||
|
std::unique_lock<std::mutex> lk(counter_guard, std::defer_lock);
|
||||||
|
const auto Lock = [&] {
|
||||||
|
if (!lk) {
|
||||||
|
lk.lock();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
u64 uncache_begin = 0;
|
||||||
|
u64 cache_begin = 0;
|
||||||
|
u64 uncache_bytes = 0;
|
||||||
|
u64 cache_bytes = 0;
|
||||||
|
const auto MarkRegionCaching = &DeviceMemoryManager<Traits>::DeviceMethods::MarkRegionCaching;
|
||||||
|
|
||||||
|
std::atomic_thread_fence(std::memory_order_acquire);
|
||||||
|
const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE);
|
||||||
|
size_t page = addr >> Memory::YUZU_PAGEBITS;
|
||||||
|
auto [asid, base_vaddress] = ExtractCPUBacking(page);
|
||||||
|
size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS;
|
||||||
|
auto* memory_device_inter = registered_processes[asid.id];
|
||||||
|
for (; page != page_end; ++page) {
|
||||||
|
std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page);
|
||||||
|
|
||||||
|
if (delta > 0) {
|
||||||
|
ASSERT_MSG(count.load(std::memory_order::relaxed) < std::numeric_limits<u8>::max(),
|
||||||
|
"Count may overflow!");
|
||||||
|
} else if (delta < 0) {
|
||||||
|
ASSERT_MSG(count.load(std::memory_order::relaxed) > 0, "Count may underflow!");
|
||||||
|
} else {
|
||||||
|
ASSERT_MSG(false, "Delta must be non-zero!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds or subtracts 1, as count is a unsigned 8-bit value
|
||||||
|
count.fetch_add(static_cast<u8>(delta), std::memory_order_release);
|
||||||
|
|
||||||
|
// Assume delta is either -1 or 1
|
||||||
|
if (count.load(std::memory_order::relaxed) == 0) {
|
||||||
|
if (uncache_bytes == 0) {
|
||||||
|
uncache_begin = vpage;
|
||||||
|
}
|
||||||
|
uncache_bytes += Memory::YUZU_PAGESIZE;
|
||||||
|
} else if (uncache_bytes > 0) {
|
||||||
|
Lock();
|
||||||
|
MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS,
|
||||||
|
uncache_bytes, false);
|
||||||
|
uncache_bytes = 0;
|
||||||
|
}
|
||||||
|
if (count.load(std::memory_order::relaxed) == 1 && delta > 0) {
|
||||||
|
if (cache_bytes == 0) {
|
||||||
|
cache_begin = vpage;
|
||||||
|
}
|
||||||
|
cache_bytes += Memory::YUZU_PAGESIZE;
|
||||||
|
} else if (cache_bytes > 0) {
|
||||||
|
Lock();
|
||||||
|
MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
|
||||||
|
true);
|
||||||
|
cache_bytes = 0;
|
||||||
|
}
|
||||||
|
vpage++;
|
||||||
|
}
|
||||||
|
if (uncache_bytes > 0) {
|
||||||
|
Lock();
|
||||||
|
MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
if (cache_bytes > 0) {
|
||||||
|
Lock();
|
||||||
|
MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Core
|
@ -26,7 +26,7 @@
|
|||||||
#include "core/file_sys/vfs_vector.h"
|
#include "core/file_sys/vfs_vector.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
#include "core/hle/service/ns/language.h"
|
#include "core/hle/service/ns/language.h"
|
||||||
#include "core/hle/service/set/set.h"
|
#include "core/hle/service/set/settings_server.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
#include "core/loader/nso.h"
|
#include "core/loader/nso.h"
|
||||||
#include "core/memory/cheat_engine.h"
|
#include "core/memory/cheat_engine.h"
|
||||||
@ -466,12 +466,12 @@ VirtualFile PatchManager::PatchRomFS(const NCA* base_nca, VirtualFile base_romfs
|
|||||||
return romfs;
|
return romfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile update_raw) const {
|
std::vector<Patch> PatchManager::GetPatches(VirtualFile update_raw) const {
|
||||||
if (title_id == 0) {
|
if (title_id == 0) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::string, std::less<>> out;
|
std::vector<Patch> out;
|
||||||
const auto& disabled = Settings::values.disabled_addons[title_id];
|
const auto& disabled = Settings::values.disabled_addons[title_id];
|
||||||
|
|
||||||
// Game Updates
|
// Game Updates
|
||||||
@ -482,20 +482,28 @@ PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile u
|
|||||||
|
|
||||||
const auto update_disabled =
|
const auto update_disabled =
|
||||||
std::find(disabled.cbegin(), disabled.cend(), "Update") != disabled.cend();
|
std::find(disabled.cbegin(), disabled.cend(), "Update") != disabled.cend();
|
||||||
const auto update_label = update_disabled ? "[D] Update" : "Update";
|
Patch update_patch = {.enabled = !update_disabled,
|
||||||
|
.name = "Update",
|
||||||
|
.version = "",
|
||||||
|
.type = PatchType::Update,
|
||||||
|
.program_id = title_id,
|
||||||
|
.title_id = title_id};
|
||||||
|
|
||||||
if (nacp != nullptr) {
|
if (nacp != nullptr) {
|
||||||
out.insert_or_assign(update_label, nacp->GetVersionString());
|
update_patch.version = nacp->GetVersionString();
|
||||||
|
out.push_back(update_patch);
|
||||||
} else {
|
} else {
|
||||||
if (content_provider.HasEntry(update_tid, ContentRecordType::Program)) {
|
if (content_provider.HasEntry(update_tid, ContentRecordType::Program)) {
|
||||||
const auto meta_ver = content_provider.GetEntryVersion(update_tid);
|
const auto meta_ver = content_provider.GetEntryVersion(update_tid);
|
||||||
if (meta_ver.value_or(0) == 0) {
|
if (meta_ver.value_or(0) == 0) {
|
||||||
out.insert_or_assign(update_label, "");
|
out.push_back(update_patch);
|
||||||
} else {
|
} else {
|
||||||
out.insert_or_assign(update_label, FormatTitleVersion(*meta_ver));
|
update_patch.version = FormatTitleVersion(*meta_ver);
|
||||||
|
out.push_back(update_patch);
|
||||||
}
|
}
|
||||||
} else if (update_raw != nullptr) {
|
} else if (update_raw != nullptr) {
|
||||||
out.insert_or_assign(update_label, "PACKED");
|
update_patch.version = "PACKED";
|
||||||
|
out.push_back(update_patch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +547,12 @@ PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile u
|
|||||||
|
|
||||||
const auto mod_disabled =
|
const auto mod_disabled =
|
||||||
std::find(disabled.begin(), disabled.end(), mod->GetName()) != disabled.end();
|
std::find(disabled.begin(), disabled.end(), mod->GetName()) != disabled.end();
|
||||||
out.insert_or_assign(mod_disabled ? "[D] " + mod->GetName() : mod->GetName(), types);
|
out.push_back({.enabled = !mod_disabled,
|
||||||
|
.name = mod->GetName(),
|
||||||
|
.version = types,
|
||||||
|
.type = PatchType::Mod,
|
||||||
|
.program_id = title_id,
|
||||||
|
.title_id = title_id});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +570,12 @@ PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile u
|
|||||||
if (!types.empty()) {
|
if (!types.empty()) {
|
||||||
const auto mod_disabled =
|
const auto mod_disabled =
|
||||||
std::find(disabled.begin(), disabled.end(), "SDMC") != disabled.end();
|
std::find(disabled.begin(), disabled.end(), "SDMC") != disabled.end();
|
||||||
out.insert_or_assign(mod_disabled ? "[D] SDMC" : "SDMC", types);
|
out.push_back({.enabled = !mod_disabled,
|
||||||
|
.name = "SDMC",
|
||||||
|
.version = types,
|
||||||
|
.type = PatchType::Mod,
|
||||||
|
.program_id = title_id,
|
||||||
|
.title_id = title_id});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +602,12 @@ PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile u
|
|||||||
|
|
||||||
const auto dlc_disabled =
|
const auto dlc_disabled =
|
||||||
std::find(disabled.begin(), disabled.end(), "DLC") != disabled.end();
|
std::find(disabled.begin(), disabled.end(), "DLC") != disabled.end();
|
||||||
out.insert_or_assign(dlc_disabled ? "[D] DLC" : "DLC", std::move(list));
|
out.push_back({.enabled = !dlc_disabled,
|
||||||
|
.name = "DLC",
|
||||||
|
.version = std::move(list),
|
||||||
|
.type = PatchType::DLC,
|
||||||
|
.program_id = title_id,
|
||||||
|
.title_id = dlc_match.back().title_id});
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
@ -26,12 +26,22 @@ class ContentProvider;
|
|||||||
class NCA;
|
class NCA;
|
||||||
class NACP;
|
class NACP;
|
||||||
|
|
||||||
|
enum class PatchType { Update, DLC, Mod };
|
||||||
|
|
||||||
|
struct Patch {
|
||||||
|
bool enabled;
|
||||||
|
std::string name;
|
||||||
|
std::string version;
|
||||||
|
PatchType type;
|
||||||
|
u64 program_id;
|
||||||
|
u64 title_id;
|
||||||
|
};
|
||||||
|
|
||||||
// A centralized class to manage patches to games.
|
// A centralized class to manage patches to games.
|
||||||
class PatchManager {
|
class PatchManager {
|
||||||
public:
|
public:
|
||||||
using BuildID = std::array<u8, 0x20>;
|
using BuildID = std::array<u8, 0x20>;
|
||||||
using Metadata = std::pair<std::unique_ptr<NACP>, VirtualFile>;
|
using Metadata = std::pair<std::unique_ptr<NACP>, VirtualFile>;
|
||||||
using PatchVersionNames = std::map<std::string, std::string, std::less<>>;
|
|
||||||
|
|
||||||
explicit PatchManager(u64 title_id_,
|
explicit PatchManager(u64 title_id_,
|
||||||
const Service::FileSystem::FileSystemController& fs_controller_,
|
const Service::FileSystem::FileSystemController& fs_controller_,
|
||||||
@ -66,9 +76,8 @@ public:
|
|||||||
VirtualFile packed_update_raw = nullptr,
|
VirtualFile packed_update_raw = nullptr,
|
||||||
bool apply_layeredfs = true) const;
|
bool apply_layeredfs = true) const;
|
||||||
|
|
||||||
// Returns a vector of pairs between patch names and patch versions.
|
// Returns a vector of patches
|
||||||
// i.e. Update 3.2.2 will return {"Update", "3.2.2"}
|
[[nodiscard]] std::vector<Patch> GetPatches(VirtualFile update_raw = nullptr) const;
|
||||||
[[nodiscard]] PatchVersionNames GetPatchVersionNames(VirtualFile update_raw = nullptr) const;
|
|
||||||
|
|
||||||
// If the game update exists, returns the u32 version field in its Meta-type NCA. If that fails,
|
// If the game update exists, returns the u32 version field in its Meta-type NCA. If that fails,
|
||||||
// it will fallback to the Meta-type NCA of the base game. If that fails, the result will be
|
// it will fallback to the Meta-type NCA of the base game. If that fails, the result will be
|
||||||
|
@ -97,8 +97,9 @@ std::string SaveDataAttribute::DebugInfo() const {
|
|||||||
static_cast<u8>(rank), index);
|
static_cast<u8>(rank), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveDataFactory::SaveDataFactory(Core::System& system_, VirtualDir save_directory_)
|
SaveDataFactory::SaveDataFactory(Core::System& system_, ProgramId program_id_,
|
||||||
: dir{std::move(save_directory_)}, system{system_} {
|
VirtualDir save_directory_)
|
||||||
|
: system{system_}, program_id{program_id_}, dir{std::move(save_directory_)} {
|
||||||
// Delete all temporary storages
|
// Delete all temporary storages
|
||||||
// On hardware, it is expected that temporary storage be empty at first use.
|
// On hardware, it is expected that temporary storage be empty at first use.
|
||||||
dir->DeleteSubdirectoryRecursive("temp");
|
dir->DeleteSubdirectoryRecursive("temp");
|
||||||
@ -110,7 +111,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut
|
|||||||
PrintSaveDataAttributeWarnings(meta);
|
PrintSaveDataAttributeWarnings(meta);
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
|
||||||
return dir->CreateDirectoryRelative(save_directory);
|
return dir->CreateDirectoryRelative(save_directory);
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut
|
|||||||
VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
|
VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const {
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
|
||||||
auto out = dir->GetDirectoryRelative(save_directory);
|
auto out = dir->GetDirectoryRelative(save_directory);
|
||||||
|
|
||||||
@ -147,14 +148,14 @@ std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SaveDataFactory::GetFullPath(Core::System& system, VirtualDir dir,
|
std::string SaveDataFactory::GetFullPath(ProgramId program_id, VirtualDir dir,
|
||||||
SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
SaveDataSpaceId space, SaveDataType type, u64 title_id,
|
||||||
u128 user_id, u64 save_id) {
|
u128 user_id, u64 save_id) {
|
||||||
// According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
|
// According to switchbrew, if a save is of type SaveData and the title id field is 0, it should
|
||||||
// be interpreted as the title id of the current process.
|
// be interpreted as the title id of the current process.
|
||||||
if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) {
|
if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) {
|
||||||
if (title_id == 0) {
|
if (title_id == 0) {
|
||||||
title_id = system.GetApplicationProcessProgramID();
|
title_id = program_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,10 +190,19 @@ std::string SaveDataFactory::GetFullPath(Core::System& system, VirtualDir dir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SaveDataFactory::GetUserGameSaveDataRoot(u128 user_id, bool future) {
|
||||||
|
if (future) {
|
||||||
|
Common::UUID uuid;
|
||||||
|
std::memcpy(uuid.uuid.data(), user_id.data(), sizeof(Common::UUID));
|
||||||
|
return fmt::format("/user/save/account/{}", uuid.RawString());
|
||||||
|
}
|
||||||
|
return fmt::format("/user/save/{:016X}/{:016X}{:016X}", 0, user_id[1], user_id[0]);
|
||||||
|
}
|
||||||
|
|
||||||
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
||||||
u128 user_id) const {
|
u128 user_id) const {
|
||||||
const auto path =
|
const auto path =
|
||||||
GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
||||||
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
||||||
|
|
||||||
const auto size_file = relative_dir->GetFile(GetSaveDataSizeFileName());
|
const auto size_file = relative_dir->GetFile(GetSaveDataSizeFileName());
|
||||||
@ -211,7 +221,7 @@ SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
|
|||||||
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
||||||
SaveDataSize new_value) const {
|
SaveDataSize new_value) const {
|
||||||
const auto path =
|
const auto path =
|
||||||
GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
|
||||||
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
|
||||||
|
|
||||||
const auto size_file = relative_dir->CreateFile(GetSaveDataSizeFileName());
|
const auto size_file = relative_dir->CreateFile(GetSaveDataSizeFileName());
|
||||||
|
@ -87,10 +87,13 @@ constexpr const char* GetSaveDataSizeFileName() {
|
|||||||
return ".yuzu_save_size";
|
return ".yuzu_save_size";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using ProgramId = u64;
|
||||||
|
|
||||||
/// File system interface to the SaveData archive
|
/// File system interface to the SaveData archive
|
||||||
class SaveDataFactory {
|
class SaveDataFactory {
|
||||||
public:
|
public:
|
||||||
explicit SaveDataFactory(Core::System& system_, VirtualDir save_directory_);
|
explicit SaveDataFactory(Core::System& system_, ProgramId program_id_,
|
||||||
|
VirtualDir save_directory_);
|
||||||
~SaveDataFactory();
|
~SaveDataFactory();
|
||||||
|
|
||||||
VirtualDir Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
VirtualDir Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
||||||
@ -99,8 +102,9 @@ public:
|
|||||||
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
||||||
|
|
||||||
static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
|
static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
|
||||||
static std::string GetFullPath(Core::System& system, VirtualDir dir, SaveDataSpaceId space,
|
static std::string GetFullPath(ProgramId program_id, VirtualDir dir, SaveDataSpaceId space,
|
||||||
SaveDataType type, u64 title_id, u128 user_id, u64 save_id);
|
SaveDataType type, u64 title_id, u128 user_id, u64 save_id);
|
||||||
|
static std::string GetUserGameSaveDataRoot(u128 user_id, bool future);
|
||||||
|
|
||||||
SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const;
|
SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const;
|
||||||
void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
|
||||||
@ -109,8 +113,9 @@ public:
|
|||||||
void SetAutoCreate(bool state);
|
void SetAutoCreate(bool state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VirtualDir dir;
|
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
|
ProgramId program_id;
|
||||||
|
VirtualDir dir;
|
||||||
bool auto_create{true};
|
bool auto_create{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void DefaultControllerApplet::ReconfigureControllers(ReconfigureCallback callbac
|
|||||||
// Connect controllers based on the following priority list from highest to lowest priority:
|
// Connect controllers based on the following priority list from highest to lowest priority:
|
||||||
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
|
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
|
||||||
if (parameters.allow_pro_controller) {
|
if (parameters.allow_pro_controller) {
|
||||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
|
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
|
||||||
controller->Connect(true);
|
controller->Connect(true);
|
||||||
} else if (parameters.allow_dual_joycons) {
|
} else if (parameters.allow_dual_joycons) {
|
||||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);
|
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/memory.h"
|
#include "core/device_memory_manager.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
~GPUDirtyMemoryManager() = default;
|
~GPUDirtyMemoryManager() = default;
|
||||||
|
|
||||||
void Collect(VAddr address, size_t size) {
|
void Collect(PAddr address, size_t size) {
|
||||||
TransformAddress t = BuildTransform(address, size);
|
TransformAddress t = BuildTransform(address, size);
|
||||||
TransformAddress tmp, original;
|
TransformAddress tmp, original;
|
||||||
do {
|
do {
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
std::memory_order_relaxed));
|
std::memory_order_relaxed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gather(std::function<void(VAddr, size_t)>& callback) {
|
void Gather(std::function<void(PAddr, size_t)>& callback) {
|
||||||
{
|
{
|
||||||
std::scoped_lock lk(guard);
|
std::scoped_lock lk(guard);
|
||||||
TransformAddress t = current.exchange(default_transform, std::memory_order_relaxed);
|
TransformAddress t = current.exchange(default_transform, std::memory_order_relaxed);
|
||||||
@ -65,7 +65,7 @@ public:
|
|||||||
mask = mask >> empty_bits;
|
mask = mask >> empty_bits;
|
||||||
|
|
||||||
const size_t continuous_bits = std::countr_one(mask);
|
const size_t continuous_bits = std::countr_one(mask);
|
||||||
callback((static_cast<VAddr>(transform.address) << page_bits) + offset,
|
callback((static_cast<PAddr>(transform.address) << page_bits) + offset,
|
||||||
continuous_bits << align_bits);
|
continuous_bits << align_bits);
|
||||||
mask = continuous_bits < align_size ? (mask >> continuous_bits) : 0;
|
mask = continuous_bits < align_size ? (mask >> continuous_bits) : 0;
|
||||||
offset += continuous_bits << align_bits;
|
offset += continuous_bits << align_bits;
|
||||||
@ -80,7 +80,7 @@ private:
|
|||||||
u32 mask;
|
u32 mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr static size_t page_bits = Memory::YUZU_PAGEBITS - 1;
|
constexpr static size_t page_bits = DEVICE_PAGEBITS - 1;
|
||||||
constexpr static size_t page_size = 1ULL << page_bits;
|
constexpr static size_t page_size = 1ULL << page_bits;
|
||||||
constexpr static size_t page_mask = page_size - 1;
|
constexpr static size_t page_mask = page_size - 1;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ private:
|
|||||||
constexpr static size_t align_mask = align_size - 1;
|
constexpr static size_t align_mask = align_size - 1;
|
||||||
constexpr static TransformAddress default_transform = {.address = ~0U, .mask = 0U};
|
constexpr static TransformAddress default_transform = {.address = ~0U, .mask = 0U};
|
||||||
|
|
||||||
bool IsValid(VAddr address) {
|
bool IsValid(PAddr address) {
|
||||||
return address < (1ULL << 39);
|
return address < (1ULL << 39);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ private:
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformAddress BuildTransform(VAddr address, size_t size) {
|
TransformAddress BuildTransform(PAddr address, size_t size) {
|
||||||
const size_t minor_address = address & page_mask;
|
const size_t minor_address = address & page_mask;
|
||||||
const size_t minor_bit = minor_address >> align_bits;
|
const size_t minor_bit = minor_address >> align_bits;
|
||||||
const size_t top_bit = (minor_address + size + align_mask) >> align_bits;
|
const size_t top_bit = (minor_address + size + align_mask) >> align_bits;
|
||||||
|
214
src/core/guest_memory.h
Normal file
214
src/core/guest_memory.h
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/scratch_buffer.h"
|
||||||
|
|
||||||
|
namespace Core::Memory {
|
||||||
|
|
||||||
|
enum GuestMemoryFlags : u32 {
|
||||||
|
Read = 1 << 0,
|
||||||
|
Write = 1 << 1,
|
||||||
|
Safe = 1 << 2,
|
||||||
|
Cached = 1 << 3,
|
||||||
|
|
||||||
|
SafeRead = Read | Safe,
|
||||||
|
SafeWrite = Write | Safe,
|
||||||
|
SafeReadWrite = SafeRead | SafeWrite,
|
||||||
|
SafeReadCachedWrite = SafeReadWrite | Cached,
|
||||||
|
|
||||||
|
UnsafeRead = Read,
|
||||||
|
UnsafeWrite = Write,
|
||||||
|
UnsafeReadWrite = UnsafeRead | UnsafeWrite,
|
||||||
|
UnsafeReadCachedWrite = UnsafeReadWrite | Cached,
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <typename M, typename T, GuestMemoryFlags FLAGS>
|
||||||
|
class GuestMemory {
|
||||||
|
using iterator = T*;
|
||||||
|
using const_iterator = const T*;
|
||||||
|
using value_type = T;
|
||||||
|
using element_type = T;
|
||||||
|
using iterator_category = std::contiguous_iterator_tag;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GuestMemory() = delete;
|
||||||
|
explicit GuestMemory(M& memory, u64 addr, std::size_t size,
|
||||||
|
Common::ScratchBuffer<T>* backup = nullptr)
|
||||||
|
: m_memory{memory}, m_addr{addr}, m_size{size} {
|
||||||
|
static_assert(FLAGS & GuestMemoryFlags::Read || FLAGS & GuestMemoryFlags::Write);
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Read) {
|
||||||
|
Read(addr, size, backup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~GuestMemory() = default;
|
||||||
|
|
||||||
|
T* data() noexcept {
|
||||||
|
return m_data_span.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* data() const noexcept {
|
||||||
|
return m_data_span.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size() const noexcept {
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size_bytes() const noexcept {
|
||||||
|
return this->size() * sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] T* begin() noexcept {
|
||||||
|
return this->data();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const T* begin() const noexcept {
|
||||||
|
return this->data();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] T* end() noexcept {
|
||||||
|
return this->data() + this->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const T* end() const noexcept {
|
||||||
|
return this->data() + this->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator[](size_t index) noexcept {
|
||||||
|
return m_data_span[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const T& operator[](size_t index) const noexcept {
|
||||||
|
return m_data_span[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetAddressAndSize(u64 addr, std::size_t size) noexcept {
|
||||||
|
m_addr = addr;
|
||||||
|
m_size = size;
|
||||||
|
m_addr_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<T> Read(u64 addr, std::size_t size,
|
||||||
|
Common::ScratchBuffer<T>* backup = nullptr) noexcept {
|
||||||
|
m_addr = addr;
|
||||||
|
m_size = size;
|
||||||
|
if (m_size == 0) {
|
||||||
|
m_is_data_copy = true;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->TrySetSpan()) {
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
||||||
|
m_memory.FlushRegion(m_addr, this->size_bytes());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (backup) {
|
||||||
|
backup->resize_destructive(this->size());
|
||||||
|
m_data_span = *backup;
|
||||||
|
} else {
|
||||||
|
m_data_copy.resize(this->size());
|
||||||
|
m_data_span = std::span(m_data_copy);
|
||||||
|
}
|
||||||
|
m_is_data_copy = true;
|
||||||
|
m_span_valid = true;
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
||||||
|
m_memory.ReadBlock(m_addr, this->data(), this->size_bytes());
|
||||||
|
} else {
|
||||||
|
m_memory.ReadBlockUnsafe(m_addr, this->data(), this->size_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_data_span;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Write(std::span<T> write_data) noexcept {
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Cached) {
|
||||||
|
m_memory.WriteBlockCached(m_addr, write_data.data(), this->size_bytes());
|
||||||
|
} else if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
||||||
|
m_memory.WriteBlock(m_addr, write_data.data(), this->size_bytes());
|
||||||
|
} else {
|
||||||
|
m_memory.WriteBlockUnsafe(m_addr, write_data.data(), this->size_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TrySetSpan() noexcept {
|
||||||
|
if (u8* ptr = m_memory.GetSpan(m_addr, this->size_bytes()); ptr) {
|
||||||
|
m_data_span = {reinterpret_cast<T*>(ptr), this->size()};
|
||||||
|
m_span_valid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool IsDataCopy() const noexcept {
|
||||||
|
return m_is_data_copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AddressChanged() const noexcept {
|
||||||
|
return m_addr_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
M& m_memory;
|
||||||
|
u64 m_addr{};
|
||||||
|
size_t m_size{};
|
||||||
|
std::span<T> m_data_span{};
|
||||||
|
std::vector<T> m_data_copy{};
|
||||||
|
bool m_span_valid{false};
|
||||||
|
bool m_is_data_copy{false};
|
||||||
|
bool m_addr_changed{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename M, typename T, GuestMemoryFlags FLAGS>
|
||||||
|
class GuestMemoryScoped : public GuestMemory<M, T, FLAGS> {
|
||||||
|
public:
|
||||||
|
GuestMemoryScoped() = delete;
|
||||||
|
explicit GuestMemoryScoped(M& memory, u64 addr, std::size_t size,
|
||||||
|
Common::ScratchBuffer<T>* backup = nullptr)
|
||||||
|
: GuestMemory<M, T, FLAGS>(memory, addr, size, backup) {
|
||||||
|
if constexpr (!(FLAGS & GuestMemoryFlags::Read)) {
|
||||||
|
if (!this->TrySetSpan()) {
|
||||||
|
if (backup) {
|
||||||
|
this->m_data_span = *backup;
|
||||||
|
this->m_span_valid = true;
|
||||||
|
this->m_is_data_copy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~GuestMemoryScoped() {
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Write) {
|
||||||
|
if (this->size() == 0) [[unlikely]] {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->AddressChanged() || this->IsDataCopy()) {
|
||||||
|
ASSERT(this->m_span_valid);
|
||||||
|
if constexpr (FLAGS & GuestMemoryFlags::Cached) {
|
||||||
|
this->m_memory.WriteBlockCached(this->m_addr, this->data(), this->size_bytes());
|
||||||
|
} else if constexpr (FLAGS & GuestMemoryFlags::Safe) {
|
||||||
|
this->m_memory.WriteBlock(this->m_addr, this->data(), this->size_bytes());
|
||||||
|
} else {
|
||||||
|
this->m_memory.WriteBlockUnsafe(this->m_addr, this->data(), this->size_bytes());
|
||||||
|
}
|
||||||
|
} else if constexpr ((FLAGS & GuestMemoryFlags::Safe) ||
|
||||||
|
(FLAGS & GuestMemoryFlags::Cached)) {
|
||||||
|
this->m_memory.InvalidateRegion(this->m_addr, this->size_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
} // namespace Core::Memory
|
@ -81,12 +81,12 @@ enum class KMemoryState : u32 {
|
|||||||
|
|
||||||
ThreadLocal = static_cast<u32>(Svc::MemoryState::ThreadLocal) | FlagLinearMapped,
|
ThreadLocal = static_cast<u32>(Svc::MemoryState::ThreadLocal) | FlagLinearMapped,
|
||||||
|
|
||||||
Transfered = static_cast<u32>(Svc::MemoryState::Transfered) | FlagsMisc |
|
Transferred = static_cast<u32>(Svc::MemoryState::Transferred) | FlagsMisc |
|
||||||
FlagCanAlignedDeviceMap | FlagCanChangeAttribute | FlagCanUseIpc |
|
FlagCanAlignedDeviceMap | FlagCanChangeAttribute | FlagCanUseIpc |
|
||||||
FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
||||||
|
|
||||||
SharedTransfered = static_cast<u32>(Svc::MemoryState::SharedTransfered) | FlagsMisc |
|
SharedTransferred = static_cast<u32>(Svc::MemoryState::SharedTransferred) | FlagsMisc |
|
||||||
FlagCanAlignedDeviceMap | FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
FlagCanAlignedDeviceMap | FlagCanUseNonSecureIpc | FlagCanUseNonDeviceIpc,
|
||||||
|
|
||||||
SharedCode = static_cast<u32>(Svc::MemoryState::SharedCode) | FlagMapped |
|
SharedCode = static_cast<u32>(Svc::MemoryState::SharedCode) | FlagMapped |
|
||||||
FlagReferenceCounted | FlagLinearMapped | FlagCanUseNonSecureIpc |
|
FlagReferenceCounted | FlagLinearMapped | FlagCanUseNonSecureIpc |
|
||||||
@ -130,8 +130,8 @@ static_assert(static_cast<u32>(KMemoryState::AliasCodeData) == 0x0FFFBD09);
|
|||||||
static_assert(static_cast<u32>(KMemoryState::Ipc) == 0x045C3C0A);
|
static_assert(static_cast<u32>(KMemoryState::Ipc) == 0x045C3C0A);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Stack) == 0x045C3C0B);
|
static_assert(static_cast<u32>(KMemoryState::Stack) == 0x045C3C0B);
|
||||||
static_assert(static_cast<u32>(KMemoryState::ThreadLocal) == 0x0400000C);
|
static_assert(static_cast<u32>(KMemoryState::ThreadLocal) == 0x0400000C);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Transfered) == 0x055C3C0D);
|
static_assert(static_cast<u32>(KMemoryState::Transferred) == 0x055C3C0D);
|
||||||
static_assert(static_cast<u32>(KMemoryState::SharedTransfered) == 0x045C380E);
|
static_assert(static_cast<u32>(KMemoryState::SharedTransferred) == 0x045C380E);
|
||||||
static_assert(static_cast<u32>(KMemoryState::SharedCode) == 0x0440380F);
|
static_assert(static_cast<u32>(KMemoryState::SharedCode) == 0x0440380F);
|
||||||
static_assert(static_cast<u32>(KMemoryState::Inaccessible) == 0x00000010);
|
static_assert(static_cast<u32>(KMemoryState::Inaccessible) == 0x00000010);
|
||||||
static_assert(static_cast<u32>(KMemoryState::NonSecureIpc) == 0x045C3811);
|
static_assert(static_cast<u32>(KMemoryState::NonSecureIpc) == 0x045C3811);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user