예제 #1
0
        public static string GetLocation(MediaportalDirectory type)
        {
            // read from MediaPortalDirs.xml
            string mpDirs = Path.Combine(GetClientInstallationDirectory(), "MediaPortalDirs.xml");
            if (!File.Exists(mpDirs))
            {
                Log.Warn("Could not find MediaPortalDirs.xml");
                return null;
            }

            XElement file = XElement.Load(mpDirs);
            var element = file.Elements("Dir").Where(x => x.Attribute("id").Value == type.ToString());
            if (element.Count() == 0)
            {
                Log.Warn("Could not find directory with id {0} in MediaPortalDirs.xml", type);
                return null;
            }

            // apply transformations
            var path = element.First().Element("Path").Value;
            path = path.Replace("%ProgramData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            if(!Path.IsPathRooted(path))
            {
                path = Path.Combine(GetClientInstallationDirectory(), path);
            }

            // and return it
            return Path.GetFullPath(path);
        }
예제 #2
0
        public static string GetLocation(MediaportalDirectory type)
        {
            if (hasMpDirs.HasValue && !hasMpDirs.Value)
            {
                return(null);
            }

            try
            {
                // read from MediaPortalDirs.xml
                string clientInstallDir = GetClientInstallationDirectory();
                string mpDirs           = clientInstallDir == null ? null : Path.Combine(clientInstallDir, "MediaPortalDirs.xml");
                if (mpDirs == null || !File.Exists(mpDirs))
                {
                    Log.Debug("Could not find MediaPortalDirs.xml");
                    hasMpDirs = false;
                    return(null);
                }

                XElement file    = XElement.Load(mpDirs);
                var      element = file.Elements("Dir").Where(x => x.Attribute("id").Value == type.ToString());
                if (element.Count() == 0)
                {
                    Log.Debug("Could not find directory with id {0} in MediaPortalDirs.xml", type);
                    return(null);
                }

                // apply transformations
                var path = element.First().Element("Path").Value;
                path = path.Replace("%ProgramData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(GetClientInstallationDirectory(), path);
                }

                // and return it
                return(Path.GetFullPath(path));
            }
            catch (Exception ex)
            {
                Log.Warn("Error while loading MediaPortalDirs.xml", ex);
                return(null);
            }
        }
예제 #3
0
        public static string GetLocation(MediaportalDirectory type)
        {
            if (hasMpDirs.HasValue && !hasMpDirs.Value)
            {
                return null;
            }

            try
            {
                // read from MediaPortalDirs.xml
                string clientInstallDir = GetClientInstallationDirectory();
                string mpDirs = clientInstallDir == null ? null : Path.Combine(clientInstallDir, "MediaPortalDirs.xml");
                if (mpDirs == null || !File.Exists(mpDirs))
                {
                    Log.Debug("Could not find MediaPortalDirs.xml");
                    hasMpDirs = false;
                    return null;
                }

                XElement file = XElement.Load(mpDirs);
                var element = file.Elements("Dir").Where(x => x.Attribute("id").Value == type.ToString());
                if (element.Count() == 0)
                {
                    Log.Debug("Could not find directory with id {0} in MediaPortalDirs.xml", type);
                    return null;
                }

                // apply transformations
                var path = element.First().Element("Path").Value;
                path = path.Replace("%ProgramData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(GetClientInstallationDirectory(), path);
                }

                // and return it
                return Path.GetFullPath(path);
            }
            catch (Exception ex)
            {
                Log.Warn("Error while loading MediaPortalDirs.xml", ex);
                return null;
            }
        }