private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext != null && this.DataContext.GetType() == typeof(DatabaseIndexData)) { DatabaseIndexData index = (DatabaseIndexData)this.DataContext; Dictionary <uint, Property> propertyContainer; try { MemoryStream byteStream = new MemoryStream(index.Data); propertyFile = new PropertyFile(); propertyFile.Read(byteStream); propertyContainer = propertyFile.Values; PathFileEntry = new PathFile(); PathFileEntry.Load(propertyFile.Values); ContainerGrid.DataContext = PathFileEntry; } catch (Exception ex) { Exception subEx = ex.InnerException; while (subEx != null) { // exceptionMessage += subEx.Message + Environment.NewLine; subEx = ex.InnerException; } } } }
void CachePropKeys() { _cacheProperties.Clear(); _cacheInstances.Clear(); _cacheGroups.Clear(); // loads up local cache. double cache is required because it will add values from props later on _cacheInstances = DatabaseManager.Instance.LoadedInstanceIds; // get instance GroupId's from the GroupContainer foreach (uint groupContainer in DatabaseManager.Instance.LoadedGroupIds) { if (!_cacheGroups.Contains(groupContainer)) { _cacheGroups.Add(groupContainer); } } // build up cache for prop files (is a bit more complex due to the value arrays) IEnumerable <DatabaseIndex> propitems = DatabaseManager.Instance.Where(item => item.TypeId == 0xb1b104); foreach (DatabaseIndex item in propitems) { PropertyFile file = new PropertyFile(); byte[] data = item.GetIndexData(true); using (MemoryStream byteStream = new MemoryStream(data)) { file.Read(byteStream); } Dictionary <uint, Property> propertyCollection; propertyCollection = file.Values; foreach (KeyValuePair <uint, Property> prop in propertyCollection) { if (_cacheProperties.Contains(prop.Key) == false) // add Prop key Name { _cacheProperties.Add(prop.Key); } if (prop.Value is ArrayProperty) // add Values from prop array's, these are all instance id's! { ArrayProperty arr = prop.Value as ArrayProperty; try { foreach (KeyProperty subProp in arr.Values) { if (_cacheInstances.Contains(subProp.InstanceId) == false && subProp.InstanceId != 0) { _cacheInstances.Add(subProp.InstanceId); } } } catch { } } } } _cacheReady = true; // set ready flag for threads to continue... }
private void writePropFile(byte[] data, string fn) { PropertyFile file = new PropertyFile(); file.Read(new MemoryStream(data)); stripGeneratedLocaleReferences(file); var output = File.Create(fn + ".xml"); XmlTextWriter writer = new XmlTextWriter(output, Encoding.UTF8); writer.Formatting = Formatting.Indented; file.WriteXML(writer); writer.Flush(); output.Close(); }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <TGIRecord> foundItems = TGIRegistry.Instance.Instances.Cache.Values.ToList(); int completed = 0; IEnumerable <DatabaseIndex> propitems = DatabaseManager.Instance.Where(item => item.TypeId == 0xb1b104); int count = propitems.Count(); foreach (DatabaseIndex item in propitems) { if (worker.CancellationPending) { e.Cancel = true; return; } try { byte[] data = item.GetIndexData(true); using (MemoryStream byteStream = new MemoryStream(data)) { PropertyFile file = new PropertyFile(); file.Read(byteStream); foreach (KeyProperty prop in file.Values.Values.Where(p => p is KeyProperty)) { //if the value is found remove it from the list. foundItems.RemoveAll(r => r.Id == prop.InstanceId); } foreach (ArrayProperty prop in file.Values.Values.Where(p => p is ArrayProperty)) { foreach (KeyProperty propi in prop.Values.Where(p => p is KeyProperty)) { foundItems.RemoveAll(r => r.Id == propi.InstanceId); } } } } catch { } worker.ReportProgress((int)(((float)completed++ / (float)count) * 100)); } e.Result = foundItems; }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext != null && this.DataContext.GetType() == typeof(DatabaseIndexData)) { DatabaseIndexData index = (DatabaseIndexData)this.DataContext; Dictionary <uint, Property> propertyContainer; try { using (MemoryStream byteStream = new MemoryStream(index.Data)) { propertyFile = new PropertyFile(); propertyFile.Read(byteStream); propertyContainer = propertyFile.Values; pnlImages.Children.RemoveRange(0, pnlImages.Children.Count); displayProperties = new List <PropertyModel>(); ReloadDisplayProperties(propertyContainer); } } catch (Exception ex) { tbxError.Visibility = System.Windows.Visibility.Visible; dataGrid1.Visibility = System.Windows.Visibility.Collapsed; string exceptionMessage = ex.Message + Environment.NewLine; Exception subEx = ex.InnerException; while (subEx != null) { exceptionMessage += subEx.Message + Environment.NewLine; subEx = ex.InnerException; } tbxError.Text = exceptionMessage + Environment.NewLine + ex.StackTrace; } } }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext != null && this.DataContext.GetType() == typeof(DatabaseIndexData)) { Decals.Clear(); index = (DatabaseIndexData)this.DataContext; Dictionary <uint, Property> propertyContainer; try { MemoryStream byteStream = new MemoryStream(index.Data); propertyFile = new PropertyFile(); propertyFile.Read(byteStream); propertyContainer = propertyFile.Values; DecalDictionaryEntry = new DecalImageDictionary(); DecalDictionaryEntry.Load(propertyContainer); gridDetails.DataContext = DecalDictionaryEntry; DecalDictionaryEntry.DecalImages.ForEach(d => d.RefreshPreview()); Decals.AddRange(DecalDictionaryEntry.DecalImages); var expression = txtMaterialId.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateTarget(); } expression = txtTextureSizeX.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateTarget(); } expression = txtTextureSizeY.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateTarget(); } expression = txtAtlasSizeX.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateTarget(); } expression = txtAtlasSizeY.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateTarget(); } } catch (Exception ex) { Exception subEx = ex.InnerException; while (subEx != null) { // exceptionMessage += subEx.Message + Environment.NewLine; subEx = ex.InnerException; } } } }
private void mnuInstanceIds_Click(object sender, RoutedEventArgs e) { if (Properties.Settings.Default.LocaleFile != string.Empty) { try { Dictionary <uint, string> itemNames = new Dictionary <uint, string>(); foreach (DatabaseIndex index in view) { //for all property files, see if the name property exists if (index.TypeId == 0x00b1b104) { using (MemoryStream byteStream = new MemoryStream(index.GetIndexData(true))) { PropertyFile propertyFile = new PropertyFile(); propertyFile.Read(byteStream); if (!itemNames.ContainsKey(index.InstanceId)) { if (propertyFile.Values.ContainsKey(0x09FB78CB)) { ArrayProperty arrprop = propertyFile.Values[0x09FB78CB] as ArrayProperty; TextProperty prop = arrprop.Values[0] as TextProperty; string name = LocaleRegistry.Instance.GetLocalizedString(prop.TableId, prop.InstanceId); itemNames.Add(index.InstanceId, name.Replace("'", "''")); } else if (propertyFile.Values.ContainsKey(0x0A09F5FA)) { ArrayProperty arrprop = propertyFile.Values[0x0A09F5FA] as ArrayProperty; TextProperty prop = arrprop.Values[0] as TextProperty; string name = LocaleRegistry.Instance.GetLocalizedString(prop.TableId, prop.InstanceId); itemNames.Add(index.InstanceId, name.Replace("'", "''")); } else if (propertyFile.Values.ContainsKey(0x09B711C3)) { ArrayProperty arrprop = propertyFile.Values[0x09B711C3] as ArrayProperty; TextProperty prop = arrprop.Values[0] as TextProperty; string name = LocaleRegistry.Instance.GetLocalizedString(prop.TableId, prop.InstanceId); itemNames.Add(index.InstanceId, name.Replace("'", "''")); } else if (propertyFile.Values.ContainsKey(0x0E28B5BC)) { ArrayProperty arrprop = propertyFile.Values[0x0E28B5BC] as ArrayProperty; TextProperty prop = arrprop.Values[0] as TextProperty; string name = LocaleRegistry.Instance.GetLocalizedString(prop.TableId, prop.InstanceId); itemNames.Add(index.InstanceId, name.Replace("'", "''")); } else if (propertyFile.Values.ContainsKey(0x0E28B5D5)) { ArrayProperty arrprop = propertyFile.Values[0x0E28B5D5] as ArrayProperty; TextProperty prop = arrprop.Values[0] as TextProperty; string name = LocaleRegistry.Instance.GetLocalizedString(prop.TableId, prop.InstanceId); itemNames.Add(index.InstanceId, name.Replace("'", "''")); } } } } } foreach (KeyValuePair <uint, string> name in itemNames) { TGIRegistry.Instance.Instances.InsertRecord(new TGIRecord() { Id = name.Key, Name = name.Value, Comments = name.Value }); } ReloadPackages(); } catch (Exception ex) { System.Windows.MessageBox.Show(string.Format("An error occurred while attempting to load instance names from your locale file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { System.Windows.MessageBox.Show("The Locale File is not specified in the application settings!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public Dictionary <uint, Property> GetParentProperties(Dictionary <uint, Property> returnProperties, Dictionary <uint, Property> parentProperties) { if (returnProperties == null) { returnProperties = new Dictionary <uint, Property>(); } //add keys that didn't exist yet foreach (uint index in parentProperties.Keys) { if (!returnProperties.ContainsKey(index) && index != 0x00B2CCCB) { //This property specifies behavior bundles to exclude - instead of adding this property, remove all the bundles from the appropriate arrays returnProperties.Add(index, parentProperties[index]); } } if (parentProperties.ContainsKey(0x00B2CCCB)) { Property parentProperty = parentProperties[0x00B2CCCB]; KeyProperty parentPropertyValue = parentProperty as KeyProperty; //search the currently opened package for this type/instance group id. if it doesn't exist, find it in the default simcity packages DatabaseIndex parentIndex = null; if (DatabaseManager.Instance.Indices.Exists(i => i.InstanceId == parentPropertyValue.InstanceId && i.TypeId == parentPropertyValue.TypeId && i.GroupContainer == parentPropertyValue.GroupContainer)) { parentIndex = DatabaseManager.Instance.Indices.First(i => i.InstanceId == parentPropertyValue.InstanceId && i.TypeId == parentPropertyValue.TypeId && i.GroupContainer == parentPropertyValue.GroupContainer); } else { string folderEcoGamePath = Properties.Settings.Default.SimCityFolder + @"\SimCityUserData\EcoGame\"; DirectoryInfo folderEcoGame = new DirectoryInfo(folderEcoGamePath); //search the simcity data packages for this type/instance group id. if it doesn't exist, find it in the default simcity packages FileInfo[] scriptsFiles = folderEcoGame.GetFiles("SimCity-Scripts_*.package", SearchOption.TopDirectoryOnly); FileInfo scriptsFile = scriptsFiles.First(sf => sf.LastWriteTime == scriptsFiles.Max(sf2 => sf2.LastWriteTime)); DatabasePackedFile ScriptsPackage = DatabasePackedFile.LoadFromFile(scriptsFile.FullName); parentIndex = ScriptsPackage.Indices.FirstOrDefault(i => i.InstanceId == parentPropertyValue.InstanceId && i.TypeId == parentPropertyValue.TypeId && i.GroupContainer == parentPropertyValue.GroupContainer); } // if(parentIndex != null) // { byte[] data = parentIndex.GetIndexData(true); using (Stream s = new MemoryStream(data, 0, data.Length)) { PropertyFile propertyFile = new PropertyFile(); propertyFile.Read(s); return(GetParentProperties(returnProperties, propertyFile.Values)); } throw new Exception("Inheritance not found!"); return(returnProperties); } else { return(returnProperties); } }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; System.Collections.Concurrent.ConcurrentBag <DatabaseIndex> foundItems = new System.Collections.Concurrent.ConcurrentBag <DatabaseIndex>(); //List<DatabaseIndex> foundItems = new List<DatabaseIndex>(); int completed = 0; IEnumerable <DatabaseIndex> propitems = DatabaseManager.Instance.Where(item => item.TypeId == 11645188); int count = propitems.Count(); Object[] args = e.Argument as Object[]; String searchText = args[0] as String; String propertyIDText = args[1] as String; uint propertyID = 0; if (!String.IsNullOrEmpty(propertyIDText)) { if (propertyIDText.StartsWith("0x")) { propertyIDText = propertyIDText.Remove(0, 2); } propertyID = UInt32.Parse(propertyIDText, System.Globalization.NumberStyles.AllowHexSpecifier); } if (searchText == null) { searchText = ""; } int propType = (int)args[2]; //foreach (DatabaseIndex item in propitems) Func <KeyValuePair <uint, Property>, bool> searchExpression = null; if (searchText == "") { searchExpression = pair => pair.Key == propertyID; } else { switch (propType) { case 0: //key searchExpression = pair => (propertyID == 0 || pair.Key == propertyID) && ((pair.Value is KeyProperty && ((KeyProperty)pair.Value).InstanceId.ToHex().Contains(searchText)) || (pair.Value is ArrayProperty && ((ArrayProperty)pair.Value).Values.Count(val => val is KeyProperty && ((KeyProperty)val).InstanceId.ToHex().Contains(searchText)) != 0)); break; case 1: //number searchExpression = pair => (propertyID == 0 || pair.Key == propertyID) && ((pair.Value is Int32Property && ((Int32Property)pair.Value).Value.ToString() == searchText) || (pair.Value is UInt32Property && ((UInt32Property)pair.Value).Value.ToString() == searchText) || (pair.Value is FloatProperty && ((FloatProperty)pair.Value).Value.ToString() == searchText) || (pair.Value is ArrayProperty && ((ArrayProperty)pair.Value).Values.Count(val => (val is Int32Property && ((Int32Property)val).Value.ToString() == searchText) || (val is UInt32Property && ((UInt32Property)val).Value.ToString() == searchText) || (val is FloatProperty && ((FloatProperty)val).Value.ToString() == searchText)) != 0)); break; case 2: //bool searchExpression = pair => (propertyID == 0 || pair.Key == propertyID) && (pair.Value is BoolProperty && ((BoolProperty)pair.Value).Value.ToString().Equals(searchText, StringComparison.CurrentCultureIgnoreCase)); break; } } Parallel.ForEach(propitems, (item, loopstate) => { if (worker.CancellationPending) { e.Cancel = true; loopstate.Stop(); //return; } byte[] data = item.GetIndexData(true); using (MemoryStream byteStream = new MemoryStream(data)) { PropertyFile file = new PropertyFile(); file.Read(byteStream); int pcount = 0; pcount = file.Values.Count(searchExpression);; if (pcount > 0) { foundItems.Add(item); } } worker.ReportProgress((int)(((float)completed++ / (float)count) * 100)); }); e.Result = foundItems; }