/// <summary> /// Creates a new mod from a folder. /// </summary> /// <param name="gamePath">Path to the game installation</param> /// <param name="folderPath">Path to folder</param> /// <returns></returns> private static ManagedMod FromFolder(string gamePath, string folderPath, Action <Progress> ProgressChanged = null) { // Get path information: folderPath = EnsureLongPathSupport(folderPath); string folderName = Path.GetFileName(folderPath); // Install mod: ManagedMod newMod = new ManagedMod(gamePath); newMod.Title = folderName; newMod.ArchiveName = folderName + ".ba2"; newMod.ManagedFolderName = folderName; if (!Utils.IsFileNameValid(newMod.ManagedFolderName) || Directory.Exists(newMod.ManagedFolderPath)) { newMod.ManagedFolderName = newMod.DefaultManagedFolderName; } // Copy folder: CopyDirectory(folderPath, newMod.ManagedFolderPath, ProgressChanged); ModActions.CleanUpFolder(newMod.ManagedFolderPath, ProgressChanged); ModActions.DetectOptimalModInstallationOptions(newMod); return(newMod); }
/// <summary> /// Creates a new mod from any supported archive. (zip, tar, rar, 7z, ba2) /// BA2 files can be installed frozen if needed. /// </summary> /// <param name="gamePath">Path to the game installation</param> /// <param name="filePath">Path to archive</param> /// <param name="useSourceBA2Archive">When false, creates a new "frozen" mod.</param> /// <returns></returns> private static ManagedMod FromArchive(string gamePath, string filePath, bool useSourceBA2Archive = false, Action <Progress> ProgressChanged = null) { // Get path information: string longFilePath = EnsureLongPathSupport(filePath); string fileNameWOEx = Path.GetFileNameWithoutExtension(longFilePath); string fileExtension = Path.GetExtension(longFilePath); // Install mod: ManagedMod newMod = new ManagedMod(gamePath); newMod.Title = fileNameWOEx; newMod.ArchiveName = fileNameWOEx + ".ba2"; newMod.ManagedFolderName = fileNameWOEx; if (!Utils.IsFileNameValid(newMod.ManagedFolderName) || Directory.Exists(newMod.ManagedFolderPath)) { newMod.ManagedFolderName = newMod.DefaultManagedFolderName; } // Extract mod: ProgressChanged?.Invoke(Progress.Indetermined($"Extracting {Path.GetFileName(filePath)}")); ModInstallations.ExtractArchive(longFilePath, newMod.ManagedFolderPath); // Freeze mod conditionally: if (useSourceBA2Archive && fileExtension == ".ba2") { // Copy *.ba2 into FrozenData: FileInfo frozenPath = new FileInfo(newMod.FrozenArchivePath); ProgressChanged?.Invoke(Progress.Indetermined($"Copying {Path.GetFileName(filePath)} to {frozenPath.DirectoryName}")); Directory.CreateDirectory(frozenPath.DirectoryName); File.Copy(longFilePath, frozenPath.FullName, true); newMod.Frozen = true; newMod.Freeze = true; newMod.PreviousMethod = ManagedMod.DeploymentMethod.SeparateBA2; newMod.Method = ManagedMod.DeploymentMethod.SeparateBA2; } else { ModActions.CleanUpFolder(newMod.ManagedFolderPath, ProgressChanged); ModActions.DetectOptimalModInstallationOptions(newMod); } return(newMod); }
/// <summary> /// Extracts the archive and then copy and replaces from the temp folder into the managed mod folder. /// </summary> public static void AddArchive(ManagedMod mod, string filePath, Action <Progress> ProgressChanged = null) { string longFilePath = EnsureLongPathSupport(filePath); string tempFolderPath = Path.Combine(Path.GetTempPath(), $"tmp_{mod.guid}"); if (Directory.Exists(tempFolderPath)) { Directory.Delete(tempFolderPath, true); } Directory.CreateDirectory(tempFolderPath); ProgressChanged?.Invoke(Progress.Indetermined($"Extracting {Path.GetFileName(filePath)}")); ModInstallations.ExtractArchive(longFilePath, tempFolderPath); ModActions.CleanUpFolder(tempFolderPath, ProgressChanged); CopyDirectory(tempFolderPath, mod.ManagedFolderPath, ProgressChanged); Directory.Delete(tempFolderPath, true); ProgressChanged?.Invoke(Progress.Done("Archive added to mod.")); }