This simple application takes the XML code for a single package in an Installer Repository and converts it a control file made for Debian APT repositories (IE repositories for Cydia). I have just integrated this application into my newer app RepoParser, but this is for people who want just the Debian Control part of RepoParser and not the whole thing (if any such people exist).
Download below and comment with ideas, suggestions, questions, and requests!
Feel Free to Donate and keep in mind that the requests of donors will always be honored!
RepoParser is a utility to view (or parse) Installer.app Repositories. I started this as a sort of test to get the code down so that I could go about improving (and most likely rewriting) my currently crappy app RepoMaker. I have been extremely pleased with my progress on this application. As of right now, it can parse both XML and Plist repositories with incredible speed. I have not yet started to use VB.NET’s built in tools for managing XML documents so it is required that the repository is well-formed and well-formatted. Becuase of this, I included a Troubleshooting section explaining this and providing a download for the free program XMLSpear which provides a one-click option to format an XML document. The most amazing part, however, is that (after hours of coding and recoding) I have managed to optimize the parsing script to a point where it takes less than half a second to parse an entire 12,000 line repository. Pretty impressive. Features currently include the following:
All in all, I’ve learned TONS with this application. I’ve learned how to create a Class that allows me to download any file from online with the click of a button (with live updates as it is downloading). I’ve learned how to parse huge repository files with speeds I thought to be impossible. I’ve honed my skills with reading and writing files and creating files and much much more. The next step for me is to start learning how to use VB.NET’s built in XML utilities to improve these applications even more.
As I said before, the XML files currently CANNOT be edited by RepoParser… I think that instead of teaching myself to do that the wrong way (IE not using the built-in XML utilities), I’m going to go ahead and learn them and start a new project that will be a full fledged RepoEditor/RepoMaker.
Download below and comment with ideas, suggestions, questions, and requests!
Feel Free to Donate and keep in mind that the requests of donors will always be honored!
Unix time (aka. POSIX time) is the number of seconds elasped since midnight UTC January 1, 1970 (not counting leap seconds) and is widely used in not only Unix-like operating systems but in many other computer systems as well. I found myself needing to find the UNIX timestamp very often (every time I packaged something for Installer.app) and I was using obnoxious PHP scripts I had found online. I wanted to make myself a small application that would determine the current UNIX timestamp from my current system time.
There are tons of ways to do this but I believe I found the most efficient… It consists of only one line of code:
DateTime.UtcNow.Subtract(#1/1/1970#).TotalSeconds
If that beautiful little line of code is thrown into a function like so:
Function UnixTimeStamp() As Integer
Return DateTime.UtcNow.Subtract(#1/1/1970#).TotalSeconds
End Function
It provides a very easy way to call UnixTimeStamp() from anywhere in your program to receive the current UNIX timestamp from your system time.
It’s worth mentioning that this little function does not take timezones into account so you will have to add code to do so yourself. For example, if you are in Eastern Standard Time (UTC-5), you could modify the function like so:
Function UnixTimeStamp() As Integer
Return DateTime.UtcNow.Subtract(#1/1/1970#).TotalSeconds - 18000
End Function
You don’t really need an example application for this snippet of code but, nonetheless, I’ve included the source (in both vb.net and .txt forms) and a standalone .exe for a simple application that, when launched, displays the current UNIX timestamp and a refresh button to update the timestamp.
Download VB.NET 2008 Source Code
I’ve decided to start blogging about some code that took me a while to find or figure out… Hopefully other people looking for this code won’t have to suffer what I did :).
MD5 Checksums are used frequently to verify both the validity of files and to check for corruption after large downloads or uploads. There are several free applications for Windows that can calculate the MD5 Checksum of a file though I wanted to be able to make myself an application customized for my own use.
You will need to import a few .NET Classes to get started:
Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
IO is used to manage loading the files in and out of your application. Cryptography will retrieve the raw MD5 Hash and Text will append it. Of course, you don’t need to import any of these but it will clean up your code and is a good programming practice.
You now need to select the file you wish to run the MD5 algorithm on. If you are building an application that will always be checking the MD5 of the same file in the same place, this is very simple. However, this is usually not the case.
Dim o As OpenFileDialog = New OpenFileDialog
Dim temp As String
Dim path As Stringo.Filter = “.zip Files|*.zip|All Files|*.*”
If (o.ShowDialog() = DialogResult.OK) Then
path = o.FileName
This snippet of code creates an OpenFileDialog and declares temp and path (temp will be used later on). The OpenFileDialog is then showed and if the user successfully selects a file it is set to path. The rest of the coding will be done in this If/Then block to avoid attempting to run the MD5 algorithm on an incorrect or nonexistent file.
The o.Filter can be used if you want only certain types of files to be visible in the file browser. The way o.Filter is set in my example, .zip Files and All Files will be selectable from the drop down list. It is quite simple to customize the o.Filter to your desire or simply omit it altogether.
We will now get the raw MD5 checksum of our file with the following code:
Dim fs As FileStream
fs = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
md5.ComputeHash(fs)
fs.Close()
Here we create a new FileStream for our previously selected file and use the built in MD5CryptoServiceProvider to compute the raw hash of our file. We end by closing the FileStream so the file can be accessed by other programs and the user.
We will now use the StringBuilder class to append our string and format it correctly:
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format(”{0:X2}”, hashByte))
Nexttemp = buff.ToString()
We now have our MD5 Checksum stored to temp! By default it is in all caps… This may be suitable in your situation but i need lower case. This is as simple as:
return temp.ToLower
And there you have it! For those of you that don’t like to read and understand things for yourself here is a fully working function.
Imports System.Security.Cryptography
Imports System.IO
Imports System.TextFunction MD5Checksum(ByVal path As String) As String
Dim temp As StringDim fs As FileStream
fs = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
md5.ComputeHash(fs)
fs.Close()Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format(”{0:X2}”, hashByte))
Nexttemp = buff.ToString()
Return temp
End Function
You will need to call this function in one of two ways:
MD5Checksum(”C:\MyFile.ext”)
In that case, you know exactly where the file you want is… if you want to browse for the file, you can use this:
Dim o As OpenFileDialog = New OpenFileDialog
Dim path As StringIf (o.ShowDialog() = DialogResult.OK) Then
MD5Checksum(o.FileName)
Feel free to download the source code to the MD5 Demo App I’ve created below! Note: I use VB.NET 2008 so you will not be able to view the source on anything below 2008. I’ve added a download link for a .txt document of the source code so you can view it if you have VB.NET 2005 or lower. And of course, you can download the standalone .exe and just use the program!
Download VB.NET 2008 Source Code