public void SetContents(string value, IPackage package) { TextResource.TextResource resource = ResourceHandlers.CreateResource(mEntry, mPackage) as TextResource.TextResource; resource.TextFileReader = new StringReader(value); mPackage.ReplaceResource(mEntry, resource); }
public string GetContents(IPackage package) { TextResource.TextResource resource = ResourceHandlers.CreateResource(mEntry, mPackage) as TextResource.TextResource; StreamReader reader = resource.TextFileReader as StreamReader; reader.BaseStream.Position = 0; return(reader.ReadToEnd()); }
protected static Dictionary <ulong, STBLImporter.Lookup> ReadTable(string prefix, string instance, IPackage package, bool addOtherKeys) { instance = prefix + instance.Substring(4); Dictionary <ulong, STBLImporter.Lookup> lookup = new Dictionary <ulong, STBLImporter.Lookup>(); IResourceIndexEntry entry = package.Find(key => ((key.ResourceType == (uint)ResourceType.STBL) && (key["Instance"] == instance))); if (entry != null) { StblResource.StblResource resource = ResourceHandlers.CreateResource(entry, package) as StblResource.StblResource; foreach (KeyValuePair <ulong, string> element in resource) { bool space = false; string keyValue = element.Value; if (prefix == "0x17") { if (keyValue.StartsWith("PackerSpace|")) { keyValue = keyValue.Replace("PackerSpace|", ""); space = true; } } if (!lookup.ContainsKey(element.Key)) { STBLImporter.Lookup recent = new STBLImporter.Lookup(keyValue, keyValue, space); lookup.Add(element.Key, recent); } if ((addOtherKeys) && (!HasSuffix(keyValue))) { foreach (string suffix in sSuffixes) { string value = keyValue + suffix; ulong key = FNV64.GetHash(value); if (lookup.ContainsKey(key)) { continue; } STBLImporter.Lookup recent = new STBLImporter.Lookup(value, value, space); lookup.Add(key, recent); } } } } return(lookup); }
public bool AddNew(ulong instance, IPackage package, bool autoSet) { mPackage = package; string filename = GetFilename(autoSet, true); if (string.IsNullOrEmpty(filename)) { return(false); } string name = CreateInstance(filename, ref instance); if (instance == 0) { return(false); } Set(mPackage.AddResource(new AResource.TGIBlock(0, null, (uint)Type, 0, instance), null, false), mPackage); if (mEntry == null) { return(false); } if (File.Exists(filename)) { Filename = filename; } else { mPackage.ReplaceResource(mEntry, ResourceHandlers.CreateResource(mEntry, mPackage)); } Name = name; return(true); }
public static Func <IResourceHandler> CreateFileHandler(string path) { string mimeType = Path.GetExtension(path) switch { ".weba" => "audio/webm", ".webm" => "audio/webm", ".wav" => "audio/wav", ".ogg" => "audio/ogg", ".mp3" => "audio/mp3", ".flac" => "audio/flac", ".opus" => "audio/ogg; codecs=opus", _ => null }; try{ return(ResourceHandlers.ForBytes(File.ReadAllBytes(path), mimeType)); }catch { FormBrowser browser = FormManager.TryFind <FormBrowser>(); browser?.InvokeAsyncSafe(() => { using FormMessage form = new FormMessage("Sound Notification Error", "Could not find custom notification sound file:\n" + path, MessageBoxIcon.Error); form.AddButton(FormMessage.Ignore, ControlType.Cancel | ControlType.Focused); Button btnViewOptions = form.AddButton("View Options"); btnViewOptions.Width += 16; btnViewOptions.Location = new Point(btnViewOptions.Location.X - 16, btnViewOptions.Location.Y); if (form.ShowDialog() == DialogResult.OK && form.ClickedButton == btnViewOptions) { browser.OpenSettings(typeof(TabSettingsSounds)); } }); return(null); } } }
protected override void Set(IResourceIndexEntry entry, IPackage package) { base.Set(entry, package); mResource = ResourceHandlers.CreateResource(entry, package) as ScriptResource.ScriptResource; }
protected ResourceRequestHandler() { this.SelfFactory = new SelfFactoryImpl(this); this.ResourceHandlers = new ResourceHandlers(); }