author | sheepluva |
Sun, 08 Dec 2019 02:09:19 +0100 | |
branch | hedgeroid |
changeset 15520 | de08a3ae4f8d |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
1 |
/* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
3 |
* Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
4 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
5 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
7 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
8 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
9 |
* of the License, or (at your option) any later version. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
10 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
14 |
* GNU General Public License for more details. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
15 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
17 |
* along with this program; if not, write to the Free Software |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
19 |
*/ |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
20 |
|
6350 | 21 |
package org.hedgewars.hedgeroid.Downloader; |
22 |
||
23 |
import java.io.File; |
|
7318
a446eafcddeb
Improved asset moving time by an order of magnitude (3s vs. 25s on my device)
Medo <smaxein@googlemail.com>
parents:
6724
diff
changeset
|
24 |
import java.io.FileNotFoundException; |
6350 | 25 |
import java.io.IOException; |
26 |
||
27 |
import org.hedgewars.hedgeroid.MainActivity; |
|
6724
03cd33624284
schemes/teams now get replaces on each version update
Xeli
parents:
6485
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.R; |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7344
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.Datastructures.Schemes; |
6724
03cd33624284
schemes/teams now get replaces on each version update
Xeli
parents:
6485
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.Datastructures.Team; |
7485 | 31 |
import org.hedgewars.hedgeroid.Datastructures.Weaponsets; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
32 |
import org.hedgewars.hedgeroid.util.FileUtils; |
6350 | 33 |
|
34 |
import android.content.res.AssetManager; |
|
35 |
import android.os.AsyncTask; |
|
36 |
import android.util.Log; |
|
37 |
||
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7326
diff
changeset
|
38 |
public class DownloadAssets extends AsyncTask<Object, Long, Boolean> { |
10017 | 39 |
private static final String VERSION_FILENAME = "assetsversion.txt"; |
40 |
private final MainActivity act; |
|
41 |
||
42 |
public DownloadAssets(MainActivity act){ |
|
43 |
this.act = act; |
|
44 |
} |
|
45 |
||
46 |
private void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException { |
|
47 |
try { |
|
48 |
FileUtils.writeStreamToFile(assetManager.open(assetPath), target); |
|
49 |
} catch(FileNotFoundException e) { |
|
50 |
/* |
|
51 |
* I can't find a better way to figure out whether an asset entry is |
|
52 |
* a file or a directory. Checking if assetManager.list(assetPath) |
|
53 |
* is empty is a bit cleaner, but SLOW. |
|
54 |
*/ |
|
55 |
if (!target.isDirectory() && !target.mkdir()) { |
|
56 |
throw new IOException("Unable to create directory "+target); |
|
57 |
} |
|
58 |
for (String asset : assetManager.list(assetPath)) { |
|
59 |
copyFileOrDir(assetManager, new File(target, asset), assetPath + "/" + asset); |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
@Override |
|
65 |
protected Boolean doInBackground(Object... params) { |
|
66 |
try { |
|
67 |
FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.schemes_builtin), Schemes.getBuiltinSchemesFile(act)); |
|
68 |
FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.weapons_builtin), Weaponsets.getBuiltinWeaponsetsFile(act)); |
|
69 |
FileUtils.resRawToFilesDir(act, R.array.teams, R.array.teamFilenames, Team.DIRECTORY_TEAMS); |
|
70 |
copyFileOrDir(act.getAssets(), FileUtils.getDataPathFile(act), "Data"); |
|
71 |
copyFileOrDir(act.getAssets(), new File(FileUtils.getCachePath(act), VERSION_FILENAME), VERSION_FILENAME); |
|
72 |
return Boolean.TRUE; |
|
73 |
} catch(IOException e) { |
|
74 |
Log.e("DownloadAssets", e.getMessage(), e); |
|
75 |
return Boolean.FALSE; |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
protected void onPostExecute(Boolean result){ |
|
81 |
act.onAssetsDownloaded(result); |
|
82 |
} |
|
6350 | 83 |
} |