[frontend] refactor: extract common firmware & key functions #38
8 changed files with 616 additions and 555 deletions
|
@ -15,6 +15,7 @@ import android.view.Surface
|
|||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.Keep
|
||||
import androidx.core.net.toUri
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import net.swiftzer.semver.SemVer
|
||||
import java.lang.ref.WeakReference
|
||||
|
@ -27,6 +28,7 @@ import org.yuzu.yuzu_emu.model.InstallResult
|
|||
import org.yuzu.yuzu_emu.model.Patch
|
||||
import org.yuzu.yuzu_emu.model.GameVerificationResult
|
||||
import org.yuzu.yuzu_emu.network.NetPlayManager
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Class which contains methods that interact
|
||||
|
@ -102,6 +104,21 @@ object NativeLibrary {
|
|||
FileUtil.getFilename(Uri.parse(path))
|
||||
}
|
||||
|
||||
@Keep
|
||||
@JvmStatic
|
||||
fun copyFileToStorage(source: String, destdir: String): Boolean {
|
||||
return FileUtil.copyUriToInternalStorage(
|
||||
source.toUri(),
|
||||
destdir
|
||||
) != null
|
||||
}
|
||||
|
||||
@Keep
|
||||
@JvmStatic
|
||||
fun getFileExtension(source: String): String {
|
||||
return FileUtil.getExtension(source.toUri())
|
||||
}
|
||||
|
||||
external fun setAppDirectory(directory: String)
|
||||
|
||||
/**
|
||||
|
|
|
@ -264,8 +264,6 @@ class DriverFetcherFragment : Fragment() {
|
|||
}
|
||||
|
||||
releases.add(release)
|
||||
|
||||
println(release.publishTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -478,7 +478,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||
}
|
||||
|
||||
private fun startEmulation(programIndex: Int = 0) {
|
||||
println("PROGRAM INDEX: $programIndex")
|
||||
if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) {
|
||||
if (!DirectoryInitialization.areDirectoriesReady) {
|
||||
DirectoryInitialization.start()
|
||||
|
|
|
@ -202,8 +202,8 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
showNegativeButton = true,
|
||||
positiveAction = {
|
||||
PreferenceManager.getDefaultSharedPreferences(applicationContext).edit() {
|
||||
putBoolean(Settings.PREF_SHOULD_SHOW_PRE_ALPHA_WARNING, false)
|
||||
}
|
||||
putBoolean(Settings.PREF_SHOULD_SHOW_PRE_ALPHA_WARNING, false)
|
||||
}
|
||||
}).show(supportFragmentManager, MessageDialogFragment.TAG)
|
||||
}
|
||||
}
|
||||
|
@ -337,59 +337,35 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
|
||||
val getAmiiboKey = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
||||
if (result != null) {
|
||||
processKey(result, "bin", false)
|
||||
processKey(result, "bin")
|
||||
}
|
||||
}
|
||||
|
||||
fun processKey(result: Uri, extension: String = "keys", check: Boolean = true): Boolean {
|
||||
if (FileUtil.getExtension(result) != extension) {
|
||||
MessageDialogFragment.newInstance(
|
||||
this,
|
||||
titleId = R.string.keys_failed,
|
||||
descriptionId = R.string.error_keys_invalid_filename
|
||||
).show(supportFragmentManager, MessageDialogFragment.TAG)
|
||||
return false
|
||||
}
|
||||
|
||||
fun processKey(result: Uri, extension: String = "keys") {
|
||||
contentResolver.takePersistableUriPermission(
|
||||
result, Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
|
||||
val dstPath = DirectoryInitialization.userDirectory + "/keys/"
|
||||
if (FileUtil.copyUriToInternalStorage(
|
||||
result, dstPath, ""
|
||||
) != null
|
||||
) {
|
||||
if (NativeLibrary.reloadKeys()) {
|
||||
Toast.makeText(
|
||||
applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT
|
||||
).show()
|
||||
val resultCode: Int = NativeLibrary.installKeys(result.toString(), extension);
|
||||
|
||||
if (check) {
|
||||
homeViewModel.setCheckKeys(true)
|
||||
if (resultCode == 0) {
|
||||
Toast.makeText(
|
||||
applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
val firstTimeSetup =
|
||||
PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||
.getBoolean(Settings.PREF_FIRST_APP_LAUNCH, true)
|
||||
if (!firstTimeSetup) {
|
||||
homeViewModel.setCheckFirmware(true)
|
||||
}
|
||||
gamesViewModel.reloadGames(true)
|
||||
|
||||
gamesViewModel.reloadGames(true)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
MessageDialogFragment.newInstance(
|
||||
this,
|
||||
titleId = R.string.keys_failed,
|
||||
descriptionId = R.string.error_keys_failed_init,
|
||||
helpLinkId = R.string.dumping_keys_quickstart_link
|
||||
).show(supportFragmentManager, MessageDialogFragment.TAG)
|
||||
return false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
return true
|
||||
val resultString: String =
|
||||
resources.getStringArray(R.array.installKeysResults)[resultCode]
|
||||
|
||||
MessageDialogFragment.newInstance(
|
||||
titleId = R.string.keys_failed,
|
||||
descriptionString = resultString,
|
||||
helpLinkId = R.string.keys_missing_help
|
||||
).show(supportFragmentManager, MessageDialogFragment.TAG)
|
||||
}
|
||||
|
||||
val getFirmware = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
||||
|
@ -542,7 +518,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
|
||||
addonViewModel.refreshAddons()
|
||||
|
||||
val separator = System.getProperty("line.separator") ?: "\n"
|
||||
val separator = System.lineSeparator() ?: "\n"
|
||||
val installResult = StringBuilder()
|
||||
if (installSuccess > 0) {
|
||||
installResult.append(
|
||||
|
|
|
@ -504,6 +504,7 @@
|
|||
</string-array>
|
||||
|
||||
<string-array name="installKeysResults">
|
||||
<item>""</item>
|
||||
<item>""</item>
|
||||
<item>@string/error_keys_copy_failed</item>
|
||||
<item>@string/error_keys_invalid_filename</item>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,6 +39,9 @@ jclass GetDiskCacheLoadCallbackStageClass();
|
|||
jclass GetGameDirClass();
|
||||
jmethodID GetGameDirConstructor();
|
||||
jmethodID GetDiskCacheLoadProgress();
|
||||
jmethodID GetCopyToStorage();
|
||||
jmethodID GetFileExists();
|
||||
jmethodID GetFileExtension();
|
||||
|
||||
jmethodID GetExitEmulationActivity();
|
||||
jmethodID GetOnEmulationStarted();
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include "firmware_manager.h"
|
||||
#include <filesystem>
|
||||
#include <jni.h>
|
||||
#include <common/android/id_cache.h>
|
||||
#include <common/android/android_common.h>
|
||||
#include <common/fs/fs_paths.h>
|
||||
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
|
@ -12,12 +16,52 @@
|
|||
#include "core/crypto/key_manager.h"
|
||||
#include "frontend_common/content_manager.h"
|
||||
|
||||
FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string location, std::string extension)
|
||||
{
|
||||
FirmwareManager::KeyInstallResult
|
||||
FirmwareManager::InstallKeys(std::string location, std::string extension) {
|
||||
LOG_INFO(Frontend, "Installing key files from {}", location);
|
||||
|
||||
const auto keys_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::KeysDir);
|
||||
|
||||
#ifdef ANDROID
|
||||
JNIEnv *env = Common::Android::GetEnvForThread();
|
||||
|
||||
jstring jsrc = Common::Android::ToJString(env, location);
|
||||
|
||||
jclass native = Common::Android::GetNativeLibraryClass();
|
||||
jmethodID getExtension = Common::Android::GetFileExtension();
|
||||
|
||||
jstring jext = static_cast<jstring>(env->CallStaticObjectMethod(
|
||||
native,
|
||||
getExtension,
|
||||
jsrc
|
||||
));
|
||||
|
||||
std::string ext = Common::Android::GetJString(env, jext);
|
||||
|
||||
if (ext != extension) {
|
||||
return ErrorWrongFilename;
|
||||
}
|
||||
|
||||
jmethodID copyToStorage = Common::Android::GetCopyToStorage();
|
||||
jstring jdest = Common::Android::ToJString(env, keys_dir.string());
|
||||
|
||||
jboolean copyResult = env->CallStaticBooleanMethod(
|
||||
native,
|
||||
copyToStorage,
|
||||
jsrc,
|
||||
jdest
|
||||
);
|
||||
|
||||
if (!copyResult) {
|
||||
return ErrorFailedCopy;
|
||||
}
|
||||
#else
|
||||
if (!location.ends_with(extension)) {
|
||||
return ErrorWrongFilename;
|
||||
}
|
||||
|
||||
bool prod_keys_found = false;
|
||||
|
||||
const std::filesystem::path prod_key_path = location;
|
||||
const std::filesystem::path key_source_path = prod_key_path.parent_path();
|
||||
|
||||
|
@ -25,7 +69,6 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
|
|||
return InvalidDir;
|
||||
}
|
||||
|
||||
bool prod_keys_found = false;
|
||||
std::vector<std::filesystem::path> source_key_files;
|
||||
|
||||
if (Common::FS::Exists(prod_key_path)) {
|
||||
|
@ -57,6 +100,7 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
|
|||
return ErrorFailedCopy;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Reinitialize the key manager
|
||||
Core::Crypto::KeyManager::Instance().ReloadKeys();
|
||||
|
@ -65,12 +109,11 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
|
|||
return Success;
|
||||
}
|
||||
|
||||
// let the frontend handle checking everything else
|
||||
// Let the frontend handle everything else
|
||||
return ErrorFailedInit;
|
||||
}
|
||||
|
||||
FirmwareManager::FirmwareCheckResult FirmwareManager::VerifyFirmware(Core::System &system)
|
||||
{
|
||||
FirmwareManager::FirmwareCheckResult FirmwareManager::VerifyFirmware(Core::System &system) {
|
||||
if (!CheckFirmwarePresence(system)) {
|
||||
return ErrorFirmwareMissing;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue