/// <summary> /// A simple constructor that initializes the object with its dependencies. /// </summary> /// <param name="p_ModManager">The current ModManager.</param> /// <param name="p_lstMods">The mod list.</param> /// <param name="p_intNewValue">The new category id.</param> public AutomaticDownloadTask(List <string> p_lstMissingMods, ModManager p_mmModManager, ProfileManager p_pmProfileManager, ConfirmOverwriteCallback p_cocConfirmOverwrite) { MissingMods = new ThreadSafeObservableList <string>(p_lstMissingMods); ModManager = p_mmModManager; ProfileManager = p_pmProfileManager; ConfirmOverwriteCallback = p_cocConfirmOverwrite; }
public IBackgroundTask AsyncAddMod(Uri p_uriPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { IBackgroundTask tskAddModTask = ModAdditionQueue.AddMod(p_uriPath, p_cocConfirmOverwrite); AsyncAddModTask(tskAddModTask); return(tskAddModTask); }
/// <summary> /// A wrapper method for calls to <see cref="ConfirmOverwriteCallback"/> delegates. /// </summary> /// <remarks> /// This wrapper encapsulates delaing with the different return values the delegate can produce. /// </remarks> /// <param name="p_dlgConfirmOverwrite">The <see cref="ConfirmOverwriteCallback"/> delegate to call.</param> /// <param name="p_strDestinationPath">The path to use as a parameter for the call.</param> /// <returns>The new filename to use for the overwrite, or <c>null</c> if the overwrite /// should not be done.</returns> private string ConfirmOverwrite(ConfirmOverwriteCallback p_dlgConfirmOverwrite, string p_strDestinationPath) { string strDest = p_strDestinationPath; if (p_dlgConfirmOverwrite(strDest, out strDest)) { return(strDest); } return(null); }
/// <summary> /// Adds the specified mod to the queue. /// </summary> /// <remarks> /// The specified mod is downloaded, and then added to the mod manager. /// </remarks> /// <param name="p_uriPath">The URL of the mod to add to the manager.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> public IBackgroundTask AddMod(Uri p_uriPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { AddModTask amtModAdder = null; if (p_uriPath.Scheme.ToLowerInvariant().ToString() == "nxm") { if (m_dicActiveTasks.ContainsKey(p_uriPath)) { return(m_dicActiveTasks[p_uriPath]); } Trace.TraceInformation(String.Format("[{0}] Adding Mod to AddModQueue", p_uriPath.ToString())); amtModAdder = new AddModTask(m_mmgModManager.GameMode, m_mmgModManager.ReadMeManager, m_mmgModManager.EnvironmentInfo, m_mmgModManager.ManagedModRegistry, m_mmgModManager.FormatRegistry, m_mmgModManager.ModRepository, p_uriPath, p_cocConfirmOverwrite); amtModAdder.TaskEnded += new EventHandler <TaskEndedEventArgs>(ModAdder_TaskEnded); amtModAdder.IsRemote = true; m_dicActiveTasks[p_uriPath] = amtModAdder; m_mmgModManager.DownloadMonitor.AddActivity(amtModAdder); amtModAdder.AddMod(false); } else { if (m_dicActiveTasks.ContainsKey(p_uriPath)) { return(m_dicActiveTasks[p_uriPath]); } Trace.TraceInformation(String.Format("[{0}] Adding Mod to AddModQueue", p_uriPath.ToString())); amtModAdder = new AddModTask(m_mmgModManager.GameMode, m_mmgModManager.ReadMeManager, m_mmgModManager.EnvironmentInfo, m_mmgModManager.ManagedModRegistry, m_mmgModManager.FormatRegistry, m_mmgModManager.ModRepository, p_uriPath, p_cocConfirmOverwrite); amtModAdder.TaskEnded += new EventHandler <TaskEndedEventArgs>(ModAdder_TaskEnded); amtModAdder.IsRemote = false; m_dicActiveTasks[p_uriPath] = amtModAdder; m_mmgModManager.DownloadMonitor.AddActivity(amtModAdder); if (LocalTaskCount > 1) { amtModAdder.AddMod(true); } else { amtModAdder.AddMod(false); } } return(amtModAdder); }
/// <summary> /// Installs the specified mod. /// </summary> /// <param name="p_strPath">The path to the mod to install.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <returns>A background task set allowing the caller to track the progress of the operation.</returns> public IBackgroundTask AddMod(string p_strPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { Uri uriPath = new Uri(p_strPath); if (uriPath.Scheme.ToLowerInvariant().ToString() == "nxm") { if (!ModRepository.IsOffline) { return(ModAdditionQueue.AddMod(uriPath, p_cocConfirmOverwrite)); } else { Login(); return(AsyncAddMod(uriPath, p_cocConfirmOverwrite)); } } else { return(ModAdditionQueue.AddMod(uriPath, p_cocConfirmOverwrite)); } }
/// <summary> /// Starts the Automatic Download. /// </summary> /// <param name="p_strPath">The path to the mod to install.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <returns>A background task set allowing the caller to track the progress of the operation.</returns> public void AsyncAutomaticDownload(List <string> p_strMissingMods, ProfileManager p_pmProfileManager, ConfirmActionMethod p_camConfirm, ConfirmOverwriteCallback p_cocConfirmOverwrite) { AutomaticDownloadTask adtAutomaticDownload = new AutomaticDownloadTask(p_strMissingMods, this, p_pmProfileManager, p_cocConfirmOverwrite); AsyncAutomaticDownloadTask(adtAutomaticDownload, p_camConfirm); }
/// <summary> /// Starts the Automatic Download. /// </summary> /// <param name="p_strPath">The path to the mod to install.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <returns>A background task set allowing the caller to track the progress of the operation.</returns> public IBackgroundTask AutomaticDownload(List <string> p_strMissingMods, ProfileManager p_pmProfileManager, ConfirmActionMethod p_camConfirm, ConfirmOverwriteCallback p_cocConfirmOverwrite) { AutomaticDownloadTask amtProfileAdder = new AutomaticDownloadTask(p_strMissingMods, this, p_pmProfileManager, p_cocConfirmOverwrite); amtProfileAdder.Update(p_camConfirm); return(amtProfileAdder); }
public IBackgroundTask AsyncAddMod(Uri p_uriPath,ConfirmOverwriteCallback p_cocConfirmOverwrite) { IBackgroundTask tskAddModTask = ModAdditionQueue.AddMod(p_uriPath, p_cocConfirmOverwrite); AsyncAddModTask(tskAddModTask); return tskAddModTask; }
/// <summary> /// Installs the specified mod. /// </summary> /// <param name="p_strPath">The path to the mod to install.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <returns>A background task set allowing the caller to track the progress of the operation.</returns> public IBackgroundTask AddMod(string p_strPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { Uri uriPath = new Uri(p_strPath); if (uriPath.Scheme.ToLowerInvariant().ToString() == "nxm") { if (!ModRepository.IsOffline) { return ModAdditionQueue.AddMod(uriPath, p_cocConfirmOverwrite); } else { Login(); return AsyncAddMod(uriPath, p_cocConfirmOverwrite); } } else { return ModAdditionQueue.AddMod(uriPath, p_cocConfirmOverwrite); } }
/// <summary> /// Builds mods from an archive. /// </summary> /// <remarks> /// If the specified archive contains mods, they are simply extracted. Otherwise, the archive /// is examined to determine if it is already in a recognized format. If not, or if the archive /// spans multiple volumes, then the archive is repackaged. /// </remarks> /// <param name="p_mfrFormats">The registry of supported mod formats.</param> /// <param name="p_strArchivePath">The archive to build into a mod.</param> /// <param name="p_dlgConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <param name="p_strMessage">The message describing the state of the task.</param> /// <returns>The paths to the new mods.</returns> /// <exception cref="ArgumentException">Thrown if the specified path is not an archive.</exception> private IList<string> DoFromArchive(IModFormatRegistry p_mfrFormats, string p_strArchivePath, ConfirmOverwriteCallback p_dlgConfirmOverwrite, out string p_strMessage) { p_strMessage = null; Trace.TraceInformation(String.Format("[{0}] Adding mod from archive.", p_strArchivePath)); if (String.IsNullOrEmpty(p_strArchivePath) || !File.Exists(p_strArchivePath) || !Archive.IsArchive(p_strArchivePath)) throw new ArgumentException("The specified path is not an archive file.", "p_strArchivePath"); List<string> lstFoundMods = new List<string>(); List<string> lstModsInArchive = new List<string>(); ItemMessage = "Examining archive..."; ItemProgress = 0; ItemProgressMaximum = p_mfrFormats.Formats.Count; IModFormat mftDestFormat = null; try { using (SevenZipExtractor szeExtractor = Archive.GetExtractor(p_strArchivePath)) { if (Status == TaskStatus.Cancelling) return lstFoundMods; ReadOnlyCollection<string> lstArchiveFiles = szeExtractor.ArchiveFileNames; foreach (IModFormat mftFormat in p_mfrFormats.Formats) { ItemMessage = String.Format("Examining archive for {0} mods...", mftFormat.Name); lstModsInArchive.AddRange(lstArchiveFiles.Where(x => mftFormat.Extension.Equals(Path.GetExtension(x), StringComparison.OrdinalIgnoreCase))); StepItemProgress(); if (Status == TaskStatus.Cancelling) return lstFoundMods; } StepOverallProgress(); } if (lstModsInArchive.Count == 0) { ItemMessage = "Determining archive format..."; ItemProgress = 0; ItemProgressMaximum = p_mfrFormats.Formats.Count; List<KeyValuePair<FormatConfidence, IModFormat>> lstFormats = new List<KeyValuePair<FormatConfidence, IModFormat>>(); foreach (IModFormat mftFormat in p_mfrFormats.Formats) { lstFormats.Add(new KeyValuePair<FormatConfidence, IModFormat>(mftFormat.CheckFormatCompliance(p_strArchivePath), mftFormat)); StepItemProgress(); if (Status == TaskStatus.Cancelling) return lstFoundMods; } lstFormats.Sort((x, y) => y.Key.CompareTo(x.Key)); if ((lstFormats.Count == 0) || (lstFormats[0].Key <= FormatConfidence.Convertible)) return lstFoundMods; mftDestFormat = lstFormats[0].Value; } StepOverallProgress(); } catch (Exception ex) { MessageBox.Show("An error has occured with the following archive: " + p_strArchivePath + "\n\n ERROR: " + ex.Message); return lstFoundMods; } string strTmpPath = null; try { using (SevenZipExtractor szeExtractor = Archive.GetExtractor(p_strArchivePath)) { if ((mftDestFormat != null) && (szeExtractor.VolumeFileNames.Count > 1) || (lstModsInArchive.Count > 0)) { ItemMessage = "Extracting archive..."; ItemProgress = 0; ItemProgressMaximum = szeExtractor.ArchiveFileNames.Count; strTmpPath = FileUtility.CreateTempDirectory(); szeExtractor.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(Extractor_FileExtractionStarted); szeExtractor.FileExtractionFinished += new EventHandler<FileInfoEventArgs>(Extractor_FileExtractionFinished); try { szeExtractor.ExtractArchive(strTmpPath); } catch (FileNotFoundException ex) { Status = TaskStatus.Error; p_strMessage = ex.Message; return lstFoundMods; } for (Int32 i = 0; i < lstModsInArchive.Count; i++) lstModsInArchive[i] = Path.Combine(strTmpPath, lstModsInArchive[i]); } else lstModsInArchive.Add(p_strArchivePath); } StepOverallProgress(); if (!String.IsNullOrEmpty(strTmpPath) && (mftDestFormat != null)) { //if we have extracted the file to do format shifting if (!mftDestFormat.SupportsModCompression) return lstFoundMods; ItemMessage = "Compressing mod..."; ItemProgress = 0; ItemProgressMaximum = Directory.GetFiles(strTmpPath, "*", SearchOption.AllDirectories).Length; IModCompressor mcpCompressor = mftDestFormat.GetModCompressor(EnvironmentInfo); mcpCompressor.FileCompressionFinished += new CancelEventHandler(Compressor_FileCompressionFinished); string strDest = Path.Combine(GameModeInfo.ModDirectory, Path.GetFileName(p_strArchivePath)); strDest = Path.ChangeExtension(strDest, mftDestFormat.Extension); strDest = ConfirmOverwrite(p_dlgConfirmOverwrite, strDest); if (!String.IsNullOrEmpty(strDest)) { mcpCompressor.Compress(strTmpPath, strDest); lstFoundMods.Add(strDest); } } else { ItemMessage = "Copying mods..."; ItemProgress = 0; ItemProgressMaximum = lstModsInArchive.Count; foreach (string strMod in lstModsInArchive) { if (Status == TaskStatus.Cancelling) return lstFoundMods; ItemMessage = String.Format("Copying mod {0}...", Path.GetFileName(strMod)); string strDest = Path.Combine(GameModeInfo.ModDirectory, Path.GetFileName(strMod)); strDest = ConfirmOverwrite(p_dlgConfirmOverwrite, strDest); if (!String.IsNullOrEmpty(strDest)) { File.Copy(strMod, strDest, true); lstFoundMods.Add(strDest); } StepItemProgress(); } } StepOverallProgress(); } finally { if (!String.IsNullOrEmpty(strTmpPath)) FileUtil.ForceDelete(strTmpPath); } return lstFoundMods; }
/// <summary> /// Builds mods from an archive. /// </summary> /// <remarks> /// If the specified archive contains mods, they are simply extracted. Otherwise, the archive /// is examined to determine if it is already in a recognized format. If not, or if the archive /// spans multiple volumes, then the archive is repackaged. /// </remarks> /// <param name="p_mfrFormats">The registry of supported mod formats.</param> /// <param name="p_strArchivePath">The archive to build into a mod.</param> /// <param name="p_dlgConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <param name="p_strMessage">The message describing the state of the task.</param> /// <returns>The paths to the new mods.</returns> /// <exception cref="ArgumentException">Thrown if the specified path is not an archive.</exception> private IList <string> DoFromArchive(IModFormatRegistry p_mfrFormats, string p_strArchivePath, ConfirmOverwriteCallback p_dlgConfirmOverwrite, out string p_strMessage) { p_strMessage = null; Trace.TraceInformation(String.Format("[{0}] Adding mod from archive.", p_strArchivePath)); if (String.IsNullOrEmpty(p_strArchivePath) || !File.Exists(p_strArchivePath) || !Archive.IsArchive(p_strArchivePath)) { throw new ArgumentException("The specified path is not an archive file.", "p_strArchivePath"); } List <string> lstFoundMods = new List <string>(); List <string> lstModsInArchive = new List <string>(); ItemMessage = "Examining archive..."; ItemProgress = 0; ItemProgressMaximum = p_mfrFormats.Formats.Count; IModFormat mftDestFormat = null; try { using (SevenZipExtractor szeExtractor = Archive.GetExtractor(p_strArchivePath)) { if (Status == TaskStatus.Cancelling) { return(lstFoundMods); } ReadOnlyCollection <string> lstArchiveFiles = szeExtractor.ArchiveFileNames; foreach (IModFormat mftFormat in p_mfrFormats.Formats) { ItemMessage = String.Format("Examining archive for {0} mods...", mftFormat.Name); lstModsInArchive.AddRange(lstArchiveFiles.Where(x => mftFormat.Extension.Equals(Path.GetExtension(x), StringComparison.OrdinalIgnoreCase))); StepItemProgress(); if (Status == TaskStatus.Cancelling) { return(lstFoundMods); } } StepOverallProgress(); } if (lstModsInArchive.Count == 0) { ItemMessage = "Determining archive format..."; ItemProgress = 0; ItemProgressMaximum = p_mfrFormats.Formats.Count; List <KeyValuePair <FormatConfidence, IModFormat> > lstFormats = new List <KeyValuePair <FormatConfidence, IModFormat> >(); foreach (IModFormat mftFormat in p_mfrFormats.Formats) { lstFormats.Add(new KeyValuePair <FormatConfidence, IModFormat>(mftFormat.CheckFormatCompliance(p_strArchivePath), mftFormat)); StepItemProgress(); if (Status == TaskStatus.Cancelling) { return(lstFoundMods); } } lstFormats.Sort((x, y) => y.Key.CompareTo(x.Key)); if ((lstFormats.Count == 0) || (lstFormats[0].Key <= FormatConfidence.Convertible)) { return(lstFoundMods); } mftDestFormat = lstFormats[0].Value; } StepOverallProgress(); } catch (Exception ex) { MessageBox.Show("An error has occured with the following archive: " + p_strArchivePath + "\n\n ERROR: " + ex.Message); return(lstFoundMods); } string strTmpPath = null; try { using (SevenZipExtractor szeExtractor = Archive.GetExtractor(p_strArchivePath)) { if ((mftDestFormat != null) && (szeExtractor.VolumeFileNames.Count > 1) || (lstModsInArchive.Count > 0)) { ItemMessage = "Extracting archive..."; ItemProgress = 0; ItemProgressMaximum = szeExtractor.ArchiveFileNames.Count; strTmpPath = FileUtility.CreateTempDirectory(); szeExtractor.FileExtractionStarted += new EventHandler <FileInfoEventArgs>(Extractor_FileExtractionStarted); szeExtractor.FileExtractionFinished += new EventHandler <FileInfoEventArgs>(Extractor_FileExtractionFinished); try { szeExtractor.ExtractArchive(strTmpPath); } catch (FileNotFoundException ex) { Status = TaskStatus.Error; p_strMessage = ex.Message; return(lstFoundMods); } for (Int32 i = 0; i < lstModsInArchive.Count; i++) { lstModsInArchive[i] = Path.Combine(strTmpPath, lstModsInArchive[i]); } } else { lstModsInArchive.Add(p_strArchivePath); } } StepOverallProgress(); if (!String.IsNullOrEmpty(strTmpPath) && (mftDestFormat != null)) { //if we have extracted the file to do format shifting if (!mftDestFormat.SupportsModCompression) { return(lstFoundMods); } ItemMessage = "Compressing mod..."; ItemProgress = 0; ItemProgressMaximum = Directory.GetFiles(strTmpPath, "*", SearchOption.AllDirectories).Length; IModCompressor mcpCompressor = mftDestFormat.GetModCompressor(EnvironmentInfo); mcpCompressor.FileCompressionFinished += new CancelEventHandler(Compressor_FileCompressionFinished); string strDest = Path.Combine(GameModeInfo.ModDirectory, Path.GetFileName(p_strArchivePath)); strDest = Path.ChangeExtension(strDest, mftDestFormat.Extension); strDest = ConfirmOverwrite(p_dlgConfirmOverwrite, strDest); if (!String.IsNullOrEmpty(strDest)) { mcpCompressor.Compress(strTmpPath, strDest); lstFoundMods.Add(strDest); } } else { ItemMessage = "Copying mods..."; ItemProgress = 0; ItemProgressMaximum = lstModsInArchive.Count; foreach (string strMod in lstModsInArchive) { if (Status == TaskStatus.Cancelling) { return(lstFoundMods); } ItemMessage = String.Format("Copying mod {0}...", Path.GetFileName(strMod)); string strDest = Path.Combine(GameModeInfo.ModDirectory, Path.GetFileName(strMod)); strDest = ConfirmOverwrite(p_dlgConfirmOverwrite, strDest); if (!String.IsNullOrEmpty(strDest)) { if (string.Equals(strMod, strDest, StringComparison.OrdinalIgnoreCase)) { throw new FileNotFoundException("You can't add a mod directly from the NMM Mods folder, please move it somewhere else before adding it to the manager!"); } File.Copy(strMod, strDest, true); lstFoundMods.Add(strDest); } StepItemProgress(); } } StepOverallProgress(); } catch (FileNotFoundException ex) { MessageBox.Show("Archive: " + p_strArchivePath + "\n\n ERROR: " + ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(lstFoundMods); } finally { if (!String.IsNullOrEmpty(strTmpPath)) { FileUtil.ForceDelete(strTmpPath); } } return(lstFoundMods); }
/// <summary> /// Builds mods from a file. /// </summary> /// <remarks> /// This detects the type of file and takes appropriate action. /// </remarks> /// <param name="p_mfrFormats">The registry of supported mod formats.</param> /// <param name="p_strFilePath">The archive to build into a mod.</param> /// <param name="p_dlgConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <exception cref="ArgumentException">Thrown if the specified path is not an archive.</exception> public void BuildFromFile(IModFormatRegistry p_mfrFormats, string p_strFilePath, ConfirmOverwriteCallback p_dlgConfirmOverwrite) { ShowItemProgress = true; OverallProgressStepSize = 1; ItemProgressStepSize = 1; OverallProgressMaximum = 4; OverallMessage = "Building Mod..."; Sources srcModSource = Sources.Archive; if (String.IsNullOrEmpty(p_strFilePath) || !File.Exists(p_strFilePath)) { throw new ArgumentException("The given file path does not exist: " + p_strFilePath); } if (!Archive.IsArchive(p_strFilePath)) { Status = TaskStatus.Error; OnTaskEnded(String.Format("Cannot add {0}. File format is not recognized.", Path.GetFileName(p_strFilePath)), null); return; } Start(srcModSource, p_mfrFormats, p_strFilePath, p_dlgConfirmOverwrite); }
/// <summary> /// A wrapper method for calls to <see cref="ConfirmOverwriteCallback"/> delegates. /// </summary> /// <remarks> /// This wrapper encapsulates delaing with the different return values the delegate can produce. /// </remarks> /// <param name="p_dlgConfirmOverwrite">The <see cref="ConfirmOverwriteCallback"/> delegate to call.</param> /// <param name="p_strDestinationPath">The path to use as a parameter for the call.</param> /// <returns>The new filename to use for the overwrite, or <c>null</c> if the overwrite /// should not be done.</returns> private string ConfirmOverwrite(ConfirmOverwriteCallback p_dlgConfirmOverwrite, string p_strDestinationPath) { string strDest = p_strDestinationPath; if (p_dlgConfirmOverwrite(strDest, out strDest)) return strDest; return null; }
/// <summary> /// A simple constructor that initializes the object with the given values. /// </summary> /// <param name="p_gmdGameMode">The game mode for which mods are being managed.</param> /// <param name="p_rmmReadMeManager">The ReadMe Manager info.</param> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list of managed <see cref="IMod"/>s.</param> /// <param name="p_frgFormatRegistry">The <see cref="IModFormatRegistry"/> that contains the list /// of supported <see cref="IModFormat"/>s.</param> /// <param name="p_mrpModRepository">The mod repository from which to get mods and mod metadata.</param> /// <param name="p_uriPath">The path to the mod to add.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> public AddModTask(IGameMode p_gmdGameMode, ReadMeManager p_rmmReadMeManager, IEnvironmentInfo p_eifEnvironmentInfo, ModRegistry p_mrgModRegistry, IModFormatRegistry p_frgFormatRegistry, IModRepository p_mrpModRepository, Uri p_uriPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { m_gmdGameMode = p_gmdGameMode; m_eifEnvironmentInfo = p_eifEnvironmentInfo; m_mrgModRegistry = p_mrgModRegistry; m_mfrModFormatRegistry = p_frgFormatRegistry; m_mrpModRepository = p_mrpModRepository; m_uriPath = p_uriPath; m_cocConfirmOverwrite = p_cocConfirmOverwrite; m_rmmReadMeManager = p_rmmReadMeManager; m_intLocalID = m_intCounter++; }
/// <summary> /// Adds the specified mod to the queue. /// </summary> /// <remarks> /// The specified mod is downloaded, and then added to the mod manager. /// </remarks> /// <param name="p_uriPath">The URL of the mod to add to the manager.</param> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> public IBackgroundTask AddMod(Uri p_uriPath, ConfirmOverwriteCallback p_cocConfirmOverwrite) { AddModTask amtModAdder = null; if (p_uriPath.Scheme.ToLowerInvariant().ToString() == "nxm") { if (m_dicActiveTasks.ContainsKey(p_uriPath)) return m_dicActiveTasks[p_uriPath]; Trace.TraceInformation(String.Format("[{0}] Adding Mod to AddModQueue", p_uriPath.ToString())); amtModAdder = new AddModTask(m_mmgModManager.GameMode, m_mmgModManager.ReadMeManager, m_mmgModManager.EnvironmentInfo, m_mmgModManager.ManagedModRegistry, m_mmgModManager.FormatRegistry, m_mmgModManager.ModRepository, p_uriPath, p_cocConfirmOverwrite); amtModAdder.TaskEnded += new EventHandler<TaskEndedEventArgs>(ModAdder_TaskEnded); amtModAdder.IsRemote = true; m_dicActiveTasks[p_uriPath] = amtModAdder; m_mmgModManager.DownloadMonitor.AddActivity(amtModAdder); amtModAdder.AddMod(false); } else { if (m_dicActiveTasks.ContainsKey(p_uriPath)) return m_dicActiveTasks[p_uriPath]; Trace.TraceInformation(String.Format("[{0}] Adding Mod to AddModQueue", p_uriPath.ToString())); amtModAdder = new AddModTask(m_mmgModManager.GameMode, m_mmgModManager.ReadMeManager, m_mmgModManager.EnvironmentInfo, m_mmgModManager.ManagedModRegistry, m_mmgModManager.FormatRegistry, m_mmgModManager.ModRepository, p_uriPath, p_cocConfirmOverwrite); amtModAdder.TaskEnded += new EventHandler<TaskEndedEventArgs>(ModAdder_TaskEnded); amtModAdder.IsRemote = false; m_dicActiveTasks[p_uriPath] = amtModAdder; m_mmgModManager.DownloadMonitor.AddActivity(amtModAdder); if (LocalTaskCount > 1) amtModAdder.AddMod(true); else amtModAdder.AddMod(false); } return amtModAdder; }
/// <summary> /// Adds the mod file to the mod manager. /// </summary> /// <param name="p_cocConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> protected void AddModFile(ConfirmOverwriteCallback p_cocConfirmOverwrite) { string strPath = String.IsNullOrEmpty(Descriptor.SourcePath) ? Descriptor.DefaultSourcePath : Descriptor.SourcePath; string strDestinationHD = String.Empty; m_booFinishedDownloads = true; FileAttributes faAttributes = new FileAttributes(); try { faAttributes = File.GetAttributes(strPath); } catch (DirectoryNotFoundException) { OverallMessage = String.Format("Could not find a part of the path: {0}", strPath); ItemMessage = "Path error"; Status = TaskStatus.Error; OnTaskEnded(OverallMessage, null); } FileInfo fiArchive = new FileInfo(strPath); long lngDestinationFreeSpace = fiArchive.Length; if (Path.GetPathRoot(m_gmdGameMode.GameModeEnvironmentInfo.ModDirectory) != Path.DirectorySeparatorChar.ToString()) { DriveInfo diDestinationHD = new DriveInfo(Path.GetPathRoot(m_gmdGameMode.GameModeEnvironmentInfo.ModDirectory)); lngDestinationFreeSpace = diDestinationHD.TotalFreeSpace; strDestinationHD = diDestinationHD.Name; } if (lngDestinationFreeSpace < fiArchive.Length) { OverallMessage = String.Format("Not enough free space on your HD: {0}", strDestinationHD); ItemMessage = "Not enough free space on your HD."; Status = TaskStatus.Error; OnTaskEnded(OverallMessage, null); } else if (faAttributes.ToString().IndexOf(FileAttributes.ReadOnly.ToString()) > -1) { OverallMessage = String.Format("The archive is read only: {0}", strPath); ItemMessage = "The archive is read only"; Status = TaskStatus.Error; OnTaskEnded(OverallMessage, null); } else if (!File.Exists(strPath)) { OverallMessage = String.Format("File does not exist: {0}", strPath); ItemMessage = "File does not exist"; Status = TaskStatus.Error; OnTaskEnded(OverallMessage, null); } else { ModBuilder mbrModBuilder = new ModBuilder(m_gmdGameMode.GameModeEnvironmentInfo, m_eifEnvironmentInfo, new NexusFileUtil(m_eifEnvironmentInfo)); mbrModBuilder.PropertyChanged += new PropertyChangedEventHandler(ModBuilder_PropertyChanged); mbrModBuilder.TaskEnded += new EventHandler<TaskEndedEventArgs>(ModBuilder_TaskEnded); mbrModBuilder.BuildFromFile(m_mfrModFormatRegistry, strPath, p_cocConfirmOverwrite); m_lstRunningTasks.Add(mbrModBuilder); } }
/// <summary> /// Builds mods from a file. /// </summary> /// <remarks> /// This detects the type of file and takes appropriate action. /// </remarks> /// <param name="p_mfrFormats">The registry of supported mod formats.</param> /// <param name="p_strFilePath">The archive to build into a mod.</param> /// <param name="p_dlgConfirmOverwrite">The delegate to call to resolve conflicts with existing files.</param> /// <exception cref="ArgumentException">Thrown if the specified path is not an archive.</exception> public void BuildFromFile(IModFormatRegistry p_mfrFormats, string p_strFilePath, ConfirmOverwriteCallback p_dlgConfirmOverwrite) { ShowItemProgress = true; OverallProgressStepSize = 1; ItemProgressStepSize = 1; OverallProgressMaximum = 4; OverallMessage = "Building Mod..."; Sources srcModSource = Sources.Archive; if (String.IsNullOrEmpty(p_strFilePath) || !File.Exists(p_strFilePath)) throw new ArgumentException("The given file path does not exist: " + p_strFilePath); if (!Archive.IsArchive(p_strFilePath)) { Status = TaskStatus.Error; OnTaskEnded(String.Format("Cannot add {0}. File format is not recognized.", Path.GetFileName(p_strFilePath)), null); return; } Start(srcModSource, p_mfrFormats, p_strFilePath, p_dlgConfirmOverwrite); }