Exemple #1
0
        private void LoadFromFileSystem(IReadOnlyFileSystem fileSystem, string directory)
        {
            var modpackFilename = Path.Combine(directory, "modpack.json");
            var modFilename     = Path.Combine(directory, "mod.json");

            if (fileSystem.FileExists(modpackFilename))
            {
                metadata = JsonConvert.DeserializeObject <ModpackMetadata>(fileSystem.ReadAllText(modpackFilename));
            }
            else if (fileSystem.FileExists(modFilename))
            {
                var modMetadata = JsonConvert.DeserializeObject <ModMetadata>(fileSystem.ReadAllText(modFilename));
                modMetadata.Enabled = true;
                metadata            = new ModpackMetadata
                {
                    Name        = modMetadata.Name,
                    Description = modMetadata.Description,
                    Mods        = new List <ModMetadata>
                    {
                        modMetadata
                    }
                };
            }
            else
            {
                throw new FileNotFoundException("Could not find a modpack.json or a mod.json file in the given directory");
            }
            mods = metadata.Mods.Select(m => new Mod(m, directory, fileSystem)).ToList();
        }
 /// <summary>
 /// Gets a <see cref="ReadOnlyFileEntry"/> for the specified path. If the file does not exist, throws a <see cref="FileNotFoundException"/>
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="filePath">The file path.</param>
 /// <returns>A new <see cref="ReadOnlyFileEntry"/> from the specified path.</returns>
 public static ReadOnlyFileEntry GetFileEntry(this IReadOnlyFileSystem fileSystem, UPath filePath)
 {
     if (!fileSystem.FileExists(filePath))
     {
         throw FileSystemExceptionHelper.NewFileNotFoundException(filePath);
     }
     return(new ReadOnlyFileEntry(fileSystem, filePath));
 }
        /// <summary>
        /// Tries to get a <see cref="ReadOnlyFileSystemEntry"/> for the specified path. If the file or directory does not exist, returns null.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="path">The file or directory path.</param>
        /// <returns>A new <see cref="ReadOnlyFileSystemEntry"/> from the specified path.</returns>
        public static ReadOnlyFileSystemEntry TryGetFileSystemEntry(this IReadOnlyFileSystem fileSystem, UPath path)
        {
            var fileExists = fileSystem.FileExists(path);

            if (fileExists)
            {
                return(new ReadOnlyFileEntry(fileSystem, path));
            }
            var directoryExists = fileSystem.DirectoryExists(path);

            return(directoryExists ? new ReadOnlyDirectoryEntry(fileSystem, path) : null);
        }
        /// <summary>
        /// Gets a <see cref="ReadOnlyFileSystemEntry"/> for the specified path. If the file or directory does not exist, throws a <see cref="FileNotFoundException"/>
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="path">The file or directory path.</param>
        /// <returns>A new <see cref="ReadOnlyFileSystemEntry"/> from the specified path.</returns>
        public static ReadOnlyFileSystemEntry GetFileSystemEntry(this IReadOnlyFileSystem fileSystem, UPath path)
        {
            var fileExists = fileSystem.FileExists(path);

            if (fileExists)
            {
                return(new ReadOnlyFileEntry(fileSystem, path));
            }
            var directoryExists = fileSystem.DirectoryExists(path);

            if (directoryExists)
            {
                return(new ReadOnlyDirectoryEntry(fileSystem, path));
            }

            throw FileSystemExceptionHelper.NewFileNotFoundException(path);
        }
 public bool FileExists(FileName path)
 {
     return(fileSystem.FileExists(basePath.Combine(path)));
 }