Afr0
Well-Known Member
Working on Project Dollhouse has allowed me to learn a lot about proper error and exception handling.
Examples:
Examples:
- Never assume that a file or directory exists.
- Never assume that a registry key exists.
- Always log if you know something can go wrong. Always.
Code:
/// <summary>
/// Returns this Sim's thumbnail image.
/// If the HeadOutfitID isn't set, an empty Bitmap instance
/// will be returned.
/// </summary>
public Bitmap Thumbnail
{
get
{
if (m_HeadOutfitID != 0)
{
if (m_Thumbnail == null)
{
m_Thumbnail = GetThumbnail();
return m_Thumbnail;
}
else
return m_Thumbnail;
}
else
return new Bitmap(1, 1);
}
}
/// <summary>
/// Gets a sim's thumbnail image.
/// </summary>
/// <returns></returns>
private Bitmap GetThumbnail()
{
Outfit Oft = new Outfit();
Appearance Apr = new Appearance();
Bitmap Thumbnail = new Bitmap(1, 1);
if (!File.Exists(GlobalSettings.Default.ClientPath + "avatardata\\heads\\outfits\\outfits.dat"))
{
Debug.WriteLine("WARNING: Couldn't find: " + GlobalSettings.Default.ClientPath +
"avatardata\\heads\\outfits\\outfits.dat");
return Thumbnail;
}
FAR3Archive Archive = new FAR3Archive(GlobalSettings.Default.ClientPath +
"avatardata\\heads\\outfits\\outfits.dat");
Oft.Read(new MemoryStream(Archive.GetItemByID(HeadOutfitID)));
Archive = new FAR3Archive(GlobalSettings.Default.ClientPath +
"avatardata\\heads\\appearances\\appearances.dat");
TSO.Common.content.ContentID ApprID;
switch (Appearance)
{
case AppearanceType.Light:
ApprID = Oft.GetAppearance(AppearanceType.Light);
Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift())));
Archive = new FAR3Archive(GlobalSettings.Default.ClientPath +
"avatardata\\heads\\thumbnails\\thumbnails.dat");
Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift())));
break;
case AppearanceType.Medium:
ApprID = Oft.GetAppearance(AppearanceType.Medium);
Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift())));
Archive = new FAR3Archive(GlobalSettings.Default.ClientPath +
"avatardata\\heads\\thumbnails\\thumbnails.dat");
Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift())));
break;
case AppearanceType.Dark:
ApprID = Oft.GetAppearance(AppearanceType.Dark);
Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift())));
Archive = new FAR3Archive(GlobalSettings.Default.ClientPath +
"avatardata\\heads\\thumbnails\\thumbnails.dat");
Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift())));
break;
}
return Thumbnail;
}