public override bool TryOpen([NotNull] string path, out IProject project, out string failureReason) { try { var rootFs = new ReadOnlyFileSystem(path); var metadata = Validate(rootFs); var p = new MagicTranslatorProject(); p.Init(metadata, rootFs); project = p; failureReason = ""; return(true); } catch (FileNotFoundException) { failureReason = "This is not a valid Magic Translator project: metadata.json file is missing."; } catch (JsonSerializationException) { failureReason = "This is not a valid Magic Translator project: the metadata.json is not valid."; } catch (InvalidDataException ex) { failureReason = $"This is not a valid Magic Translator project: ${ex.Message}"; } project = null; return(false); }
public void CreateBaseFileSystem(string path) { IFileSystem fs; IFileSystem subfs; IFileSystem rofs; if (Directory.Exists(path)) { fs = new PhysicalFileSystem(); subfs = new SubFileSystem(fs, path); rofs = new ReadOnlyFileSystem(subfs); } else { throw new DirectoryNotFoundException($"The destination path `{path}` does not exist, please correct your settings"); } if (_dynamicFS == null) { _dynamicFS = new Dictionary <string, IFileSystem>() { { "root", subfs }, { "root.ro", rofs } }; } else { _dynamicFS.Remove("root"); _dynamicFS.Remove("root.ro"); _dynamicFS.Add("root", subfs); _dynamicFS.Add("root.ro", rofs); } }
public static ResultCode LoadSaveDataFileSystem(ServiceCtx context, bool readOnly, out IFileSystem loadedFileSystem) { loadedFileSystem = null; SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); ulong titleId = context.RequestData.ReadUInt64(); UInt128 userId = context.RequestData.ReadStruct <UInt128>(); long saveId = context.RequestData.ReadInt64(); SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, saveSpaceId, userId); string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo); try { LocalFileSystem fileSystem = new LocalFileSystem(savePath); LibHac.Fs.IFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem); if (readOnly) { saveFileSystem = new ReadOnlyFileSystem(saveFileSystem); } loadedFileSystem = new IFileSystem(saveFileSystem); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } return(ResultCode.Success); }
public SiteObject(ILoggerFactory loggerFactory = null) { var sharedFolder = Path.Combine(Path.GetDirectoryName(typeof(SiteObject).GetTypeInfo().Assembly.Location), SharedFolderName); _contentFileSystems = new List <IFileSystem>(); var sharedPhysicalFileSystem = new PhysicalFileSystem(); // Make sure that SharedFileSystem is a read-only filesystem SharedFileSystem = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder))); SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder); _fileSystem = new AggregateFileSystem(SharedFileSystem); MetaFileSystem = new SubFileSystem(_fileSystem, LunetFolder); ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName); StaticFiles = new PageCollection(); Pages = new PageCollection(); DynamicPages = new PageCollection(); // Create the logger LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder => { builder.AddProvider(new LoggerProviderIntercept(this)) .AddFilter(LogFilter) .AddConsole(); }); Log = LoggerFactory.CreateLogger("lunet"); ContentTypes = new ContentTypeManager(); DefaultPageExtension = DefaultPageExtensionValue; Html = new HtmlObject(this); SetValue(SiteVariables.Html, Html, true); CommandLine = new LunetCommandLine(this); Statistics = new SiteStatistics(); Scripts = new ScriptingPlugin(this); Content = new ContentPlugin(this); Plugins = new OrderedList <ISitePlugin>(); _pluginBuilders = new ContainerBuilder(); _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>(); _pluginBuilders.RegisterInstance(this); }
public Result OpenFileSystem(out IFileSystem fileSystem, U8Span path, FileSystemProxyType type, bool canMountSystemDataPrivate, ulong programId) { fileSystem = default; // Get a reference to the path that will be advanced as each part of the path is parsed U8Span currentPath = path.Slice(0, StringUtils.GetLength(path)); // Open the root filesystem based on the path's mount name Result rc = OpenFileSystemFromMountName(ref currentPath, out IFileSystem baseFileSystem, out bool shouldContinue, out MountNameInfo mountNameInfo); if (rc.IsFailure()) { return(rc); } // Don't continue if the rest of the path is empty if (!shouldContinue) { return(ResultFs.InvalidArgument.Log()); } if (type == FileSystemProxyType.Logo && mountNameInfo.IsGameCard) { rc = OpenGameCardFileSystem(out fileSystem, new GameCardHandle(mountNameInfo.GcHandle), GameCardPartition.Logo); if (rc.IsSuccess()) { return(Result.Success); } if (!ResultFs.PartitionNotFound.Includes(rc)) { return(rc); } } rc = IsContentPathDir(ref currentPath, out bool isDirectory); if (rc.IsFailure()) { return(rc); } if (isDirectory) { if (!mountNameInfo.IsHostFs) { return(ResultFs.PermissionDenied.Log()); } if (type == FileSystemProxyType.Manual) { rc = TryOpenCaseSensitiveContentDirectory(out IFileSystem manualFileSystem, baseFileSystem, currentPath); if (rc.IsFailure()) { return(rc); } fileSystem = new ReadOnlyFileSystem(manualFileSystem); return(Result.Success); } return(TryOpenContentDirectory(currentPath, out fileSystem, baseFileSystem, type, true)); } rc = TryOpenNsp(ref currentPath, out IFileSystem nspFileSystem, baseFileSystem); if (rc.IsSuccess()) { // Must be the end of the path to open Application Package FS type if (currentPath.Length == 0 || currentPath[0] == 0) { if (type == FileSystemProxyType.Package) { fileSystem = nspFileSystem; return(Result.Success); } return(ResultFs.InvalidArgument.Log()); } baseFileSystem = nspFileSystem; } if (!mountNameInfo.CanMountNca) { return(ResultFs.InvalidNcaMountPoint.Log()); } ulong openProgramId = mountNameInfo.IsHostFs ? ulong.MaxValue : programId; rc = TryOpenNca(ref currentPath, out Nca nca, baseFileSystem, openProgramId); if (rc.IsFailure()) { return(rc); } rc = OpenNcaStorage(out IStorage ncaSectionStorage, nca, out NcaFormatType fsType, type, mountNameInfo.IsGameCard, canMountSystemDataPrivate); if (rc.IsFailure()) { return(rc); } switch (fsType) { case NcaFormatType.Romfs: return(FsCreators.RomFileSystemCreator.Create(out fileSystem, ncaSectionStorage)); case NcaFormatType.Pfs0: return(FsCreators.PartitionFileSystemCreator.Create(out fileSystem, ncaSectionStorage)); default: return(ResultFs.InvalidNcaFsType.Log()); } }
public void TestCommonReadOnly() { var rofs = new ReadOnlyFileSystem(GetCommonMemoryFileSystem()); AssertCommonReadOnly(rofs); }
public SiteObject(ILoggerFactory loggerFactory = null) { ReadmeAsIndex = true; ErrorRedirect = "/404.html"; var sharedFolder = Path.Combine(AppContext.BaseDirectory, SharedFolderName); _contentFileSystems = new List <IFileSystem>(); var sharedPhysicalFileSystem = new PhysicalFileSystem(); // Make sure that SharedFileSystem is a read-only filesystem SharedFileSystem = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder))); SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder); _fileSystem = new AggregateFileSystem(SharedFileSystem); // MetaFileSystem provides an aggregate view of the shared meta file system + the user meta file system _metaFileSystem = new AggregateFileSystem(SharedMetaFileSystem); MetaFileSystem = _metaFileSystem; ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName); StaticFiles = new PageCollection(); Pages = new PageCollection(); DynamicPages = new PageCollection(); // Create the logger LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder => { // Similar to builder.AddSimpleConsole // But we are using our own console that stays on the same line if the message doesn't have new lines builder.AddConfiguration(); builder.AddProvider(new LoggerProviderIntercept(this)) .AddFilter(LogFilter) .AddConsoleFormatter <SimpleConsoleFormatter, SimpleConsoleFormatterOptions>(configure => { configure.SingleLine = true; }); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, ConsoleLoggerProvider>()); LoggerProviderOptions.RegisterProviderOptions <ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services); }); Log = LoggerFactory.CreateLogger("lunet"); ContentTypes = new ContentTypeManager(); DefaultPageExtension = DefaultPageExtensionValue; Html = new HtmlPage(this); CommandLine = new LunetCommandLine(this); Statistics = new SiteStatistics(); Scripts = new ScriptingPlugin(this); Content = new ContentPlugin(this); Plugins = new OrderedList <ISitePlugin>(); Builtins = new BuiltinsObject(this); ForceExcludes = new GlobCollection() { $"**/{LunetFolderName}/{BuildFolderName}/**", $"/{DefaultConfigFileName}", }; Excludes = new GlobCollection() { "**/~*/**", "**/.*/**", "**/_*/**", }; Includes = new GlobCollection() { $"**/{LunetFolderName}/**", }; SetValue(SiteVariables.ForceExcludes, ForceExcludes, true); SetValue(SiteVariables.Excludes, Excludes, true); SetValue(SiteVariables.Includes, Includes, true); SetValue(SiteVariables.Pages, Pages, true); _pluginBuilders = new ContainerBuilder(); _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>(); _pluginBuilders.RegisterInstance(this); }