lundi 25 avril 2016

How to Automatically Check the MD5 Sum of a Download!

Back in the middle of March, we dedicated an entire week to many awesome Tasker tips and tricks that you’ve likely never seen elsewhere to best enhance your smartphone’s utility. Hopefully, you’ve learned a bit about how to work with Tasker having played with some real-world examples.

Today, I’m bringing you a new idea I’ve come up with that should please the many flashaholics on our forums.

If you’re a user who likes to take control of your own device by flashing custom ROMs, kernels, etc then you are likely someone who downloads a lot of files off of sites like AndroidFileHost.com. You will notice that each and every file on hosting sites like this include the MD5 sum for you to compare when you finish downloading it.

Oops

Oops

It’s super important that you compare the MD5 sums before flashing a critical file such as a radio or bootloader, to ensure that you aren’t flashing a corrupted file. But it’s a nuisance to do so on mobile, because you need to manually find the file in your file explorer app and copy/paste the MD5 sum into a text box in order to compare the sums.

Checking MD5 Sums using a File Explorer Using the standalone HashStamp App

I stopped and thought to myself, why not automate this with Tasker? I looked it up and was surprised to not have found this mentioned anywhere, but it’s possible and actually quite easy to do!

How It’s Done

How it works: You copy the md5 sum to your clipboard BEFORE downloading, then when the download finishes you are prompted whether or not you want to compare values. If you press yes, then Tasker will calculate the MD5 sum of the downloaded file and compare it to what’s in your clipboard.


Prerequisites

  • Notification Listener or AutoNotification. I personally use AutoNotification but for the sake of this tutorial I set it up using Notification Listener because it’s free to use.
  • Snackbar Tasker Plugin. Not required (though if you import my profile it uses it) but it beats having to create a scene with buttons. I’ve set up the tutorial to only use the free features of the app.

Screenshot_20160424-180854


Instructions

  • Create a new profile and name it ‘Check MD5 Sums.’ For the context, go to Events –> Plugins –> Notification Listener. Select “Posted” and scroll down and pick your browser app. I personally use Chrome Dev so I selected that.
  • Task –> If. Set it to If %nltext ~ Download complete. (Or whatever sub-text your notification says when your browser app tells you a download has been completed.) This is so the task will trigger when it detects that a download has been completed, as indicated by the browser notification.
  • Plugins –> Snackbar Tasker Plugin. Select “Bottom Sheet.” For the title, make it something like “Check MD5 Sums?”, for Items make it “Yes,No” and for commands make it “Y,N”.
  • Task –> If. Set it to If %bs_command ~ Y.
  • Code –> Run Shell. For the code make it
    ls /sdcard/Download
    Set it to store result in %files. (Change whatever is after /sdcard/ to the path of your download folder. /sdcard/Download is the default for most people)
  • Variables –> Variable Split. Split %files.
  • Variables –> Array Pop. Pop %files, position 1, and set it to %download.
  • Code –> Run Shell. For the code make it
    md5sum /sdcard/Download/%download
    Set it to store result in %md5. Again, change the download directory as needed.
  • Variables –> Variable Split. Split %md5. Don’t set a splitter.
  • Alert –> Flash. Text: “MD5 Sums Match!” Check If and set it to If %md51 ~ %CLIP.
  • Alert –> Flash. Text: “MD5 Sums are Mismatched!” Check If and set it to If %md51 !~ %CLIP.
  • Task –> End If.
  • Task –> End If.

Here are screenshots of the Task editor screen, to give you a better picture of the order of actions:

Screenshot_20160424-181022 Screenshot_20160424-181218

Interested in importing the XML yourself? Follow this link to my thread in our Tasker Tips & Tricks forum and scroll to the attachments for the file. To import it, open up Tasker, long-press on the profiles tab up top, press import, and browse to the .prf.xml file you downloaded.


Have an idea that you’ve always wanted to implement in Tasker but didn’t know how? Let us know below and we may feature a solution to your idea in the future!



from xda-developers http://ift.tt/23VOZ6f
via IFTTT

Aucun commentaire:

Enregistrer un commentaire