android: frontend: Limit game list to a single directory.

This commit is contained in:
bunnei 2020-03-11 00:54:29 -04:00 committed by xperia64
parent 85947d83a4
commit 4dbd955d70
4 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,9 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.os.Environment;
import java.nio.file.Path;
import java.nio.file.Paths;
public final class Game {
private static final String PATH_SCREENSHOT_FOLDER =
"file://" + Environment.getExternalStorageDirectory().getPath() + "/citra-emu/ScreenShots/";
@ -32,6 +35,11 @@ public final class Game {
int country, String path, String gameId, String company) {
ContentValues values = new ContentValues();
if (gameId.isEmpty()) {
// Homebrew, etc. may not have a game ID, use filename as a unique identifier
gameId = Paths.get(path).getFileName().toString();
}
String screenPath = PATH_SCREENSHOT_FOLDER + gameId + "/" + gameId + "-1.png";
values.put(GameDatabase.KEY_GAME_TITLE, title);

View File

@ -103,6 +103,14 @@ public final class GameDatabase extends SQLiteOpenHelper {
scanLibrary(database);
}
public void resetDatabase(SQLiteDatabase database) {
execSqlAndLog(database, SQL_DELETE_FOLDERS);
execSqlAndLog(database, SQL_CREATE_FOLDERS);
execSqlAndLog(database, SQL_DELETE_GAMES);
execSqlAndLog(database, SQL_CREATE_GAMES);
}
public void scanLibrary(SQLiteDatabase database) {
// Before scanning known folders, go through the game table and remove any entries for which the file itself is missing.
Cursor fileCursor = database.query(TABLE_NAME_GAMES,

View File

@ -16,6 +16,7 @@ import org.citra.citra_emu.utils.Log;
*/
public final class GameProvider extends ContentProvider {
public static final String REFRESH_LIBRARY = "refresh";
public static final String RESET_LIBRARY = "reset";
public static final String AUTHORITY = "content://" + BuildConfig.APPLICATION_ID + ".provider";
public static final Uri URI_FOLDER =
@ -23,6 +24,7 @@ public final class GameProvider extends ContentProvider {
public static final Uri URI_GAME =
Uri.parse(AUTHORITY + "/" + GameDatabase.TABLE_NAME_GAMES + "/");
public static final Uri URI_REFRESH = Uri.parse(AUTHORITY + "/" + REFRESH_LIBRARY + "/");
public static final Uri URI_RESET = Uri.parse(AUTHORITY + "/" + RESET_LIBRARY + "/");
public static final String MIME_TYPE_FOLDER = "vnd.android.cursor.item/vnd.dolphin.folder";
public static final String MIME_TYPE_GAME = "vnd.android.cursor.item/vnd.dolphin.game";
@ -89,6 +91,10 @@ public final class GameProvider extends ContentProvider {
long id = -1;
if (table != null) {
if (table.equals(RESET_LIBRARY)) {
mDbHelper.resetDatabase(database);
return uri;
}
if (table.equals(REFRESH_LIBRARY)) {
Log.info(
"[GameProvider] URI specified table REFRESH_LIBRARY. No insertion necessary; refreshing library contents...");

View File

@ -148,6 +148,11 @@ public final class MainActivity extends AppCompatActivity implements MainView {
case MainPresenter.REQUEST_ADD_DIRECTORY:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK) {
// When a new directory is picked, we currently will reset the existing games
// database. This effectively means that only one game directory is supported.
// TODO(bunnei): Consider fixing this in the future, or removing code for this.
getContentResolver().insert(GameProvider.URI_RESET, null);
// Add the new directory
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedDirectory(result));
}
break;