Esempio 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>();
 }
Esempio 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);
        }
Esempio 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));
        }
Esempio 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;
            }
        }
Esempio n. 5
0
 public Texture(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Esempio n. 6
0
 public Event(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <EventEntry>();
 }
Esempio 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);
        }
Esempio n. 8
0
 public Tone2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Pedals     = new List <Pedal>();
     Processors = new List <AudioProcessor>();
 }
Esempio n. 9
0
 public AudioEffect(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <AudioEffectEntry>();
 }
Esempio n. 10
0
 public Catalog2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <Catalog2Entry>();
 }
Esempio n. 11
0
 public Video(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Esempio n. 12
0
 public Instrument(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     TrackPaths = new List <HKey>();
 }
Esempio n. 13
0
 public ZObject this[HKey index] => GetZObject(Index?.Entries.SingleOrDefault(x => x.FilePath == index));
Esempio 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();
        }
Esempio n. 15
0
 // Used mostly for debugging
 private static List <HKey> CreateStringTablePaths(HKey directory) => Global.StringTableLocalizations.Select(x => (HKey)(directory.Value + "." + x.Value)).ToList();
Esempio n. 16
0
 public Measure(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <MeasureEntry>();
 }
Esempio n. 17
0
 public ZObject(HKey filePath, HKey directoryPath)
 {
     _filePath      = filePath;
     _directoryPath = directoryPath;
 }
Esempio n. 18
0
 public Whammy(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <WhammyEntry>();
 }
Esempio n. 19
0
 public PackageDef(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <string>();
 }
Esempio n. 20
0
 public VoxSpread(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <SpreadEntry>();
 }
Esempio n. 21
0
 public VoxPushPhrase(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TimeEvent>();
 }
Esempio n. 22
0
 public Index2(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Entries = new List <Index2Entry>();
 }
Esempio 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);
        }
Esempio n. 24
0
 public Section(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TextEvent>();
 }
Esempio n. 25
0
 public TimeSignature(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <TimeSignatureEntry>();
 }
Esempio n. 26
0
 public StringTable(HKey filePath, HKey directoryPath, Localization localization = Localization.English) : base(filePath, directoryPath)
 {
     _localization = localization;
     _strings      = new Dictionary <ulong, string>();
 }
Esempio n. 27
0
 public Audio(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
 }
Esempio n. 28
0
 internal static bool IsValidLocalization(HKey key) => LocalizationPair.Localizations.Count(x => x.HashValue == key.Key) != 0;
Esempio n. 29
0
 public Vox(HKey filePath, HKey directoryPath) : base(filePath, directoryPath)
 {
     Events = new List <VoxEntry>();
 }
Esempio n. 30
0
 internal static Localization GetLocalization(HKey key) => LocalizationPair.Localizations.FirstOrDefault(x => x.HashValue == key).EnumValue;