4 import java.io.FileNotFoundException; |
4 import java.io.FileNotFoundException; |
5 import java.io.IOException; |
5 import java.io.IOException; |
6 |
6 |
7 import org.hedgewars.hedgeroid.MainActivity; |
7 import org.hedgewars.hedgeroid.MainActivity; |
8 import org.hedgewars.hedgeroid.R; |
8 import org.hedgewars.hedgeroid.R; |
9 import org.hedgewars.hedgeroid.Utils; |
|
10 import org.hedgewars.hedgeroid.Datastructures.Schemes; |
9 import org.hedgewars.hedgeroid.Datastructures.Schemes; |
11 import org.hedgewars.hedgeroid.Datastructures.Team; |
10 import org.hedgewars.hedgeroid.Datastructures.Team; |
12 import org.hedgewars.hedgeroid.Datastructures.Weaponsets; |
11 import org.hedgewars.hedgeroid.Datastructures.Weaponsets; |
|
12 import org.hedgewars.hedgeroid.util.FileUtils; |
13 |
13 |
14 import android.content.res.AssetManager; |
14 import android.content.res.AssetManager; |
15 import android.os.AsyncTask; |
15 import android.os.AsyncTask; |
16 import android.util.Log; |
16 import android.util.Log; |
17 |
17 |
23 this.act = act; |
23 this.act = act; |
24 } |
24 } |
25 |
25 |
26 private void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException { |
26 private void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException { |
27 try { |
27 try { |
28 Utils.writeStreamToFile(assetManager.open(assetPath), target); |
28 FileUtils.writeStreamToFile(assetManager.open(assetPath), target); |
29 } catch(FileNotFoundException e) { |
29 } catch(FileNotFoundException e) { |
30 /* |
30 /* |
31 * I can't find a better way to figure out whether an asset entry is |
31 * I can't find a better way to figure out whether an asset entry is |
32 * a file or a directory. Checking if assetManager.list(assetPath) |
32 * a file or a directory. Checking if assetManager.list(assetPath) |
33 * is empty is a bit cleaner, but SLOW. |
33 * is empty is a bit cleaner, but SLOW. |
42 } |
42 } |
43 |
43 |
44 @Override |
44 @Override |
45 protected Boolean doInBackground(Object... params) { |
45 protected Boolean doInBackground(Object... params) { |
46 try { |
46 try { |
47 Utils.writeStreamToFile(act.getResources().openRawResource(R.raw.schemes_builtin), Schemes.getBuiltinSchemesFile(act)); |
47 FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.schemes_builtin), Schemes.getBuiltinSchemesFile(act)); |
48 Utils.writeStreamToFile(act.getResources().openRawResource(R.raw.weapons_builtin), Weaponsets.getBuiltinWeaponsetsFile(act)); |
48 FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.weapons_builtin), Weaponsets.getBuiltinWeaponsetsFile(act)); |
49 Utils.resRawToFilesDir(act, R.array.teams, Team.DIRECTORY_TEAMS); |
49 FileUtils.resRawToFilesDir(act, R.array.teams, R.array.teamFilenames, Team.DIRECTORY_TEAMS); |
50 copyFileOrDir(act.getAssets(), Utils.getDataPathFile(act), "Data"); |
50 copyFileOrDir(act.getAssets(), FileUtils.getDataPathFile(act), "Data"); |
51 copyFileOrDir(act.getAssets(), new File(Utils.getCachePath(act), VERSION_FILENAME), VERSION_FILENAME); |
51 copyFileOrDir(act.getAssets(), new File(FileUtils.getCachePath(act), VERSION_FILENAME), VERSION_FILENAME); |
52 return Boolean.TRUE; |
52 return Boolean.TRUE; |
53 } catch(IOException e) { |
53 } catch(IOException e) { |
54 Log.e("DownloadAssets", e.getMessage(), e); |
54 Log.e("DownloadAssets", e.getMessage(), e); |
55 return Boolean.FALSE; |
55 return Boolean.FALSE; |
56 } |
56 } |