mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-28 05:52:38 +00:00
Android: Extract Sys to a different folder than the User folder
This commit is contained in:
parent
d1c1793a34
commit
b3b7aef09a
7 changed files with 96 additions and 54 deletions
|
@ -302,11 +302,6 @@ public final class NativeLibrary
|
|||
*/
|
||||
public static native void LoadState(int slot);
|
||||
|
||||
/**
|
||||
* Creates the initial folder structure in /sdcard/dolphin-emu/
|
||||
*/
|
||||
public static native void CreateUserFolders();
|
||||
|
||||
/**
|
||||
* Sets the current working user directory
|
||||
* If not set, it auto-detects a location
|
||||
|
|
|
@ -59,7 +59,8 @@ public final class DirectoryInitializationService extends IntentService
|
|||
}
|
||||
else if (PermissionsHandler.hasWriteAccess(this))
|
||||
{
|
||||
initDolphinDirectories();
|
||||
initializeInternalStorage();
|
||||
initializeExternalStorage();
|
||||
directoryState = DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;
|
||||
sendBroadcastState(directoryState);
|
||||
}
|
||||
|
@ -69,21 +70,47 @@ public final class DirectoryInitializationService extends IntentService
|
|||
}
|
||||
}
|
||||
|
||||
private void initDolphinDirectories()
|
||||
private void initializeInternalStorage()
|
||||
{
|
||||
String BaseDir = NativeLibrary.GetUserDirectory();
|
||||
String ConfigDir = BaseDir + File.separator + "Config";
|
||||
File sysDirectory = new File(getFilesDir(), "Sys");
|
||||
|
||||
// Copy assets if needed
|
||||
NativeLibrary.CreateUserFolders();
|
||||
copyAssetFolder("GC", BaseDir + File.separator + "GC", false);
|
||||
copyAssetFolder("Shaders", BaseDir + File.separator + "Shaders", false);
|
||||
copyAssetFolder("Wii", BaseDir + File.separator + "Wii", false);
|
||||
// Delete the existing extracted Sys directory in case it's from a different version of Dolphin.
|
||||
deleteDirectoryRecursively(sysDirectory);
|
||||
|
||||
// Always copy over the GCPad config in case of change or corruption.
|
||||
// Not a user configurable file.
|
||||
copyAsset("GCPadNew.ini", ConfigDir + File.separator + "GCPadNew.ini", true);
|
||||
copyAsset("WiimoteNew.ini", ConfigDir + File.separator + "WiimoteNew.ini", false);
|
||||
// Extract the Sys directory to app-local internal storage.
|
||||
copyAssetFolder("Sys", sysDirectory, true);
|
||||
|
||||
// Let the native code know where the Sys directory is.
|
||||
SetSysDirectory(sysDirectory.getPath());
|
||||
}
|
||||
|
||||
private void initializeExternalStorage()
|
||||
{
|
||||
// Create User directory structure and copy some NAND files from the extracted Sys directory.
|
||||
CreateUserDirectories();
|
||||
|
||||
// GCPadNew.ini and WiimoteNew.ini must contain specific values in order for controller
|
||||
// input to work as intended (they aren't user configurable), so we overwrite them just
|
||||
// in case the user has tried to modify them manually.
|
||||
//
|
||||
// ...Except WiimoteNew.ini contains the user configurable settings for Wii Remote
|
||||
// extensions in addition to all of its lines that aren't user configurable, so since we
|
||||
// don't want to lose the selected extensions, we don't overwrite that file if it exists.
|
||||
//
|
||||
// TODO: Redo the Android controller system so that we don't have to extract these INIs.
|
||||
String configDirectory = NativeLibrary.GetUserDirectory() + File.separator + "Config";
|
||||
copyAsset("GCPadNew.ini", new File(configDirectory, "GCPadNew.ini"), true);
|
||||
copyAsset("WiimoteNew.ini", new File(configDirectory,"WiimoteNew.ini"), false);
|
||||
}
|
||||
|
||||
private static void deleteDirectoryRecursively(File file)
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
for (File child : file.listFiles())
|
||||
deleteDirectoryRecursively(child);
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public static boolean areDolphinDirectoriesReady()
|
||||
|
@ -99,19 +126,16 @@ public final class DirectoryInitializationService extends IntentService
|
|||
LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
|
||||
}
|
||||
|
||||
private void copyAsset(String asset, String output, Boolean overwrite)
|
||||
private void copyAsset(String asset, File output, Boolean overwrite)
|
||||
{
|
||||
Log.verbose("[DirectoryInitializationService] Copying File " + asset + " to " + output);
|
||||
InputStream in;
|
||||
OutputStream out;
|
||||
|
||||
try
|
||||
{
|
||||
File file = new File(output);
|
||||
if (!file.exists() || overwrite)
|
||||
if (!output.exists() || overwrite)
|
||||
{
|
||||
in = getAssets().open(asset);
|
||||
out = new FileOutputStream(output);
|
||||
InputStream in = getAssets().open(asset);
|
||||
OutputStream out = new FileOutputStream(output);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
out.close();
|
||||
|
@ -123,16 +147,22 @@ public final class DirectoryInitializationService extends IntentService
|
|||
}
|
||||
}
|
||||
|
||||
private void copyAssetFolder(String assetFolder, String outputFolder, Boolean overwrite)
|
||||
private void copyAssetFolder(String assetFolder, File outputFolder, Boolean overwrite)
|
||||
{
|
||||
Log.verbose("[DirectoryInitializationService] Copying Folder " + assetFolder + " to " + outputFolder);
|
||||
|
||||
try
|
||||
{
|
||||
boolean createdFolder = false;
|
||||
for (String file : getAssets().list(assetFolder))
|
||||
{
|
||||
copyAssetFolder(assetFolder + File.separator + file, outputFolder + File.separator + file, overwrite);
|
||||
copyAsset(assetFolder + File.separator + file, outputFolder + File.separator + file, overwrite);
|
||||
if (!createdFolder)
|
||||
{
|
||||
outputFolder.mkdir();
|
||||
createdFolder = true;
|
||||
}
|
||||
copyAssetFolder(assetFolder + File.separator + file, new File(outputFolder, file), overwrite);
|
||||
copyAsset(assetFolder + File.separator + file, new File(outputFolder, file), overwrite);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -151,4 +181,7 @@ public final class DirectoryInitializationService extends IntentService
|
|||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void CreateUserDirectories();
|
||||
private static native void SetSysDirectory(String path);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue