Skip to content

Commit 420e45d

Browse files
committed
install from assets
1 parent f423376 commit 420e45d

File tree

8 files changed

+69
-166
lines changed

8 files changed

+69
-166
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
minSdkVersion rootProject.ext.minSdkVersion
1212
targetSdkVersion rootProject.ext.targetSdkVersion
1313
multiDexEnabled true
14-
versionCode 28
15-
versionName "1.2.0 beta"
14+
versionCode 29
15+
versionName "1.2.1"
1616
vectorDrawables.useSupportLibrary = true
1717
ndk {
1818
moduleName "aapt"

app/proguard-rules.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
-dontwarn java.awt.**
8585

8686
-keep class com.android.** { *; }
87-
#-keep class com.duy.** { *; }
87+
-keep class com.duy.** { *; }
8888
-keep class com.spartacusrex.spartacuside.**
8989
-keep class proguard.**
9090
-keep class com.simplecityapps.**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
adb uninstall com.duy.compiler.javanide
2-
adb install -r app-prod-release.apk
2+
adb install -r app-release.apk
33
clear
44
echo success.
55
adb shell am start -n "com.duy.compiler.javanide/com.duy.ide.activities.ActivitySplashScreen" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
14.4 MB
Binary file not shown.

app/src/main/java/com/duy/ide/activities/InstallActivity.java

Lines changed: 61 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.content.DialogInterface;
66
import android.content.Intent;
7+
import android.content.res.AssetManager;
78
import android.net.ConnectivityManager;
89
import android.net.Uri;
910
import android.os.AsyncTask;
@@ -36,6 +37,7 @@
3637
import java.io.File;
3738
import java.io.FileOutputStream;
3839
import java.io.IOException;
40+
import java.io.InputStream;
3941
import java.util.Enumeration;
4042
import java.util.Locale;
4143
import java.util.zip.ZipEntry;
@@ -66,21 +68,24 @@ protected void onCreate(Bundle savedInstanceState) {
6668
setTitle(R.string.install);
6769

6870
mPreferences = new AppSetting(this);
69-
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
70-
mInfo = (TextView) findViewById(R.id.txt_info);
71-
mInstallButton = (Button) findViewById(R.id.btn_install);
71+
mProgressBar = findViewById(R.id.progress_bar);
72+
mInfo = findViewById(R.id.txt_info);
73+
mInstallButton = findViewById(R.id.btn_install);
7274

7375
// mTxtVersion = (TextView) findViewById(R.id.txt_version);
7476
// String version = getString(R.string.system_version) + mPreferences.getSystemVersion();
7577
// mTxtVersion.setText(version);
7678
findViewById(R.id.btn_install).setOnClickListener(this);
7779
findViewById(R.id.btn_select_file).setOnClickListener(this);
7880
findViewById(R.id.down_load_from_github).setOnClickListener(this);
81+
82+
extractFileFromAsset();
7983
}
8084

85+
8186
@Override
8287
public void onClick(View v) {
83-
if (v.getId() == R.id.btn_install) {
88+
/* if (v.getId() == R.id.btn_install) {
8489
if (isConnected()) {
8590
downloadFile();
8691
} else {
@@ -90,7 +95,11 @@ public void onClick(View v) {
9095
selectFile();
9196
} else if (v.getId() == R.id.down_load_from_github) {
9297
downloadFromGit();
93-
}
98+
}*/
99+
}
100+
101+
private void extractFileFromAsset() {
102+
new CopyFromAssetTask(this).execute();
94103
}
95104

96105
private void downloadFromGit() {
@@ -226,6 +235,10 @@ private void showDialogDownload() {
226235
builder.setTitle("Download system");
227236
}
228237

238+
private void installFailed() {
239+
Toast.makeText(this, "Install failed", Toast.LENGTH_SHORT).show();
240+
}
241+
229242
private class InstallTask extends AsyncTask<File, String, Boolean> {
230243
private Exception error = null;
231244
private Context context;
@@ -256,77 +269,10 @@ protected Boolean doInBackground(File... params) {
256269
throw new RuntimeException("Install failed, Not a classes.zip file");
257270
}
258271

259-
// File tmp = new File(home, "tmp");
260-
// if (!tmp.exists()) tmp.mkdirs();
261-
//
262-
// File worker = new File(tmp, "WORK_" + System.currentTimeMillis());
263-
// if (!worker.exists()) worker.mkdirs();
264-
//
265-
// File busytar = new File(worker, "busybox");
266-
// if (busytar.exists()) busytar.delete();
267-
//
268-
// publishProgress("Extract busybox");
269-
// FileManager.extractAsset(context, "busybox.mp3", busytar);
270-
//
271-
// String[] env = new String[2];
272-
// env[0] = "PATH=/sbin" + ":/vendor/bin" + ":/system/sbin" + ":/system/bin" +
273-
// ":/system/xbin";
274-
//
275-
// env[1] = "LD_LIBRARY_PATH=" + "/vendor/lib" + ":/vendor/lib64" + ":/system/lib" +
276-
// ":/system/lib64";
277-
//
278-
// busytar.setReadable(true, true);
279-
// busytar.setWritable(true, true);
280-
// busytar.setExecutable(true, false);
281-
//
282-
// publishProgress("Extract system file");
283-
// File systar = new File(worker, "system.tar.gz");
284-
// org.apache.commons.io.FileUtils.copyFile(params[0], systar);
285-
// publishProgress("Extracted system");
286-
//
287-
// Process pp;
288-
// publishProgress("Removing Old System");
289-
//
290-
// File systemFolder = new File(home, "system");
291-
// FileManager.deleteFolder(systemFolder);
292-
//
293-
// publishProgress("Config system file");
294-
// String busyboxCmd_ = busytar.getPath() + " ";
295-
// pp = Runtime.getRuntime().exec(busyboxCmd_ + "tar -C " + home.getPath() + " -xzf " + systar.getPath(), env, home);
296-
// pp.waitFor();
297-
//
298-
// File bindir = new File(systemFolder, "bin");
299-
// File bbindir = new File(bindir, "bbdir");
300-
// if (!bbindir.exists()) bbindir.mkdirs();
301-
//
302-
// File busybox = new File(bindir, "busybox");
303-
// String command = busybox.getPath() + " --install -s " + bbindir.getPath();
304-
// pp = Runtime.getRuntime().exec(command, env, home);
305-
// pp.waitFor();
306-
//
307-
// //Now delete the SU link.. too much confusion..
308-
// File su = new File(bbindir, "su");
309-
// su.delete();
310-
//
311-
// publishProgress("Copy config file");
312-
// copyFileConfig(home, systemFolder, busyboxCmd_, env);
313-
//
314-
// publishProgress("Create local file");
315-
// createLocalFile(home);
316-
//
317-
// publishProgress("Cleaning up...");
318-
// FileManager.deleteFolder(worker);
319-
// FileManager.deleteFolder(params[0]);
320-
//
321-
// mPreferences.put("system_installed", true);
322-
// mPreferences.put("system_version", SYSTEM_VERSION);
323272

324273
} catch (Exception e) {
325274
publishProgress("Error when install system");
326275

327-
// mPreferences.put("system_installed", false);
328-
// mPreferences.put("system_version", "");
329-
330276
e.printStackTrace();
331277
error = e;
332278
return false;
@@ -337,92 +283,6 @@ protected Boolean doInBackground(File... params) {
337283
return true;
338284
}
339285

340-
private void copyFileConfig(File home, File systemFolder, String busyboxCmd_, String[] env)
341-
throws IOException, InterruptedException {
342-
boolean override = true;
343-
Process pp;
344-
File bashrc = new File(systemFolder, "bashrc");
345-
File bashrcu = new File(home, ".bashrc");
346-
if (!bashrcu.exists() || override) {
347-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + bashrc.getPath() + " " + bashrcu.getPath(), env, home);
348-
pp.waitFor();
349-
}
350-
351-
File nanorc = new File(systemFolder, "nanorc");
352-
File nanorcu = new File(home, ".nanorc");
353-
if (!nanorcu.exists() || override) {
354-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + nanorc.getPath() + " " + nanorcu.getPath(), env, home);
355-
pp.waitFor();
356-
}
357-
358-
File tmuxrc = new File(systemFolder, "tmux.conf");
359-
File tmuxrcu = new File(home, ".tmux.conf");
360-
if (!tmuxrcu.exists() || override) {
361-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + tmuxrc.getPath() + " " + tmuxrcu.getPath(), env, home);
362-
pp.waitFor();
363-
}
364-
365-
366-
File ini = new File(systemFolder, "mc.ini");
367-
File conf = new File(home, ".config");
368-
File confmc = new File(conf, "mc");
369-
if (!confmc.exists()) confmc.mkdirs();
370-
File mcini = new File(confmc, "ini");
371-
if (!mcini.exists() || override) {
372-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + ini.getPath() + " " + mcini.getPath(), env, home);
373-
pp.waitFor();
374-
}
375-
376-
File inputrc = new File(systemFolder, "inputrc");
377-
File inputrcu = new File(home, ".inputrc");
378-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + inputrc.getPath() + " " + inputrcu.getPath(), env, home);
379-
pp.waitFor();
380-
381-
//config vim
382-
File vimrc = new File(systemFolder, "vimrc");
383-
File vimrcu = new File(home, ".vimrc");
384-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -f " + vimrc.getPath() + " " + vimrcu.getPath(), env, home);
385-
pp.waitFor();
386-
387-
//Check the home vim folder
388-
File vimh = new File(systemFolder, "etc/default_vim");
389-
File vimhu = new File(home, ".vim");
390-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "cp -rf " + vimh.getPath() + " " + vimhu.getPath(), env, home);
391-
pp.waitFor();
392-
393-
//Create a link to the sdcard
394-
File sdcard = Environment.getExternalStorageDirectory();
395-
File lnsdcard = new File(home, "sdcard");
396-
pp = Runtime.getRuntime().exec(busyboxCmd_ + "ln -s " + sdcard.getPath() + " " + lnsdcard.getPath(), env, home);
397-
pp.waitFor();
398-
399-
}
400-
401-
/**
402-
* create local dir
403-
*
404-
* @param home
405-
*/
406-
private void createLocalFile(File home) {
407-
File local = new File(home, "local");
408-
if (!local.exists()) local.mkdirs();
409-
410-
File bin = new File(local, "bin");
411-
if (!bin.exists()) bin.mkdirs();
412-
413-
bin = new File(local, "lib");
414-
if (!bin.exists()) bin.mkdirs();
415-
416-
bin = new File(local, "include");
417-
if (!bin.exists()) bin.mkdirs();
418-
419-
bin = new File(home, "tmp");
420-
if (!bin.exists()) bin.mkdirs();
421-
422-
bin = new File(home, "projects");
423-
if (!bin.exists()) bin.mkdirs();
424-
}
425-
426286
@Override
427287
protected void onProgressUpdate(String... values) {
428288
super.onProgressUpdate(values);
@@ -483,5 +343,48 @@ private void createDir(File dir) {
483343

484344
}
485345

346+
private class CopyFromAssetTask extends AsyncTask<File, String, File> {
347+
private Context context;
348+
349+
public CopyFromAssetTask(Context context) {
350+
this.context = context;
351+
}
352+
353+
@Override
354+
protected void onPreExecute() {
355+
super.onPreExecute();
356+
mInfo.setText(R.string.start_install_system);
357+
mProgressBar.setIndeterminate(true);
358+
mInstallButton.setEnabled(false);
359+
installing = true;
360+
}
361+
362+
@Override
363+
protected File doInBackground(File... params) {
364+
try {
365+
AssetManager assets = context.getAssets();
366+
InputStream open = assets.open("classes/classes.zip");
367+
File outFile = new File(getFilesDir(), "classes.zip");
368+
FileOutputStream fileOutputStream = new FileOutputStream(outFile);
369+
FileManager.copyStream(open, fileOutputStream);
370+
fileOutputStream.close();
371+
return outFile;
372+
} catch (IOException e) {
373+
e.printStackTrace();
374+
}
375+
return null;
376+
}
377+
378+
@Override
379+
protected void onPostExecute(File file) {
380+
super.onPostExecute(file);
381+
if (file != null) {
382+
new InstallTask(context).execute(file);
383+
} else {
384+
installFailed();
385+
}
386+
}
387+
}
388+
486389

487390
}

app/src/main/java/com/duy/ide/file/FileManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static boolean deleteFolder(File zFile) {
159159
return zFile.delete();
160160
}
161161

162-
public static void copyFile(InputStream in, OutputStream out) throws IOException {
162+
public static void copyStream(InputStream in, OutputStream out) throws IOException {
163163
byte[] buffer = new byte[1024];
164164
int read;
165165
while ((read = in.read(buffer)) != -1) {
@@ -171,7 +171,7 @@ public static void copyFile(InputStream in, OutputStream out) throws IOException
171171
public static void extractAsset(Context zContext, String zAssetFile, File zOuput) throws IOException {
172172
InputStream in = zContext.getAssets().open(zAssetFile);
173173
OutputStream os = new FileOutputStream(zOuput);
174-
copyFile(in, os);
174+
copyStream(in, os);
175175
in.close();
176176
os.close();
177177
}

app/src/main/java/com/duy/project/dialog/DialogNewAndroidProject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void doCreateProject() {
158158
//copy keystore
159159
File file = projectFile.getKeyStore().getFile();
160160
FileOutputStream out = new FileOutputStream(file);
161-
FileManager.copyFile(assets.open("templates/src/main/androiddebug.jks"), out);
161+
FileManager.copyStream(assets.open("templates/src/main/androiddebug.jks"), out);
162162
out.close();
163163

164164
//copy android support library

app/src/main/java/com/duy/project/file/android/AndroidProjectFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void checkKeyStoreExits(Context context) {
207207
try {
208208
key.createNewFile();
209209
FileOutputStream out = new FileOutputStream(key);
210-
FileManager.copyFile(context.getAssets().open(Constants.KEY_STORE_ASSET_PATH), out);
210+
FileManager.copyStream(context.getAssets().open(Constants.KEY_STORE_ASSET_PATH), out);
211211
out.close();
212212
setKeystore(new KeyStore(key, Constants.KEY_STORE_PASSWORD,
213213
Constants.KEY_STORE_ALIAS, Constants.KEY_STORE_ALIAS_PASS));

0 commit comments

Comments
 (0)