private void updateSolutionFiles() { Trace.WriteLine($"Updating solution files"); var slnPath = Path.Combine(scriptsSourcePath, "storyboard.sln"); File.WriteAllBytes(slnPath, resourceContainer.GetBytes("project/storyboard.sln", ResourceSource.Embedded | ResourceSource.Relative)); var csProjPath = Path.Combine(scriptsSourcePath, "scripts.csproj"); var document = new XmlDocument() { PreserveWhitespace = false, }; try { using (var stream = resourceContainer.GetStream("project/scripts.csproj", ResourceSource.Embedded | ResourceSource.Relative)) document.Load(stream); var xmlns = document.DocumentElement.GetAttribute("xmlns"); var compileGroup = document.CreateElement("ItemGroup", xmlns); document.DocumentElement.AppendChild(compileGroup); foreach (var path in Directory.EnumerateFiles(scriptsSourcePath, "*.cs", SearchOption.AllDirectories)) { var relativePath = PathHelper.GetRelativePath(scriptsSourcePath, path); var compileNode = document.CreateElement("Compile", xmlns); compileNode.SetAttribute("Include", relativePath); compileGroup.AppendChild(compileNode); } var referencedAssembliesGroup = document.CreateElement("ItemGroup", xmlns); document.DocumentElement.AppendChild(referencedAssembliesGroup); var importedAssemblies = referencedAssemblies.Where(e => !Project.DefaultAssemblies.Contains(e)); foreach (var path in importedAssemblies) { var relativePath = PathHelper.GetRelativePath(scriptsSourcePath, path); var compileNode = document.CreateElement("Reference", xmlns); compileNode.SetAttribute("Include", AssemblyName.GetAssemblyName(path).Name); var hintPath = document.CreateElement("HintPath", xmlns); hintPath.AppendChild(document.CreateTextNode(relativePath)); compileNode.AppendChild(hintPath); referencedAssembliesGroup.AppendChild(compileNode); } document.Save(csProjPath); } catch (Exception e) { Trace.WriteLine($"Failed to update scripts.csproj: {e}"); } }
public static TextureOptions Load(string filename, ResourceContainer resourceContainer = null) { byte[] data; if (File.Exists(filename)) { data = File.ReadAllBytes(filename); } else { data = resourceContainer?.GetBytes(filename); } return(data != null?load(data.ToJObject()) : null); }
private JObject loadJson(string filename, ResourceContainer resourceContainer) { byte[] data; if (File.Exists(filename)) { data = File.ReadAllBytes(filename); } else { data = resourceContainer?.GetBytes(filename); } if (data == null) { throw new FileNotFoundException(filename); } return(resolveIncludes(data.ToJObject(), resourceContainer)); }
internal AudioSample(AudioManager audioManager, string path, ResourceContainer resourceContainer) { Manager = audioManager; this.path = path; sample = Bass.SampleLoad(path, 0, 0, MaxSimultaneousPlayBacks, BassFlags.SampleOverrideLongestPlaying); if (sample != 0) { return; } var bytes = resourceContainer?.GetBytes(path); if (bytes != null) { sample = Bass.SampleLoad(bytes, 0, 0, MaxSimultaneousPlayBacks, BassFlags.SampleOverrideLongestPlaying); if (sample != 0) { return; } } Trace.WriteLine($"Failed to load audio sample ({path}): {Bass.LastError}"); }
public byte[] GetBytes(string filename, ResourceSource sources = ResourceSource.Embedded) => resourceContainer.GetBytes(applyPath(filename), sources) ?? resourceContainer.GetBytes(filename, sources);
private Font getFont(string name, float emSize, FontStyle style) { var identifier = $"{name}|{emSize}|{(int)style}"; if (fonts.TryGetValue(identifier, out Font font)) { recentlyUsedFonts.Remove(identifier); recentlyUsedFonts.AddFirst(identifier); return(font); } else { recentlyUsedFonts.AddFirst(identifier); } if (recentlyUsedFonts.Count > 64) { while (recentlyUsedFonts.Count > 32) { var lastFontIdentifier = recentlyUsedFonts.Last.Value; recentlyUsedFonts.RemoveLast(); fonts[lastFontIdentifier].Dispose(); fonts.Remove(lastFontIdentifier); } } if (!fontFamilies.TryGetValue(name, out FontFamily fontFamily)) { var bytes = resourceContainer.GetBytes(name); if (bytes != null) { GCHandle pinnedArray = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { if (!fontCollections.TryGetValue(name, out PrivateFontCollection fontCollection)) { fontCollections.Add(name, fontCollection = new PrivateFontCollection()); } IntPtr ptr = pinnedArray.AddrOfPinnedObject(); fontCollection.AddMemoryFont(ptr, bytes.Length); if (fontCollection.Families.Length == 1) { fontFamily = fontCollection.Families[0]; Trace.WriteLine($"Loaded font {fontFamily.Name} for {name}"); } else { Trace.WriteLine($"Failed to load font {name}: Expected one family, got {fontCollection.Families.Length}"); } } catch (Exception e) { Trace.WriteLine($"Failed to load font {name}: {e.Message}"); } finally { pinnedArray.Free(); } } fontFamilies.Add(name, fontFamily); } if (fontFamily != null) { font = new Font(fontFamily, emSize, style); } else { font = new Font(name, emSize, style); Trace.WriteLine($"Using font system font for {name}"); } fonts.Add(identifier, font); return(font); }