public static void Freeze(ManagedMod mod)
        {
            // TODO: Remove connection to ManagedMods
            // Only freeze if not already frozen:
            if (mod.Frozen && File.Exists(mod.FrozenArchivePath))
            {
                // TODO: ModActions.Freeze: Should the mod get "refrozen"?
                //ManagedMods.Instance.logFile.WriteLine($"Cannot freeze a mod ('{mod.Title}') that is already frozen.\n");
                return;
            }

            Directory.CreateDirectory(mod.FrozenDataPath);

            // Getting preset:
            Archive2.Preset preset = ModHelpers.GetArchive2Preset(mod);

            ModDeployment.LogFile.WriteLine($"      Freezing mod '{mod.Title}'...");
            ModDeployment.LogFile.WriteLine($"         Format:      {preset.format}");
            ModDeployment.LogFile.WriteLine($"         Compression: {preset.compression}");
            ModDeployment.LogFile.WriteLine($"         Destination: FrozenData\\{mod.FrozenArchiveName}");

            // Create archive:
            Archive2.Create(mod.FrozenArchivePath, mod.ManagedFolderPath, preset);

            // Change DiskState and save:
            mod.Frozen            = true;
            mod.FrozenCompression = mod.Compression;
            mod.FrozenFormat      = mod.Format;
        }
示例#2
0
        public static void Deploy(ManagedMods mods, Action <Progress> ProgressChanged, bool invalidateBundledFrozenArchives = true)
        {
            LogFile.WriteLine("\n\n");
            LogFile.WriteTimeStamp();
            LogFile.WriteLine($"Version {Shared.VERSION}, deploying...");
            LogFile.WriteLine($"Game path: {mods.GamePath}");

            // TODO: More descriptive ProgressChanged
            ProgressChanged?.Invoke(Progress.Indetermined("Deploying..."));

            // Check for conflicts:
            LogFile.WriteLine("Checking for conflicting archive names...");
            List <ModHelpers.Conflict> conflicts = ModHelpers.GetConflictingArchiveNames(mods.Mods);

            if (conflicts.Count > 0)
            {
                LogFile.WriteLine("Conflicts found, abort.");
                foreach (ModHelpers.Conflict conflict in conflicts)
                {
                    LogFile.WriteLine($"   Conflict: {conflict.conflictText}");
                }
                throw new DeploymentFailedException("Conflicting archive names.");
            }

            // Restore *.dll files:
            RestoreAddedDLLs(mods.GamePath);

            // Remove all currently deployed mods:
            ProgressChanged?.Invoke(Progress.Indetermined("Removing mods..."));
            ModDeployment.RemoveAll(mods);
            mods.Save();

            // If mods are enabled:
            if (!mods.ModsDisabled)
            {
                LogFile.WriteLine("Installing mods...");

                // Deploy all SeparateBA2 and Loose mods:
                foreach (ManagedMod mod in mods)
                {
                    ProgressChanged?.Invoke(Progress.Indetermined($"Deploying {mod.Title}..."));
                    if (mod.Enabled &&
                        Directory.Exists(mod.ManagedFolderPath) &&
                        !Utils.IsDirectoryEmpty(mod.ManagedFolderPath))
                    {
                        switch (mod.Method)
                        {
                        case ManagedMod.DeploymentMethod.SeparateBA2:
                            DeploySeparateArchive(mod, mods.Resources);
                            mods.Save();
                            break;

                        case ManagedMod.DeploymentMethod.LooseFiles:
                            DeployLooseFiles(mods, mod, mods.GamePath);
                            mods.Save();
                            break;
                        }
                    }
                }

                // Deploy all BundledBA2 mods:
                ProgressChanged?.Invoke(Progress.Indetermined($"Building bundled archives..."));
                ModDeployment.DeployBundledArchives(mods, IniFiles.Config.GetBool("Mods", "bFreezeBundledArchives", false), invalidateBundledFrozenArchives);

                mods.Save();
                ProgressChanged?.Invoke(Progress.Done("Mods deployed."));
            }
            else
            {
                ProgressChanged?.Invoke(Progress.Done("Mods removed."));
            }

            LogFile.WriteLine("Deployment finished.");
            LogFile.WriteLine($"Resource list ({mods.Resources.Count} files): \"{mods.Resources}\"");
        }
示例#3
0
        /// <summary>
        /// Used in the deployment chain to deploy a single mod with the SeparateBA2 method.
        /// Freezes a mod if necessary.
        /// </summary>
        private static void DeploySeparateArchive(ManagedMod mod, ResourceList resources)
        {
            LogFile.WriteLine($"   Installing mod '{mod.Title}' as SeparateBA2");

            // If mod is supposed to be deployed frozen...
            if (mod.Freeze)
            {
                // ... freeze if necessary ...
                if (!mod.Frozen)
                {
                    //LogFile.WriteLine($"      Freezing mod...");
                    ModActions.Freeze(mod);
                }

                LogFile.WriteLine($"      Copying frozen archive...");

                // ... and copy it to the Data folder.
                if (Configuration.bUseHardlinks)
                {
                    Utils.CreateHardLink(
                        mod.FrozenArchivePath,
                        mod.ArchivePath,
                        true);
                }
                else
                {
                    File.Copy(
                        mod.FrozenArchivePath,
                        mod.ArchivePath,
                        true);
                }
            }

            // If mod isn't supposed to be deployed frozen...
            else
            {
                // ... unfreeze mod if needed ...
                if (mod.Frozen)
                {
                    LogFile.WriteLine($"      Unfreezing mod...");
                    ModActions.Unfreeze(mod);
                }

                // Getting preset:
                Archive2.Preset preset = ModHelpers.GetArchive2Preset(mod);

                LogFile.WriteLine($"      Creating new archive...");
                LogFile.WriteLine($"         Format:      {preset.format}");
                LogFile.WriteLine($"         Compression: {preset.compression}");

                // ... and create a new archive.
                Archive2.Create(
                    mod.ArchivePath,
                    mod.ManagedFolderPath,
                    preset);
            }

            // Finally, update the disk state ...
            mod.CurrentArchiveName = mod.ArchiveName;
            mod.CurrentCompression = mod.Frozen ? mod.FrozenCompression : mod.Compression;
            mod.CurrentFormat      = mod.Frozen ? mod.FrozenFormat : mod.Format;
            mod.Deployed           = true;
            mod.PreviousMethod     = ManagedMod.DeploymentMethod.SeparateBA2;

            // ... and add the archive to the resource list.
            resources.Add(mod.ArchiveName);

            LogFile.WriteLine($"      Installed.");
        }