Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #573 from sigmabeta/file-copies-intentservice
Get rid of the UI-less Activity that launches from Android's home screen.
  • Loading branch information
lioncash committed Jul 10, 2014
2 parents bc655d1 + 94b1eea commit a546ef3
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 122 deletions.
15 changes: 6 additions & 9 deletions Source/Android/AndroidManifest.xml
Expand Up @@ -21,14 +21,13 @@
android:label="@string/app_name"
android:allowBackup="true">
<activity
android:name="org.dolphinemu.dolphinemu.DolphinEmulator"
android:configChanges="locale|keyboard|keyboardHidden|navigation|fontScale|uiMode"
android:name="org.dolphinemu.dolphinemu.gamelist.GameListActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
android:theme="@android:style/Theme.Holo.Light" >

<!-- This intentfilter marks this Activity as the one that gets launched from Home screen.-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -37,10 +36,6 @@
android:name="org.dolphinemu.dolphinemu.about.AboutActivity"
android:theme="@android:style/Theme.Holo.Light" />

<activity
android:name="org.dolphinemu.dolphinemu.gamelist.GameListActivity"
android:theme="@android:style/Theme.Holo.Light" />

<activity
android:name="org.dolphinemu.dolphinemu.emulation.EmulationActivity"
android:screenOrientation="landscape" />
Expand All @@ -55,6 +50,8 @@
android:label="@string/settings"
android:theme="@android:style/Theme.Holo.Light" />

<service android:name=".AssetCopyService"/>

</application>

</manifest>
116 changes: 116 additions & 0 deletions Source/Android/src/org/dolphinemu/dolphinemu/AssetCopyService.java
@@ -0,0 +1,116 @@
/**
* Copyright 2014 Dolphin Emulator Project
* Licensed under GPLv2
* Refer to the license.txt file included.
*/

package org.dolphinemu.dolphinemu;

import android.app.IntentService;
import android.content.Intent;
import android.os.Environment;
import android.util.Log;

import org.dolphinemu.dolphinemu.settings.UserPreferences;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* A service that spawns its own thread in order to copy several binary and shader files
* from the Dolphin APK to the external file system.
*/
public final class AssetCopyService extends IntentService
{
private static final String TAG = "DolphinEmulator";

public AssetCopyService()
{
// Superclass constructor is called to name the thread on which this service executes.
super("AssetCopyService");
}

@Override
protected void onHandleIntent(Intent intent)
{
String BaseDir = Environment.getExternalStorageDirectory() + File.separator + "dolphin-emu";
String ConfigDir = BaseDir + File.separator + "Config";
String GCDir = BaseDir + File.separator + "GC";

// Copy assets if needed
File file = new File(GCDir + File.separator + "font_sjis.bin");
if(!file.exists())
{
NativeLibrary.CreateUserFolders();
copyAsset("Dolphin.ini", ConfigDir + File.separator + "Dolphin.ini");
copyAsset("dsp_coef.bin", GCDir + File.separator + "dsp_coef.bin");
copyAsset("dsp_rom.bin", GCDir + File.separator + "dsp_rom.bin");
copyAsset("font_ansi.bin", GCDir + File.separator + "font_ansi.bin");
copyAsset("font_sjis.bin", GCDir + File.separator + "font_sjis.bin");
copyAssetFolder("Shaders", BaseDir + File.separator + "Shaders");
}
else
{
Log.v(TAG, "Skipping asset copy operation.");
}

// 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");

// Load the configuration keys set in the Dolphin ini and gfx ini files
// into the application's shared preferences.
UserPreferences.LoadIniToPrefs(this);
}

private void copyAsset(String asset, String output)
{
Log.v(TAG, "Copying " + asset + " to " + output);
InputStream in = null;
OutputStream out = null;

try
{
in = getAssets().open(asset);
out = new FileOutputStream(output);
copyFile(in, out);
in.close();
out.close();
}
catch (IOException e)
{
Log.e(TAG, "Failed to copy asset file: " + asset, e);
}
}

private void copyAssetFolder(String assetFolder, String outputFolder)
{
Log.v(TAG, "Copying " + assetFolder + " to " + outputFolder);

try
{
for (String file : getAssets().list(assetFolder))
{
copyAsset(assetFolder + File.separator + file, outputFolder + File.separator + file);
}
}
catch (IOException e)
{
Log.e(TAG, "Failed to copy asset folder: " + assetFolder, e);
}
}

private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;

while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
}
111 changes: 0 additions & 111 deletions Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java

This file was deleted.

Expand Up @@ -24,6 +24,7 @@
import android.widget.AdapterView;
import android.widget.ListView;

import org.dolphinemu.dolphinemu.AssetCopyService;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.about.AboutActivity;
Expand Down Expand Up @@ -103,10 +104,15 @@ public void onDrawerOpened(View drawerView) {
};
mDrawerLayout.setDrawerListener(mDrawerToggle);

// Display the game list fragment on activity creation,
// but only if no previous states have been saved.

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
{
// Copy assets into appropriate locations.
Intent copyAssets = new Intent(this, AssetCopyService.class);
startService(copyAssets);

// Display the game list fragment.
final GameListFragment gameList = new GameListFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, gameList);
Expand Down

0 comments on commit a546ef3

Please sign in to comment.