@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.manifest_view); // Register the exit button Button back_button = (Button) findViewById(R.id.mv_back); back_button.setOnClickListener(this); // Get the intent with its data Intent intent = this.getIntent(); // Fill the screen TextView author_tv = (TextView) findViewById(R.id.mv_author); author_tv.setText(intent.getStringExtra("author")); TextView version_tv = (TextView) findViewById(R.id.mv_version); version_tv.setText(intent.getStringExtra("version")); TextView hash_tv = (TextView) findViewById(R.id.mv_hash); hash_tv.setText(intent.getStringExtra("hash")); TextView size_tv = (TextView) findViewById(R.id.mv_size); size_tv.setText(intent.getStringExtra("size")); TextView date_tv = (TextView) findViewById(R.id.mv_date); date_tv.setText(intent.getStringExtra("date")); TextView name_tv = (TextView) findViewById(R.id.mv_name); name_tv.setText(intent.getStringExtra("name")); // Compute the hash of the file and compares it to the manifest's one. File f = new File(RhizomeUtils.dirRhizome, intent.getStringExtra("name")); String f_hash = RhizomeUtils.ToHexString(RhizomeUtils.DigestFile(f)); TextView hash_ok = (TextView) findViewById(R.id.mv_hash_ok); hash_ok.setText(f_hash.equals(intent.getStringExtra("hash")) + ""); // Check if the certificate is signed correctly (TODO) TextView sign_ok = (TextView) findViewById(R.id.mv_sign_ok); sign_ok.setText("TODO"); }
/** * Create a manifest file for the imported file. The timestamp is set at the current value. * * @param fileName Name of the file * @param author Author of the file * @param version Version of the file * @param size */ public static void GenerateManifestForFilename(String fileName, String author, float version) { try { Properties manifestP = new Properties(); // Set up the property object manifestP.put("author", author); manifestP.put("name", fileName); manifestP.put("version", version + ""); manifestP.put("date", System.currentTimeMillis() + ""); // The locally computed manifestP.put("size", new File(RhizomeUtils.dirRhizome, fileName).length() + ""); manifestP.put( "hash", RhizomeUtils.ToHexString( RhizomeUtils.DigestFile(new File(RhizomeUtils.dirRhizome, fileName)))); // Save the file File tmpManifest = new File(RhizomeUtils.dirRhizome, "." + fileName + ".manifest"); Log.v(TAG, tmpManifest + ""); manifestP.store(new FileOutputStream(tmpManifest), "Rhizome manifest data for " + fileName); } catch (IOException e) { Log.e(TAG, "Error when creating manifest for " + fileName); } }
/** * Export the file in the given dir. The directory is defined in the main app. * * @throws IOException If the copy fails. */ public void export() throws IOException { RhizomeUtils.CopyFileToDir(file, RhizomeUtils.dirExport); }