Exemplo n.º 1
0
        public ICollection <IFileSystemResourceAccessor> GetFiles()
        {
            if (string.IsNullOrEmpty(_path))
            {
                return(null);
            }
            if (_path == "/")
            {
                // No files at root level - there are only logical drives
                return(new List <IFileSystemResourceAccessor>());
            }
            string dosPath = LocalFsResourceProviderBase.ToDosPath(_path);

            return((!string.IsNullOrEmpty(dosPath) && Directory.Exists(dosPath)) ? CreateChildResourceAccessors(Directory.GetFiles(dosPath), false) : null);
        }
        public ICollection <IFileSystemResourceAccessor> GetChildDirectories()
        {
            if (string.IsNullOrEmpty(_path))
            {
                return(null);
            }
            if (_path == "/")
            {
                return(Directory.GetLogicalDrives().Where(drive => new DriveInfo(drive).IsReady).Select <string, IFileSystemResourceAccessor>(
                           drive => new LocalFsResourceAccessor(_provider, "/" + FileUtils.RemoveTrailingPathDelimiter(drive) + "/")).ToList());
            }
            string dosPath = LocalFsResourceProviderBase.ToDosPath(_path);

            return((!string.IsNullOrEmpty(dosPath) && Directory.Exists(dosPath)) ? CreateChildResourceAccessors(Directory.GetDirectories(dosPath), true) : null);
        }
        public Stream CreateOpenWrite(string file, bool overwrite)
        {
            string dosPath = LocalFsResourceProviderBase.ToDosPath(_path);

            if (string.IsNullOrEmpty(dosPath) || !Directory.Exists(dosPath))
            {
                return(null);
            }
            string filePath = System.IO.Path.Combine(dosPath, file);

            if (File.Exists(filePath) && !overwrite)
            {
                return(File.OpenWrite(filePath));
            }
            return(File.Create(filePath));
        }
    private string GetRemovableMediaItemPath(MediaItem mediaItem)
    {
      if (mediaItem == null)
        return null;

      foreach (var pra in mediaItem.PrimaryResources)
      {
        var resPath = ResourcePath.Deserialize(pra.GetAttributeValue<string>(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH));
        var dosPath = LocalFsResourceProviderBase.ToDosPath(resPath);
        if (string.IsNullOrEmpty(dosPath))
          continue;
        if (DriveUtils.IsDVD(dosPath))
          return dosPath;
      }
      return null;
    }
Exemplo n.º 5
0
        public void ShowWorkingDirectoryDialog()
        {
            string       workingDirectory = WorkingDirectory;
            ResourcePath initialPath      = string.IsNullOrEmpty(workingDirectory) ? null : LocalFsResourceProviderBase.ToResourcePath(workingDirectory);
            Guid         dialogHandle     = ServiceRegistration.Get <IPathBrowser>().ShowPathBrowser("[Emulators.Config.WorkingDirectory.Label]", false, false, initialPath,
                                                                                                     path =>
            {
                string chosenPath = LocalFsResourceProviderBase.ToDosPath(path.LastPathSegment.Path);
                return(!string.IsNullOrEmpty(chosenPath));
            });

            if (_pathBrowserCloseWatcher != null)
            {
                _pathBrowserCloseWatcher.Dispose();
            }
            _pathBrowserCloseWatcher = new PathBrowserCloseWatcher(this, dialogHandle, chosenPath => WorkingDirectory = LocalFsResourceProviderBase.ToDosPath(chosenPath), null);
        }
Exemplo n.º 6
0
        public void FinishEmulatorConfiguration()
        {
            EmulatorConfiguration configuration;

            if (_emulatorProxy.Configuration != null)
            {
                configuration = _emulatorProxy.Configuration;
            }
            else
            {
                configuration = new EmulatorConfiguration()
                {
                    IsNative      = _emulatorProxy.EmulatorType == EmulatorType.Native,
                    IsLibRetro    = _emulatorProxy.EmulatorType == EmulatorType.LibRetro,
                    Id            = Guid.NewGuid(),
                    LocalSystemId = ServiceRegistration.Get <ISystemResolver>().LocalSystemId,
                    // Libretro configs are platform specific, assume it requires the current platform
                    Is64Bit = _emulatorProxy.EmulatorType == EmulatorType.LibRetro && Utils.IsCurrentPlatform64Bit()
                };
            }

            if (!configuration.IsNative)
            {
                configuration.Path = LocalFsResourceProviderBase.ToDosPath(_emulatorProxy.PathBrowser.ChoosenResourcePath);
            }
            configuration.Arguments        = _emulatorProxy.Arguments;
            configuration.WorkingDirectory = _emulatorProxy.WorkingDirectory;
            configuration.UseQuotes        = _emulatorProxy.UseQuotes;
            configuration.Name             = _emulatorProxy.Name;
            configuration.FileExtensions   = _emulatorProxy.FileExtensions;
            configuration.ExitsOnEscapeKey = _emulatorProxy.ExitsOnEscapeKey;
            configuration.Platforms.Clear();
            foreach (string category in _emulatorProxy.SelectedGameCategories)
            {
                configuration.Platforms.Add(category);
            }
            ServiceRegistration.Get <IEmulatorManager>().AddOrUpdate(configuration);
            if (configuration.IsLibRetro && _emulatorProxy.LibRetroProxy != null)
            {
                UpdateLibRetroCoreSetting(configuration.Path, _emulatorProxy.LibRetroProxy.Variables);
            }
            UpdateConfigurations();
            NavigateBackToOverview();
        }
Exemplo n.º 7
0
        public string GetFileSystemPath()
        {
            if (!string.IsNullOrEmpty(SourcePath))
            {
                var systemPath = LocalFsResourceProviderBase.ToDosPath(SourcePath);
                if (File.Exists(systemPath))
                {
                    return(systemPath);
                }

                var path = ResourcePath.Deserialize(SourcePath);
                if (path.BasePathSegment.ProviderId == LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID)
                {
                    return(LocalFsResourceProviderBase.ToDosPath(path));
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        public bool IsVirtualResource(ResourcePath rp)
        {
            if (rp == null)
            {
                return(false);
            }
            int numPathSegments = rp.Count();

            if (numPathSegments == 0)
            {
                return(false);
            }
            ResourcePath firstRPSegment = new ResourcePath(new ProviderPathSegment[] { rp[0] });
            String       pathRoot       = Path.GetPathRoot(LocalFsResourceProviderBase.ToDosPath(firstRPSegment));

            if (string.IsNullOrEmpty(pathRoot))
            {
                return(false);
            }
            return(Dokan.Dokan.IsDokanDrive(pathRoot[0]));
        }
        public bool IsVirtualResource(ResourcePath rp)
        {
            if (rp == null)
            {
                return(false);
            }
            int numPathSegments = rp.Count();

            if (numPathSegments == 0)
            {
                return(false);
            }
            ResourcePath firstRPSegment = new ResourcePath(new ProviderPathSegment[] { rp[0] });
            String       pathRoot       = Path.GetPathRoot(LocalFsResourceProviderBase.ToDosPath(firstRPSegment));

            if (string.IsNullOrEmpty(pathRoot) || pathRoot.Length < 2)
            {
                return(false);
            }
            // The provider may also point to an UNC path, so we need to check this first. Dokan based check depends on actual drive letters.
            return(pathRoot[1] == ':' && Dokan.Dokan.IsDokanDrive(pathRoot[0]));
        }
Exemplo n.º 10
0
        public void SearchIcon()
        {
            string initialPath  = "C:\\";
            Guid   dialogHandle = ServiceRegistration.Get <IPathBrowser>().ShowPathBrowser(S_ICO, true, false,
                                                                                           string.IsNullOrEmpty(initialPath) ? null : LocalFsResourceProviderBase.ToResourcePath(initialPath),
                                                                                           path =>
            {
                string choosenPath = LocalFsResourceProviderBase.ToDosPath(path.LastPathSegment.Path);
                if (string.IsNullOrEmpty(choosenPath))
                {
                    return(false);
                }

                return(true);
            });

            if (_pathBrowserCloseWatcher != null)
            {
                _pathBrowserCloseWatcher.Dispose();
            }

            _pathBrowserCloseWatcher = new PathBrowserCloseWatcher(this, dialogHandle, choosenPath => { IconPath = LocalFsResourceProviderBase.ToDosPath(choosenPath); }, null);
        }
Exemplo n.º 11
0
        public bool Delete()
        {
            string dosPath = LocalFsResourceProviderBase.ToDosPath(_path);

            try
            {
                if (IsDirectory)
                {
                    Directory.Delete(dosPath);
                    return(true);
                }
                if (IsFile)
                {
                    File.Delete(dosPath);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // There can be a wide range of exceptions because of read-only filesystems, access denied, file in use etc...
                ServiceRegistration.Get <ILogger>().Error("Error deleting resource '{0}'", ex, dosPath);
            }
            return(false); // Non existing or exception
        }
        protected int FindExternalSubtitles(ILocalFsResourceAccessor lfsra, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData)
        {
            int subtitleCount = 0;

            try
            {
                IList <MultipleMediaItemAspect> providerResourceAspects;
                if (!MediaItemAspect.TryGetAspects(extractedAspectData, ProviderResourceAspect.Metadata, out providerResourceAspects))
                {
                    return(0);
                }

                int newResourceIndex = -1;
                foreach (MultipleMediaItemAspect providerResourceAspect in providerResourceAspects)
                {
                    int resouceIndex = providerResourceAspect.GetAttributeValue <int>(ProviderResourceAspect.ATTR_RESOURCE_INDEX);
                    if (newResourceIndex < resouceIndex)
                    {
                        newResourceIndex = resouceIndex;
                    }
                }
                newResourceIndex++;

                using (lfsra.EnsureLocalFileSystemAccess())
                {
                    foreach (MultipleMediaItemAspect mmia in providerResourceAspects)
                    {
                        string       accessorPath = (string)mmia.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);
                        ResourcePath resourcePath = ResourcePath.Deserialize(accessorPath);

                        if (mmia.GetAttributeValue <int>(ProviderResourceAspect.ATTR_TYPE) != ProviderResourceAspect.TYPE_PRIMARY)
                        {
                            continue;
                        }

                        string filePath = LocalFsResourceProviderBase.ToDosPath(resourcePath);
                        if (string.IsNullOrEmpty(filePath))
                        {
                            continue;
                        }

                        List <string> subs = new List <string>();
                        int           videoResouceIndex = (int)mmia.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_INDEX);
                        string[]      subFiles          = Directory.GetFiles(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "*.*");
                        if (subFiles != null)
                        {
                            subs.AddRange(subFiles);
                        }
                        foreach (string folder in SUBTITLE_FOLDERS)
                        {
                            if (string.IsNullOrEmpty(Path.GetPathRoot(folder)) && Directory.Exists(Path.Combine(Path.GetDirectoryName(filePath), folder))) //Is relative path
                            {
                                subFiles = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(filePath), folder), Path.GetFileNameWithoutExtension(filePath) + "*.*");
                            }
                            else if (Directory.Exists(folder)) //Is absolute path
                            {
                                subFiles = Directory.GetFiles(folder, Path.GetFileNameWithoutExtension(filePath) + "*.*");
                            }

                            if (subFiles != null)
                            {
                                subs.AddRange(subFiles);
                            }
                        }
                        foreach (string subFile in subFiles)
                        {
                            if (!HasSubtitleExtension(subFile))
                            {
                                continue;
                            }

                            LocalFsResourceAccessor fsra = new LocalFsResourceAccessor((LocalFsResourceProvider)lfsra.ParentProvider, LocalFsResourceProviderBase.ToProviderPath(subFile));

                            //Check if already exists
                            bool exists = false;
                            foreach (MultipleMediaItemAspect providerResourceAspect in providerResourceAspects)
                            {
                                string       subAccessorPath = (string)providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);
                                ResourcePath subResourcePath = ResourcePath.Deserialize(subAccessorPath);
                                if (subResourcePath.Equals(fsra.CanonicalLocalResourcePath))
                                {
                                    //Already exists
                                    exists = true;
                                    break;
                                }
                            }
                            if (exists)
                            {
                                continue;
                            }

                            string subFormat = GetSubtitleFormat(subFile);
                            if (!string.IsNullOrEmpty(subFormat))
                            {
                                MultipleMediaItemAspect providerResourceAspect = MediaItemAspect.CreateAspect(extractedAspectData, ProviderResourceAspect.Metadata);
                                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_INDEX, newResourceIndex);
                                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_TYPE, ProviderResourceAspect.TYPE_SECONDARY);
                                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, GetSubtitleMime(subFormat));
                                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SIZE, fsra.Size);
                                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, fsra.CanonicalLocalResourcePath.Serialize());

                                MultipleMediaItemAspect subtitleResourceAspect = MediaItemAspect.CreateAspect(extractedAspectData, SubtitleAspect.Metadata);
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_RESOURCE_INDEX, newResourceIndex);
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_VIDEO_RESOURCE_INDEX, videoResouceIndex);
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_STREAM_INDEX, -1); //External subtitle
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_FORMAT, subFormat);
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_INTERNAL, false);
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_DEFAULT, subFile.ToLowerInvariant().Contains(".default."));
                                subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_FORCED, subFile.ToLowerInvariant().Contains(".forced."));

                                bool   imageBased = IsImageBasedSubtitle(subFormat);
                                string language   = GetSubtitleLanguage(subFile, imageBased);
                                if (language != null)
                                {
                                    subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_LANGUAGE, language);
                                }
                                if (imageBased == false)
                                {
                                    string encoding = GetSubtitleEncoding(subFile, language);
                                    if (encoding != null)
                                    {
                                        subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_ENCODING, encoding);
                                    }
                                }
                                else
                                {
                                    subtitleResourceAspect.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_ENCODING, SubtitleAspect.BINARY_ENCODING);
                                }
                                newResourceIndex++;
                                subtitleCount++;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Info("SubtitleMetadataExtractor: Exception finding external subtitles for resource '{0}' (Text: '{1}')", e, lfsra.CanonicalLocalResourcePath, e.Message);
            }
            return(subtitleCount);
        }
Exemplo n.º 13
0
        protected bool IsPathValid(ResourcePath resourcePath)
        {
            string chosenPath = LocalFsResourceProviderBase.ToDosPath(resourcePath);

            return(DosPathHelper.GetFileName(chosenPath) != null);
        }