Beispiel #1
0
        public static HttpMimeDictionary GetDefaults()
        {
            HttpMimeDictionary set = new HttpMimeDictionary();

            set.Add(new HttpMime(".asf", "x-ms-asf", MediaType.Video));
            set.Add(new HttpMime(".avi", "avi", MediaType.Video));
            set.Add(new HttpMime(".flv", "x-flv", MediaType.Video));
            set.Add(new HttpMime(".m1v", "mpeg", MediaType.Video));
            set.Add(new HttpMime(".m2v", "mpeg", MediaType.Video));
            set.Add(new HttpMime(".mkv", "x-matroska", MediaType.Video));
            set.Add(new HttpMime(".mp4", "mp4", MediaType.Video));
            set.Add(new HttpMime(".mpeg", "mpeg", MediaType.Video));
            set.Add(new HttpMime(".mpg", "mpeg", MediaType.Video));
            set.Add(new HttpMime(".webm", "webm", MediaType.Video));
            set.Add(new HttpMime(".wmv", "x-ms-wmv", MediaType.Video));
            set.Add(new HttpMime(".iso", "iso", MediaType.Video));

            set.Add(new HttpMime(".flac", "flac", MediaType.Audio));
            set.Add(new HttpMime(".m2a", "mpeg", MediaType.Audio));
            set.Add(new HttpMime(".mid", "midi", MediaType.Audio));
            set.Add(new HttpMime(".midi", "midi", MediaType.Audio));
            set.Add(new HttpMime(".mp2", "mpeg", MediaType.Audio));
            set.Add(new HttpMime(".mp3", "mpeg", MediaType.Audio));
            set.Add(new HttpMime(".mpa", "mpeg", MediaType.Audio));
            set.Add(new HttpMime(".mpga", "mpeg", MediaType.Audio));
            set.Add(new HttpMime(".wav", "wav", MediaType.Audio));
            set.Add(new HttpMime(".wma", "x-ms-wma", MediaType.Audio));

            set.Add(new HttpMime(".bmp", "bmp", MediaType.Image));
            set.Add(new HttpMime(".gif", "gif", MediaType.Image));
            set.Add(new HttpMime(".jpe", "jpeg", MediaType.Image));
            set.Add(new HttpMime(".jpeg", "jpeg", MediaType.Image));
            set.Add(new HttpMime(".jpg", "jpeg", MediaType.Image));
            set.Add(new HttpMime(".png", "png", MediaType.Image));
            set.Add(new HttpMime(".tif", "tiff", MediaType.Image));
            set.Add(new HttpMime(".tiff", "tiff", MediaType.Image));

            set.Add(new HttpMime(".m3u", "mpegurl", MediaType.Other));

            return(set);
        }
Beispiel #2
0
        internal void LoadSettings(XmlDocument xmlReader, string databasePath)
        {
            if (xmlReader != null)
            {
                XmlNode node = xmlReader.SelectSingleNode("/HomeMediaCenter/RealTimeDatabaseRefresh");
                if (node != null)
                {
                    bool.TryParse(node.InnerText, out this.realTimeDatabaseRefresh);
                }

                node = xmlReader.SelectSingleNode("/HomeMediaCenter/LiteDatabaseRefresh");
                if (node != null)
                {
                    bool.TryParse(node.InnerText, out this.liteDatabaseRefresh);
                }

                node = xmlReader.SelectSingleNode("/HomeMediaCenter/EnableDesktopStreaming");
                if (node != null)
                {
                    bool.TryParse(node.InnerText, out this.enableDesktopStreaming);
                }

                node = xmlReader.SelectSingleNode("/HomeMediaCenter/EnableWebcamStreaming");
                if (node != null)
                {
                    bool.TryParse(node.InnerText, out this.enableWebcamStreaming);
                }

                node = xmlReader.SelectSingleNode("/HomeMediaCenter/ShowHiddenFiles");
                if (node != null)
                {
                    bool.TryParse(node.InnerText, out this.showHiddenFiles);
                }

                lock (this.directories)
                {
                    foreach (Dir dir in this.directories)
                    {
                        dir.Watcher.Dispose();
                    }
                    this.directories.Clear();
                    foreach (XmlNode directory in xmlReader.SelectNodes("/HomeMediaCenter/Directories/*"))
                    {
                        XmlAttribute title = directory.Attributes["Title"];
                        AddDirectoryInt(directory.InnerText, title == null ? null : title.Value);
                    }
                }

                this.subtitleExt.Clear();
                foreach (XmlNode subtitle in xmlReader.SelectNodes("/HomeMediaCenter/Subtitles/*"))
                {
                    this.subtitleExt.Add(subtitle.InnerText);
                }

                this.mimeTypes = HttpMimeDictionary.DeserializeMe(xmlReader);

                this.settings.LoadSettings(xmlReader);
            }

            this.dbConnectionString = "Data Source=" + databasePath;
            if (!File.Exists(databasePath))
            {
                using (SqlCeEngine engine = new SqlCeEngine(this.dbConnectionString))
                {
                    engine.CreateDatabase();
                }

                using (SqlCeConnection conn = new SqlCeConnection(this.dbConnectionString))
                    using (DataContext context = new DataContext(conn))
                    {
                        string command = CreateTable(context.Mapping.GetTable(typeof(Item)));
                        context.ExecuteCommand(command);
                        context.ExecuteCommand("CREATE INDEX pathidx ON [Items]([Path])");

                        ItemContainerRoot root = new ItemContainerRoot();
                        context.GetTable <Item>().InsertOnSubmit(root);
                        context.SubmitChanges();

                        if (root.Id != 0)
                        {
                            throw new MediaCenterException("Root container must have id with value 0");
                        }
                    }
            }
            else
            {
                using (SqlCeConnection conn = new SqlCeConnection(this.dbConnectionString))
                    using (DataContext context = new DataContext(conn))
                    {
                        Item root = context.GetTable <Item>().Single(a => a.GetType() == typeof(ItemContainerRoot));
                        if (root.Id != 0)
                        {
                            throw new MediaCenterException("Root container must have id with value 0");
                        }
                    }
            }
        }