Skip to content

Commit

Permalink
update kcptun to 20160725
Browse files Browse the repository at this point in the history
change version name to v0.2
optimize kcptun bin file update logic
  • Loading branch information
shutup committed Aug 6, 2016
1 parent f758d1f commit a8b20c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
23 changes: 12 additions & 11 deletions app/src/main/java/com/shutup/kcptun_android/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
* Created by shutup on 16/7/20.
*/
public interface Constants {
public static final String SettingChanged = "SettingChanged";
String AppVersionCode = "AppVersionCode";
String SettingChanged = "SettingChanged";

public static final String RemoteServerIp = "RemoteServerIp";
public static final String RemoteServerPort = "RemoteServerPort";
public static final String LocalServerPort = "LocalServerPort";
public static final String ServerKey = "ServerKey";
public static final String ServerMode = "ServerMode";
String RemoteServerIp = "RemoteServerIp";
String RemoteServerPort = "RemoteServerPort";
String LocalServerPort = "LocalServerPort";
String ServerKey = "ServerKey";
String ServerMode = "ServerMode";

public static final int SET_INFO_CONTENT = 0;
public static final int APPEND_INFO_CONTENT = 1;
public static final int CHANGE_START_BTN_NAME = 2;
public static final int CHANGE_START_BTN_ENABLE = 3;
public static final int CHANGE_SETTING_BTN_ENABLE = 5;
int SET_INFO_CONTENT = 0;
int APPEND_INFO_CONTENT = 1;
int CHANGE_START_BTN_NAME = 2;
int CHANGE_START_BTN_ENABLE = 3;
int CHANGE_SETTING_BTN_ENABLE = 5;
}
23 changes: 20 additions & 3 deletions app/src/main/java/com/shutup/kcptun_android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -179,13 +181,13 @@ private int detectCpuArchInfo() {
* @param filename
* @return
*/
private static String installBinary(Context ctx, int resId, String filename) {
private String installBinary(Context ctx, int resId, String filename) {
try {
File f = new File(ctx.getDir("bin", 0), filename);
if (f.exists()) {

handleKcptunUpdate(ctx, resId, f);
} else {
copyRawFile(ctx, resId, f, "0755");
handleKcptunUpdate(ctx, resId, f);
}
return f.getCanonicalPath();
} catch (Exception e) {
Expand All @@ -194,6 +196,21 @@ private static String installBinary(Context ctx, int resId, String filename) {
}
}

private void handleKcptunUpdate(Context ctx, int resId, File f) throws PackageManager.NameNotFoundException, IOException, InterruptedException {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int currentVersionCode = pInfo.versionCode;
int localVersionCode = mSharedPreferences.getInt(AppVersionCode,0);
if (localVersionCode < currentVersionCode) {
copyRawFile(ctx,resId,f,"0755");
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(AppVersionCode,currentVersionCode);
editor.commit();
}
else{
if (BuildConfig.DEBUG) Log.d(TAG, "no update");
}
}

private static void copyRawFile(Context ctx, int resid, File file, String mode) throws IOException, InterruptedException {
final String abspath = file.getAbsolutePath();
final FileOutputStream out = new FileOutputStream(file);
Expand Down

0 comments on commit a8b20c6

Please sign in to comment.