Example #1
0
        /// <summary>
        /// Sort entries to be in ascending order with no gaps.
        /// </summary>
        private void SortEntries()
        {
            //Quick and dirty duplicate ID check
            var conflicts = bacFile.BacEntries.Where(x => bacFile.BacEntries.Any(y => y.SortID == x.SortID && y != x));

            if (conflicts.Count() > 0)
            {
                throw new Exception($"Multiple BAC entries with the ID {conflicts.First().SortID} were found!");
            }

            //Duplicate bacFile so changes here dont affect the original (would really cause havok with the undo stack on XenoKit...)
            bacFile = bacFile.Copy();
            bacFile.SortEntries();
            if (bacFile.BacEntries.Count == 0)
            {
                return;                                //No bac entries. Gtfo
            }
            int lastIndex = bacFile.BacEntries[bacFile.BacEntries.Count - 1].SortID;

            for (int a = 0; a <= lastIndex; a++)
            {
                if (bacFile.BacEntries.FirstOrDefault(x => x.SortID == a) == null)
                {
                    bacFile.BacEntries.Add(BAC_Entry.Empty(a));
                }
            }

            bacFile.SortEntries();
        }
Example #2
0
 public Deserializer(BAC_File _bacFile, string location)
 {
     saveLocation = location;
     bacFile      = _bacFile;
     WriteBac();
     File.WriteAllBytes(saveLocation, bytes.ToArray());
 }
Example #3
0
        public Deserializer(string location)
        {
            saveLocation = String.Format("{0}/{1}", Path.GetDirectoryName(location), Path.GetFileNameWithoutExtension(location));
            YAXSerializer serializer = new YAXSerializer(typeof(BAC_File), YAXSerializationOptions.DontSerializeNullObjects);

            bacFile = (BAC_File)serializer.DeserializeFromFile(location);

            WriteBac();
            File.WriteAllBytes(saveLocation, bytes.ToArray());
        }
Example #4
0
        private void Uninstall_BAC(string path, _File file)
        {
            try
            {
                BAC_File binaryFile = (BAC_File)GetParsedFile <BAC_File>(path, false);
                BAC_File cpkBinFile = (BAC_File)GetParsedFile <BAC_File>(path, true, false);

                Section section = file.GetSection(Sections.BAC_Entries);

                if (section != null)
                {
                    UninstallEntries(binaryFile.BacEntries, (cpkBinFile != null) ? cpkBinFile.BacEntries : null, section.IDs);
                }
            }
            catch (Exception ex)
            {
                string error = string.Format("Failed at {0} uninstall phase ({1}).", ErrorCode.BAC, path);
                throw new Exception(error, ex);
            }
        }
Example #5
0
 public Deserializer(BAC_File _bacFile)
 {
     bacFile = _bacFile;
     WriteBac();
 }