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;
        }
        /// <summary>
        /// Converts ManagedMod.ArchiveCompression and ManagedMod.ArchiveFormat to an Archive2.Preset.
        /// Automatically determines appropriate compression and format if needed.
        /// </summary>
        public static Archive2.Preset GetArchive2Preset(String managedFolderPath, ManagedMod.ArchiveFormat format, ManagedMod.ArchiveCompression compression)
        {
            var preset = new Archive2.Preset();

            // No detection needed, "convert" ArchiveCompression to Archive2.Compression and ArchiveFormat to Archive2.Format:
            if (compression != ManagedMod.ArchiveCompression.Auto && format != ManagedMod.ArchiveFormat.Auto)
            {
                preset.compression = compression == ManagedMod.ArchiveCompression.Compressed ? Archive2.Compression.Default : Archive2.Compression.None;
                preset.format      = format == ManagedMod.ArchiveFormat.General ? Archive2.Format.General : Archive2.Format.DDS;

                return(preset);
            }

            // Detect mod type:

            int generalFoldersCount = 0;
            int textureFoldersCount = 0;
            int soundFoldersCount   = 0;

            IEnumerable <string> folders = Directory.EnumerateDirectories(managedFolderPath);

            foreach (string path in folders)
            {
                string folderName = Path.GetFileName(path).ToLower();

                if (GeneralFolders.Contains(folderName))
                {
                    generalFoldersCount++;
                }
                else if (TextureFolders.Contains(folderName))
                {
                    textureFoldersCount++;
                }
                else if (SoundFolders.Contains(folderName))
                {
                    soundFoldersCount++;
                }
            }

            if (soundFoldersCount > generalFoldersCount && soundFoldersCount > textureFoldersCount)
            {
                preset.compression = Archive2.Compression.None;
                preset.format      = Archive2.Format.General;
            }
            else if (textureFoldersCount > generalFoldersCount && textureFoldersCount > soundFoldersCount)
            {
                preset.compression = Archive2.Compression.Default;
                preset.format      = Archive2.Format.DDS;
            }
            else
            {
                preset.compression = Archive2.Compression.Default;
                preset.format      = Archive2.Format.General;
            }

            return(preset);
        }
Ejemplo n.º 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.");
        }
Ejemplo n.º 4
0
 public static void Create(String ba2Archive, String folder, Archive2.Preset preset)
 {
     Archive2.Create(ba2Archive, folder, preset.compression, preset.format);
 }