public RebuildPropertyFile(string path)
        {
            try
            {
                var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                var reader = XmlReader.Create(stream);
                var file = new PropertyFile();
                file.ReadXML(reader);
                reader.Close();
                stream.Close();

                stream = new FileStream(path + ".part", FileMode.Create, FileAccess.Write);
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                file.WriteXML(writer);
                writer.Close();
                stream.Close();
            }
            catch (Exception)
            {
                failed = true;
                if (File.Exists(path + ".part")) File.Delete(path + ".part");
                return;
            }
            File.Replace(path + ".part", path, path + ".backup");
            File.Delete(path + ".backup");
        }
Beispiel #2
0
        public static 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
                //{
                parentIndex = DatabaseIndex.FindIndex(parentPropertyValue.TypeId, parentPropertyValue.GroupContainer, null, parentPropertyValue.InstanceId, true, true);
                //}

                // 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!");
            }
            else
            {
                return(returnProperties);
            }
        }
Beispiel #3
0
 void writePropFile(string groupName, string instanceName, string inputFileName, Stream output, out byte[] locale)
 {
     // Convert .prop.xml to binary .prop file and write it to output
     var reader = XmlReader.Create( File.OpenText(inputFileName) );
     var file = new PropertyFile();
     file.ReadXML( reader );
     reader.Close();
     locale = generateLocale(file, groupName, instanceName);
     file.Write(output);
 }
Beispiel #4
0
 byte[] generateLocale(PropertyFile file, string group, string instance)
 {
     // Create a .locale file from placeholder text if there are any <text>
     //   tags with no instance or table ID
     var locale = new StringBuilder();
     uint locale_index = 0;
     var locale_name = "auto_" + group + "_" + instance;
     foreach (var prop1 in file.Values.Values)
     {
         var arr = prop1 as ArrayProperty;
         if (arr == null) continue;
         foreach (var prop in arr.Values)
         {
             var text = prop as TextProperty;
             if (text != null && text.InstanceId == 0 && text.TableId == 0)
             {
                 if (locale_index == 0) locale.Append("# This file generated from " + group + "/" + instance + ".prop.xml by SporeMaster.\n");
                 text.TableId = NameRegistry.Files.toHash(locale_name);
                 text.InstanceId = ++locale_index;
                 locale.AppendFormat("0x{0:X8} {1}\n", text.InstanceId, text.PlaceholderText);
             }
         }
     }
     return Encoding.UTF8.GetBytes( locale.ToString() );
 }
Beispiel #5
0
 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();
 }
Beispiel #6
0
 private void stripGeneratedLocaleReferences(PropertyFile file)
 {
     // Effectively, we are undoing the work of PackagePack.generateLocale()
     foreach (var prop1 in file.Values.Values)
     {
         var arr = prop1 as ArrayProperty;
         if (arr == null) continue;
         foreach (var prop in arr.Values)
         {
             var text = prop as TextProperty;
             if (text != null &&
                     (NameRegistry.Files.toName(text.TableId).StartsWith("auto_") ||
                      NameRegistry.Files.toName(text.TableId).EndsWith("_auto")))
             {
                 text.InstanceId = 0;
                 text.TableId = 0;
             }
         }
     }
 }