|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using GGG.GameAttackCombos.Logic;
namespace GGG.GameAttackCombos.Client {
/// <summary>
/// Works with resources of the current skin of the application.
/// </summary>
public class CurrentSkinResource : IDisposable {
// Last requested skin resource information.
private string LastNameRequested;
private Stream LastStreamRequested;
/// <summary>
/// Gets a Stream to a resource for the currently viewed skin of the application.
/// </summary>
/// <param name="resourceName">The name of the skin resource to retrieve.</param>
/// <returns></returns>
public Stream LoadResourceByName(string resourceName) {
// Check if this resource was last requested.
if (string.Compare(resourceName, LastNameRequested) != 0 || LastStreamRequested == null) {
// Dispose of any previously requested stream to be safe.
if (LastStreamRequested != null) {
LastStreamRequested.Dispose();
}
// Store the name of the resource requested for comparison later.
LastNameRequested = resourceName;
// Get the main form.
if (Application.Current != null) {
MainWindow Main = Application.Current.MainWindow as MainWindow;
if (Main != null) {
// Open the current combo package being viewed.
// TODO: Fix this! Copy the stream from the package to a memory stream.
LastStreamRequested = File.Open(@"C:\Development\Applications\GameAttackCombos\Assets\Prince of Persia 2008\PrinceOfPersia2008Background.png", FileMode.Open, FileAccess.Read);
//using (ComboPackage Package = Main.OpenCurrentComboPackage()) {
// LastStreamRequested = Package.OpenSkinResourceStream(resourceName);
//}
}
}
}
return LastStreamRequested;
}
#region IDisposable Members
/// <summary>
/// Disposes of any remaining resources as a fail safe.
/// </summary>
public void Dispose() {
// Dispose of any read stream that is still lingering.
if (LastStreamRequested != null &&
LastStreamRequested.CanSeek &&
LastStreamRequested.Position >= LastStreamRequested.Length - 1) {
// This should never be necessary because of the BitmapImage property
// CacheOption. It should be set to OnLoad from a skin file to dispose of the
// stream itself. This is just a fail safe in case it is forgotten.
LastStreamRequested.Dispose();
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.
The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).