/// <summary>
/// Saves the avatar archive.
/// </summary>
/// <returns><c>true</c>, if avatar archive was saved, <c>false</c> otherwise.</returns>
/// <param name="fileName">File name.</param>
/// <param name="principalID">Principal I.</param>
/// <param name="folderName">Folder name.</param>
/// <param name="snapshotUUID">Snapshot UUI.</param>
/// <param name="isPublic">If set to <c>true</c> is public.</param>
/// <param name="isPortable">If set to <c>true</c> create a portable archive.</param>
public bool SaveAvatarArchive (string fileName, UUID principalID, string folderName,
UUID snapshotUUID, bool isPublic, bool isPortable)
{
UserAccount account = userAccountService.GetUserAccount (null, principalID);
if (account == null) {
MainConsole.Instance.Error ("[Avatar Archiver]: User not found!");
return false;
}
AvatarAppearance appearance = avatarService.GetAppearance (account.PrincipalID);
if (appearance == null) {
MainConsole.Instance.Error ("[Avatar Archiver] Appearance not found!");
return false;
}
string archiveName = Path.GetFileNameWithoutExtension (fileName);
string filePath = Path.GetDirectoryName (fileName);
AvatarArchive archive = new AvatarArchive ();
archive.AssetsMap = new OSDMap ();
archive.ItemsMap = new OSDMap ();
int wearCount = 0;
foreach (AvatarWearable wear in appearance.Wearables) {
for (int i = 0; i < wear.Count; i++) {
WearableItem w = wear [i];
if (w.AssetID != UUID.Zero) {
SaveItem (w.ItemID, ref archive);
SaveAsset (w.AssetID, ref archive, isPortable);
wearCount++;
}
}
}
MainConsole.Instance.InfoFormat ("[Avatar Archiver] Adding {0} wearables to {1}", wearCount, archiveName);
int attachCount = 0;
List<AvatarAttachment> attachments = appearance.GetAttachments ();
foreach (AvatarAttachment a in attachments.Where (a => a.AssetID != UUID.Zero)) {
SaveItem (a.ItemID, ref archive);
SaveAsset (a.AssetID, ref archive, isPortable);
attachCount++;
}
MainConsole.Instance.InfoFormat ("[Avatar Archiver] Adding {0} attachments to {1}", attachCount, archiveName);
// set details
archive.Appearance = appearance;
archive.BodyMap = appearance.Pack ();
archive.FolderName = folderName;
archive.Snapshot = snapshotUUID;
archive.IsPublic = isPublic;
archive.IsPortable = isPortable;
File.WriteAllText (fileName, OSDParser.SerializeLLSDXmlString (archive.ToOSD ()));
if (snapshotUUID != UUID.Zero) {
ExportArchiveImage (snapshotUUID, archiveName, filePath);
MainConsole.Instance.Info ("[Avatar Archiver] Saved archive snapshot");
}
MainConsole.Instance.Info ("[Avatar Archiver] Saved archive to " + fileName);
return true;
}