Jun 292011
 

Are the users of the application that you developed using the latest version? If your application doesn’t have automatic checking built in, you have to rely on the users to periodically check the site where you host the software for updates, or else you have to email the users or otherwise notify them. Certainly, the very best solution is to have your application self check itself to see if a newer version is available. I will present a simple solution here that uses a small php script placed on a web server. Data about my applications is stored in a mysql database. Then I will show you how I have a C# application check for updates. It’s a really easy solution and anyone with a little programming experience will be able to do it. First, here is the php code that is placed on the server where I host my applications for download.

<!--?php
/*
* To use, place this on a web server of your choice.  Next, create a mysql database
* where you will store information about your applications, such as the latest version.
* From now on, when you update an application, you will also need to update the
* information in the database about that application. Configure the database with the
* following columns: app_name, latest_version, build_date, url
*
* Then, in your application, when it checks for updates, have it send a request to the
* web server formed like this:
* http://myserver.com/app_updates.php?app_name=MyAppName
* where MyAppName above is exactly the same as the app_name stored in the mysql
* database. If MyAppName is found in the database, then it will return a small
* xml string with the data for that record.  If MyAppName is not found, it will
* return nothing. The xml output will look like this
*
* <?xml version="1.0"?-->
*
*   SevereWeatherGrowler
*   1.2.0
*   20110629
*   http://skipstechtalk.net/severe-weather-growler/
*
*
*
* It is up to your application to decide what to do with the returned data. For
* instance, one way to check if an update is available is to always store the build
* date in your application. Then when your application checks the sever, it can
* compare its build data to the build date for the latest version. If they are
* different, then an update is required. You can then direct the user to the url
* provided to get the update.
*/
$dbuser = 'my_database_user_name';
$dbname = 'my_database_name';
$dbpasswd = 'my_super_secret_password';
$dbhost = 'my_db_host'; // might be 'localhost'
$table_name = 'app_updates';
 
// test the connection
$dbh = @mysql_connect($dbhost, $dbuser, $dbpasswd);
if (!$dbh)
{
  echo "Could not connect to MySQL server on " . $dbhost;
  die();
}
 
// get the app_name from the url
$app_name = $_REQUEST['app_name'];
 
// get the data from the database for that app_name
$query = "SELECT * FROM $dbname.$table_name WHERE app_name = '$app_name'";
$result = query($query);
$row = mysql_fetch_object($result);
//print_r ($row);
 
// build the xml output
if ($row != null)
{
  $xmlstr = "<!--?xml version='1.0' ?-->\n";
  $xml = new SimpleXMLElement($xmlstr);
  $xml->addChild('app_name', $row->app_name);
  $xml->addChild('latest_version', $row->latest_version);
  $xml->addChild('build_date', $row->build_date);
  $xml->addChild('url', $row->url);
  //print_r($xml);
  echo $xml->asXml();
}
 
function query($query) {
  if(!($result = mysql_query($query)))
  {
    //can't execute query
    echo ( "Couldn't query table!\n");
    echo ( "MySQL Reports: " . mysql_error() . "\n" . "Query was: " . $query);
    exit();
  }
  return $result;
}
 
?&gt;

 

 

The code is pretty well documented (in my opinion). As it says in the comments, just have your application check http://yourwebserver.com/app_updates.php?app_name=MyAppName. The server will then return a small xml string that can be parsed by your application.  Here’s how I do it with C#

 

public const string UPDATE_CHECKER_URL = "http://my_webserver.com/app_updates.php";
public const int BUILD_DATE = 20110629;
 
public static void appUpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
  try
  {
    WebClient wc = new WebClient();
    string updateCheckerUrl = UPDATE_CHECKER_URL + "?app_name=" +
         System.Windows.Forms.Application.ProductName;
    string updateText = wc.DownloadString(updateCheckerUrl);
    XmlDocument myXmlDoc = new XmlDocument();
    myXmlDoc.LoadXml(updateText);
 
    string latestVersion =
       myXmlDoc.SelectSingleNode("/appdata/latest_version").InnerText;
    string build_date =
       myXmlDoc.SelectSingleNode("/appdata/build_date").InnerText;
    string updateUrl =
       myXmlDoc.SelectSingleNode("/appdata/url").InnerText;
    int result = 0;
    Int32.TryParse(build_date, out result);
 
    if (BUILD_DATE != result)
    {
      MessageBox.Show("There is an update available. Please check " +
           updateUrl + " for details.");
    }
  }
  catch
  {
    //do nothing.
  }
}

Then all that’s left is to set a timer to periodically call this function.  Put this in your Main() or someplace appropriate.

appUpdateTimer.Interval = 4 * 60 * 60 * 1000; //check every four hours
appUpdateTimer.AutoReset = true;
appUpdateTimer.Elapsed += new ElapsedEventHandler(appUpdateTimer_Elapsed);
appUpdateTimer.Start();

 

 Posted by at 1:40 pm
May 082010
 

Do you have billions and billions of password to remember? Well, maybe not quite that many, but I can tell you that I currently have 113 username and password pairs that I am remembering, mostly for logins to different websites. What if I told you that most of my passwords are something like “L6qjB5NM04GEXjTTeXeQ”. I try hard to not use the same username and password for every site I visit. I used to. It’s the only way you could possibly remember all those passwords.

Now I use a free program called KeePass to manage my passwords. Every time I register for a new account at a new website, I fire up KeePass and add a new entry. KeePass already has generated a password similar to the one I showed above. I then copy and paste that pre-generated password in the desired password field on the registration for on the website. If the website accepts the new password I save the entry in KeePass. The websites almost always accept the generated password from KeePass, but would you believe that sometimes my passwords are too long and the website forces me to trim down the length of the password? Sad. And that’s it. No more having to remember passwords.

Ahh, but you don’t want to use a password manager because you have multiple computers and you will need access to your passwords no matter where you are. I get that. That was what kept me away from such a program too. Well, I have the perfect solution. And it comes with lots of nice side effect features too. Get yourself a free Dropbox account. Dropbox is a file synchronizer that allows you to automatically sync up files and folders over the internet. If you work on some files at home and work, then you have undoubtedly forgotten your thumb drive once before, or forgot to copy over the latest version before you left. Well, dropbox can easily solve that problem for you. The Dropbox program watches a certain folder (or folders) on your computer. Whenever a file is added, changed, or deleted in that folder, the change is propagated automatically over the internet to any other computers on which you have installed dropox. So when you get to work after adding a new file to your dropbox at home, the file is happily waiting for you in your dropbox folder at work. So, to make this work with KeePass, just save your “key ring” (your database) to the dropbox folder. KeePass allows you to save and open database files from any folder, so this works quite well. Then all you have to do is install KeePass on your work computer too, and tell it to look in the DropBox folder for the key ring, and you will see all of your entries saved their. Now you can easily add new entries on either computer, and the change will be propagated to the other computer. Of course you could also install Dropbox and KeePass on your laptop too, so that you have access to your passwords (and files) when you travel.

Finally, there is an Android app for KeePass too. There is not a dropbox app, so you will have to periodically copy over (or email) the latest database to your phone so it has (a somewhat) up to date database. I try to do it around once a month or so. This also has the added benefit of backing up my database. Dropbox is pretty good about recovering accidentally deleted files, but really bad things can happen, and losing every password would be really bad. By having a copy in my email that I can go back to retrieve a copy, I know that I will always have a fairly recent backup that I can rely on.

And for the record, even though Lifehacker has also given instructions on how to do this, I figured it out before they did :) I just wasn’t smart enough to blog about it.

http://lifehacker.com/5063176/how-to-use-dropbox-as-the-ultimate-password-syncer

Apr 302010
 

Do you rip your movies to your hard drive?  I have a five-year-old daughter and we own about half of the Disney collection.  Some old and some new.  Most are on DVD, but we have started getting some on blu-ray.  One thing that I learned a little over a year ago was that it sucked looking for the movie that my daughter said she wanted to watch (what?  You put all of your movies back in the case as soon as you are done watching them and then put the movie back where it belongs? Riiiight…)  Furthermore, those DVDs and Blu-rays can get scratched, and we have ruined a couple of discs by them getting damaged one way or another.  Fortunately about that time, home theater personal computers, or HTPCs were becoming really popular.  Now, I have actually had an HTPC for about six years.  That’s a little longer than my daughter is old.  Yeah, I love HTPCs and the convenience they provide.  I have my music collection on there, many of my photos, and my daughter’s movies.  Using Windows Media Center, I can listen to that music, look at those pictures, and watch all of those movies.  And I don’t have to get out of my couch.  I can display a menu on the TV that shows cover art and posters from all the movies in the collection so my daughter can point to the movie she wants to watch.  I just click on the movie she chooses and it starts to play.  What could be simpler?  But that’s another post, so I will leave that for another day.

In order to be able to watch my movies in this fashion, I have to rip my movies from their physical medium to my HTPC hard drive.  By the way, “rip” means “copy” here.  It’s not like ripping a page out of a book.  No, it’s more like photocopying a page from a book. But we call it ripping.  If you search for “rip dvd” or “rip blu ray”, you will get thousands of software solutions to help you with this.  I personally use a program called DVD Fab 6, but this past week when I went to rip my first blu-ray movie (Ratatouille), I had to look for something new to help me.  DVD Fab says it can rip blu-rays, and it looked like it was ripping the movie correctly, but there was no sound at all from the saved AVI when it was done.  So I looked around for another program to see if it would work better for me, and I came across AVS Video Converter 6.4.  And this is where it gets interesting.  According to their documentation, all you have to do when ripping a blu-ray is select the index.bdmv file on the disc as the source, and that should automatically bring the entire movie along with it.  Well, that didn’t work for me.  Next, i tried selecting the individual m2ts files in the stream folder.  But then the movie was out of order.  It wasn’t looking promising for this program either.  I was actually beginning to think that ripping blu-rays was still not quite ready for prime time, which was disappointing because the only copy of Ratatouille I had was on blu-ray.  Finally, I had an idea.  What if it wasn’t the software, or my processing, but instead, what if it was something unique about the Ratatouille disc?  I did some searching and what do you know?  I happened to pick what is probably the hardest disc in the American movie collection to rip as my first disc.  It turns out that Ratatouille is a “Seemless branching disc” and also has multiple viewing angles.  I found a web page that actually listed the correct order for the Ratatouille m2ts chapters, put them in that order, re-ripped the disc and it worked perfectly!

I don’t know if DVD Fab actually ripped the movie in the right order because since it didn’t have any sound, the rip was useless to me and I only watched a few minutes of the movie just to verify that it did not have any sound.  In any case, neither program worked perfectly, but ultimately AVS Video Converter pulled it off, with some serious finagling from me.  I think ripping blu-rays is still kind of “tip of the spear” stuff, and full automation for the majority of the discs is probably still a ways off.  Or maybe not.

Just in case the web page with the Ratatouille chapters goes away, I am going to post the correct order for the chapters here:
00027.m2ts + 00028.m2ts + 00000.m2ts + 00001.m2ts + 00002.m2ts + 00005.m2ts + 00008.m2ts + 00009.m2ts + 00012.m2ts + 00013.m2ts + 00016.m2ts + 00018.m2ts + 00021.m2ts + 00017.m2ts + 00033.m2ts + 00034.m2ts + 00049.m2ts + 00037.m2ts + 00050.m2ts + 00040.m2ts + 00051.m2ts + 00043.m2ts + 00052.m2ts + 00046.m2ts + 00053.m2ts + 00056.m2ts + 00054.m2ts + 00059.m2ts + 00055.m2ts + 00062.m2ts + 00065.m2ts