public void CanRenderCasparPostTemplate() { var fs = new DiskFileSystem(); var handlebars = Handlebars.Create(new HandlebarsConfiguration() { FileSystem = fs }); AddHelpers(handlebars); var renderView = handlebars.CompileView("ViewEngine/Casper-master/post.hbs"); var output = renderView(new { blog = new { url = "http://someblog.com", title = "This is the blog title" }, post = new { title = "My Post Title", image = "/someimage.png", post_class = "somepostclass" } }); var cq = CsQuery.CQ.CreateDocument(output); Assert.Equal("My Post Title", cq["h1.post-title"].Html()); }
// Constructors /// <summary> /// DataTrack (abstract) /// </summary> /// <param name="fileStream">The iso file stream</param> /// <param name="trackNumber">The track number</param> /// <param name="system">File system used for this data track</param> /// <param name="mode">The sector mode of the track</param> internal DataTrack(FileStream fileStream, int trackNumber, DiskFileSystem system, DataTrackMode mode) : base(fileStream, trackNumber, TrackType.DATA) { _system = system; _mode = mode; _sectorSize = mode == DataTrackMode.RAW ? 2048 : 2352; _isXa = false; _pregapSize = 150; switch (_mode) { case DataTrackMode.MODE1: _defaultSectorMode = SectorMode.MODE1; break; case DataTrackMode.MODE2: _defaultSectorMode = SectorMode.MODE2; break; case DataTrackMode.MODE2_XA: _defaultSectorMode = SectorMode.XA_FORM1; _isXa = true; break; case DataTrackMode.RAW: default: _defaultSectorMode = SectorMode.RAW; break; } }
// Constructors /// <summary> /// DataTrackReader /// </summary> /// <param name="stream">The stream of iso</param> /// <param name="trackNumber">The track number</param> /// <param name="system">File system used for this data track</param> /// <param name="mode">The sector mode of the track</param> /// <param name="readDescriptors">Read descriptors immediately</param> /// <param name="buildIndex">Build the index cache immediately</param> internal DataTrackReader(CBinaryReader stream, int trackNumber, DiskFileSystem system, DataTrackMode mode, bool readDescriptors = true, bool buildIndex = true) : base((FileStream)stream.BaseStream, trackNumber, system, mode) { _stream = stream; _descriptorsRead = false; _indexBuilt = false; _entriesOrder = DataTrackEntriesOrder.DEFAULT; try { if (readDescriptors) { ReadVolumeDescriptors(); } if (buildIndex) { BuildIndex(); } SeekSector(0); } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading data track : unable to read the data track"); } }
// Constructors /// <summary> /// Disk (abstract) /// </summary> /// <param name="fileUrl">Path to the ISO file</param> /// <param name="system">File system used for data track</param> internal Disk(DiskFileSystem system) { _fileOpen = false; _system = system; _hasDataTrack = false; _tracks = new List <Track>(); }
private static ReplayFile LoadReplayFile([CallerMemberName] string testName = null) { using (var fileSystem = new DiskFileSystem(Path.Combine(Environment.CurrentDirectory, "Data", "Rep", "Assets"))) { var entry = fileSystem.GetFile(testName + ".rep"); return(ReplayFile.FromFileSystemEntry(entry)); } }
private RoadTopology LoadTopologyFromMapFile([CallerMemberName] string mapName = "") { var fileSystem = new DiskFileSystem(Path.Combine(Environment.CurrentDirectory, "Terrain", "Roads", "RoadAlignmentTests")); var mapFile = MapFile.FromFileSystemEntry(fileSystem.GetFile(mapName + ".map")); var topology = RoadTopologyLoader.FromMapObjects(mapFile.ObjectsList.Objects); topology.AlignOrientation(); return(topology); }
public static ViewEngineFileSystem Create(QuartzminOptions options) { ViewEngineFileSystem fs; if (string.IsNullOrEmpty(options.ViewsRootDirectory)) { fs = new EmbeddedFileSystem(); } else { fs = new DiskFileSystem(options.ViewsRootDirectory); } return(fs); }
// Constructors /// <summary> /// DiskWriter (multi tracks) /// </summary> /// <param name="fileUrl">Path to the ISO file to create</param> /// <param name="system">File system used for data track</param> /// <param name="overwriteIfExists">Overwite file if exists</param> private DiskWriter(string fileUrl, DiskFileSystem system, bool overwriteIfExists = true) : base(system) { try { _file = new FileInfo(fileUrl); _fileStream = new FileStream(_file.FullName, overwriteIfExists ? FileMode.Create : FileMode.CreateNew, FileAccess.Write, FileShare.Read); _stream = new CBinaryWriter(_fileStream); _fileOpen = true; } catch (Exception) { throw new FrameworkException("Error while while writing ISO : Unable to create the ISO File"); } }
// Constructors /// <summary> /// DataTrackWriter /// </summary> /// <param name="stream">The stream of iso</param> /// <param name="trackNumber">The track number</param> /// <param name="system">File system used for this data track</param> /// <param name="mode">The sector mode of the track</param> internal DataTrackWriter(CBinaryWriter stream, int trackNumber, DiskFileSystem system, DataTrackMode mode) : base((FileStream)stream.BaseStream, trackNumber, system, mode) { _stream = stream; _prepared = false; _finalized = false; _appendVersionToFileName = true; try { // Allocation for system area WriteEmptySectors(16); } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while while writing data track : unable to write the data track"); } }
/// <summary> /// DiskReader (single data track) /// </summary> /// <param name="fileUrl">Path to the ISO/BIN/IMG file to read</param> /// <param name="system">File system used for the data track</param> /// <param name="mode">The sector mode of the track</param> /// <param name="readDescriptors">Read descriptors immediately</param> /// <param name="buildIndex">Build the index cache immediately</param> private DiskReader(string fileUrl, DiskFileSystem system, DataTrackMode mode, bool readDescriptors = true, bool buildIndex = true) : base(system) { try { _file = new FileInfo(fileUrl); _fileStream = new FileStream(_file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); _stream = new CBinaryReader(_fileStream); _fileOpen = true; _stream.Position = 0; _tracks.Add(new DataTrackReader(_stream, 1, system, mode, readDescriptors, buildIndex)); } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading ISO : Unable to open the ISO File"); } }
public void CanRenderVariablesInCasperLayout() { var fs = new DiskFileSystem(); var handlebars = Handlebars.Create(new HandlebarsConfiguration() { FileSystem = fs }); AddHelpers(handlebars); var renderView = handlebars.CompileView("ViewEngine/Casper-master/index.hbs"); var output = renderView( new { posts = new[] { new { title = "My Post Title", image = "/someimage.png", post_class = "somepostclass" } } }, new { blog = new { url = "http://someblog.com", title = "This is the blog title" } } ); var cq = CsQuery.CQ.CreateDocument(output); Assert.Equal("This is the blog title", cq["section.copyright a"].Text()); }
static void Main(string[] args) { try { foreach (var path in Directory.EnumerateDirectories(".")) { CleanDirectory(path); ProcessProfiles(DiskFileSystem.Folder(path), Path.Combine(path, "profiles.json")); } foreach (var zip in Directory.EnumerateFiles(".", "*.zip")) { ProcessProfiles(ZipFileSystem.Open(zip), Path.ChangeExtension(zip, "json")); } ProcessProfiles(DiskFileSystem.Folder(PortableFrameworkProfileEnumerator.MachineProfilePath), "profiles.json"); Console.WriteLine("Done."); } catch (Exception ex) { Console.Error.WriteLine(ex); } Console.ReadKey(); }
/// <summary> /// Initialize a new single data track DiskReader /// </summary> /// <param name="fileUrl">Path to the ISO/BIN/IMG file to read</param> /// <param name="system">File system used for the track</param> /// <param name="mode">The sector mode of the track</param> /// <param name="readDescriptors">Read descriptors immediately</param> /// <param name="buildIndex">Build the index cache immediately</param> public static DiskReader InitFromIso(string fileUrl, DiskFileSystem system, DataTrackMode mode, bool readDescriptors = true, bool buildIndex = true) { return(new DiskReader(fileUrl, system, mode, readDescriptors, buildIndex)); }
// Methods /// <summary> /// Initialize a new multi tracks DiskReader /// </summary> /// <param name="fileUrl">Path to the CUE file to read</param> /// <param name="system">File system used for data track</param> public static DiskReader InitFromCue(string fileUrl, DiskFileSystem system) { return(new DiskReader(fileUrl, system)); }
// Methods /// <summary> /// Initialize a new multi tracks DiskWriter /// </summary> /// <param name="fileUrl">Path to the ISO file to create</param> /// <param name="system">File system used for the track</param> /// <param name="overwriteIfExists">Overwite file if exists</param> public static DiskWriter Init(string fileUrl, DiskFileSystem system, bool overwriteIfExists = true) { return(new DiskWriter(fileUrl, system, overwriteIfExists)); }
// Constructors /// <summary> /// DiskReader (multi tracks) /// </summary> /// <param name="fileUrl">Path to the CUE file to read</param> /// <param name="system">File system used for data track</param> private DiskReader(string fileUrl, DiskFileSystem system) : base(system) { try { var cueFile = new FileInfo(fileUrl); using (var cueFileStream = new FileStream(cueFile.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var cueStream = new StreamReader(cueFileStream)) { var tracksDic = new Dictionary <int, Track>(); var indexOffsets = new List <long>(); Match match = null; Track track = null; int trackNumber = 0; int m, s, b; string line; string keyWord; while ((line = cueStream.ReadLine()) != null) { keyWord = _regCueKeyWord.Match(line).Groups[1].Value.ToUpper(); switch (keyWord) { case "FILE": if (_fileOpen) { throw new FrameworkException("Error while parsing cue sheet : framework does not support multi files per cue but only one file with multi tracks"); } fileUrl = _regCueFile.Match(line).Groups[1].Value; if (!(fileUrl.StartsWith("/") || fileUrl.StartsWith("\\") || fileUrl.Contains(":/") || fileUrl.Contains(":\\"))) { fileUrl = cueFile.DirectoryName + "/" + fileUrl; } _file = new FileInfo(fileUrl); if (!_file.Exists) { throw new FrameworkException("Error while parsing cue sheet : targeted file \"{0}\" not found", fileUrl); } string extension = _file.Extension.ToUpper(); if (!(extension == ".BIN" || extension == ".IMG" || extension == ".ISO")) { throw new FrameworkException("Error while parsing cue sheet : targeted file \"{0}\" is not a BIN/IMG/ISO file", fileUrl); } _fileStream = new FileStream(_file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); _stream = new CBinaryReader(_fileStream); _fileOpen = true; break; case "TRACK": if (!_fileOpen) { throw new FrameworkException("Error while parsing cue sheet : TRACK defined before FILE"); } match = _regCueTrack.Match(line); if (!int.TryParse(match.Groups[1].Value, out trackNumber)) { throw new FrameworkException("Error while parsing cue sheet : track number invalid"); } string mode = match.Groups[2].Value.ToUpper(); if ((!mode.StartsWith("MODE") && !_hasDataTrack)) { throw new FrameworkException("Error while parsing cue sheet : only Mixed Mode multi tracks disks are supported, the first track must be a DATA track"); } else if ((mode.StartsWith("MODE") && _hasDataTrack)) { throw new FrameworkException("Error while parsing cue sheet : only Mixed Mode multi tracks disks are supported, it must contains only one DATA track"); } switch (mode) { case "RAW": case "RAW/2048": case "MODE1/2048": track = new DataTrackReader(_stream, trackNumber, _system, DataTrackMode.RAW, false, false); _hasDataTrack = true; break; case "MODE1/2352": track = new DataTrackReader(_stream, trackNumber, _system, DataTrackMode.MODE1, false, false); _hasDataTrack = true; break; case "MODE2/2336": track = new DataTrackReader(_stream, trackNumber, _system, DataTrackMode.MODE2, false, false); _hasDataTrack = true; break; case "MODE2/2352": track = new DataTrackReader(_stream, trackNumber, _system, DataTrackMode.MODE2_XA, false, false); _hasDataTrack = true; break; case "AUDIO": track = new AudioTrackReader(_stream, trackNumber); break; default: throw new FrameworkException("Error while parsing cue sheet : unknown/not supported track type \"{0}\"", mode); } tracksDic.Add(trackNumber, track); _tracks.Add(track); break; case "INDEX": track = tracksDic[trackNumber]; match = _regCueIndex.Match(line); int indexNumber; if (!int.TryParse(match.Groups[1].Value, out indexNumber) || indexNumber > 2) { throw new FrameworkException("Error while parsing cue sheet : index number invalid"); } if (!int.TryParse(match.Groups[2].Value, out m) || !int.TryParse(match.Groups[3].Value, out s) || s > 59 || !int.TryParse(match.Groups[4].Value, out b) || s > 74) { throw new FrameworkException("Error while parsing cue sheet : index time code invalid"); } uint offset = (uint)(((((m * 60) + s) * 75) + b) * track.SectorSize); indexOffsets.Add(offset); if (indexNumber == 0) { track.HasPause = true; } break; case "PREGAP": case "POSTGAP": track = tracksDic[trackNumber]; match = _regCueGap.Match(line); if (!int.TryParse(match.Groups[1].Value, out m) || !int.TryParse(match.Groups[2].Value, out s) || s > 59 || !int.TryParse(match.Groups[3].Value, out b) || s > 74) { throw new FrameworkException("Error while parsing cue sheet : gap size invalid"); } uint gapSize = (uint)((((m * 60) + s) * 75) + b); if (keyWord == "PREGAP") { track.PregapSize = gapSize; } else { track.PostgapSize = gapSize; } break; } } indexOffsets.Add(_fileStream.Length); for (int i = 0, u = 0, max = _tracks.Count; i < max; i++) { track = _tracks[i]; if (track.HasPause) { track.PauseOffset = indexOffsets[u]; track.PauseSize = (uint)((indexOffsets[u + 1] - indexOffsets[u]) / track.SectorSize); u++; } track.Offset = indexOffsets[u]; track.Size = (uint)((indexOffsets[u + 1] - indexOffsets[u]) / track.SectorSize); u++; } } _stream.Position = 0; } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading ISO : Unable to open the ISO File"); } }
public Engine(HostType hostType, ICommandLine commandLine, string gameDirectory, EngineConfiguration engineConfiguration, ILogger logger, ForwardingTextWriter forwardingTextWriter) { _hostType = hostType; CommandLine = commandLine ?? throw new ArgumentNullException(nameof(commandLine)); GameDirectory = gameDirectory ?? throw new ArgumentNullException(nameof(gameDirectory)); EngineConfiguration = engineConfiguration ?? throw new ArgumentNullException(nameof(engineConfiguration)); Log.Logger = Logger = logger ?? throw new ArgumentNullException(nameof(logger)); LogTextWriter = forwardingTextWriter ?? throw new ArgumentNullException(nameof(forwardingTextWriter)); FileSystem = new DiskFileSystem(); SetupFileSystem(GameDirectory); CommandSystem = new SharpLife.CommandSystem.CommandSystem(Logger, CultureInfo.InvariantCulture); EngineContext = CommandSystem.CreateContext("EngineContext"); var startupState = new EngineStartupState(Logger, GameDirectory, new IModelFormatProvider[] { new SpriteModelFormatProvider(), new StudioModelFormatProvider(), //BSP loader comes last due to not having a way to positively recognize the format new BSPModelFormatProvider(Framework.BSPModelNamePrefix) }); //Add the engine assembly so builtin data gets added startupState.EntitySystemMetaData.AddAssembly(typeof(Engine).Assembly); //create the game window if this is a client if (_hostType == HostType.Client) { Client = new EngineClient(this, startupState); } Server = new EngineServer(this, Logger, startupState); PluginManager = startupState.PluginManager.Build(); //Automatically add in all plugin assemblies to the entity system foreach (var pluginAssembly in PluginManager.Assemblies) { startupState.EntitySystemMetaData.AddAssembly(pluginAssembly); } var renderer = (IRenderer)Client?.UserInterface.Renderer ?? new ServerRenderer(); World = new WorldState( Logger, EventSystem, FileSystem, startupState.EntitySystemMetaData.Build(), renderer, startupState.ModelFormats); _engineTimeStopwatch.Start(); EngineContext.AddStuffCmds(Logger, CommandLine); EngineContext.AddExec(Logger, FileSystem, ExecPathIDs); EngineContext.AddEcho(Logger); EngineContext.AddAlias(Logger); EngineContext.AddFind(Logger); EngineContext.AddHelp(Logger); _fpsMax = EngineContext.RegisterVariable( new VirtualVariableInfo <uint>("fps_max", DefaultFPS) .WithHelpInfo("Sets the maximum frames per second") .WithChangeHandler((ref VariableChangeEvent <uint> @event) => { @event.Value = Math.Min(@event.Value, MaximumFPS); var desiredFPS = @event.Value; if (desiredFPS == 0) { desiredFPS = MaximumFPS; } _desiredFrameLengthSeconds = 1.0 / desiredFPS; })); EngineContext.RegisterVariable("engine_builddate", () => BuildDate, "The engine's build date"); EngineContext.RegisterCommand(new CommandInfo("map", StartNewMap).WithHelpInfo("Loads the specified map")); //Get the build date from the generated resource file var assembly = typeof(Engine).Assembly; using (var reader = new StreamReader(assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Resources.BuildDate.txt"))) { string buildTimestamp = reader.ReadToEnd(); BuildDate = DateTimeOffset.Parse(buildTimestamp); Logger.Information($"Exe: {BuildDate.ToString("HH:mm:ss MMM dd yyyy")}"); } //TODO: initialize subsystems }