GBA Development with HAM 2.71 SDK for Windows

30. September 2013 13:17 by Cameron in GBA  //  Tags: , , , , , ,   //   Comments

I'm starting development for the GBA with Jonathan S. Harbour's book and the HAM SDK. Jonathan's website links to the HAM 2.80 SDK, but I have read many reports that this version of the SDK does not compile C++ code properly and that one should use the HAM 2.71 SDK for Windows. It was quite difficult to find the HAM 2.71 SDK for Windows because nobody seemed to have it and the original website, www.ngine.de, has been down for quite some time. This is not surprising as the peek of GBA development was over 10 years ago. However, some of us are nostalgic for the old GBA especially if we can manage to get ahold of a flash cart like the discontinued EZ-Flash IV (Best GBA flashcart in existence and super rare) or the SuperCard MinSD (not so great for commercial roms but acceptable for development). Provided below is a link to the Windows version of the HAM 2.71 SDK:

HAM 2.7 SDK

HAM 2.71 Update

Dropbox Mirror HAM 2.7

Dropbox Mirror HAM 2.71

Qt Development on OS X Mountain Lion

1. October 2012 21:18 by Cameron in C++, Mac, Mac OS X, Qt  //  Tags: , , , , , ,   //   Comments

OS X Mountain Lion changes a few things on how XCode is installed. Xcode is now contained in an app bundle and the SDKs directory is part of the bundle contents, thus you will need to update your SDK paths in your project file like so:

MAC_SDK  = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    if( !exists( $$MAC_SDK) ) {
        error("The selected Mac OSX SDK does not exist at $$MAC_SDK!")
    }
    QMAKE_MAC_SDK = $$MAC_SDK

If you want to support Snow Leopard as a target platform with your Qt applications, be sure to use the 10.7 SDK and not the default 10.8 SDK. Your app should work just fine in Snow Leopard provided that you don't make any calls to Lion specific features while using the 10.7 SDK.

Another important thing is to install the command line tools for GCC so that Qt can find the compiler during installation and successfully compile C/C++ applications from Qt Creator. If you do use the 10.8 SDK with any Qt version less than Qt 5.0, it will give warnings that OS X 10.8 is unsupported during compilation. These warnings can be safely ignored. Aside from that, everything else should be the same as before. Happy coding!

ODBC vs RESTful API

31. August 2012 00:55 by Cameron in C++, Qt  //  Tags: , , , , , , , , , ,   //   Comments

In the process of writing the IGA desktop application, I've been faced with several design decisions. One of the most challenging decisions I had to make was how I should most effectively interact with a database backend. To help with this decision, I weighed out the pros and cons of using ODBC and a RESTful web API. Each of these methods are very good for certain purposes.

ODBC

Pros

  • Cross platform support through C/C++ libraries
  • Secure using username and password (connection encrypted)

Cons

  • Some ISPs/Schools block port 1433 (used with SQL Server) or other database ports (MySQL, Postgre, etc)
  • Slow response time in some instances (running multiple queries can take a fair amount of time)

RESTful API

Pros

  • Fast response time
  • Abstracts data backend - i.e. allows for an easy switch of database servers or switch of web server languages
  • Easily allows for multiple desktop and mobile frontends by adhering the web API interface (ODBC isn't usually standard in mobile platforms)

Cons

  • Requires tighter security
  • All requests must be encrypted using SSL or  plain text is sent to the server
  • Requires some sort of authentication either by API key or other method to prevent arbitrary access to server

Ultimately, I decided to go with using a RESTful web API for maintaining separation of the database architecture from the IGA desktop application. This will allow me to change the database backend without breaking the application as long as I keep the API interface the same. Another huge factor in choosing a RESTful web API is that my school blocks port 1433 on its campus wireless networks. I want college students to be able to use the IGA desktop application while on campus so this was a necessary choice. Overall, both provide advantages and disadvantages and neither one is "better" than the other. I hope this helps people with the decision between ODBC and a RESTful API.

Authenticate with ASP.NET membership provider using Qt and C++

5. July 2012 00:42 by Cameron in   //  Tags: , , , , , ,   //   Comments

Today, I was looking at a method of authenticating users in the IGA desktop application using the website's membership provider. I remembered a post I made a while back on Stack Overflow about how to authenticate users with Ignite OpenFire and in the answer, there was some Java code showing how to correctly hash a password with a salt and compare it with the membership table. I ventured into porting the algorithm to C++ and was successful! Here's the C++ code for anyone interested:

QString hashPassword(QString password, QString salt)
{

    // get utf-16 representation of password

    QByteArray passwordBytes((const char*) (password.utf16()), password.size() * 2);

    // get utf-16 representation of salt

    QByteArray saltBytes((const char*) (salt.utf16()), salt.size() * 2);

    // decode base64 salt byte array

    QByteArray saltDecodedBytes = QByteArray::fromBase64(saltBytes);

    QByteArray dst;

    dst.append(saltDecodedBytes);

    dst.append(passwordBytes);



    QByteArray hashed = QCryptographicHash::hash(dst, QCryptographicHash::Sha1);

    return QString::fromLatin1(hashed.toBase64().data());
}

Please note that in order for this to work, your passwords must be hashed. I had to convert any non-hashed passwords using an automated script that I found on Stack Overflow. It's pretty straight forward. Just add a second provider that uses hashed passwords and get the passwords from the encrypted/clear text provider and change them using the hashed provider. Be sure to set your default provider to the hashed provider so that you won't have to run this script at a later point. I had to modify the code that I found from Stack Overflow a bit to use a try catch block around the user.GetPassword() method as some passwords may already have been hashed and can't be decrypted. Here's the C# code for anyone interested:

void HashAllPasswords()
{          
	SqlMembershipProvider hashedProvider = (SqlMembershipProvider)Membership.Providers["HashedProvider"];
	SqlMembershipProvider encryptedProvider = (SqlMembershipProvider)Membership.Providers["EncryptedProvider"];
	if (encryptedProvider == null || hashedProvider == null) return;
	Dictionary<string, string> passwords = new Dictionary<string, string>();
	int unimportant;
	foreach (MembershipUser user in encryptedProvider.GetAllUsers(0, Int32.MaxValue, out unimportant))
	{
		try
		{
			passwords.Add(user.UserName, user.GetPassword());
		}
		catch (Exception e)
		{
		}
	}

	using (var conn = new SqlConnection(
		   ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
	{
		conn.Open();
		using (var cmd = new SqlCommand(
			   "UPDATE [aspnet_Membership] SET [PasswordFormat]=1", conn))
			cmd.ExecuteNonQuery();
	}

	foreach (var entry in passwords)
	{
		var resetPassword = hashedProvider.ResetPassword(entry.Key, null);
		hashedProvider.ChangePassword(entry.Key, resetPassword, entry.Value);
	}
}

Improving speed of iterating a result set from a QSqlQuery

4. July 2012 16:22 by Cameron in C++, Qt  //  Tags: , , , , , , , ,   //   Comments

Today, I had to figure out why it was taking so long to iterate a result set using a QSqlQuery. A query that I ran in about 1 second from SQL Server Management Studio was taking 15 seconds to complete from my C++ application. I found that if you don't set ForwardOnly to true using setForwardOnly(true), it will drastically decrease performance of iterating through the query's results. You should also prepare the query before executing. After applying those changes, I got my query to run in under a second! Huge difference! You can see an example of how to connect to a SQL Server database and query a table using the QODBC3 driver. The speed improvements should also apply to SQLite databases.

QString connectionTemplate = "DRIVER={SQL SERVER};SERVER=server;DATABASE=Users;";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3", "db");
db.setDatabaseName(connectionTemplate);
db.setUserName("sa");
db.setPassword("password");
if (db.open()) {
	qDebug() << "OK!";
	QSqlQuery * query = new QSqlQuery(db);
	query->setForwardOnly(true);
	query->prepare("SELECT [UserName]"
				   "  FROM [dbo].[Users]");
	QTime begin = QTime::currentTime();
	if(query->exec())      {
		while(query->next())
		{
			QString userName = query->value(0).toString();
			qDebug() << userName;
		}
		QTime end = QTime::currentTime();
		qDebug() << "finished in " + QVariant(end.second() - now.second()).toString() + " seconds";
	}
	db.close();
}
else {
	qDebug() << db.lastError().text();
}

Started Development of a Collapsible Frame Qt Widget

5. May 2012 22:14 by Cameron in C++, Qt  //  Tags: , ,   //   Comments

Today, I started development of a collapsible frame Qt widget. I needed a widget that could show/hide its contents by clicking on an open/close button but couldn't find a solution online so I decided to create my own. The code is still a work in progress, but the basis of the code involves the use of nested layouts to achieve the hide/show effect. I had to write a custom clickable label class and subclass QLabel as QLabel doesn't have a clicked() signal. I'm using style sheets to apply the icon to the QLabel so that it has the correct image based on open/close and hover over states. The code is available on github under the Apache 2.0 license. Feel free to check out the code and see if you'd like to fork it yourself and contribute.

https://github.com/pcmantinker/Qt-Collapsible-Panel

Qt Cross Platform Notification System

25. March 2012 16:30 by Cameron in C++, Qt  //  Tags: , , , , ,   //   Comments

I've been working on a cross-platform notification system built on Qt which is modeled after Mac OS X's Growl notification system. This is for use in a project that I'm currently working on. You may view the source code here: https://github.com/pcmantinker/Tray-Notification-System

I am still playing around with the window flags for the notification system as sometimes when a new notification is shown, within the Windows operating system, it steals focus from full screen applications. If you have any suggestions, feel free to let me know in the comments. Also, feel free to fork my repository and contribute to the code base if you're interested.

Qt Application Development in Mac OS X Lion

1. February 2012 01:52 by Cameron in Qt, Mac OS X, C++  //  Tags: , , , , ,   //   Comments

I've been working on some code using the QtSDK lately and I've been researching how to deploy applications for Mac OS X 10.6 and above. Luckily, it's pretty simple to deploy applications as the QtSDK includes a tool called macdeployqt. The tool copies all required Qt frameworks to the app bundle and re-assigns the library reference paths for the app to use the libraries within the app bundle and not the user's system directory (/usr/lib). It doesn't copy 3rd party libraries that aren't in the /usr/lib directory so you will have to manually add those.

Please note that macdeployqt on Qt 4.7.x doesn't seem to assign the correct library paths when linking against QtWebKit. This is a known bug that was fixed in Qt 4.8.0.

Also, if you want to insure that your app will not have problems on Snow Leopard, be sure to add this to your .pro file: 

macx:QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.6.sdk

This tells Qt to use the Snow Leopard SDK instead of the Lion SDK. If you build your application with the 10.6 SDK, it will work with Mac OS X 10.6 or higher.

One last thing is that there seems to be a problem with Xcode 4 and Qt Creator not being able to find g++-4.2 which is installed with older versions of Xcode. A work around for this until a new version of Qt Creator:

sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

I hope this helps anyone experiencing the same issues.

 

EDIT:
As of the February 1, 2012 QtSDK update, it appears as though the problems with g++ and using macdeployqt have been fixed. Please be sure to update to the latest SDK release. 

Month List

Tag cloud