New Week – New FileExplorer Release

To continue the tradition of a weekly FileExplorer build, here is the next update, bringing you the following capabilities and fixes:

Show the path

You can actually see the current folder tree path in the control when navigating through. You can also select and copy the path (but not modify it at this point).

Use file format restrictions

As you already know, when accessing the Windows Phone external storage (if any is present, of course), you are only limited to seeing the files that have been explicitly associated with your application.

However, in a lot of cases you might want to restrict the visible file range even further. For those scenarios, the FileExplorer control now carries two new properties:

  • ExtensionRestrictions – an enum value that can be one of the following: None, InheritManifest, Custom. When None is selected, you will see all files when working with the isolated storage, and only files that have registered file extensions in external storage. InheritManifest, on the other hand, might be handy if you want to select a file from the isolated storage and limit the picker to files that are “pre-approved” in the manifest – obviously, this setting is unnecessary when handling external storage, since the policy is enforced by the OS by default. Last but not least, Custom allows you to define a set of your own filters. And more about that below.

  • Extensions – a generic collection that contains a set of extensions that you want to restrict the picker to. It is only used when the ExtensionRestriction property is set to Custom. You need to preserve all extensions in the .[EXT] format. So if, let’s say, I want to let the user pick only XPS files, I need to add a .xps entry to the collection. This property will not allow you to select files from external storage with extensions that have not been registered in the manifest.

As usual, you can download the latest (79607) checkin and go to Experimental > FileExplorerExperimental to see what this control is about.

I would love to hear your feedback and comments.

Testing the Future

…control that will be integrated in the Coding4Fun ToolkitFileExplorer!

You can download the Coding4Fun Toolkit source code here. Once downloaded, go to Experimental > FileExplorer. The sample project carries an alpha implementation of the control, and I would love to get your feedback on it – let me know what you want to see become a part of it.

NOTE: This custom control currently works only on Windows Phone 8.

wp_ss_20130625_0001

The control will play the role of the standard Windows 8 FilePicker, but on Windows Phone. Its goal is to allow developers to provide an easy-to-use interface to interact with the isolated storage, as well as with the external storage in the context of native phone applications.

What can the control do at this point?

  • 1. Pick a file from the isolated storage (no file format restrictions)
  • 2. Pick a file from the external storage, if such is available (restricted to files that have an extension registered with the app)
  • 3. Navigate through the folder tree in both the isolated storage and external storage (where available)

 

In its current implementation, I am using the control as a way to open files for read. No built-in functionality is introduced to facilitate writing at this point.

What do I have planned for the control?

  • 1. File extension filter for files in the isolated storage (this can be both manifest-based and individual)
  • 2. Multi-file select (return a batch of files from one or different locations)
  • 3. Folder select
  • 4. Windows Phone 7.x support for isolated storage

 

Important disclaimer

The control is in its alpha stage. DO NOT use it in production.

Last.fm API for a Windows Phone App – Auth

As per the request of many Beem users, I am implementing Last.fm track scrobbling. The first part of this task is to implement an API client for the Last.fm web service, and step one is user authentication. Last.fm is not using OAuth, but rather its own implementation of an authentication engine that relies on a composite MD5 secret.

But let’s begin with the basics. As it is a mobile application, I need to perform a request to the core endpoint with the auth.getMobileSession method. The URL is https://ws.audioscrobbler.com/2.0/. Remember to use HTTPS, as it is an inherent requirement for the request to be successful. Two required components of the request are the API key and the API secret – both can be obtained as you register your own application on the Last.fm developer portal.

NOTE: Ignore the is+[space] part and just use the code that comes afterwards.

The API call is complete only when it is accompanied by a signature. The signature is generated by building a composite string, made of each parameter and value concatenated together (with no delimiters) in alphabetical order, followed by the API secret, that are later hashed with an MD5 helper. Since by default the Windows Phone 7.1 SDK comes without the standard .NET MD5CryptoServiceProvider, I have to carry an internal implementation. You could take a look at the specifics of the MD5 algorithm here, or you could download a ready-to-go class created by Reid Borsuk and Jenny Zheng here (which is what I am using in the app). The method I am using to get the signature looks like this:

 public string GetSignature(Dictionary<string, string> parameters)
{
string result = string.Empty;

IOrderedEnumerable<KeyValuePair<string, string>> data = parameters.OrderBy(x=>x.Key);

foreach (var s in data)
{
result += s.Key + s.Value;
}

result += SECRET;
result = MD5Core.GetHashString(Encoding.UTF8.GetBytes(result));

return result;
}

The next step is to perform the authentication request itself, to get the session key. A raw implementation of the necessary method can look like this:

 public void GetMobileSession(string userName, string password, Action<string> onCompletion)
{
var parameters = new Dictionary<string, string>();
parameters.Add("username", userName);
parameters.Add("password", password);
parameters.Add("method", "auth.getMobileSession");
parameters.Add("api_key", API_KEY);

string signature = GetSignature(parameters);

string comboUrl = string.Concat(CORE_URL, "?method=auth.getMobileSession", "&api_key=", API_KEY,
"&username=", userName, "&password=", password, "&api_sig=", signature);

var client = new WebClient();
client.UploadStringAsync(new Uri(comboUrl),string.Empty);
client.UploadStringCompleted += (s, e) =>
{
try
{
onCompletion(e.Result);
}
catch (WebException ex)
{
HttpWebResponse response = (HttpWebResponse)ex.Response;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
Debug.WriteLine(reader.ReadToEnd());
}
}
};
}

As the signature is obtained, I still need to include the parameters in the URL, including the method, API key and the proper credentials. The request has to be a POST one, therefore I am using UploadStringAsync instead of DownloadStringAsync, which will execute a GET request.

Simple as that, you have the auth session key.

FallFury is now in the Windows Store

With the full tutorial series and the PDF eBook, it would only be logical that the next step in the FallFury story would be releasing the game in the Windows Store. Today, I am happy to announce that my first big game development project successfully passed certification and is now available in most of the locations worldwide in the Windows Store.

clip_image010[6]

You can download it here.

It is a project that I am constantly improving, so more levels and items will be added. Feel free to review the game and give me some feedback on how the overall gameplay experience can be better.

FallFury eBook Available

Almost a week ago, my FallFury series (building a hybrid Windows Store XAML/DirectX/C++ game) was released on Channel9. 12 articles and associated videos is a lot to go through, and you might not always have an active internet connection.

That’s why Brian Peek tackled the task of creating a PDF version of the series, and he did a fantastic job at it. 130 pages of content that will help you get started with creating games for Windows Store.

Download Here

Also, remember that you can download the FallFury source code on the official project CodePlex page.