Exemplo n.º 1
0
 public Song(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     MetadataTags    = new List <HKey>();
     GenreTags       = new List <HKey>();
     Labels          = new List <FString>();
     InstrumentPaths = new List <HKey>();
 }
Exemplo n.º 2
0
        private static void CreateHKeys(string name)
        {
            // Creates paths for packagedef + index2
            HKey packageFilePath  = new HKey("PackageDefs." + name + ".PackageDef");
            HKey packageDirectory = packageFilePath.GetParentDirectory();

            CreateStringTablePaths(packageDirectory);

            HKey indexFilePath  = new HKey("packages." + name + ".index2");
            HKey indexDirectory = indexFilePath.GetParentDirectory();

            CreateStringTablePaths(indexDirectory);
        }
Exemplo n.º 3
0
        internal HKey Extend(string extension)
        {
            if (!IsValidValue(extension))
            {
                throw new Exception(InvalidValueMessage());
            }

            ulong newKey = HKey.GetHash(extension, _key);

            if (StringKey.ContainsStringKey(_key))
            {
                // Adds new value
                string newValue = StringKey.GetValue(_key, Localization.English) + extension;
                StringKey.UpdateValue(newKey, newValue);
                return(new HKey(newKey));
            }

            return(new HKey(newKey));
        }
Exemplo n.º 4
0
        public void UpdateIndexEntryAsPending(HKey filePath, HKey type, string physicalPath, HKey packageFilePath)
        {
            Index2Entry indexEntry = Index.Entries.FirstOrDefault(x => x.FilePath == filePath);

            if (indexEntry == null)
            {
                // Creates new entry
                indexEntry = new Index2Entry()
                {
                    FilePath = filePath,
                    Type     = type
                };

                Index.Entries.Add(indexEntry);
            }

            Index2PackageEntry packageEntry = indexEntry.PackageEntries.FirstOrDefault(x => x.Package == packageFilePath);

            if (packageEntry == null)
            {
                // Creates new entry
                packageEntry = new Index2PackageEntry()
                {
                    Package          = packageFilePath,
                    ExternalFilePath = physicalPath
                };

                // Inserts at the front
                indexEntry.PackageEntries.Insert(0, packageEntry);
            }
            else
            {
                // Updates external file path
                packageEntry.ExternalFilePath = physicalPath;
            }
        }
Exemplo n.º 5
0
 public Texture(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Exemplo n.º 6
0
 public Event(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <EventEntry>();
 }
Exemplo n.º 7
0
        private static RiffFile FromStream(Stream stream)
        {
            RiffFile      riff = new RiffFile();
            AwesomeReader ar   = new AwesomeReader(stream);

            // Checks for "RIFF" magic.
            switch (ar.ReadInt32())
            {
            case MAGIC_RIFF:
                ar.BigEndian = false;
                break;

            case MAGIC_RIFF_R:
                ar.BigEndian = true;
                break;

            default:
                throw new Exception("Invalid magic. Expected \"RIFF\"");
            }

            riff.BigEndian          = ar.BigEndian; // Sets endianess
            ar.BaseStream.Position += 4;            // Skips total size

            int chunkType = GetChunkType(ar);

            if (chunkType != MAGIC_INDX)
            {
                throw new Exception("First chunk was not an Index!");
            }

            Index index = new Index(ar);

            foreach (IndexEntry entry in index.Entries)
            {
                ar.BaseStream.Position = entry.Offset; // Jumps to offset
                chunkType = GetChunkType(ar);

                if (chunkType != MAGIC_STBL && chunkType != MAGIC_ZOBJ)
                {
                    continue;
                }

                // Reads header info
                HKey filePath      = new HKey(ar.ReadUInt64());
                HKey directoryPath = new HKey(ar.ReadUInt64());
                HKey type          = new HKey(ar.ReadUInt64());
                ar.BaseStream.Position += 8;

                if (chunkType == MAGIC_STBL)
                {
                    // Gets localization
                    if (!StringTable.IsValidLocalization(type))
                    {
                        continue;
                    }

                    // Loads string table
                    StringTable table = new StringTable(filePath, directoryPath, StringTable.GetLocalization(type));
                    table.ReadData(ar);
                    riff._objects.Add(table);
                }
                else if (chunkType == MAGIC_ZOBJ)
                {
                    if (!Global.ZObjectTypes.ContainsKey(type))
                    {
                        continue;                                         // Unsupported type
                    }
                    // Loads zobject
                    ZObject obj = Activator.CreateInstance(Global.ZObjectTypes[type], new object[] { filePath, directoryPath }) as ZObject;
                    obj.ReadData(ar);
                    riff._objects.Add(obj);
                }
                else
                {
                    // Unknown chunk
                    continue;
                }
            }

            return(riff);
        }
Exemplo n.º 8
0
 public Tone2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Pedals     = new List <Pedal>();
     Processors = new List <AudioProcessor>();
 }
Exemplo n.º 9
0
 public AudioEffect(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <AudioEffectEntry>();
 }
Exemplo n.º 10
0
 public Catalog2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <Catalog2Entry>();
 }
Exemplo n.º 11
0
 public Video(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Exemplo n.º 12
0
 public Instrument(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     TrackPaths = new List <HKey>();
 }
Exemplo n.º 13
0
 public ZObject this[HKey index] => GetZObject(Index?.Entries.SingleOrDefault(x => x.FilePath == index));
Exemplo n.º 14
0
        public void SavePendingChanges()
        {
            if (!PendingChanges)
            {
                return;
            }

            // Groups objects by package
            var packages = _pendingChanges.Select(obj => new
            {
                ZObject      = obj,
                PackageEntry = Index.Entries.First(idx => idx.FilePath == obj.FilePath).PackageEntries.First()
            }).OrderBy(x => x.PackageEntry.ExternalFilePath).GroupBy(x => x.PackageEntry.Package);

            foreach (var package in packages)
            {
                HKey   packagePath         = package.Key;
                string physicalPackagePath = _packagePaths[packagePath];

                var fusedFiles = package.GroupBy(x => x.PackageEntry.ExternalFilePath);

                foreach (var fusedFile in fusedFiles)
                {
                    string   fusedFilePath = Path.Combine(physicalPackagePath, fusedFile.Key);
                    RiffFile rif           = null;

                    // TODO: Find a better solution (Less ugly)
                    if (File.Exists(fusedFilePath))
                    {
                        try
                        {
                            // Opens existing file to preserve zobjects
                            rif = RiffFile.FromFile(fusedFilePath);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            if (rif == null)
                            {
                                rif = new RiffFile();
                            }
                        }
                    }
                    else
                    {
                        rif = new RiffFile();
                    }

                    foreach (var zobject in fusedFile.Select(x => x.ZObject))
                    {
                        // Removes existing zobject if present
                        rif.Objects.RemoveAll(x => x.FilePath == zobject.FilePath);

                        // Adds new zobject
                        rif.Objects.Add(zobject);
                    }

                    // Saves new rif file
                    rif.WriteToFile(fusedFilePath);
                }
            }

            // Sorts index entries by file paths
            Index.Entries.Sort((x, y) => string.Compare(x.FilePath, y.FilePath, true));

            // Saves index for current package only
            RiffFile indexRif = new RiffFile();

            indexRif.Objects.Add(Index);
            indexRif.WriteToFile(Path.Combine(CurrentPackageDirectory, "index2.rif"));

            _pendingChanges.Clear();
        }
Exemplo n.º 15
0
 // Used mostly for debugging
 private static List <HKey> CreateStringTablePaths(HKey directory) => Global.StringTableLocalizations.Select(x => (HKey)(directory.Value + "." + x.Value)).ToList();
Exemplo n.º 16
0
 public Measure(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <MeasureEntry>();
 }
Exemplo n.º 17
0
 public ZObject(HKey filePath, HKey directoryPath)
 {
     _filePath      = filePath;
     _directoryPath = directoryPath;
 }
Exemplo n.º 18
0
 public Whammy(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <WhammyEntry>();
 }
Exemplo n.º 19
0
 public PackageDef(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <string>();
 }
Exemplo n.º 20
0
 public VoxSpread(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <SpreadEntry>();
 }
Exemplo n.º 21
0
 public VoxPushPhrase(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TimeEvent>();
 }
Exemplo n.º 22
0
 public Index2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <Index2Entry>();
 }
Exemplo n.º 23
0
        private List <StringTable> CreateStringTables(List <ZObject> zobjects)
        {
            List <StringTable> tables = new List <StringTable>();
            var groups = zobjects.Where(x => !(x is StringTable)).GroupBy(x => x.DirectoryPath);

            foreach (var group in groups)
            {
                if (group.Key.Key != 0)
                {
                    // Creates shared string tables
                    foreach (HKey local in Global.StringTableLocalizationsOnDisc)
                    {
                        List <FString> strings = group.SelectMany(x => x.GetAllStrings()).Distinct().ToList();

                        HKey        localGroupDirectory = group.Key.Extend("." + local);
                        StringTable table = new StringTable(localGroupDirectory, group.Key.GetParentDirectory(), StringTable.GetLocalization(local));

                        // Adds strings from zobjects
                        foreach (FString str in strings)
                        {
                            table.Strings.Add(str.Key, StringKey.GetValue(str.Key, table.Localization));
                        }

                        // Adds strings from table (Directory string)
                        foreach (FString str in table.GetAllStrings().Where(x => !table.Strings.ContainsKey(x)))
                        {
                            table.Strings.Add(str, StringKey.GetValue(str.Key, table.Localization));
                        }

                        tables.Add(table);
                    }

                    continue;
                }

                // Creates string table for singular zobject (Uses file path)
                foreach (ZObject obj in group)
                {
                    List <FString> strings = obj.GetAllStrings();

                    foreach (HKey local in Global.StringTableLocalizationsOnDisc)
                    {
                        HKey        objectDirectory = obj.FilePath.Extend("." + local);
                        StringTable table           = new StringTable(objectDirectory, obj.FilePath.GetParentDirectory(), StringTable.GetLocalization(local));

                        // Adds strings from zobjects
                        foreach (FString str in strings)
                        {
                            table.Strings.Add(str.Key, StringKey.GetValue(str.Key, table.Localization));
                        }

                        // Adds strings from table (Directory string)
                        foreach (FString str in table.GetAllStrings().Where(x => !table.Strings.ContainsKey(x)))
                        {
                            table.Strings.Add(str, StringKey.GetValue(str.Key, table.Localization));
                        }

                        tables.Add(table);
                    }
                }
            }

            return(tables);
        }
Exemplo n.º 24
0
 public Section(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TextEvent>();
 }
Exemplo n.º 25
0
 public TimeSignature(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TimeSignatureEntry>();
 }
Exemplo n.º 26
0
 public StringTable(HKey filePath, HKey directoryPath, Localization localization = Localization.English) : base(filePath, directoryPath)
 {
     _localization = localization;
     _strings      = new Dictionary <ulong, string>();
 }
Exemplo n.º 27
0
 public Audio(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Exemplo n.º 28
0
 internal static bool IsValidLocalization(HKey key) => LocalizationPair.Localizations.Count(x => x.HashValue == key.Key) != 0;
Exemplo n.º 29
0
 public Vox(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <VoxEntry>();
 }
Exemplo n.º 30
0
 internal static Localization GetLocalization(HKey key) => LocalizationPair.Localizations.FirstOrDefault(x => x.HashValue == key).EnumValue;