/// <summary> /// Creates a fomod from a source. /// </summary> /// <remarks> /// The source can be a folder or an archive. /// </remarks> /// <param name="p_strPath">The path to the source from which to create the fomod.</param> /// <param name="p_nxaNexus">An initialized website API from which to retireve mod info.</param> /// <returns>The path to the new fomod if it was successfully built; <lang cref="null"/> otherwise.</returns> public IList<string> BuildFomodFromSource(string p_strPath, NexusAPI p_nxaNexus) { string strSource = p_strPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); List<string> lstPackedFOModPaths = new List<string>(); bool booCreateFromFolder = true; if (File.Exists(strSource)) { booCreateFromFolder = false; if (!Archive.IsArchive(strSource)) throw new ArgumentException("Unrecognized file format.", "p_strPath"); string[] strFOMods = null; using (Archive arcMod = new Archive(strSource)) { strFOMods = arcMod.GetFiles(null, "*.fomod"); if ((strFOMods.Length == 0) && (arcMod.VolumeFileNames.Length > 1)) { if (MessageBox.Show("This mod consists of " + arcMod.VolumeFileNames.Length + " files. It needs to be extracted and repacked.", "Repack Required", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return lstPackedFOModPaths; booCreateFromFolder = true; } } if (!booCreateFromFolder) { if (strFOMods.Length > 0) { foreach (string strFOMod in strFOMods) { string strNewPath = Path.Combine(Program.GameMode.ModDirectory, Path.GetFileName(strFOMod)); if (CheckFileName(ref strNewPath)) { using (SevenZipExtractor szeExtractor = Archive.GetExtractor(strSource)) { using (FileStream fsmFOMod = new FileStream(strNewPath, FileMode.Create)) szeExtractor.ExtractFile(strFOMod, fsmFOMod); } lstPackedFOModPaths.Add(strNewPath); } } } else { fomod mof = new fomod(strSource, false); if (!mof.HasInstallScript && mof.RequiresScript) { if (MessageBox.Show("This mod requires a script to install properly, but doesn't have one." + Environment.NewLine + "Would you like to continue?", "Missing Script", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) return lstPackedFOModPaths; } //remove the file extension string strPackedFomodPath = Path.GetFileNameWithoutExtension(strSource); //remove the .part1 or what have for multipart files strPackedFomodPath = Path.GetFileNameWithoutExtension(strPackedFomodPath); strPackedFomodPath = Path.Combine(Program.GameMode.ModDirectory, strPackedFomodPath); if (!strPackedFomodPath.EndsWith(".fomod", StringComparison.OrdinalIgnoreCase)) strPackedFomodPath += ".fomod"; string strNewPath = strPackedFomodPath; if (CheckFileName(ref strNewPath)) { FileUtil.ForceDelete(strNewPath); if (MessageBox.Show("Make a copy of the original file?", "", MessageBoxButtons.YesNo) != DialogResult.Yes) File.Move(strSource, strNewPath); else File.Copy(strSource, strNewPath, true); lstPackedFOModPaths.Add(strNewPath); } } } } if (booCreateFromFolder) { string strFomodName = null; if (File.Exists(strSource)) { //remove the file extension strFomodName = Path.GetFileNameWithoutExtension(strSource); //remove the .part1 or what have for multipart files strFomodName = Path.GetFileNameWithoutExtension(strFomodName); } else { Int32 intLastSeparatorPos = strSource.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); strFomodName = strSource.Substring(intLastSeparatorPos + 1); } string strPackedFomodPath = Path.Combine(Program.GameMode.ModDirectory, strFomodName + ".fomod"); strPackedFomodPath = GenerateFomod(new BuildFomodArgs(strFomodName, strSource, null, strPackedFomodPath)); if (!String.IsNullOrEmpty(strPackedFomodPath)) lstPackedFOModPaths.Add(strPackedFomodPath); } ModInfo mifInfo = null; if (Properties.Settings.Default.addMissingInfoToMods) { mifInfo = p_nxaNexus.GetFileInfoGuessVersion(strSource, true); if (mifInfo != null) { foreach (string strFomod in lstPackedFOModPaths) { fomod fomodMod = new fomod(strFomod); fomodMod.SetMissingInfo(mifInfo); } } } return lstPackedFOModPaths; }
/// <summary> /// Logins into the websites. /// </summary> /// <remarks> /// If needed, credentials are gathered from the user. /// </remarks> private void WebsiteLogin() { if (!Properties.Settings.Default.checkForNewModVersionsInitialized) { string strMessage = "Would you like FOMM to check for new versions of your mods?" + Environment.NewLine + "This may require you to login to some mod sites. You can change this " + "setting in the Settings window."; switch (MessageBox.Show(this, strMessage, "Check For New Mods", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { case DialogResult.Yes: Properties.Settings.Default.checkForNewModVersions = true; break; case DialogResult.No: Properties.Settings.Default.checkForNewModVersions = false; break; } Properties.Settings.Default.checkForNewModVersionsInitialized = true; Properties.Settings.Default.Save(); } if (!Properties.Settings.Default.addMissingInfoToModsInitialized) { string strMessage = "Would you like FOMM to add missing information to newly added mods?" + Environment.NewLine + "This may require you to login to some mod sites. You can change this " + "setting in the Settings window."; switch (MessageBox.Show(this, strMessage, "Add Missing Mod Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { case DialogResult.Yes: Properties.Settings.Default.addMissingInfoToMods = true; break; case DialogResult.No: Properties.Settings.Default.addMissingInfoToMods = false; break; } Properties.Settings.Default.addMissingInfoToModsInitialized = true; Properties.Settings.Default.Save(); } if (Properties.Settings.Default.checkForNewModVersions || Properties.Settings.Default.addMissingInfoToMods) { if (Program.GameMode.HasNexusSite) { string strNexusLoginKey = Properties.Settings.Default.nexusLoginKey; if (String.IsNullOrEmpty(strNexusLoginKey)) { string strMessage = "You must log into the Nexus website."; LoginForm lgfLogin = new LoginForm(strMessage, Properties.Settings.Default.nexusUsername); while (lgfLogin.ShowDialog(this) != DialogResult.Cancel) { Properties.Settings.Default.nexusUsername = lgfLogin.Username; m_nxaNexus = new NexusAPI(Program.GameMode.NexusSite, lgfLogin.Username, lgfLogin.Password); if (!m_nxaNexus.Login()) { lgfLogin.ErrorMessage = "The given login information is invalid."; continue; } if (lgfLogin.StayLoggedIn) { strNexusLoginKey = m_nxaNexus.LoginKey; Properties.Settings.Default.nexusLoginKey = strNexusLoginKey; } Properties.Settings.Default.Save(); break; } return; } m_nxaNexus = new NexusAPI(Program.GameMode.NexusSite, strNexusLoginKey); } } }