/// <summary> /// Creates a BASS stream that represents the song. /// </summary> /// <param name="flags">The flags to apply to the stream that is created.</param> /// <returns>The handle to the BASS stream that was created.</returns> public UInt32 CreateInstance(UInt32 flags) { var fileSystemService = FileSystemService.Create(); var instance = fileSystemService.OpenRead(file); var instanceID = this.nextInstanceID++; instances.Add(instanceID, instance); var stream = 0u; try { var procs = new BASS_FILEPROCS(fnClose, fnLength, fnRead, fnSeek); unsafe { stream = BASSNative.StreamCreateFileUser(1, BASSNative.BASS_STREAM_DECODE, &procs, new IntPtr((int)instanceID)); if (!BASSUtil.IsValidHandle(stream)) { throw new BASSException(); } } } catch { instance.Dispose(); instances.Remove(instanceID); throw; } return(stream); }
/// <summary> /// Initializes a new instance of the BASSSoundEffect class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="filename">The filename of the sample to load.</param> public BASSSoundEffect(UltravioletContext uv, String filename) : base(uv) { var fileSystemService = FileSystemService.Create(); var fileData = default(Byte[]); using (var stream = fileSystemService.OpenRead(filename)) { fileData = new Byte[stream.Length]; stream.Read(fileData, 0, fileData.Length); } sample = BASSNative.SampleLoad(fileData, 0, (UInt32)fileData.Length, UInt16.MaxValue, 0); if (!BASSUtil.IsValidHandle(sample)) { throw new BASSException(); } if (!BASSNative.SampleGetInfo(sample, out this.sampleInfo)) { throw new BASSException(); } this.data = Marshal.AllocHGlobal((int)sampleInfo.length); if (!BASSNative.SampleGetData(sample, this.data)) { throw new BASSException(); } }
public static FMOD_RESULT UserOpen(String name, UInt32 *filesize, void **handle, void *userdata) { var fss = FileSystemService.Create(); if (fss.FileExists(name)) { var iostream = default(Stream); try { iostream = fss.OpenRead(name); } catch (FileNotFoundException) { return(FMOD_ERR_FILE_NOTFOUND); } var fmodstream = new FMODFileStream(iostream); var handlenum = Interlocked.Increment(ref nexthandle); var handlemem = Marshal.AllocHGlobal(sizeof(Int64));; *(Int64 *)handlemem = handlenum; *filesize = (UInt32)iostream.Length; *handle = (void *)handlemem; lockSlim.EnterWriteLock(); try { streams[handlenum] = fmodstream; } finally { lockSlim.ExitWriteLock(); } return(FMOD_OK); } else { return(FMOD_ERR_FILE_NOTFOUND); } }
/// <inheritdoc/> public override UIPanelDefinition Process(ContentManager manager, IContentProcessorMetadata metadata, XDocument input) { var fss = FileSystemService.Create(); var defaultOpenTransitionDuration = input.Root.AttributeValueDouble("DefaultOpenTransitionDuration") ?? 0.0; var defaultCloseTransitionDuration = input.Root.AttributeValueDouble("DefaultCloseTransitionDuration") ?? 0.0; var styleSheetRoot = Path.GetDirectoryName(metadata.AssetPath); var styleSheetElements = input.Root.Elements("StyleSheet"); var styleSheetAssets = styleSheetElements.Select(x => Path.Combine(styleSheetRoot, x.Value)); var styleSheetPaths = styleSheetAssets.Select(x => manager.ResolveAssetFilePath(x, metadata.AssetDensity, metadata.IsLoadedFromSolution)); var styleSheetSources = new List <String>(); foreach (var styleSheetPath in styleSheetPaths) { using (var stream = fss.OpenRead(styleSheetPath)) { using (var reader = new StreamReader(stream)) { var source = reader.ReadToEnd(); styleSheetSources.Add(source); } } } var directives = new List <UIPanelDirective>(); var xmlDirectives = input.Root.Elements("Directive"); foreach (var xmlDirective in xmlDirectives) { var directiveType = (String)xmlDirective.Attribute("Type"); if (String.IsNullOrEmpty(directiveType)) { throw new InvalidDataException(UltravioletStrings.ViewDirectiveMustHaveType.Format(metadata.AssetFilePath)); } directives.Add(new UIPanelDirective(directiveType, xmlDirective.Value)); } foreach (var styleSheetAsset in styleSheetAssets) { metadata.AddAssetDependency(styleSheetAsset); } return(new UIPanelDefinition() { AssetFilePath = metadata.AssetFilePath, DefaultOpenTransitionDuration = TimeSpan.FromMilliseconds(defaultOpenTransitionDuration), DefaultCloseTransitionDuration = TimeSpan.FromMilliseconds(defaultCloseTransitionDuration), RootElement = input.Root, ViewElement = input.Root.Element("View"), StyleSheetAssets = styleSheetAssets, StyleSheetSources = styleSheetSources, Directives = directives, }); }
/// <summary> /// Loads a content manifest from the JSON file at the specified path. /// </summary> /// <param name="path">The path to the JSON file to load.</param> /// <returns>The <see cref="ContentManifest"/> that was loaded from the specified JSON file.</returns> public static ContentManifest LoadJson(String path) { Contract.RequireNotEmpty(path, nameof(path)); var fss = FileSystemService.Create(); using (var stream = fss.OpenRead(path)) { return(LoadJson(stream)); } }
/// <summary> /// Loads the application's localization databases. /// </summary> protected void LoadLocalizationDatabases() { var fss = FileSystemService.Create(); var databases = content.GetAssetFilePathsInDirectory("Localization", "*.xml"); foreach (var database in databases) { using (var stream = fss.OpenRead(database)) { Localization.Strings.LoadFromStream(stream); } } }
/// <summary> /// Initializes a new instance of the <see cref="BASSSoundEffect"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="filename">The filename of the sample to load.</param> public BASSSoundEffect(UltravioletContext uv, String filename) : base(uv) { Contract.Require(filename, nameof(filename)); var fileSystemService = FileSystemService.Create(); var fileData = default(Byte[]); using (var stream = fileSystemService.OpenRead(filename)) { fileData = new Byte[stream.Length]; stream.Read(fileData, 0, fileData.Length); } InitializeSampleData(fileData, out this.sample, out this.sampleInfo, out this.sampleData); }
/// <summary> /// Loads the application's localization plugins. /// </summary> protected void LoadLocalizationPlugins() { var fss = FileSystemService.Create(); var plugins = content.GetAssetFilePathsInDirectory(Path.Combine("Localization", "Plugins"), "*.dll"); foreach (var plugin in plugins) { try { var asm = Assembly.Load(plugin); Localization.LoadPlugins(asm); } catch (Exception e) when(e is BadImageFormatException || e is FileLoadException) { } } }
/// <inheritdoc/> protected override Stream OpenFileStream(String path) { var fss = FileSystemService.Create(); return(fss.OpenRead(path)); }