summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogDan Vatra <bog_dan_ro@yahoo.com>2012-08-16 21:44:49 +0300
committerBogDan Vatra <bog_dan_ro@yahoo.com>2012-08-16 22:07:00 +0300
commit9afa21ccd6379b45f34e2df62d73fa0747c5e04f (patch)
tree31fd163ed02aad79432f9f1b5dc8df2035dba653
parent3e629e45e5658a82c32ae9af8d0e4a9b5051455f (diff)
Make sure that all needed libs are downloaded.
-rw-r--r--Ministro/AndroidManifest.xml2
-rw-r--r--Ministro/res/values/strings.xml4
-rw-r--r--Ministro/src/org/kde/necessitas/ministro/Library.java17
-rw-r--r--Ministro/src/org/kde/necessitas/ministro/MinistroActivity.java120
-rw-r--r--Ministro/src/org/kde/necessitas/ministro/MinistroConfigActivity.java6
-rw-r--r--Ministro/src/org/kde/necessitas/ministro/MinistroService.java39
6 files changed, 109 insertions, 79 deletions
diff --git a/Ministro/AndroidManifest.xml b/Ministro/AndroidManifest.xml
index 30ac068..98fbd85 100644
--- a/Ministro/AndroidManifest.xml
+++ b/Ministro/AndroidManifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.kde.necessitas.ministro" android:versionName="7.0" android:versionCode="7">
+ package="org.kde.necessitas.ministro" android:versionName="8.3" android:versionCode="8">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MinistroActivity"
android:label="@string/app_name"
diff --git a/Ministro/res/values/strings.xml b/Ministro/res/values/strings.xml
index 7885699..464c3d4 100644
--- a/Ministro/res/values/strings.xml
+++ b/Ministro/res/values/strings.xml
@@ -11,8 +11,8 @@
<string name="downloading_qt_libraries_msg">Downloading libraries</string>
<string name="checking_libraries_msg">Checking libraries. Please wait...</string>
<string name="extracting_SSL_msg">Extracting SSL root certificates. Please wait...</string>
- <string name="new_qt_libs_msg">New libs has been found</string>
- <string name="new_qt_libs_tap_msg">New libs has been found tap to update.</string>
+ <string name="new_qt_libs_msg">New libs have been found</string>
+ <string name="new_qt_libs_tap_msg">New libs have been found tap to update.</string>
<string name="ministro_repository_msg">Ministro will use %1$s repository</string>
<string name="ministro_repository_changed_msg">Ministro repository changed</string>
<string name="ministro_update_msg">Ministro update</string>
diff --git a/Ministro/src/org/kde/necessitas/ministro/Library.java b/Ministro/src/org/kde/necessitas/ministro/Library.java
index 0646d86..7e1a9fe 100644
--- a/Ministro/src/org/kde/necessitas/ministro/Library.java
+++ b/Ministro/src/org/kde/necessitas/ministro/Library.java
@@ -174,6 +174,7 @@ class Library
{
digester.update(tmp, 0, downloaded);
}
+ inFile.close();
return sha1.equalsIgnoreCase(convertToHex(digester.digest()));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
@@ -199,11 +200,23 @@ class Library
public static void removeAllFiles(String path)
{
- String files[]=new File(path).list();
+ File f = new File(path);
+ if (!f.exists())
+ return;
+ String files[]=f.list();
if (!path.endsWith("/"))
path+="/";
for (int i=0;i<files.length;i++)
- new File(path+files[i]).delete();
+ {
+ try
+ {
+ new File(path+files[i]).delete();
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
}
public static String join(Collection<String> s, String delimiter)
diff --git a/Ministro/src/org/kde/necessitas/ministro/MinistroActivity.java b/Ministro/src/org/kde/necessitas/ministro/MinistroActivity.java
index 703bfdb..8a96208 100644
--- a/Ministro/src/org/kde/necessitas/ministro/MinistroActivity.java
+++ b/Ministro/src/org/kde/necessitas/ministro/MinistroActivity.java
@@ -67,6 +67,7 @@ import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.provider.Settings;
+import android.util.Log;
public class MinistroActivity extends Activity
{
@@ -91,10 +92,8 @@ public class MinistroActivity extends Activity
builder.setMessage(getResources().getString(R.string.ministro_network_access_msg));
builder.setCancelable(true);
builder.setNeutralButton(getResources().getString(R.string.settings_msg), new DialogInterface.OnClickListener() {
- @Override
public void onClick(DialogInterface dialog, int id) {
final ProgressDialog m_dialog = ProgressDialog.show(MinistroActivity.this, null, getResources().getString(R.string.wait_for_network_connection_msg), true, true, new DialogInterface.OnCancelListener() {
- @Override
public void onCancel(DialogInterface dialog)
{
finishMe();
@@ -108,7 +107,6 @@ public class MinistroActivity extends Activity
{
getApplication().unregisterReceiver(this);
runOnUiThread(new Runnable() {
- @Override
public void run()
{
m_dialog.dismiss();
@@ -123,14 +121,12 @@ public class MinistroActivity extends Activity
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- @Override
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
public void onCancel(DialogInterface dialog)
{
finishMe();
@@ -143,7 +139,6 @@ public class MinistroActivity extends Activity
private ServiceConnection m_ministroConnection=new ServiceConnection()
{
- @Override
public void onServiceConnected(ComponentName name, IBinder service)
{
if (getIntent().hasExtra("id"))
@@ -157,14 +152,12 @@ public class MinistroActivity extends Activity
getIntent().getExtras().getString("name")))
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
- @Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
checkNetworkAndDownload(false);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
- @Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finishMe();
@@ -177,7 +170,6 @@ public class MinistroActivity extends Activity
checkNetworkAndDownload(true);
}
- @Override
public void onServiceDisconnected(ComponentName name)
{
m_ministroConnection = null;
@@ -231,6 +223,7 @@ public class MinistroActivity extends Activity
break;
}
}
+ br.close();
} catch (Exception e) {
e.printStackTrace();
return "";
@@ -313,7 +306,6 @@ public class MinistroActivity extends Activity
m_dialog.setMessage(m_status);
m_dialog.setCancelable(true);
m_dialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
- @Override
public void onCancel(DialogInterface dialog)
{
DownloadManager.this.cancel(false);
@@ -326,53 +318,64 @@ public class MinistroActivity extends Activity
private boolean DownloadItem(String url, String file, long size, String fileSha1) throws NoSuchAlgorithmException, MalformedURLException, IOException
{
- MessageDigest digester = MessageDigest.getInstance("SHA-1");
- URLConnection connection = new URL(url).openConnection();
- Library.mkdirParents(m_qtLibsRootPath, file, 1);
- String filePath=m_qtLibsRootPath+file;
- int progressSize=0;
- try
+ for (int i=0;i<2;i++)
{
- FileOutputStream outstream = new FileOutputStream(filePath);
- InputStream instream = connection.getInputStream();
- int downloaded;
- byte[] tmp = new byte[2048];
- int oldProgress=-1;
- while ((downloaded = instream.read(tmp)) != -1)
+ MessageDigest digester = MessageDigest.getInstance("SHA-1");
+ URLConnection connection = new URL(url).openConnection();
+ Library.mkdirParents(m_qtLibsRootPath, file, 1);
+ String filePath=m_qtLibsRootPath+file;
+ int progressSize=0;
+ try
{
- if (isCancelled())
- break;
- progressSize+=downloaded;
- m_totalProgressSize+=downloaded;
- digester.update(tmp, 0, downloaded);
- outstream.write(tmp, 0, downloaded);
- int progress=(int)(progressSize*100/size);
- if (progress!=oldProgress)
+ FileOutputStream outstream = new FileOutputStream(filePath);
+ InputStream instream = connection.getInputStream();
+ int downloaded;
+ byte[] tmp = new byte[2048];
+ int oldProgress=-1;
+ while ((downloaded = instream.read(tmp)) != -1)
{
- publishProgress(progress
- , m_totalProgressSize);
- oldProgress = progress;
+ if (isCancelled())
+ break;
+ progressSize+=downloaded;
+ m_totalProgressSize+=downloaded;
+ digester.update(tmp, 0, downloaded);
+ outstream.write(tmp, 0, downloaded);
+ int progress=(int)(progressSize*100/size);
+ if (progress!=oldProgress)
+ {
+ publishProgress(progress
+ , m_totalProgressSize);
+ oldProgress = progress;
+ }
}
- }
- String sha1 = Library.convertToHex(digester.digest());
- if (sha1.equalsIgnoreCase(fileSha1))
- {
+ String sha1 = Library.convertToHex(digester.digest());
+ if (sha1.equalsIgnoreCase(fileSha1))
+ {
+ outstream.close();
+ nativeChmode(filePath, 0644);
+ return true;
+ }
+ else
+ Log.e("Ministro", "sha1 mismatch, the file:"+file+" will be removed, expected sha1:"+fileSha1+" got sha1:"+sha1+" file was downloaded from "+url);
outstream.close();
- nativeChmode(filePath, 0644);
- return true;
+ File f = new File(filePath);
+ f.delete();
+ } catch (Exception e) {
+ e.printStackTrace();
+ File f = new File(filePath);
+ f.delete();
}
- outstream.close();
- File f = new File(filePath);
- f.delete();
- } catch (Exception e) {
- e.printStackTrace();
- File f = new File(filePath);
- f.delete();
+ m_totalProgressSize-=progressSize;
}
- m_totalProgressSize-=progressSize;
return false;
}
+ void removeFile(String file)
+ {
+ File f = new File(m_qtLibsRootPath+file);
+ f.delete();
+ }
+
@Override
protected Long doInBackground(Library... params)
{
@@ -387,7 +390,6 @@ public class MinistroActivity extends Activity
}
m_dialog.setMax(m_totalSize);
- int lastId=-1;
for (int i=0;i<params.length;i++)
{
if (isCancelled())
@@ -398,16 +400,8 @@ public class MinistroActivity extends Activity
}
publishProgress(0, m_totalProgressSize);
if (!DownloadItem(params[i].url, params[i].filePath, params[i].size, params[i].sha1))
- {
- // sometimes for some reasons which I don't understand, Ministro receives corrupt data, so let's give it another chance.
- if (i == lastId)
- break;
- lastId=i;
- --i;
- continue;
- }
+ break;
- lastId=-1;
if (null != params[i].needs)
for (int j=0;j<params[i].needs.length;j++)
{
@@ -418,14 +412,11 @@ public class MinistroActivity extends Activity
publishProgress(0, m_totalProgressSize);
if (!DownloadItem(params[i].needs[j].url, params[i].needs[j].filePath, params[i].needs[j].size, params[i].needs[j].sha1))
{
- // sometimes for some reasons which I don't understand, Ministro receives corrupt data, so let's give it another chance.
- if (j == lastId)
- break;
- lastId=j;
- --j;
- continue;
+ for (int k=0;k<j;k++) // remove previous neede files
+ removeFile(params[i].needs[k].filePath);
+ removeFile(params[i].filePath); // remove the parent
+ break;
}
- lastId=-1;
}
}
} catch (NoSuchAlgorithmException e) {
@@ -475,7 +466,6 @@ public class MinistroActivity extends Activity
{
runOnUiThread(new Runnable()
{
- @Override
public void run()
{
dialog = ProgressDialog.show(MinistroActivity.this, null,
diff --git a/Ministro/src/org/kde/necessitas/ministro/MinistroConfigActivity.java b/Ministro/src/org/kde/necessitas/ministro/MinistroConfigActivity.java
index ca8181d..91b5d06 100644
--- a/Ministro/src/org/kde/necessitas/ministro/MinistroConfigActivity.java
+++ b/Ministro/src/org/kde/necessitas/ministro/MinistroConfigActivity.java
@@ -43,7 +43,6 @@ public class MinistroConfigActivity extends Activity {
repositoriesSpinner.setAdapter(repositories);
repositoriesSpinner.setSelection(repositories.getPosition(MinistroService.getRepository(this)));
repositoriesSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
- @Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
Toast.makeText(parent.getContext()
@@ -51,7 +50,6 @@ public class MinistroConfigActivity extends Activity {
, parent.getItemAtPosition(pos).toString()), Toast.LENGTH_SHORT).show();
MinistroService.setRepository(MinistroConfigActivity.this, parent.getItemAtPosition(pos).toString());
}
- @Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
@@ -63,13 +61,11 @@ public class MinistroConfigActivity extends Activity {
checkFrequencySpinner.setAdapter(checkFrequency);
checkFrequencySpinner.setSelection(checkFrequency.getPosition(MinistroService.getCheckFrequency(this).toString()));
checkFrequencySpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
- @Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
MinistroService.setCheckFrequency(MinistroConfigActivity.this, Long.parseLong(parent.getItemAtPosition(pos).toString()));
}
- @Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
@@ -103,4 +99,4 @@ public class MinistroConfigActivity extends Activity {
}
super.onDestroy();
}
-} \ No newline at end of file
+}
diff --git a/Ministro/src/org/kde/necessitas/ministro/MinistroService.java b/Ministro/src/org/kde/necessitas/ministro/MinistroService.java
index 44610da..eb75801 100644
--- a/Ministro/src/org/kde/necessitas/ministro/MinistroService.java
+++ b/Ministro/src/org/kde/necessitas/ministro/MinistroService.java
@@ -235,7 +235,41 @@ public class MinistroService extends Service
if (checkCrc && !Library.checkCRC(file.getAbsolutePath(), lib.sha1))
file.delete();
else
- m_downloadedLibraries.add(lib);
+ {
+
+ boolean allOk = true;
+ if (lib.needs != null)
+ {
+ for(NeedsStruct needed: lib.needs)// check if its needed files are available
+ if (needed.type != null && needed.type.equals("jar"))
+ {
+ File f=new File(m_qtLibsRootPath + needed.filePath);
+ if (!f.exists())
+ {
+ allOk = false;
+ break;
+ }
+ }
+ if (!allOk)
+ {
+ for(NeedsStruct needed: lib.needs)// remove all needed files
+ if (needed.type != null && needed.type.equals("jar"))
+ {
+ try {
+ File f=new File(m_qtLibsRootPath + needed.filePath);
+ if (f.exists())
+ f.delete();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ file.delete(); // delete the parent
+ }
+ }
+ if (allOk)
+ m_downloadedLibraries.add(lib);
+ }
}
m_availableLibraries.add(lib);
}
@@ -333,7 +367,6 @@ public class MinistroService extends Service
{
return new IMinistro.Stub()
{
- @Override
public void requestLoader(IMinistroCallback callback, Bundle parameters) throws RemoteException
{
@@ -478,7 +511,6 @@ public class MinistroService extends Service
try
{
m_handler.postDelayed(new Runnable() {
- @Override
public void run() {
MinistroService.this.startActivity(intent);
}
@@ -697,7 +729,6 @@ public class MinistroService extends Service
*/
static private class ModuleCompare implements Comparator<Module>
{
- @Override
public int compare(Module a, Module b)
{
return a.level-b.level;