Android: Check asset overwrite per file.

So new files will be added, eg the missed Wii directory.
This commit is contained in:
degasus 2016-04-03 10:43:11 +02:00
parent 3f704dca75
commit 18db9498d7
1 changed files with 21 additions and 24 deletions

View File

@ -39,23 +39,15 @@ public final class AssetCopyService extends IntentService
String ConfigDir = BaseDir + File.separator + "Config"; String ConfigDir = BaseDir + File.separator + "Config";
// Copy assets if needed // Copy assets if needed
File file = new File(BaseDir + File.separator + "GC" + File.separator + "font_sjis.bin");
if(!file.exists())
{
NativeLibrary.CreateUserFolders(); NativeLibrary.CreateUserFolders();
copyAssetFolder("GC", BaseDir + File.separator + "GC"); copyAssetFolder("GC", BaseDir + File.separator + "GC", false);
copyAssetFolder("Shaders", BaseDir + File.separator + "Shaders"); copyAssetFolder("Shaders", BaseDir + File.separator + "Shaders", false);
copyAssetFolder("Wii", BaseDir + File.separator + "Wii"); copyAssetFolder("Wii", BaseDir + File.separator + "Wii", false);
}
else
{
Log.verbose("[AssetCopyService] Skipping asset copy operation.");
}
// Always copy over the GCPad config in case of change or corruption. // Always copy over the GCPad config in case of change or corruption.
// Not a user configurable file. // Not a user configurable file.
copyAsset("GCPadNew.ini", ConfigDir + File.separator + "GCPadNew.ini"); copyAsset("GCPadNew.ini", ConfigDir + File.separator + "GCPadNew.ini", true);
copyAsset("WiimoteNew.ini", ConfigDir + File.separator + "WiimoteNew.ini"); copyAsset("WiimoteNew.ini", ConfigDir + File.separator + "WiimoteNew.ini", true);
// Record the fact that we've done this before, so we don't do it on every launch. // Record the fact that we've done this before, so we don't do it on every launch.
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
@ -65,13 +57,16 @@ public final class AssetCopyService extends IntentService
editor.commit(); editor.commit();
} }
private void copyAsset(String asset, String output) private void copyAsset(String asset, String output, Boolean overwrite)
{ {
Log.verbose("[AssetCopyService] Copying " + asset + " to " + output); Log.verbose("[AssetCopyService] Copying File " + asset + " to " + output);
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
try try
{
File file = new File(output);
if(!file.exists() || overwrite)
{ {
in = getAssets().open(asset); in = getAssets().open(asset);
out = new FileOutputStream(output); out = new FileOutputStream(output);
@ -79,21 +74,23 @@ public final class AssetCopyService extends IntentService
in.close(); in.close();
out.close(); out.close();
} }
}
catch (IOException e) catch (IOException e)
{ {
Log.error("[AssetCopyService] Failed to copy asset file: " + asset + e.getMessage()); Log.error("[AssetCopyService] Failed to copy asset file: " + asset + e.getMessage());
} }
} }
private void copyAssetFolder(String assetFolder, String outputFolder) private void copyAssetFolder(String assetFolder, String outputFolder, Boolean overwrite)
{ {
Log.verbose("[AssetCopyService] Copying " + assetFolder + " to " + outputFolder); Log.verbose("[AssetCopyService] Copying Folder " + assetFolder + " to " + outputFolder);
try try
{ {
for (String file : getAssets().list(assetFolder)) for (String file : getAssets().list(assetFolder))
{ {
copyAsset(assetFolder + File.separator + file, outputFolder + File.separator + file); copyAssetFolder(assetFolder + File.separator + file, outputFolder + File.separator + file, overwrite);
copyAsset(assetFolder + File.separator + file, outputFolder + File.separator + file, overwrite);
} }
} }
catch (IOException e) catch (IOException e)