public void LoadBedrockPacks(IProgressReceiver progressReceiver, DirectoryInfo directoryInfo) { progressReceiver?.UpdateProgress(0, "Loading bedrock .MCPack files..."); var files = directoryInfo.EnumerateFiles("*.mcpack").ToArray(); for (var index = 0; index < files.Length; index++) { var file = files[index]; progressReceiver?.UpdateProgress(index * (files.Length / 100), "Loading bedrock .MCPack files...", file.Name); try { using (var archive = new ZipArchive(file.Open(FileMode.Open, FileAccess.Read), ZipArchiveMode.Read)) { MCPack pack = new MCPack(archive); Packs.Add(pack); } } catch (Exception ex) { Log.Warn(ex, $"Failed to load bedrock .MCPack file: {file.Name}: {ex}"); } } }
private AssetManagerInfo _Read(StringStreamReader reader) { Version = reader.ReadString(); Date = DateTime.Parse(reader.ReadString()); var count = reader.ReadNumber(); for (var i = 0; i < count; ++i) { var key = reader.ReadIndexString("/"); var value = new AssetPackInfo()._Read(reader); Packs.Add(key, value); } count = reader.ReadNumber(); for (var i = 0; i < count; ++i) { var key = reader.ReadIndexString("/"); var value = new AssetInfo()._Read(reader); Assets.Add(key, value); } return(this); }
private void loadFromFileNames(object sender, object arg) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; IEnumerable <string> fileNames = (IEnumerable <string>)arg; for (int i = 0; i < fileNames.Count(); ++i) { string fileName = fileNames.ElementAt(i); Pack pack = null; if (!Packs.TryGetValue(fileName.GetHashCode(), out pack)) { pack = Pack.Load(fileName); if (pack != null) { Packs.Add(fileName.GetHashCode(), pack); foreach (Asset asset in pack.Assets.Values) { if (!AssetsByType.ContainsKey(asset.Type)) { AssetsByType.Add(asset.Type, new List <Asset>()); } AssetsByType[asset.Type].Add(asset); } } } float percent = (Single)(i + 1) / (Single)fileNames.Count(); backgroundWorker.ReportProgress((int)(percent * 100.0f), System.IO.Path.GetFileName(fileName)); } }
private void loadBinaryFromPaths(object sender, object arg) { BackgroundWorker backgroundWorker = (BackgroundWorker)sender; IEnumerable <string> paths = (IEnumerable <string>)arg; for (Int32 i = 0; i < paths.Count(); ++i) { String path = paths.ElementAt(i); Pack pack = null; if (packLookupCache.TryGetValue(path.GetHashCode(), out pack) == false) { pack = Pack.LoadBinary(path); if (pack != null) { packLookupCache.Add(path.GetHashCode(), pack); Packs.Add(pack); foreach (Asset asset in pack.Assets) { if (false == AssetsByType.ContainsKey(asset.Type)) { AssetsByType.Add(asset.Type, new List <Asset>()); } AssetsByType[asset.Type].Add(asset); } } } Single percent = (Single)(i + 1) / (Single)paths.Count(); backgroundWorker.ReportProgress((Int32)(percent * 100.0f), System.IO.Path.GetFileName(path)); } }
public static SmileyPack AddPack(string name) { var pack = new SmileyPack(name, false); Directory.CreateDirectory(GetPath(pack)); Packs.Add(pack); return(pack); }
/// <summary> /// Add a pack to main list /// </summary> /// <param name="task"></param> public static void AddPack(LanguagePack pack) { if (Packs == null) { Packs = new Dictionary <string, LanguagePack>(); } Packs.Add(pack.Language, pack); }
/// <summary> /// Load pack from bytes /// </summary> /// <param name="s">Bytes to load</param> public static void LoadFromBytes(byte[] s) { if (Packs == null) { Packs = new Dictionary <string, LanguagePack>(); } LanguagePack lp = LanguagePack.Load(s); Packs.Add(lp.Language, lp); }
public async Task LoadAsync() { var lookup = await _packLookupService.GetPackLookupAsync(); Packs.Clear(); foreach (var item in lookup) { Packs.Add(item); } }
/// <summary> /// Adds the players and calls the event. /// </summary> private void AddPlayers() { this.Players = waitingPlayers.Select(p => p).ToList(); // todo check if needed //this.PlayerCount = waitingPlayers.Count; foreach (Client c in Players) { Packs.Add(c, new CardPack()); c.CurrentGame = this; } OnPlayersAdded(); }
public async void Reload() { Packs.Clear(); foreach (var pack in await _shaderPackService.LoadAllAsync()) { if (pack.IsEnabled) { _enabledPack = pack; } Packs.Add(pack); } }
private void AddSetClicked(object sender, RoutedEventArgs e) { e.Handled = true; if (packsCombo.SelectedItem == null) { return; } // I am creating lightweight "clones" of the pack, because the // WPF ListBox doesn't like having multiple copies of the same // instance and messes up selection var pack = (DataNew.Entities.Pack)packsCombo.SelectedItem; Packs.Add(new SelectedPack { Id = pack.Id, FullName = pack.GetFullName() }); }
public static void Load() { string currentPackName = CurrentPack == null ? null : CurrentPack.Name; Packs.Clear(); var defaultDirs = new DirectoryInfo(DefaultSmileysFolder).EnumerateDirectories(); var customDirs = new DirectoryInfo(CustomSmileysFolder).EnumerateDirectories(); foreach (var dir in defaultDirs.Concat(customDirs)) { var doc = XDocument.Load(Path.Combine(dir.FullName, ManifestFileName)); bool isDefault = bool.Parse(doc.Root.Attribute(IsDefaultAttributeName).Value); var pack = new SmileyPack(dir.Name, isDefault); foreach (var elem in doc.Root.Elements(SmileyElementName)) { string fileName = elem.Attribute(FileNameAttributeName).Value; string[] shortcuts = elem.Attribute(ShortcutsAttributeName).Value .Split(SmileyShortcutsSeparator); var smiley = new Smiley(); smiley.FileName = fileName; smiley.Image = GetImage(Path.Combine(GetPath(pack), fileName)); foreach (string s in shortcuts) { smiley.Shortcuts.Add(s); } pack.Smileys.Add(smiley); } Packs.Add(pack); } if (currentPackName == null) { CurrentPack = Packs.First(); } else { SetCurrentPack(currentPackName); } }
public void LoadPack(string path) { Pack pack; if (!packLookupCache.TryGetValue(path, out pack)) { pack = Pack.LoadBinary(path); if (pack != null) { packLookupCache.TryAdd(path, pack); Packs.Add(pack); foreach (AssetRef asset in pack.Assets) { AssetsByType[asset.Type].Add(asset); } } } }
protected override void OnLoad() { var fileJson = File.ReadAllText(Path); var a = fileJson.FromJson <Dictionary <string, object> >(); if (a == null) { throw new FileFormatException("Json load failed"); } var author = SetIfContains(a, "Author", "Anonymous"); bool IsSinglePack = false; if (a["Type"] is string) { if (a["Type"].ToString().ToUpperInvariant() == "SINGLE") { IsSinglePack = true; } } if (IsSinglePack) { var tmp = new LocalizationDictionary() { Version = SetIfContains(a, "Version"), Author = author, EnglishName = SetIfContains(a, "EnglishName"), CultureName = SetIfContains(a, "CultureName"), CultureId = SetIfContains(a, "Culture"), RTL = SetIfContains(a, "RTL", "FALSE").ToUpperInvariant() == "TRUE" }; if (!(a["Data"] is List <object> data)) { return; } foreach (Dictionary <string, object> node in data) { if (node == null) { continue; } var innerData = new Dictionary <string, string>(); foreach (var attribute in node) { if (attribute.Key.ToUpperInvariant() == "ID") { continue; } innerData[attribute.Key] = attribute.Value.ToString(); } if (tmp.Data.ContainsKey(node["Id"].ToString())) { continue; } tmp.Data.Add(node["Id"].ToString(), innerData); } Packs.Add(tmp); } else { var version = SetIfContains(a, "Version"); Dictionary <string, LocalizationDictionary> temps = new Dictionary <string, LocalizationDictionary>(); if (!(a["Languages"] is List <object> langs)) { return; } foreach (Dictionary <string, object> node in langs) { if (node == null) { continue; } var tmp = new LocalizationDictionary() { Version = version, EnglishName = SetIfContains(node, "EnglishName"), CultureName = SetIfContains(node, "CultureName"), Author = author, CultureId = SetIfContains(node, "Culture"), RTL = SetIfContains(a, "RTL", "FALSE").ToUpperInvariant() == "TRUE" }; temps.Add(tmp.CultureId, tmp); } if (!(a["Data"] is List <object> data)) { return; } foreach (var node in data) { if (node == null) { continue; } if (!(data[0] is Dictionary <string, object> nodec)) { return; } if (!(nodec["data"] is List <object> nodechild)) { return; } foreach (Dictionary <string, object> attributes in nodechild) { var innerData = new Dictionary <string, Dictionary <string, string> >(); var currId = 0; foreach (var attribute in attributes) { if (attribute.Key.ToUpperInvariant() == "ID") { currId = Convert.ToInt32(attribute.Value, CultureInfo.InvariantCulture); continue; } if (!(attribute.Value is Dictionary <string, object> child)) { continue; } foreach (var item in child) { if (!innerData.ContainsKey(item.Key)) { innerData[item.Key] = new Dictionary <string, string>(); } innerData[item.Key][attribute.Key] = item.Value.ToString(); } } foreach (var item in innerData) { var vals = item.Value; if (!temps[item.Key].Data.ContainsKey($"{currId}")) { temps[item.Key].Data[$"{currId}"] = new Dictionary <string, string>(); } foreach (var ia in vals) { temps[item.Key].Data[$"{currId}"].Add(ia.Key, ia.Value); } } } } foreach (var item in temps.Values) { Packs.Add(item); } temps.Clear(); } }
protected override void OnLoad() { var xmlDocument = new XmlDocument() { XmlResolver = null }; xmlDocument.Load(Path); var docElement = xmlDocument.DocumentElement; if (docElement == null) { return; } if (docElement.Name != "Pack") { throw new XmlException("Invalid root element. Must be Pack"); } var tmp = new LocalizationDictionary() { Version = docElement.Attributes["Version"]?.Value, Author = docElement.Attributes["Author"]?.Value, EnglishName = docElement.Attributes["EnglishName"]?.Value, CultureName = docElement.Attributes["CultureName"]?.Value, CultureId = docElement.Attributes["Culture"]?.Value, }; foreach (XmlNode node in docElement.ChildNodes) { if (node.Name != "Value") { continue; } var innerData = new Dictionary <string, string>(); if (node.Attributes == null) { continue; } foreach (XmlAttribute attribute in node.Attributes) { if (attribute.Name == "Id") { if (tmp.Data.ContainsKey(attribute.Value)) { continue; } tmp.Data[attribute.Value] = innerData; } else { innerData[attribute.Name] = attribute.Value; } } } Packs.Add(tmp); }