Пример #1
0
        private void ReloadIndex(string rootPath)
        {
            string indexPath = Path.Combine(rootPath, "index2.rif");

            if (!File.Exists(indexPath))
            {
                return;
            }

            RiffFile rif      = RiffFile.FromFile(indexPath);
            Index2   newIndex = rif.Objects.FirstOrDefault(x => x is Index2) as Index2;

            if (newIndex == null)
            {
                return;
            }

            // Updates index2 object
            if (Index == null || newIndex.Version >= Index.Version)
            {
                Index = newIndex;

                // Creates directory paths for entries
                foreach (Index2Entry entry in Index.Entries)
                {
                    entry.FilePath.GetParentDirectory();
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        private bool LoadRiffFile(string path, Index2PackageEntry packageEntry)
        {
            RiffFile rif = RiffFile.FromFile(path);

            if (rif == null)
            {
                return(false);
            }

            _tempObjects.Clear();
            _tempObjectsPackageEntry = packageEntry;

            // Loads all zobjects from riff file
            foreach (ZObject obj in rif.Objects.Where(x => !(x is StringTable)))
            {
                CreateStringTablePaths(obj.DirectoryPath); // Creates string table path
                _tempObjects.Add(obj);
            }

            return(true);
        }
Пример #4
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();
        }