Game Development Reference
In-Depth Information
if (fileMatches.Length > 0 && fileMatches[0].Length > 0)
{
using (Stream loadStream = new IsolatedStorageFileStream(fileName,
FileMode.Open, storage))
{
BinaryFormatter formatter = new BinaryFormatter();
Hashtable settings = formatter.Deserialize(loadStream)
as Hashtable;
if (settings != null)
{
return (TYPE)settings[key];
}
}
}
return default(TYPE);
}
catch (Exception)
{
return default(TYPE);
}
}
Using the code is very straightforward, but you may want to know if an applica-
tion is launching for the first time or not so you can save default settings into iso-
lated storage. The following code shows how to determine whether an application
is launching for the first time.
bool firstRun = !ReadSetting<string, bool>(“MySettingsFile.dat”,
“FirstTimeLaunching”);
if (firstRun)
{
WriteSetting(“MySettingsFile.dat”, “FirstTimeLaunching”, true);
}
Levels of Isolation
The whole idea behind isolated storage is that the physical location of stored files
is managed by the .NET framework, not the application directly. Ignoring politics, it
is important to understand how the framework associates an isolated storage location
with a particular application. The association with an isolated storage location all
comes down to how applications are identified by the framework.
Search Nedrilad ::




Custom Search