Build XNA Game Installer: ClickOnce

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This article is the first of two on how to package your XNA game into an installer for Windows environments. The first is the easier but less customizable option of using Visual Studio’s built in ClickOnce installer. ClickOnce is essentially a hand-holding tool to package up prerequisites, dependencies, manifests, and content. Additionally, it allows you to specify locations from which the users will install the package (CD, Web, Shared Drive). More conveniently, ClickOnce allows you to specify where the application should check for updates in order to automatically update the content when new versions of the application are released. For example, you could specify a URL that the application will use to check for new versions. If a new version is detected, you can specify either the same URL or a different URL to use for downloading the new content.

While ClickOnce is easy to use, it is not perfect for every scenario and can fail quite spectacularly. I have personally run into situations where users could not install updates to the application because of cryptic errors that were only resolved by completely recreating a user account in Windows (I kid you not, this is a Microsoft-sanctioned approach). Many of the errors are difficult to diagnose and the documentation does not help much when it comes to the more advanced features of ClickOnce. It is definitely convenient, but do not use it if you want customization or extendability.

That said, here is how you use ClickOnce to package your XNA game into an installer.

  1. Open your solution in Visual Studio
  2. Right click your main project -> Properties…
  3. Click Publish tab
    • Publishing Folder: local or remote path that will be the destination of the publish (example: C:DevGamesGame1Installer)
    • Installation Folder URL: optional unless you want the users to install from a location different from the publish location
    • Install Mode: Pick offline availability (users should not have to be connected to the internet to play video games!)
    • Click Application Files…
      • Make sure the Publish Status of your game files is set to Include (Auto)
      • Make sure the Publish Status of the XNA libraries is set to Prerequisite (Auto)
    • Click Prerequisites…
      • Microsoft .NET Framework 4 Client Profile
      • Microsoft XNA Framework Redistributable 4.0
      • Windows Installer 3.1
    • Click Updates…
      • Check for updates if you want your application to check for updates through ClickOnce
      • A lot of the options are self explanatory on this screen
    • Click Options…
      • Description tab
        • Publisher name: your company name
        • Suite name: optional used to define a super application that manages this one
        • Product name: the name of your game
      • Deployment tab
        • If you want to deploy to a web page, specify the URL here
        • Check the other options here if need them
      • Manifests
        • Click “Create desktop shortcut” if you want a shortcut
        • Ignore the other options unless you really need them
  4. Specify the version of this publish (you can have it auto increment if you want)
  5. Click either the Publish wizard (which just confirms your already entered information) or Publish Now to begin publish

Your published files will be organized like this:

  • Application Files
    • Contains every version that has been published (in case user needs to rollback to a previous version)
    • Contains “Content” folder which includes files from your Content project in your XNA solution
    • .dll libraries that you created
    • Game icon
    • Game thumbnail
    • ClickOnce application file used to check for updates
    • Game executable
    • Executable manifest
  • ClickOnce application file used to check for updates
  • Setup.exe used to install the game

Note that the Application Files directory will contain a history of every version of your application.… Read more

Free/Busy Data from Exchange Web Services via Java

Exchange Server 2007 and 2010 offer web services that can be accessed via standard SOAP messages. This post will hopefully help you in consuming a very specific web service operation (free/busy data) from your Java environment. I expect that you can take the information found in this post and extend it to other operations. Please note that I will not discuss how to setup Exchange Web Services and will instead assume that such a service is already operational and online.

I cannot guarantee that this is the best, fastest, or most efficient way to get this working. These are the steps that I have compiled through self-teaching, reading various Microsoft documentation, and sifting through a large amount of blogs on separate issues that collectively guided me to the solution. Unlike most of the guides I found, this post should take you from the beginning of the coding process all the way to the end.

The first step is to obtain the WSDL and XSD files that describe the Exchange Web Services. These are usually hosted in the same location as the actual ASMX web service. I only have experience with the setup I use at my company, so results my differ for your Exchange setup.

  • Download Services.wsdl to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/Services.wsdl)
  • Download messages.xsd to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/messages.xsd)
  • Download types.xsd to local folder from URL to Exchange Web Service (ie. https://webmail.company.com/ews/types.xsd)

Microsoft likes to make things complicated and this is true with the files we just downloaded. The WSDL does not contain a ‘services’ tag so the importer we use to create the proxy classes will not work properly.

  • Edit the Services.wsdl file and add the following as the last tag in the main tag.

  • Download this XSD file to the same directory as the above three: http://www.w3.org/2009/01/xml.xsd
  • Edit the types.xsd file that we downloaded by changing the <import namespace> tag to the following:

  • Edit Services.wsdl by adding <services> section to end. See [1] for tag to add to .wsdl.
  • Edit types.xsd to point to correct xml.xsd schema. <xs:import namespace=“http://www.w3.org/XML/1998/namespace” schemaLocation=“xml.xsd”/>

Alright, enough editing, time to create the proxy classes so that we can finally call this service.

  • Open a command prompt, change directory to the folder that contains your WSDL and XSD files from above
  • Type wsimport -keep -Xnocompile Services.wsdl -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl to generate proxy classes

wsimport is the name of the Java tool that will parse the WSDL and generate Java class files from the schema. Here is what the flags do:

  • keep: keeps the generated files
  • Xnocompile: does not create compiled .class files (you’ll see why in a second)
  • Services.wsdl: name of the WSDL file to parse
  • -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl: this will generate the proxy classes and tell them to point to this temporary and non-existent location (you’ll see why in a minute)

The generated files are in a long tree of folders.… Read more

Blu-Ray Containers, Video/Audio Codecs, and Subtitles

In the previous couple of posts, I described some short techniques to accomplishing a simple media server using your legally purchased Blu-Ray and DVD movies. If you are anything like me, you will most likely start getting confused when you look at MakeMKV and Handbrakes more advanced features such as which video/audio codecs to use. You may even run into some crazy streaming playback anomalies regarding TrueHD 7.1 and PGS subtitles like I did. Well, I do not have all the answers for you, but I can at least give you a little bit of information and allow you to take solace in the fact that someone else out there is experiencing similar problems!

Please note that these lists of containers and codecs is not comprehensive. I have chosen commonly found files and formats for convenience and brevity.

Media Container Formats

A lot of people get confused about the differences between all the slang, acronyms, terminologies, and file formats that get tossed around on forums and blogs. Trust me, I know that it can be confusing when someone says something like, “Oh, it’s easy, just create a .mkv, and encode the video with x.264 and the audio in AC-3.” If you have no prior knowledge of these terms, you will be more than a little bit confused.

The bottom line is that there are four common components to movie media files: containers, video tracks, audio tracks, and subtitle tracks. Containers do exactly what you would guess: they contain the rest of the content. When you see a .avi file, that’s a movie file using the AVI container format. It contains video tracks, audio tracks, and possibly subtitle tracks.

See the following for a comparison between different containers: http://en.wikipedia.org/wiki/Comparison_of_container_formats.

  • .m2ts – Non-open format commonly found in Blu-Ray discs and AVHCD. You’ll find this format when you rip a Blu-Ray using straight Blu-Ray copy software like DVDFab. This format supports menus that are commonly found on Blu-Ray discs.
  • .mkv – Open source, widely supported container that can support an unlimited amount of any video, audio, and subtitle tracks.
  • .avi – Microsoft developed container developed in the early 90s with too many limitations to list here. There is no reason to use this container over .mkv.
  • .mp4 – Widely supported container based on the MPEG-4 standard with similar capabilities as .mkv. There are some limitations as to which video and audio codecs it will accept, but most of the more common codecs are supported.

My recommendation for most movies that you rip: MKV

Video Codecs

Contained within a file, video codecs determine the quality and other attributes of a video track. For the most part, you are going to run into H.264 and VC-1 when dealing with Blu-Rays and MPEG-2 when dealing with DVDs.

See the following for a comparison between different video codecs: http://en.wikipedia.org/wiki/Comparison_of_video_codecs.

  • H.264 – The most commonly used high definition video compression codec used in Blu-Rays (players must support H.264), YouTube, iTunes, Flash Player, Silverlight, and various media broadcasts.
Read more

Ripping Blu-Rays and DVDs to a Media Server

Hardware needed:

  • PC
  • BD-ROM / DVD-ROM
  • Large Hard Drive (mine is 2 TB)

Software needed:

Media is increasingly migrating towards streaming-only distribution. Discs, even BD/HD-DVD formats, have rather low limits on the amount of data that can be stored on each. These low limits and the increasing availability of high-speed and high-bandwidth internet connections are just two reasons that consumers have begun to rely on streaming digital content including movies, music, videos, and pictures. The convenience of streaming services like Netflix and Hulu allow consumers to avoid commercials and watch what they want and when they want. Products like DVR and TiVo are only band-aids on top of the real problem: cable companies disallowing customers to choose their own content at convenient times.

Just think about what you have to do in order to watch your DVDs and Blu-Rays. I have Blu-Rays in my possession that literally take 5 minutes just to load the main menu. This problem is magnified by useless services like BD-Live that require internet connectivity in order to load content like chat rooms and trailers that users may never even use. For users like me, I want to be able to access my content immediately and in the format of my choosing. The current implementation of HD media inconveniences consumers by disallowing various viewing options and restricting Blu-Rays to only existing on the original disc. In fact, the legality of copying  Blu-Rays for personal use even when creating simple backups is questionable because of the insane policies of the MPAA and the legislative pockets that they influence.

Unless you’re sharing and distributing your backups, I sincerely doubt any authority is going to care. The MPAA and other organizations that rely on Blu-Ray sales isn’t losing a single penny if you backup your physical media. You’ve already legally purchased the disc and are simply transferring the contents to a device of your choosing. Continue at your own discretion and follow these steps. Keep in mind that MakeMKV is not going to perform any transcoding of your content. The original video/audio codecs will be left untouched and will simply be transferred to a .mkv container.

  1. Download and install MakeMKV from the link above.
  2. Download and install Handbrake from the link above. (optional)
  3. Download and install VLC Player from the link above. (optional)
  4. Start up MakeMKV.
  5. Insert the DVD or Blu-Ray of your choice into your BD-ROM/DVD-ROM drive.
  6. Wait for MakeMKV to scan the disc and then click the big Disc –> HDD icon.
  7. Wait for MakeMKV to scan for titles, video, audio, and subtitles.
  8. Check and uncheck the desired contents to be included in the final .mkv output file. (I will write another post about specifics on video/audio codecs and subtitles.)
  9. Change the output path in the right panel and click the button to the right of the output path.
  10. Wait for MakeMKV to complete the process and transfer the final output to the shared folder of your media server.
Read more

Creating a Media Server using PS3 Media Server and a PS3

Hardware needed:

  • PC
  • PS3
  • TV
  • Switch
  • Receiver (optional)

Software needed:

Ideally your setup will look something like: PC (media server) –> Switch –> PS3 –> Receiver (optional) –> TV. The advantages of including a receiver between the PS3 and the TV include better speakers and the ability to decode some of the newer proprietary audio codecs such as DTS-HD and TrueHD (more on that in a different post.)

Follow these steps:

  1. Use the link above to obtain and install PS3 Media Server on the PC you’re using as your media server.
  2. Turn on your PS3.
  3. Start up PS3 Media Server and wait for it to scan the network for available renderers. When it’s done, you should see your PS3 in the “Detected media renderers” section. You can confirm connections or view any errors in the “Traces” tab.
  4. Under the “Navigation/Share Settings” tab, add any folders you want to share with your media renderers under the “Shared folders” section.
  5. On the PS3 menu, go to the appropriate section that you want to stream under (Pictures, Music, or Video), find the PS3 Media Server, and navigate to the content you want to stream.
  6. When you start streaming, PS3 Media Server will display information about what it is currently streaming, the buffer status, and the bitrate under the “Status” tab.

Quite honestly, this is all that needed to be done to get content streaming properly to my TV. In a separate post, I’ll talk about some of the more advanced options of PS3 Media Server, transcoding, video/audio codecs, subtitles, ripping Blu-Rays/DVDs, and lessons learned for the best streaming performance.… Read more

ASP.NET Web Services Part 2

You may have noticed that this post is about two months late. Time flies, doesn’t it? The previous post on an introduction to web services and how they work with ASP.NET provided you with a cursory glance. This post will provide you will how to implement a very basic web service both on the server side for consumption and the client side for use in an application.

Prerequisites

  • Visual Studio 2005 or 2008
  • Basic knowledge of C#
  • Basic knowledge of ASP.NET Web Services

Step 1 – Create the ASP.NET Web Service

  • Visual Studio –> File –> New –> Project… –> Visual C# –> Web –> ASP.NET Web Service Application

Once the web service application project is created, notice that a templated web service was also created (Service1.asmx). The only section of this template to be worried about at the moment is the HelloWorld method marked with the [WebMethod] attribute. Marking methods as a [WebMethod] identifies that they will be used by an external caller through XML SOAP communication and are required to be exposed by the web service WSDL described in the previous post.

  • Make sure the HelloWorld method looks exactly like below.

  • That is literally all it takes to expose a web service method to the world! Press F5 to begin debugging this application in a local web server and continue to Step 2.

Step 2 – Utilize the Exposed Web Service Methods

One thing to note is that because web services are implemented via XML, any application that can properly serialize commands into the correct format as described by the web service WSDL has the ability to utilize web services. That said, the following section will be written using a simple C# console application.

  • Visual Studio –> File –> New –> Project… –> Visual C# –> Windows –> Console Application
  • Like library references, you need to add a reference to the URL path of the hosted web service. In the case of this article, the web service is hosted locally in the previous step.
  • In the main project of the solution explorer, right click Web References –> Add New Web Reference…
  • In the URL textbox, copy and paste the URL found in your browser that popped up from Step 1 when you pressed F5 to debug.
  • Press the Go button to the right of the URL textbox to search for any exposed methods at the URL provided.
  • When found, enter a name for the Web reference in the bottom right (I named it localhost.)
  • Press add reference to allow Visual Studio to create classes that allow consumption of the web service.
  • Add the following code to the Main method. Make sure you change “localhost” to whatever you called your web reference and change Service1 to the name of your exposed web service class.

Read more

ASP.NET Web Services

NOTE: Microsoft no longer suggests using this method of web services, but it is useful knowledge if you are supporting legacy systems or are still required to implement these features for business purposes. This method of web service is still useful for internal operations that do not require high security.

Below is an overview image of common web service architectures. It’s easiest to think of web services at “web methods” contained within a “web library” that contains methods to be executed on a server. The strength of this approach is that all communication is done in a standard XML format, regardless of the platforms communicating. This allows for brand new systems to communicate with extremely legacy systems, assuming that each system can properly implement a valid SOAP request and response according to the WSDL contract.

Client: Any application that requires consumption of whatever methods the web service is exposing.
Web Server: A process that hosts the web services for consumption.
Broker: Provides the definition of the web services being exposed.
SOAP: XML formatted request and results containing data according to the WSDL (see below.)
WSDL: Definition language describing which method to execute, what parameters the method requires, what data types the parameters are, what results will be returned from the web service, and what data type to expect back from the web service.

A common SOAP request with a body but no header. Note that the method being executed is defined in the <m:GetStockPrice> tag and the parameters passed are described in the <m:StockName> tag.

A common SOAP response with a body but no header. Note that the response being returned is defined in the <m:GetStockPriceResponse> tag and the return value is described in the <m:StockNamResponsee> tag.

Stay tuned for the next post which will include how to create a web service client and server in Visual Studio 2008 using C#.… Read more

Object-Oriented Connection Class in PHP

I started out in professional web development by using ASP.NET, so I was spoiled by the fact that Microsoft offers a SqlConnection class to use for various database related connectivity features. When I started with PHP, I decided to do some research and write a similar (albeit, much simpler) Connection class. Keep in mind that this class example only supports MySQL.

I started by defining some members of this class and came up with six useful members.

  • Database connection object returned from mysql_connect
  • Boolean to determine if the connection is currently open or closed
  • Database server host name
  • Database catalog name
  • Database user
  • Database password

In order to use this class, we need to add a constructor. I began by creating a default constructor that simply initializes values of the member properties. Take notice that not all of the properties are initialized by the default constructor. $dbConnection is not initialized until the Open() method is called and $isConnectionAlive is already false by default.

Now that the class can be instantiated, we need to add methods to allow operations. Below are the two methods that will perform the opening of the database connection and the closing of the database connection. Refer to the comments inline to understand what is happening.

Read more

Simple Class Declaration and Initialization with PHP5

If you’re used to classes with C#, C++, and Java, then you’re used to classes in PHP as well. If you’re brand new to classes, I suggest you read up on the definition and uses of them before trying to implement them via this tiny tutorial.

To begin, let’s create a simple class that will store information about a logged in user from a session. This class should hold the user’s username, first name, and last name to identify who it is on subsequent pages and requests. Begin by naming this class as “UserPassport” and adding the three previously described properties. They should not have default values because the class does not make sense without properties assigned during construction.

Expanding on this class, we need to add a constructor and a method to use these properties in a semi-meaningful manner.

There’s nothing crazy going on in the constructor. It’s a simple matter of assigning the properties values from whatever was passed in at construction. To display the information, a displayInfo method is created that places the three values in an array and splices them together separated by a comma and a single space. This value is then echoed to the output stream.

Now, this class is pretty useless if nothing is instantiating instances of it. Below is an example of how to instantiate and display the contents of our class. I used the xhtml 1.1 from The Web Standards Project to define a blank page.

The __autoload method is used to allow auto instantiation of classes without requiring an include statement to the .php file containing the definition.… Read more