From f857fa652905a78fac852bf3917878bfb21416b3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Sep 2022 18:20:22 +0200 Subject: [PATCH] Android: Add s prefix to static variables in GameFileCacheManager --- .../services/GameFileCacheManager.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java index f53e3de56f..ad5f225374 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheManager.java @@ -23,14 +23,14 @@ import java.util.concurrent.Executors; */ public final class GameFileCacheManager { - private static GameFileCache gameFileCache = null; - private static final MutableLiveData gameFiles = + private static GameFileCache sGameFileCache = null; + private static final MutableLiveData sGameFiles = new MutableLiveData<>(new GameFile[]{}); - private static boolean runRescanAfterLoad = false; + private static boolean sRunRescanAfterLoad = false; - private static final ExecutorService executor = Executors.newFixedThreadPool(1); - private static final MutableLiveData loadInProgress = new MutableLiveData<>(false); - private static final MutableLiveData rescanInProgress = new MutableLiveData<>(false); + private static final ExecutorService sExecutor = Executors.newFixedThreadPool(1); + private static final MutableLiveData sLoadInProgress = new MutableLiveData<>(false); + private static final MutableLiveData sRescanInProgress = new MutableLiveData<>(false); private GameFileCacheManager() { @@ -38,12 +38,12 @@ public final class GameFileCacheManager public static LiveData getGameFiles() { - return gameFiles; + return sGameFiles; } public static List getGameFilesForPlatform(Platform platform) { - GameFile[] allGames = gameFiles.getValue(); + GameFile[] allGames = sGameFiles.getValue(); ArrayList platformGames = new ArrayList<>(); for (GameFile game : allGames) { @@ -57,7 +57,7 @@ public final class GameFileCacheManager public static GameFile getGameFileByGameId(String gameId) { - GameFile[] allGames = gameFiles.getValue(); + GameFile[] allGames = sGameFiles.getValue(); for (GameFile game : allGames) { if (game.getGameId().equals(gameId)) @@ -72,7 +72,7 @@ public final class GameFileCacheManager { GameFile matchWithoutRevision = null; - GameFile[] allGames = gameFiles.getValue(); + GameFile[] allGames = sGameFiles.getValue(); for (GameFile otherGame : allGames) { if (game.getGameId().equals(otherGame.getGameId()) && @@ -102,7 +102,7 @@ public final class GameFileCacheManager */ public static LiveData isLoading() { - return loadInProgress; + return sLoadInProgress; } /** @@ -110,12 +110,12 @@ public final class GameFileCacheManager */ public static LiveData isRescanning() { - return rescanInProgress; + return sRescanInProgress; } public static boolean isLoadingOrRescanning() { - return loadInProgress.getValue() || rescanInProgress.getValue(); + return sLoadInProgress.getValue() || sRescanInProgress.getValue(); } /** @@ -125,11 +125,11 @@ public final class GameFileCacheManager */ public static void startLoad(Context context) { - if (!loadInProgress.getValue()) + if (!sLoadInProgress.getValue()) { - loadInProgress.setValue(true); + sLoadInProgress.setValue(true); new AfterDirectoryInitializationRunner().runWithoutLifecycle( - () -> executor.execute(GameFileCacheManager::load)); + () -> sExecutor.execute(GameFileCacheManager::load)); } } @@ -141,11 +141,11 @@ public final class GameFileCacheManager */ public static void startRescan(Context context) { - if (!rescanInProgress.getValue()) + if (!sRescanInProgress.getValue()) { - rescanInProgress.setValue(true); + sRescanInProgress.setValue(true); new AfterDirectoryInitializationRunner().runWithoutLifecycle( - () -> executor.execute(GameFileCacheManager::rescan)); + () -> sExecutor.execute(GameFileCacheManager::rescan)); } } @@ -153,8 +153,8 @@ public final class GameFileCacheManager { // Common case: The game is in the cache, so just grab it from there. // (Actually, addOrGet already checks for this case, but we want to avoid calling it if possible - // because onHandleIntent may hold a lock on gameFileCache for extended periods of time.) - GameFile[] allGames = gameFiles.getValue(); + // because onHandleIntent may hold a lock on sGameFileCache for extended periods of time.) + GameFile[] allGames = sGameFiles.getValue(); for (GameFile game : allGames) { if (game.getPath().equals(gamePath)) @@ -165,9 +165,9 @@ public final class GameFileCacheManager // Unusual case: The game wasn't found in the cache. // Scan the game and add it to the cache so that we can return it. - synchronized (gameFileCache) + synchronized (sGameFileCache) { - return gameFileCache.addOrGet(gamePath); + return sGameFileCache.addOrGet(gamePath); } } @@ -178,30 +178,30 @@ public final class GameFileCacheManager */ private static void load() { - if (gameFileCache == null) + if (sGameFileCache == null) { GameFileCache temp = new GameFileCache(); synchronized (temp) { - gameFileCache = temp; - gameFileCache.load(); - if (gameFileCache.getSize() != 0) + sGameFileCache = temp; + sGameFileCache.load(); + if (sGameFileCache.getSize() != 0) { updateGameFileArray(); } } } - if (runRescanAfterLoad) + if (sRunRescanAfterLoad) { - rescanInProgress.postValue(true); + sRescanInProgress.postValue(true); } - loadInProgress.postValue(false); + sLoadInProgress.postValue(false); - if (runRescanAfterLoad) + if (sRunRescanAfterLoad) { - runRescanAfterLoad = false; + sRunRescanAfterLoad = false; rescan(); } } @@ -214,25 +214,25 @@ public final class GameFileCacheManager */ private static void rescan() { - if (gameFileCache == null) + if (sGameFileCache == null) { - runRescanAfterLoad = true; + sRunRescanAfterLoad = true; } else { String[] gamePaths = GameFileCache.getAllGamePaths(); boolean changed; - synchronized (gameFileCache) + synchronized (sGameFileCache) { - changed = gameFileCache.update(gamePaths); + changed = sGameFileCache.update(gamePaths); } if (changed) { updateGameFileArray(); } - boolean additionalMetadataChanged = gameFileCache.updateAdditionalMetadata(); + boolean additionalMetadataChanged = sGameFileCache.updateAdditionalMetadata(); if (additionalMetadataChanged) { updateGameFileArray(); @@ -240,17 +240,17 @@ public final class GameFileCacheManager if (changed || additionalMetadataChanged) { - gameFileCache.save(); + sGameFileCache.save(); } } - rescanInProgress.postValue(false); + sRescanInProgress.postValue(false); } private static void updateGameFileArray() { - GameFile[] gameFilesTemp = gameFileCache.getAllGames(); + GameFile[] gameFilesTemp = sGameFileCache.getAllGames(); Arrays.sort(gameFilesTemp, (lhs, rhs) -> lhs.getTitle().compareToIgnoreCase(rhs.getTitle())); - gameFiles.postValue(gameFilesTemp); + sGameFiles.postValue(gameFilesTemp); } }