Various fixes to the previous shoddy (excuse: I couldn't run it on that machine) commit
This commit is contained in:
parent
1f019f0c5b
commit
918aa224cb
@ -386,13 +386,15 @@ public class AppDetails extends ListActivity {
|
|||||||
saveit.close();
|
saveit.close();
|
||||||
File f = new File(localfile);
|
File f = new File(localfile);
|
||||||
Md5Handler hash = new Md5Handler();
|
Md5Handler hash = new Md5Handler();
|
||||||
|
String calcedhash = hash.md5Calc(f);
|
||||||
if (curapk.hash.equalsIgnoreCase(hash.md5Calc(f))) {
|
if (curapk.hash.equalsIgnoreCase(calcedhash)) {
|
||||||
apk_file = localfile;
|
apk_file = localfile;
|
||||||
} else {
|
} else {
|
||||||
msg = new Message();
|
msg = new Message();
|
||||||
msg.obj = getString(R.string.corrupt_download);
|
msg.obj = getString(R.string.corrupt_download);
|
||||||
download_error_handler.sendMessage(msg);
|
download_error_handler.sendMessage(msg);
|
||||||
|
Log.d("FDroid", "Downloaded file hash of " + calcedhash
|
||||||
|
+ " did not match repo's " + curapk.hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -37,18 +37,18 @@ public class DB {
|
|||||||
private static final String DATABASE_NAME = "fdroid_db";
|
private static final String DATABASE_NAME = "fdroid_db";
|
||||||
|
|
||||||
private SQLiteDatabase db;
|
private SQLiteDatabase db;
|
||||||
|
private Context mctx;
|
||||||
|
|
||||||
// The TABLE_VERSION table tracks the database version.
|
// The TABLE_VERSION table tracks the database version.
|
||||||
private static final String TABLE_VERSION = "fdroid_version";
|
private static final String TABLE_VERSION = "fdroid_version";
|
||||||
private static final String CREATE_TABLE_VERSION = "create table "
|
private static final String CREATE_TABLE_VERSION = "create table "
|
||||||
+ TABLE_VERSION + "(version int not null); insert into "
|
+ TABLE_VERSION + " (version int not null);";
|
||||||
+ TABLE_VERSION + "(version) values (1);";
|
|
||||||
|
|
||||||
// The TABLE_APP table stores details of all the applications we know about.
|
// The TABLE_APP table stores details of all the applications we know about.
|
||||||
// This information is retrieved from the repositories.
|
// This information is retrieved from the repositories.
|
||||||
private static final String TABLE_APP = "fdroid_app";
|
private static final String TABLE_APP = "fdroid_app";
|
||||||
private static final String CREATE_TABLE_APP = "create table " + TABLE_APP
|
private static final String CREATE_TABLE_APP = "create table " + TABLE_APP
|
||||||
+ "( " + "id text not null, " + "name text not null, "
|
+ " ( " + "id text not null, " + "name text not null, "
|
||||||
+ "summary text not null, " + "icon text, "
|
+ "summary text not null, " + "icon text, "
|
||||||
+ "description text not null, " + "license text not null, "
|
+ "description text not null, " + "license text not null, "
|
||||||
+ "webURL text, " + "trackerURL text, " + "sourceURL text, "
|
+ "webURL text, " + "trackerURL text, " + "sourceURL text, "
|
||||||
@ -100,15 +100,15 @@ public class DB {
|
|||||||
// one, that most users would want by default. It might not be the
|
// one, that most users would want by default. It might not be the
|
||||||
// most recent, if for example there are betas etc.
|
// most recent, if for example there are betas etc.
|
||||||
public Apk getCurrentVersion() {
|
public Apk getCurrentVersion() {
|
||||||
|
|
||||||
// Try and return the version that's in Google's market first...
|
// Try and return the version that's in Google's market first...
|
||||||
if(marketVersion!=null && marketVercode>0) {
|
if (marketVersion != null && marketVercode > 0) {
|
||||||
for(Apk apk : apks) {
|
for (Apk apk : apks) {
|
||||||
if(apk.vercode == marketVercode)
|
if (apk.vercode == marketVercode)
|
||||||
return apk;
|
return apk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't know the market version, or we don't have it, we
|
// If we don't know the market version, or we don't have it, we
|
||||||
// return the most recent version we have...
|
// return the most recent version we have...
|
||||||
int latestcode = -1;
|
int latestcode = -1;
|
||||||
@ -130,7 +130,7 @@ public class DB {
|
|||||||
// This information is retrieved from the repositories.
|
// This information is retrieved from the repositories.
|
||||||
private static final String TABLE_APK = "fdroid_apk";
|
private static final String TABLE_APK = "fdroid_apk";
|
||||||
private static final String CREATE_TABLE_APK = "create table " + TABLE_APK
|
private static final String CREATE_TABLE_APK = "create table " + TABLE_APK
|
||||||
+ "( " + "id text not null, " + "version text not null, "
|
+ " ( " + "id text not null, " + "version text not null, "
|
||||||
+ "server text not null, " + "hash text not null, "
|
+ "server text not null, " + "hash text not null, "
|
||||||
+ "vercode int not null," + "apkName text not null, "
|
+ "vercode int not null," + "apkName text not null, "
|
||||||
+ "size int not null," + "primary key(id,version));";
|
+ "size int not null," + "primary key(id,version));";
|
||||||
@ -186,11 +186,12 @@ public class DB {
|
|||||||
// * The current version is tracked by an entry in the TABLE_VERSION
|
// * The current version is tracked by an entry in the TABLE_VERSION
|
||||||
// table.
|
// table.
|
||||||
//
|
//
|
||||||
private static final String[] DB_UPGRADES = {
|
private static final String[][] DB_UPGRADES = {
|
||||||
|
|
||||||
// Version 2...
|
// Version 2...
|
||||||
"alter table " + TABLE_APK + " add marketVersion text; " + "alter table "
|
{"alter table " + TABLE_APP + " add marketVersion text",
|
||||||
+ TABLE_APK + " add marketVercode integer; "
|
"alter table "+ TABLE_APP + " add marketVercode integer"
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -201,6 +202,7 @@ public class DB {
|
|||||||
private PackageManager mPm;
|
private PackageManager mPm;
|
||||||
|
|
||||||
public DB(Context ctx) {
|
public DB(Context ctx) {
|
||||||
|
mctx = ctx;
|
||||||
db = ctx.openOrCreateDatabase(DATABASE_NAME, 0, null);
|
db = ctx.openOrCreateDatabase(DATABASE_NAME, 0, null);
|
||||||
|
|
||||||
// Check if we already have a database and create or upgrade as
|
// Check if we already have a database and create or upgrade as
|
||||||
@ -228,6 +230,8 @@ public class DB {
|
|||||||
db.execSQL("drop table if exists " + TABLE_APP);
|
db.execSQL("drop table if exists " + TABLE_APP);
|
||||||
db.execSQL("drop table if exists " + TABLE_APK);
|
db.execSQL("drop table if exists " + TABLE_APK);
|
||||||
db.execSQL(CREATE_TABLE_VERSION);
|
db.execSQL(CREATE_TABLE_VERSION);
|
||||||
|
db.execSQL("insert into " + TABLE_VERSION
|
||||||
|
+ " (version) values (1);");
|
||||||
db.execSQL(CREATE_TABLE_REPO);
|
db.execSQL(CREATE_TABLE_REPO);
|
||||||
db.execSQL(CREATE_TABLE_APP);
|
db.execSQL(CREATE_TABLE_APP);
|
||||||
db.execSQL(CREATE_TABLE_APK);
|
db.execSQL(CREATE_TABLE_APK);
|
||||||
@ -238,16 +242,35 @@ public class DB {
|
|||||||
Cursor c = db
|
Cursor c = db
|
||||||
.rawQuery("SELECT version from " + TABLE_VERSION, null);
|
.rawQuery("SELECT version from " + TABLE_VERSION, null);
|
||||||
c.moveToFirst();
|
c.moveToFirst();
|
||||||
version = c.getInt(0);
|
if (c.isAfterLast()) {
|
||||||
c.close();
|
c.close();
|
||||||
|
Log.d("FDroid", "Missing version record - assuming 1");
|
||||||
|
db.execSQL("INSERT into " + TABLE_VERSION
|
||||||
|
+ " (version) values (1);");
|
||||||
|
version = 1;
|
||||||
|
} else {
|
||||||
|
version = c.getInt(0);
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run upgrade scripts if necessary...
|
// Run upgrade scripts if necessary...
|
||||||
|
boolean modified = false;
|
||||||
while (version < DB_UPGRADES.length + 1) {
|
while (version < DB_UPGRADES.length + 1) {
|
||||||
db.execSQL(DB_UPGRADES[version - 1]);
|
for(int i=0;i<DB_UPGRADES[version -1].length;i++)
|
||||||
|
db.execSQL(DB_UPGRADES[version - 1][i]);
|
||||||
version++;
|
version++;
|
||||||
db.execSQL("update " + TABLE_VERSION + " set version = " + version
|
db.execSQL("update " + TABLE_VERSION + " set version = " + version
|
||||||
+ ";");
|
+ ";");
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified || reset) {
|
||||||
|
// Close and reopen to ensure underlying prepared statements are
|
||||||
|
// dropped, otherwise
|
||||||
|
// they will fail to execute.
|
||||||
|
db.close();
|
||||||
|
db = mctx.openOrCreateDatabase(DATABASE_NAME, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -293,10 +316,9 @@ public class DB {
|
|||||||
app.sourceURL = c.getString(c.getColumnIndex("sourceURL"));
|
app.sourceURL = c.getString(c.getColumnIndex("sourceURL"));
|
||||||
app.installedVersion = c.getString(c
|
app.installedVersion = c.getString(c
|
||||||
.getColumnIndex("installedVersion"));
|
.getColumnIndex("installedVersion"));
|
||||||
app.marketVersion = c2.getString(c2
|
app.marketVersion = c.getString(c
|
||||||
.getColumnIndex("marketVersion"));
|
.getColumnIndex("marketVersion"));
|
||||||
app.marketVercode = c2.getInt(c2
|
app.marketVercode = c.getInt(c.getColumnIndex("marketVercode"));
|
||||||
.getColumnIndex("marketVercode"));
|
|
||||||
app.hasUpdates = false;
|
app.hasUpdates = false;
|
||||||
|
|
||||||
c2 = db.rawQuery("select * from " + TABLE_APK + " where "
|
c2 = db.rawQuery("select * from " + TABLE_APK + " where "
|
||||||
@ -322,7 +344,7 @@ public class DB {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("FDroid", "Exception during database reading - "
|
Log.d("FDroid", "Exception during database reading - "
|
||||||
+ e.getMessage());
|
+ e.getMessage() + " ... " + e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.close();
|
c.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user