Ejemplo n.º 1
0
        public static void RemoveAll(ManagedMods mods)
        {
            LogFile.WriteLine("Removing all installed mods");

            // Delete bundled archives:
            DeployArchiveList deployArchives = new DeployArchiveList(mods.GamePath);

            foreach (DeployArchive deployArchive in deployArchives)
            {
                LogFile.WriteLine($"   Removing {deployArchive.ArchiveName}");
                if (File.Exists(deployArchive.GetArchivePath()))
                {
                    File.Delete(deployArchive.GetArchivePath());
                }
                mods.Resources.Remove(deployArchive.ArchiveName);
            }
            LogFile.WriteLine($"   Deleting temporary folders");
            deployArchives.DeleteTempFolder();

            // Remove mods:
            foreach (ManagedMod mod in mods)
            {
                LogFile.WriteLine($"   Removing mod {mod.Title}");
                ModDeployment.Remove(mod, mods.Resources, mods.GamePath);
            }

            mods.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used in the deployment chain to copy frozen bundled archives from FrozenData to Data.
        /// </summary>
        private static void CopyFrozenBundledArchives(ResourceList resources, DeployArchiveList archives)
        {
            LogFile.WriteLine($"      Copy frozen bundled archives...");

            // For each archive...
            foreach (DeployArchive archive in archives)
            {
                // ... if it had been frozen ...
                if (File.Exists(archive.GetFrozenArchivePath()))
                {
                    LogFile.WriteLine($"         Copying {archive.ArchiveName}");

                    // ... copy it into the Data folder ...
                    if (Configuration.bUseHardlinks)
                    {
                        Utils.CreateHardLink(archive.GetFrozenArchivePath(), archive.GetArchivePath(), true);
                    }
                    else
                    {
                        File.Copy(archive.GetFrozenArchivePath(), archive.GetArchivePath(), true);
                    }

                    // ... and add it to the resource list.
                    resources.Insert(0, archive.ArchiveName);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used in the deployment chain to deploy mods with the BundledBA2 method.
        /// </summary>
        private static void DeployBundledArchives(ManagedMods mods, bool freezeArchives = false, bool invalidateFrozenArchives = true)
        {
            LogFile.WriteLine($"   Installing BundledBA2 mods...");
            DeployArchiveList archives = new DeployArchiveList(mods.GamePath);

            // We want to use frozen archives but haven't invalidated them...
            // ... so just copy bundled archives if available:
            if (freezeArchives && !invalidateFrozenArchives)
            {
                CopyFrozenBundledArchives(mods.Resources, archives);
                return;
            }

            // Otherwise iterate over each enabled mod...
            foreach (ManagedMod mod in mods)
            {
                if (mod.Enabled && mod.Method == ManagedMod.DeploymentMethod.BundledBA2)
                {
                    LogFile.WriteLine($"      Copy files of mod '{mod.Title}' to temp folder...");

                    // ... copy it's files into temporary folders ...
                    CopyFilesToTempSorted(mod, archives);
                    mod.Deployed       = true;
                    mod.PreviousMethod = ManagedMod.DeploymentMethod.BundledBA2;
                }
            }

            // ... and pack those folders to archives.
            PackBundledArchives(mods.Resources, archives, freezeArchives);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Used in the deployment chain to copy individual files to a temporary folder.
        /// It sorts files into different temporary folders.
        /// Each temporary folder gets packed to a bundled *.ba2 archive.
        /// </summary>
        private static void CopyFilesToTempSorted(ManagedMod mod, DeployArchiveList archives)
        {
            // Iterate over each file in the managed folder:
            IEnumerable <string> files = Directory.EnumerateFiles(mod.ManagedFolderPath, "*.*", SearchOption.AllDirectories);

            foreach (string filePath in files)
            {
                FileInfo info          = new FileInfo(filePath);
                string   fileExtension = info.Extension.ToLower();

                // Make a relative path:
                string relativePath = Utils.MakeRelativePath(mod.ManagedFolderPath, filePath);

                // Determine the type of archive:
                string destinationPath;
                if (relativePath.Trim().ToLower().StartsWith("sound") || relativePath.Trim().ToLower().StartsWith("music") ||
                    (new string[] { ".wav", ".xwm", ".fuz", ".lip" }).Contains(fileExtension))
                {
                    archives.SoundsArchive.Count++;
                    destinationPath = Path.Combine(archives.SoundsArchive.TempPath, relativePath);
                }
                else if (fileExtension == ".dds")
                {
                    archives.TexturesArchive.Count++;
                    destinationPath = Path.Combine(archives.TexturesArchive.TempPath, relativePath);
                }
                else
                {
                    archives.GeneralArchive.Count++;
                    destinationPath = Path.Combine(archives.GeneralArchive.TempPath, relativePath);
                }

                // Copy the file to the correct temp folder:
                Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));

                if (Configuration.bUseHardlinks)
                {
                    Utils.CreateHardLink(filePath, destinationPath, true);
                }
                else
                {
                    File.Copy(filePath, destinationPath, true);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Used in the deployment chain to pack each bundled temporary folder to an archive.
        /// </summary>
        private static void PackBundledArchives(ResourceList resources, DeployArchiveList archives, bool freezeArchives)
        {
            // For each archive...
            foreach (DeployArchive archive in archives.Reverse())
            {
                // ... if needed ...
                if (archive.Count > 0 && !Utils.IsDirectoryEmpty(archive.TempPath))
                {
                    // ... pack the temporary folder to an archive ...
                    if (freezeArchives)
                    {
                        LogFile.WriteLine($"      Freezing archive '{archive.ArchiveName}'");

                        // either freeze to FrozenData and then copy to Data:
                        Archive2.Create(archive.GetFrozenArchivePath(), archive.TempPath, archive.Compression, archive.Format);

                        if (Configuration.bUseHardlinks)
                        {
                            Utils.CreateHardLink(archive.GetFrozenArchivePath(), archive.GetArchivePath(), true);
                        }
                        else
                        {
                            File.Copy(archive.GetFrozenArchivePath(), archive.GetArchivePath(), true);
                        }
                    }
                    else
                    {
                        LogFile.WriteLine($"      Creating archive '{archive.ArchiveName}'");

                        // or create directly in Data:
                        Archive2.Create(archive.GetArchivePath(), archive.TempPath, archive.Compression, archive.Format);
                    }

                    // ... and add it to the resource list.
                    resources.Insert(0, archive.ArchiveName);
                }
            }

            // Clean up after we're finished.
            LogFile.WriteLine($"      Deleting temporary folder...");
            archives.DeleteTempFolder();
        }