Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C# by Arnon ( 15 years ago )
public class TemplateInfoData
{
    // Fields
    private Guid baseId;
    private Size baseScreenSize;
    private string content;
    private List<Guid> createIdList;
    private long dataPos;
    private static readonly string ext = "gtd";
    private readonly string filePath;
    private Guid genreId;
    private string genreText;
    private static readonly int HeaderSize = 3;
    private Guid id;
    private string name;
    private static readonly ushort nowVersionNo = 2;
    private List<Guid> plugInDataIdList;
    private bool reverseScreen;
    private static readonly string templateHeader = "GTD";
    private Image thumbnail;
    private TemplateType type;
    private ushort versionNo;

    // Methods
    private TemplateInfoData(string filePath)
    {
        this.filePath = filePath;
    }

    public ProjectData CreateProject(string name, TemplateInfoData moodTemplateInfo, TemplateInfoData musicTemplateInfo, TemplateInfoData playerTemplateInfo)
    {
        try
        {
            ProjectData projectData = this.LoadProject();
            projectData.GameName = name;
            projectData.Content = this.Content;
            projectData.Thumbnail = this.Thumbnail;
            if (!this.SetCustomData(projectData, moodTemplateInfo))
            {
                return null;
            }
            if (!this.SetCustomData(projectData, musicTemplateInfo))
            {
                return null;
            }
            if (!this.SetCustomData(projectData, playerTemplateInfo))
            {
                return null;
            }
            return projectData;
        }
        catch (Exception)
        {
            return null;
        }
    }

    public static TemplateInfoData FromFile(string filePath)
    {
        try
        {
            TemplateInfoData data = new TemplateInfoData(filePath);
            using (ProjectBinaryReader reader = new ProjectBinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read)))
            {
                if (data.LoadInfo(reader))
                {
                    return data;
                }
            }
        }
        catch (Exception)
        {
        }
        return null;
    }

    public static string GetTemplateFolderName(TemplateType type)
    {
        switch (type)
        {
            case TemplateType.Mood:
                return Resources.MoodFolderName;

            case TemplateType.Music:
                return Resources.MusicFolderName;

            case TemplateType.Player:
                return Resources.PlayerFolderName;
        }
        return string.Empty;
    }

    private Dictionary<ModuleData.ItemDataType, List<CustomData>> LoadCustomData()
    {
        Dictionary<ModuleData.ItemDataType, List<CustomData>> dictionary2;
        try
        {
            using (ProjectBinaryReader reader = new ProjectBinaryReader(new FileStream(this.filePath, FileMode.Open, FileAccess.Read)))
            {
                reader.BaseStream.Position = this.DataPos;
                Dictionary<ModuleData.ItemDataType, List<CustomData>> dictionary = new Dictionary<ModuleData.ItemDataType, List<CustomData>>(2);
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    ModuleData.ItemDataType key = (ModuleData.ItemDataType) reader.ReadInt();
                    int capacity = reader.ReadInt();
                    List<CustomData> list = new List<CustomData>(capacity);
                    for (int i = 0; i < capacity; i++)
                    {
                        list.Add(CustomData.FromFile(reader));
                    }
                    dictionary.Add(key, list);
                }
                dictionary2 = dictionary;
            }
        }
        catch (Exception)
        {
            dictionary2 = null;
        }
        return dictionary2;
    }

    private bool LoadInfo(ProjectBinaryReader reader)
    {
        byte[] buffer = reader.ReadBytes(HeaderSize);
        for (int i = 0; i < HeaderSize; i++)
        {
            if (buffer[i] != ((byte) TemplateHeader[i]))
            {
                return false;
            }
        }
        this.Type = (TemplateType) reader.ReadInt();
        switch (this.Type)
        {
            case TemplateType.Base:
            case TemplateType.Mood:
            case TemplateType.Music:
            case TemplateType.Player:
                this.VersionNo = reader.ReadUInt16();
                if (NowVersionNo >= this.VersionNo)
                {
                    if (reader.ReadInt64() != reader.BaseStream.Length)
                    {
                        return false;
                    }
                    long num3 = reader.BaseStream.Position + reader.ReadInt32();
                    this.Id = reader.ReadGuid();
                    this.Name = reader.ReadName();
                    this.Content = reader.ReadName();
                    if (reader.ReadBool())
                    {
                        this.GenreId = reader.ReadGuid();
                    }
                    else
                    {
                        this.GenreText = reader.ReadName();
                    }
                    this.Thumbnail = reader.ReadImage();
                    if (this.Type == TemplateType.Base)
                    {
                        if ((1 < this.VersionNo) && ProjectData.IsUnSupportVersionNo(reader.ReadUInt16()))
                        {
                            return false;
                        }
                        this.BaseScreenSize = reader.ReadSize();
                        this.ReverseScreen = reader.ReadBool();
                        int capacity = reader.ReadInt();
                        this.PlugInDataIdList = new List<Guid>(capacity);
                        for (int j = 0; j < capacity; j++)
                        {
                            this.PlugInDataIdList.Add(reader.ReadGuid());
                        }
                        capacity = reader.ReadInt();
                        this.CreateIdList = new List<Guid>(capacity);
                        for (int k = 0; k < capacity; k++)
                        {
                            this.CreateIdList.Add(reader.ReadGuid());
                        }
                    }
                    else
                    {
                        this.BaseId = reader.ReadGuid();
                    }
                    byte num8 = 0;
                    foreach (byte num9 in this.Id.ToByteArray())
                    {
                        num8 = (byte) (num8 + num9);
                    }
                    if (((byte) (reader.ReadByte() - num8)) != 0)
                    {
                        return false;
                    }
                    this.DataPos = reader.BaseStream.Position;
                    return (num3 == this.DataPos);
                }
                return false;
        }
        return false;
    }

    public ProjectData LoadProject()
    {
        ProjectData data;
        try
        {
            using (ProjectBinaryReader reader = new ProjectBinaryReader(new FileStream(this.filePath, FileMode.Open, FileAccess.Read)))
            {
                reader.BaseStream.Position = this.DataPos;
                data = ProjectData.FromTemplateFile(reader);
            }
        }
        catch (Exception)
        {
            data = null;
        }
        return data;
    }

    private bool SetCustomData(ProjectData projectData, TemplateInfoData templateInfo)
    {
        if ((templateInfo != null) && (this != templateInfo))
        {
            Dictionary<ModuleData.ItemDataType, List<CustomData>> customDataDic = templateInfo.LoadCustomData();
            if (customDataDic == null)
            {
                return false;
            }
            this.SetCustomData(projectData, customDataDic);
        }
        return true;
    }

    private void SetCustomData(ProjectData projectData, Dictionary<ModuleData.ItemDataType, List<CustomData>> customDataDic)
    {
        Dictionary<ModuleData.ItemDataType, List<CustomData>>.Enumerator enumerator = customDataDic.GetEnumerator();
        while (enumerator.MoveNext())
        {
            KeyValuePair<ModuleData.ItemDataType, List<CustomData>> current = enumerator.Current;
            foreach (CustomData data in current.Value)
            {
                ModuleData.FileItemData data2 = projectData.GetData(data.Id) as ModuleData.FileItemData;
                if (data2 != null)
                {
                    KeyValuePair<ModuleData.ItemDataType, List<CustomData>> pair2 = enumerator.Current;
                    if (data2.ItemType == ((ModuleData.ItemDataType) pair2.Key))
                    {
                        data2.DataBinary = data.Binary;
                    }
                }
            }
        }
    }

    // Properties
    public Size BaseDrawScreenSize
    {
        get
        {
            if (this.ReverseScreen)
            {
                return new Size(this.baseScreenSize.Height, this.baseScreenSize.Width);
            }
            return this.baseScreenSize;
        }
    }

    public Guid BaseId
    {
        get
        {
            return this.baseId;
        }
        set
        {
            this.baseId = value;
        }
    }

    public Size BaseScreenSize
    {
        get
        {
            return this.baseScreenSize;
        }
        set
        {
            this.baseScreenSize = value;
        }
    }

    public string Content
    {
        get
        {
            return this.content;
        }
        set
        {
            this.content = value;
        }
    }

    public List<Guid> CreateIdList
    {
        get
        {
            return this.createIdList;
        }
        set
        {
            this.createIdList = value;
        }
    }

    public long DataPos
    {
        get
        {
            return this.dataPos;
        }
        set
        {
            this.dataPos = value;
        }
    }

    public static string Ext
    {
        get
        {
            return ext;
        }
    }

    public string FilePath
    {
        get
        {
            return this.filePath;
        }
    }

    public Guid GenreId
    {
        get
        {
            return this.genreId;
        }
        set
        {
            this.genreId = value;
        }
    }

    public string GenreText
    {
        get
        {
            return this.genreText;
        }
        set
        {
            this.genreText = value;
        }
    }

    public Guid Id
    {
        get
        {
            return this.id;
        }
        set
        {
            this.id = value;
        }
    }

    public string Name
    {
        get
        {
            return this.name;
        }
        set
        {
            this.name = value;
        }
    }

    public static ushort NowVersionNo
    {
        get
        {
            return nowVersionNo;
        }
    }

    public List<Guid> PlugInDataIdList
    {
        get
        {
            return this.plugInDataIdList;
        }
        set
        {
            this.plugInDataIdList = value;
        }
    }

    public bool ReverseScreen
    {
        get
        {
            return this.reverseScreen;
        }
        set
        {
            this.reverseScreen = value;
        }
    }

    public static string TemplateHeader
    {
        get
        {
            return templateHeader;
        }
    }

    public Image Thumbnail
    {
        get
        {
            return this.thumbnail;
        }
        set
        {
            this.thumbnail = value;
        }
    }

    public TemplateType Type
    {
        get
        {
            return this.type;
        }
        set
        {
            this.type = value;
        }
    }

    public ushort VersionNo
    {
        get
        {
            return this.versionNo;
        }
        set
        {
            this.versionNo = value;
        }
    }

    // Nested Types
    private class CustomData
    {
        // Fields
        private readonly byte[] binary;
        private readonly Guid id;

        // Methods
        private CustomData(Guid id, byte[] binary)
        {
            this.id = id;
            this.binary = binary;
        }

        public static TemplateInfoData.CustomData FromFile(ProjectBinaryReader reader)
        {
            return new TemplateInfoData.CustomData(reader.ReadGuid(), reader.ReadBinary());
        }

        // Properties
        public byte[] Binary
        {
            get
            {
                return this.binary;
            }
        }

        public Guid Id
        {
            get
            {
                return this.id;
            }
        }
    }

    public enum TemplateType
    {
        Base = 0,
        Mood = 1,
        Music = 2,
        None = -1,
        Player = 3
    }
}

 

Revise this Paste

Your Name: Code Language: