diff --git a/Src/Workshell.PE.Resources/Dialogs/Dialog.cs b/Src/Workshell.PE.Resources/Dialogs/Dialog.cs index 2f3a5ec..4dec89c 100644 --- a/Src/Workshell.PE.Resources/Dialogs/Dialog.cs +++ b/Src/Workshell.PE.Resources/Dialogs/Dialog.cs @@ -37,6 +37,28 @@ namespace Workshell.PE.Resources public sealed class Dialog { + internal Dialog(DialogResource dialogResource, uint languageId) + { + Resource = dialogResource; + Language = languageId; + } + + #region Properties + + public DialogResource Resource + { + get; + private set; + } + + public uint Language + { + get; + private set; + } + + #endregion + } } diff --git a/Src/Workshell.PE.Resources/Dialogs/DialogEx.cs b/Src/Workshell.PE.Resources/Dialogs/DialogEx.cs index f179937..951879d 100644 --- a/Src/Workshell.PE.Resources/Dialogs/DialogEx.cs +++ b/Src/Workshell.PE.Resources/Dialogs/DialogEx.cs @@ -231,6 +231,9 @@ public byte[] ExtraData public sealed class DialogEx : IEnumerable { + private DialogResource resource; + private uint language_id; + private uint help_id; private uint ex_styles; private uint styles; @@ -243,8 +246,11 @@ public sealed class DialogEx : IEnumerable private CharacterSet char_set; private DialogItemEx[] items; - internal DialogEx(Stream stream) + internal DialogEx(DialogResource dialogResource, uint languageId, Stream stream) { + resource = dialogResource; + language_id = languageId; + ushort ver = Utils.ReadUInt16(stream); ushort sig = Utils.ReadUInt16(stream); @@ -359,6 +365,22 @@ public DialogStyle GetDialogStyles() #region Properties + public DialogResource Resource + { + get + { + return resource; + } + } + + public uint Language + { + get + { + return language_id; + } + } + public uint HelpId { get diff --git a/Src/Workshell.PE.Resources/Dialogs/DialogResource.cs b/Src/Workshell.PE.Resources/Dialogs/DialogResource.cs index 5f6afa6..ddfb1ed 100644 --- a/Src/Workshell.PE.Resources/Dialogs/DialogResource.cs +++ b/Src/Workshell.PE.Resources/Dialogs/DialogResource.cs @@ -42,152 +42,75 @@ namespace Workshell.PE.Resources { - public enum DialogSaveFormat - { - Raw, - Resource - } - - public sealed class DialogResource + public sealed class DialogResource : Resource { - private Resource resource; - private uint language_id; - private bool is_extended; - private Dialog dialog; - private DialogEx dialog_ex; - - internal DialogResource(Resource sourceResource, uint languageId, byte[] data) + public DialogResource(ResourceType owningType, ResourceDirectoryEntry directoryEntry) : base(owningType, directoryEntry) { - resource = sourceResource; - language_id = languageId; - - MemoryStream mem = resource.Type.Resources.Image.MemoryStreamProvider.GetStream(data); - - using (mem) - { - ushort ver = Utils.ReadUInt16(mem); - ushort sig = Utils.ReadUInt16(mem); - - is_extended = (ver == 1 && sig == 0xFFFF); - - mem.Seek(0, SeekOrigin.Begin); - - if (!is_extended) - { - dialog = null; - } - else - { - dialog_ex = new DialogEx(mem); - } - } } #region Static Methods - public static DialogResource Load(Resource resource) + public static bool Register() { - return Load(resource, Resource.DEFAULT_LANGUAGE); - } - - public static DialogResource Load(Resource resource, uint language) - { - if (!resource.Languages.Contains(language)) - return null; - - if (resource.Type.Id != ResourceType.RT_DIALOG) - return null; + ResourceId resource_type = new ResourceId(ResourceType.RT_DIALOG); - byte[] data = resource.GetBytes(language); - DialogResource result = new DialogResource(resource, language, data); - - return result; + return ResourceType.Register(resource_type, typeof(DialogResource)); } #endregion #region Methods - public Dialog GetDialog() + public Dialog GetDialog(uint languageId) { - return dialog; - } + byte[] data = GetBytes(languageId); - public DialogEx GetDialogEx() - { - return dialog_ex; - } + using (MemoryStream mem = new MemoryStream(data)) + { + ushort ver = Utils.ReadUInt16(mem); + ushort sig = Utils.ReadUInt16(mem); - public void Save(string fileName) - { - Save(fileName, DialogSaveFormat.Raw); - } + bool is_extended = (ver == 1 && sig == 0xFFFF); - public void Save(Stream stream) - { - Save(stream, DialogSaveFormat.Raw); - } + mem.Seek(0, SeekOrigin.Begin); - public void Save(string fileName, DialogSaveFormat format) - { - using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) - { - Save(file, format); - file.Flush(); - } - } + if (!is_extended) + { + Dialog dialog = new Dialog(this, languageId); - public void Save(Stream stream, DialogSaveFormat format) - { - switch (format) - { - case DialogSaveFormat.Raw: - SaveRaw(stream); - break; - case DialogSaveFormat.Resource: - SaveResource(stream); - break; + return dialog; + } + else + { + return null; + } } } - private void SaveRaw(Stream stream) + public DialogEx GetDialogEx(uint languageId) { - byte[] data = resource.GetBytes(language_id); - - stream.Write(data, 0, data.Length); - } + byte[] data = GetBytes(languageId); - private void SaveResource(Stream stream) - { - throw new NotImplementedException(); - } - - #endregion + using (MemoryStream mem = new MemoryStream(data)) + { + ushort ver = Utils.ReadUInt16(mem); + ushort sig = Utils.ReadUInt16(mem); - #region Properties + bool is_extended = (ver == 1 && sig == 0xFFFF); - public Resource Resource - { - get - { - return resource; - } - } + mem.Seek(0, SeekOrigin.Begin); - public uint Language - { - get - { - return language_id; - } - } + if (!is_extended) + { + return null; + } + else + { + DialogEx dialog = new DialogEx(this, languageId, mem); - public bool IsExtended - { - get - { - return is_extended; + return dialog; + } } }