using System.Collections.Generic;

namespace Sex
{
	public partial class Sex : System.Web.UI.Page
	{
        public enum E_ObjectCommand { CODE, DIRECTORY, DOWNLOAD, EMBED, EXIF, FRAME, HEX, INLINE, LINK, NEWWIN, NONE, PERMISSIONS, SPECIAL, TEXT, THUMBS };

        public class FileGroup
        {
            public enum Type { AUDIO, AUDVID, APPLI, APPLIEXE, BINARY, CODE, CODEEXE, EXIF, IMAGE, INLINE, NOTYPE, OTHER, VIDEO };

            public static int CompareExtensionsAction(FileGroup x, FileGroup y)
            {
                return x.FileType.ToString().CompareTo(y.FileType.ToString());
            }
            public Type FileType;
            public string Description;
            public string Icon;
            public bool ShowCode;
            public bool ShowFrame;
            public bool ShowInline;
            public bool ShowDownload;
            public bool ShowHex;
            public bool ShowPermissions;
            public bool ShowEmbedded;
            public bool ShowSpecial;
            public bool ShowExif;
            public E_ObjectCommand ShowFirst;
            public E_ObjectCommand ShowInThumb;
            public FileGroup(Type FileType, string Description, string Icon, bool ShowCode, bool ShowFrame, bool ShowInline, bool ShowDownload, bool ShowHex, bool ShowPermissions, bool ShowEmbedded, bool ShowSpecial, bool ShowExif, E_ObjectCommand ShowFirst, E_ObjectCommand ShowInThumb)
            {
                this.FileType = FileType;
                this.Description = Description;
                this.Icon = Icon;
                this.ShowCode = ShowCode;
                this.ShowFrame = ShowFrame;
                this.ShowInline = ShowInline;
                this.ShowDownload = ShowDownload;
                this.ShowHex = ShowHex;
                this.ShowPermissions = ShowPermissions;
                this.ShowEmbedded = ShowEmbedded;
                this.ShowSpecial = ShowSpecial;
                this.ShowExif = ShowExif;
                this.ShowFirst = ShowFirst;
                this.ShowInThumb = ShowInThumb;
            }
        }
        public static class FileGroups
        {
            public static bool IsSorted = false;
            public static void Sort()
            {
                if (!IsSorted)
                {
                    list.Sort(FileGroup.CompareExtensionsAction);
                    IsSorted = true;
                }
            }
            public static FileGroup.Type ExtensionTypeToFind = FileGroup.Type.NOTYPE;

            public static E_ObjectCommand GetThumbCommand(FileGroup.Type etf)
            {
                FileGroup fg = Get(etf);
                return fg.ShowInThumb;
            }
            public static FileGroup Get(FileGroup.Type etf)
            {
                ExtensionTypeToFind = etf;
                return list.Find(
                    delegate(FileGroup eaf)
                    {
                        return (ExtensionTypeToFind == eaf.FileType);
                });
            }
            // the following construct does not work with framework 2.0 when running in single file mode
            public static List<FileGroup> list = new List<FileGroup>() 
            {
                new FileGroup(FileGroup.Type.OTHER, "Binary", "", false, false, false, true, true, true, false, false, false, E_ObjectCommand.HEX, E_ObjectCommand.NONE),
            
                new FileGroup(FileGroup.Type.APPLIEXE, "Display", "", false, true, false, true, true, true, false, false, false, E_ObjectCommand.FRAME, E_ObjectCommand.FRAME),

                new FileGroup(FileGroup.Type.CODE, "Code", "", true, false, false, true, true, true, false, false, false, E_ObjectCommand.CODE, E_ObjectCommand.TEXT),

                new FileGroup(FileGroup.Type.CODEEXE, "Code-Display", "", true, true, false, true, true, true, false, false, false, E_ObjectCommand.CODE, E_ObjectCommand.FRAME),

                new FileGroup(FileGroup.Type.IMAGE, "Image", "", false, true, false, true, true, true, true, true, false, E_ObjectCommand.EMBED, E_ObjectCommand.EMBED),

                new FileGroup(FileGroup.Type.EXIF, "Image-Exif", "", false, true, false, true, true, true, true, true, true, E_ObjectCommand.EMBED, E_ObjectCommand.EMBED),

                new FileGroup(FileGroup.Type.AUDVID, "Audio and Video", "", false, true, true, true, true, true, true, false, false, E_ObjectCommand.EMBED, E_ObjectCommand.LINK),
                new FileGroup(FileGroup.Type.AUDIO, "Audio", "", false, true, true, true, true, true, true, false, false, E_ObjectCommand.EMBED, E_ObjectCommand.LINK),
                new FileGroup(FileGroup.Type.VIDEO, "Video", "", false, true, true, true, true, true, true, false, false, E_ObjectCommand.EMBED, E_ObjectCommand.LINK),

                new FileGroup(FileGroup.Type.INLINE, "Inline", "", true, true, true, true, true, true, false, false, false, E_ObjectCommand.INLINE, E_ObjectCommand.FRAME)
            };
        }
    }
}