internal static string FolderSubstitution(string input)
        {
            // program data
            input = input.Replace("%ProgramData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));

            // streaming directory
            string streamingDirectory = Installation.GetFileLayoutType() == FileLayoutType.Source ?
                                        Path.Combine(Installation.GetSourceRootDirectory(), "Libraries", "Streaming") :
                                        Path.Combine(Installation.GetInstallDirectory(), "Streaming");

            input = input.Replace("%mpextended-streaming%", streamingDirectory);

            // mp settings
            input = Regex.Replace(input, @"%mp-([^-]+)-([^-]+)%", delegate(Match match)
            {
                var section = Mediaportal.ReadSectionFromConfigFile(match.Groups[1].Value);
                if (!section.ContainsKey(match.Groups[2].Value))
                {
                    Log.Info("Replacing unknown Mediaportal path substitution %mp-{0}-{1}% with empty string", match.Groups[1].Value, match.Groups[2].Value);
                    return(String.Empty);
                }
                else
                {
                    return(section[match.Groups[2].Value]);
                }
            });

            return(input);
        }
Beispiel #2
0
        protected IPEndPoint ReadConfiguredTVServerAddress()
        {
            // Try to read the TV server IP address from MediaPortal's configuration
            if (!Mediaportal.HasValidConfigFile())
            {
                return(null);
            }

            // read the hostname
            Dictionary <string, string> tvSection = Mediaportal.ReadSectionFromConfigFile("tvservice");

            if (tvSection == null || !tvSection.ContainsKey("hostname") || string.IsNullOrWhiteSpace(tvSection["hostname"]))
            {
                return(null);
            }
            string hostname = tvSection["hostname"];

            try
            {
                // Return as IP addresses
                var address = Dns.GetHostAddresses(hostname).First();
                return(new IPEndPoint(address, Configuration.DEFAULT_PORT));
            }
            catch (SocketException)
            {
                Log.Info("Failed to resolve hostname {0} configured as default TV Server", hostname);
                return(null);
            }
        }
Beispiel #3
0
        public MPPictureShares(IPluginData data) : base(data)
        {
            if (!Mediaportal.HasValidConfigFile())
            {
                Supported = false;
                return;
            }

            IEnumerable <KeyValuePair <string, string> > list = Mediaportal.ReadSectionFromConfigFile("pictures");

            Extensions = list.Where(x => x.Key == "extensions").Select(x => x.Value).First().Split(',');

            shares = new List <Share>();
            int count = list.Where(x => x.Key.StartsWith("sharename")).Count();

            for (int i = 0; i < count; i++)
            {
                if (list.Where(x => x.Key == "sharetype" + i).Select(x => x.Value).First() == "yes")
                {
                    continue;
                }

                shares.Add(new Share()
                {
                    Name  = list.Where(x => x.Key == "sharename" + i).Select(x => x.Value).First(),
                    Path  = Path.GetFullPath(list.Where(x => x.Key == "sharepath" + i).Select(x => x.Value).First()),
                    Index = i
                });
            }

            shareCache = new Dictionary <string, Share>();
            Supported  = true;
        }
Beispiel #4
0
        public ShareLibrary(IPluginData data, string[] sections)
        {
            this.data          = data;
            this.configuration = data.GetConfiguration("MP Shares");

            if (!Mediaportal.HasValidConfigFile())
            {
                Supported = false;
                return;
            }

            var localsharelist = new List <Share>();

            foreach (string section in sections)
            {
                IEnumerable <KeyValuePair <string, string> > list = Mediaportal.ReadSectionFromConfigFile(section);
                string[] extensions = list.Where(x => x.Key == "extensions").Select(x => x.Value).First().Split(',');
                int      count      = list.Where(x => x.Key.StartsWith("sharename")).Count();

                for (int i = 0; i < count; i++)
                {
                    if (list.Where(x => x.Key == "sharetype" + i).Select(x => x.Value).First() == "yes")
                    {
                        continue;
                    }

                    string path = list.Where(x => x.Key == "sharepath" + i).Select(x => x.Value).First();
                    localsharelist.Add(new Share()
                    {
                        Name       = list.Where(x => x.Key == "sharename" + i).Select(x => x.Value).First(),
                        Path       = path,
                        Extensions = extensions.ToList(),
                    });
                }
            }

            // make shares unique
            shares = localsharelist.GroupBy(x => x.Path, (path, gshares) => new Share()
            {
                Name       = gshares.First().Name,
                Path       = path,
                Extensions = gshares.SelectMany(x => x.Extensions).ToList()
            }).ToList();
            int shareNr = 0;

            foreach (Share share in shares)
            {
                share.Id = "s" + (shareNr++);
            }

            Supported = true;
        }
Beispiel #5
0
        private void ReadConfiguration()
        {
            var localsharelist = new List <Share>();

            foreach (string section in sections)
            {
                IEnumerable <KeyValuePair <string, string> > list = Mediaportal.ReadSectionFromConfigFile(section);
                if (!list.Any())
                {
                    Log.Warn("MPShares: Failed to read section {0} from MediaPortal configuration file, aborting configuration reading", section);
                    return;
                }

                string[] extensions = list.Where(x => x.Key == "extensions").Select(x => x.Value).First().Split(',');
                int      count      = list.Where(x => x.Key.StartsWith("sharename")).Count();

                for (int i = 0; i < count; i++)
                {
                    if (list.Where(x => x.Key == "sharetype" + i).Select(x => x.Value).First() == "yes")
                    {
                        continue;
                    }

                    string path = list.Where(x => x.Key == "sharepath" + i).Select(x => x.Value).First();
                    localsharelist.Add(new Share()
                    {
                        Name       = list.Where(x => x.Key == "sharename" + i).Select(x => x.Value).First(),
                        Path       = path,
                        Extensions = extensions.ToList(),
                    });
                }
            }

            // make shares unique
            shares = localsharelist.GroupBy(x => x.Path, (path, gshares) => new Share()
            {
                Name       = gshares.First().Name,
                Path       = path,
                Extensions = gshares.SelectMany(x => x.Extensions).ToList()
            }).ToList();
            int shareNr = 0;

            foreach (Share share in shares)
            {
                share.Id = "s" + (shareNr++);
            }
        }