Skip to content

Commit

Permalink
Merge pull request #173 from kairusds/master
Browse files Browse the repository at this point in the history
Fix crashes on devices running below Android 11
  • Loading branch information
Acivev authored Jan 8, 2022
2 parents f60c22b + de0cc2d commit f91edec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
29 changes: 15 additions & 14 deletions src/ru/nsu/ccfit/zuev/osu/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ public static void loadConfig(final Context context) {
soundVolume = prefs.getInt("soundvolume", 100) / 100f;
bgmVolume = prefs.getInt("bgmvolume", 100) / 100f;
cursorSize = prefs.getInt("cursorSize", 50) / 100f;
}catch(RuntimeException e) { // migrate to integers to prevent crash
}catch(RuntimeException e) { // use valid integer since this makes the game crash on android m
prefs.edit()
.putInt("offset", Integer.parseInt(prefs.getString("offset", "0")))
.putInt("bgbrightness", Integer.parseInt(prefs.getString("bgbrightness", "25")))
.putInt("soundvolume", Integer.parseInt(prefs.getString("soundvolume", "100")))
.putInt("bgmvolume", Integer.parseInt(prefs.getString("bgmvolume", "100")))
.putInt("cursorSize", Integer.parseInt(prefs.getString("cursorSize", "50")))
.putInt("offset", 0)
.putInt("bgbrightness", 25)
.putInt("soundvolume", 100)
.putInt("bgmvolume", 100)
.putInt("cursorSize", 50)
.commit();
Config.loadConfig(context);
}
Expand Down Expand Up @@ -196,14 +196,6 @@ public static void loadConfig(final Context context) {
comboColors[i - 1] = RGBColor.hex2Rgb(ColorPickerPreference.convertToRGB(prefs.getInt("combo" + i, 0xff000000)));
}

// skins
File[] folders = FileUtils.listFiles(new File(skinTopPath), file -> file.isDirectory() && !file.getName().startsWith("."));
skins = new HashMap<String, String>();
for(File folder : folders) {
skins.put(folder.getName(), folder.getPath());
Debug.i("skins: " + folder.getName() + " - " + folder.getPath());
}

// beatmaps
DELETE_OSZ = prefs.getBoolean("deleteosz", true);
SCAN_DOWNLOAD = prefs.getBoolean("scandownload", false);
Expand Down Expand Up @@ -767,6 +759,15 @@ public static String getDefaultCorePath() {
return defaultCorePath;
}

public static void loadSkins() {
File[] folders = FileUtils.listFiles(new File(skinTopPath), file -> file.isDirectory() && !file.getName().startsWith("."));
skins = new HashMap<String, String>();
for(File folder : folders) {
skins.put(folder.getName(), folder.getPath());
Debug.i("skins: " + folder.getName() + " - " + folder.getPath());
}
}

public static Map<String, String> getSkins(){
return skins;
}
Expand Down
1 change: 1 addition & 0 deletions src/ru/nsu/ccfit/zuev/osu/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public void run() {
GlobalManager.getInstance().init();
analytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, null);
GlobalManager.getInstance().setLoadingProgress(50);
Config.loadSkins();
checkNewSkins();
checkNewBeatmaps();
if (!LibraryManager.getInstance().loadLibraryCache(MainActivity.this, true)) {
Expand Down
13 changes: 5 additions & 8 deletions src/ru/nsu/ccfit/zuev/osu/helper/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;

Expand Down Expand Up @@ -176,11 +177,9 @@ public static File[] listFiles(File directory, String[] endsWithExtensions) {
return null;
}

public static File[] listFiles(File directory, FileUtilsFilter filter) {
public static File[] listFiles(File directory, FileFilter filter) {
File[] filelist = null;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
filelist = directory.listFiles(pathname -> filter.accept(pathname));
}else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LinkedList<File> cachedFiles = new LinkedList<File>();
DirectoryStream.Filter<Path> directoryFilter = new DirectoryStream.Filter<Path>() {
@Override
Expand All @@ -196,12 +195,10 @@ public boolean accept(Path entry) {
Debug.e("FileUtils.listFiles: " + err.getMessage(), err);
}
filelist = cachedFiles.toArray(new File[cachedFiles.size()]);
}else {
filelist = directory.listFiles(filter);
}
return filelist;
}

public interface FileUtilsFilter {
boolean accept(File file);
}

}

0 comments on commit f91edec

Please sign in to comment.