android: Add initial CIA installation

This commit is contained in:
BreadFish64 2020-05-25 19:53:39 -05:00 committed by xperia64
parent 1c2203c98e
commit 82c1065929
10 changed files with 87 additions and 17 deletions

View File

@ -482,6 +482,8 @@ public final class NativeLibrary {
public static native void RemoveAmiibo();
public static native void InstallCIAS(String[] path);
/**
* Button type for use in onTouchEvent
*/

View File

@ -381,7 +381,9 @@ public final class EmulationActivity extends AppCompatActivity {
break;
case MENU_ACTION_LOAD_AMIIBO:
FileBrowserHelper.openFilePicker(this, REQUEST_SELECT_AMIIBO, R.string.select_amiibo, Collections.singletonList("bin"));
FileBrowserHelper.openFilePicker(this, REQUEST_SELECT_AMIIBO,
R.string.select_amiibo,
Collections.singletonList("bin"), false);
break;
case MENU_ACTION_REMOVE_AMIIBO:

View File

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import org.citra.citra_emu.NativeLibrary;
import org.citra.citra_emu.R;
import org.citra.citra_emu.activities.EmulationActivity;
import org.citra.citra_emu.features.settings.ui.SettingsActivity;
@ -27,6 +28,7 @@ import org.citra.citra_emu.utils.StartupHandler;
import org.citra.citra_emu.utils.ThemeUtil;
import java.util.Arrays;
import java.util.Collections;
/**
* The main Activity of the Lollipop style UI. Manages several PlatformGamesFragments, which
@ -141,11 +143,24 @@ public final class MainActivity extends AppCompatActivity implements MainView {
}
@Override
public void launchFileListActivity() {
public void launchFileListActivity(int request) {
if (PermissionsHandler.hasWriteAccess(this)) {
FileBrowserHelper.openDirectoryPicker(this, MainPresenter.REQUEST_ADD_DIRECTORY,
R.string.select_game_folder, Arrays.asList("elf", "axf", "cci", "3ds", "cxi", "app", "3dsx", "cia",
"rar", "zip", "7z", "torrent", "tar", "gz"));
switch (request) {
case MainPresenter.REQUEST_ADD_DIRECTORY:
FileBrowserHelper.openDirectoryPicker(this,
MainPresenter.REQUEST_ADD_DIRECTORY,
R.string.select_game_folder,
Arrays.asList("elf", "axf", "cci", "3ds",
"cxi", "app", "3dsx", "cia",
"rar", "zip", "7z", "torrent",
"tar", "gz"));
break;
case MainPresenter.REQUEST_INSTALL_CIA:
FileBrowserHelper.openFilePicker(this, MainPresenter.REQUEST_INSTALL_CIA,
R.string.install_cia_title,
Collections.singletonList("cia"), true);
break;
}
} else {
PermissionsHandler.checkWritePermission(this);
}
@ -171,6 +186,12 @@ public final class MainActivity extends AppCompatActivity implements MainView {
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedDirectory(result));
}
break;
case MainPresenter.REQUEST_INSTALL_CIA:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK) {
NativeLibrary.InstallCIAS(FileBrowserHelper.getSelectedFiles(result));
}
break;
}
}
@ -187,7 +208,7 @@ public final class MainActivity extends AppCompatActivity implements MainView {
// Immediately prompt user to select a game directory on first boot
if (mPresenter != null) {
mPresenter.launchFileListActivity();
mPresenter.launchFileListActivity(MainPresenter.REQUEST_ADD_DIRECTORY);
}
} else {
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT)

View File

@ -12,6 +12,7 @@ import org.citra.citra_emu.utils.AddDirectoryHelper;
public final class MainPresenter {
public static final int REQUEST_ADD_DIRECTORY = 1;
public static final int REQUEST_INSTALL_CIA = 2;
private final MainView mView;
private String mDirToAdd;
@ -27,9 +28,9 @@ public final class MainPresenter {
refeshGameList();
}
public void launchFileListActivity() {
public void launchFileListActivity(int request) {
if (mView != null) {
mView.launchFileListActivity();
mView.launchFileListActivity(request);
}
}
@ -46,7 +47,11 @@ public final class MainPresenter {
return true;
case R.id.button_add_directory:
launchFileListActivity();
launchFileListActivity(REQUEST_ADD_DIRECTORY);
return true;
case R.id.button_install_cia:
launchFileListActivity(REQUEST_INSTALL_CIA);
return true;
case R.id.button_premium:

View File

@ -21,5 +21,5 @@ public interface MainView {
void launchSettingsActivity(String menuTag);
void launchFileListActivity();
void launchFileListActivity(int request);
}

View File

@ -30,10 +30,11 @@ public final class FileBrowserHelper {
activity.startActivityForResult(i, requestCode);
}
public static void openFilePicker(FragmentActivity activity, int requestCode, int title, List<String> extensions) {
public static void openFilePicker(FragmentActivity activity, int requestCode, int title,
List<String> extensions, boolean allowMultiple) {
Intent i = new Intent(activity, CustomFilePickerActivity.class);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, allowMultiple);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
i.putExtra(FilePickerActivity.EXTRA_START_PATH,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
#include <iostream>
#include <regex>
#include <thread>
@ -563,4 +564,28 @@ void Java_org_citra_citra_1emu_NativeLibrary_RemoveAmiibo(JNIEnv* env, jclass cl
nfc->RemoveAmiibo();
}
void Java_org_citra_citra_1emu_NativeLibrary_InstallCIAS(JNIEnv* env, [[maybe_unused]] jclass clazz,
jobjectArray path) {
const jsize count{env->GetArrayLength(path)};
std::vector<std::string> paths;
for (jsize idx{0}; idx < count; ++idx) {
paths.emplace_back(
GetJString(env, static_cast<jstring>(env->GetObjectArrayElement(path, idx))));
}
std::atomic<jsize> idx{count};
std::vector<std::thread> threads;
std::generate_n(std::back_inserter(threads),
std::min<jsize>(std::thread::hardware_concurrency(), count), [&] {
return std::thread{[&idx, &paths, env] {
jsize work_idx;
while ((work_idx = --idx) >= 0) {
LOG_INFO(Frontend, "Installing CIA {}", work_idx);
Service::AM::InstallCIA(paths[work_idx]);
}
}};
});
for (auto& thread : threads)
thread.join();
}
} // extern "C"

View File

@ -142,6 +142,8 @@ JNIEXPORT jboolean Java_org_citra_citra_1emu_NativeLibrary_LoadAmiibo(JNIEnv* en
JNIEXPORT void Java_org_citra_citra_1emu_NativeLibrary_RemoveAmiibo(JNIEnv* env, jclass clazz);
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_NativeLibrary_InstallCIAS(JNIEnv* env, jclass clazz, jobjectArray path);
#ifdef __cplusplus
}
#endif

View File

@ -8,14 +8,26 @@
android:title="@string/premium_text"
app:showAsAction="ifRoom" />
<item
android:id="@+id/button_add_directory"
android:id="@+id/button_file_menu"
android:icon="@drawable/ic_folder"
android:title="@string/add_directory_title"
app:showAsAction="ifRoom" />
android:title="@string/select_game_folder"
app:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/button_add_directory"
android:icon="@drawable/ic_folder"
android:title="@string/select_game_folder"
app:showAsAction="ifRoom" />
<item
android:id="@+id/button_install_cia"
android:title="@string/install_cia_title"
app:showAsAction="ifRoom" />
</menu>
</item>
<item
android:id="@+id/menu_settings_core"
android:icon="@drawable/ic_settings_core"
android:title="@string/grid_menu_core_settings"
app:showAsAction="ifRoom" />
</menu>
</menu>

View File

@ -113,7 +113,7 @@
<!-- Add Directory Screen-->
<string name="select_game_folder">Select Game Folder</string>
<string name="add_directory_title">Add Folder to Library</string>
<string name="install_cia_title">Install CIA</string>
<!-- Preferences Screen -->
<string name="preferences_settings">Settings</string>