public void LoadPackage(string rootPath)
        {
            string fullRootPath = Path.GetFullPath(rootPath);
            string defDirectory = Path.Combine(rootPath, "packagedefs");

            // Loads PackageDef
            if (!Directory.Exists(fullRootPath) || !Directory.Exists(defDirectory))
            {
                return;
            }

            string[] packageRifs = Directory.GetFiles(defDirectory, "*.rif", SearchOption.AllDirectories);
            if (packageRifs.Length <= 0)
            {
                return;
            }

            foreach (string packageRif in packageRifs)
            {
                RiffFile   rif        = RiffFile.FromFile(packageRif);
                PackageDef newPackage = rif.Objects.FirstOrDefault(x => x is PackageDef) as PackageDef;
                if (newPackage == null)
                {
                    continue;
                }

                // Updates package path
                if (_packagePaths.ContainsKey(newPackage.FilePath))
                {
                    _packagePaths.Remove(newPackage.FilePath);
                }
                _packagePaths.Add(newPackage.FilePath, fullRootPath);

                CreateHKeys(newPackage.PackageName);
                newPackage.Entries.ForEach(x => CreateHKeys(x));

                // Adds package definition to collection
                _packageDefinitions.RemoveAll(x => x.Version == newPackage.Version);
                _packageDefinitions.Add(newPackage);
            }

            ReloadIndex(fullRootPath);
        }
        public static FEnvironment New(string directory, string packageName, int version)
        {
            FEnvironment env = new FEnvironment();

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (string.IsNullOrEmpty(packageName))
            {
                packageName = "bfforever";
            }

            Index2 index = new Index2($"packages.{packageName}.index2", $"packages.{packageName}")
            {
                Version = version
            };

            PackageDef def = new PackageDef($"PackageDefs.{packageName}.PackageDef", $"PackageDefs.{packageName}")
            {
                PackageName = packageName,
                Version     = version
            };

            Catalog2 cat = new Catalog2("catalog2", "catalog2");

            env.Index = index;
            env._packageDefinitions.Add(def);
            env._packagePaths.Add(def.FilePath, Path.GetFullPath(directory));

            env.AddZObjectAsPending(cat);
            env.UpdateIndexEntryAsPending(cat.FilePath, cat.Type, "catalog2.rif", env.Definition.FilePath);

            return(env);
        }
Exemple #3
0
        public static Chunk FromStream(AwesomeReader ar)
        {
            int chunkType = ar.ReadInt32(); // INDX or STbl or ZOBJ
            int chunkSize = ar.ReadInt32();

            long idx = 0; // Index key

            Chunk chunk;

            switch (chunkType)
            {
            case Constant.INDX:
                chunk = new Index();
                chunk.ImportData(ar);

                break;

            case Constant.STbl:
                idx   = ar.ReadInt64();   // Reads idx key
                chunk = new StringTable(idx);
                chunk.ImportData(ar);

                break;

            case Constant.ZOBJ:
                idx = ar.ReadInt64();     // Reads idx key
                FString directory = ar.ReadInt64();
                FString type      = ar.ReadInt64();
                ar.BaseStream.Position += 8;     // Skips zeros

                switch (type.Key)
                {
                case Constant.RIFF_Index2:
                    chunk = new Index2(idx);
                    break;

                case Constant.RIFF_PackageDef:
                    chunk = new PackageDef(idx);
                    break;

                case Constant.RIFF_Catalog2:
                    chunk = new Catalog2(idx);
                    break;

                case Constant.RIFF_Song:
                    chunk = new Song(idx);
                    break;

                case Constant.RIFF_Audio:
                    chunk = new Audio(idx);
                    break;

                case Constant.RIFF_Instrument:
                    chunk = new Instrument(idx);
                    break;

                case Constant.RIFF_Vox:
                    chunk = new Vox(idx);
                    break;

                case Constant.RIFF_VoxPushPhrase:
                    chunk = new VoxPushPhrase(idx);
                    break;

                case Constant.RIFF_Tempo:
                    chunk = new Tempo(idx);
                    break;

                case Constant.RIFF_Measure:
                    chunk = new Measure(idx);
                    break;

                case Constant.RIFF_TimeSignature:
                    chunk = new TimeSignature(idx);
                    break;

                case Constant.RIFF_Section:
                    chunk = new Section(idx);
                    break;

                case Constant.RIFF_Chord:
                    chunk = new Chord(idx);
                    break;

                case Constant.RIFF_AudioEffect:
                    chunk = new AudioEffect(idx);
                    break;

                case Constant.RIFF_Event:
                    chunk = new Event(idx);
                    break;

                case Constant.RIFF_Video:
                    chunk = new Video(idx);
                    break;

                case Constant.RIFF_Texture:
                    chunk = new Texture(idx);
                    break;

                case Constant.RIFF_Tab:
                    chunk = new Tab(idx);
                    break;

                case Constant.RIFF_UILocStrings:
                    chunk = new UILocStrings(idx);
                    break;

                case Constant.RIFF_TRCPromptGroup:
                    chunk = new TRCPromptGroup(idx);
                    break;

                default:
                    return(null);
                }
                ((ZObject)chunk).Directory = directory;
                chunk.ImportData(ar);

                break;

            default:
                return(null);
            }

            return(chunk);
        }