/// <summary> /// Compares the given <see cref="ListViewItem"/>s representing <see cref="InstallableFile"/>s. /// </summary> /// <remarks> /// The underlying <see cref="InstallableFile"/>s are compared. /// </remarks> /// <param name="x">An object to compare to another object.</param> /// <param name="y">An object to compare to another object.</param> /// <returns>A value less than 0 if <paramref name="x"/> is less than <paramref name="y"/>. /// 0 if this node is equal to the other. /// A value greater than 0 if <paramref name="x"/> is greater than <paramref name="y"/>.</returns> public int Compare(object x, object y) { InstallableFile iflX = (InstallableFile)((ListViewItem)x).Tag; InstallableFile iflY = (InstallableFile)((ListViewItem)y).Tag; return(iflX.Priority.CompareTo(iflY.Priority)); }
/// <summary> /// Adds the given <see cref="InstallableFile"/> to the list view. /// </summary> /// <param name="p_iflFile">The <see cref="InstallableFile"/> to add to the list view.</param> protected void AddInstallableFile(InstallableFile p_iflFile) { ListViewItem lviFile = new ListViewItem(p_iflFile.Source); lviFile.SubItems[0].Name = "Source"; lviFile.SubItems.Add(p_iflFile.Destination); lviFile.SubItems[1].Name = "Destination"; lviFile.SubItems.Add(p_iflFile.Priority.ToString()); lviFile.SubItems[2].Name = "Priority"; lviFile.Tag = p_iflFile; lvwInstallableFiles.Items.Add(lviFile); }
/// <summary> /// Handles the <see cref="FileListEditorVM.FileDeleted"/> event of the view model. /// </summary> /// <remarks> /// This removed the delete <see cref="InstallableFile"/> from the list view. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">An <see cref="EventArgs{InstallableFile}"/> describing the event arguments.</param> private void FileDeleted(object sender, EventArgs <InstallableFile> e) { InstallableFile fliFile = e.Argument; for (Int32 i = lvwInstallableFiles.Items.Count - 1; i >= 0; i--) { if (lvwInstallableFiles.Items[i].Tag == fliFile) { lvwInstallableFiles.Items.RemoveAt(i); if (i < lvwInstallableFiles.Items.Count) { lvwInstallableFiles.Items[i].Selected = true; } break; } } }
/// <summary> /// Handles the <see cref="FileListEditorVM.FileEdited"/> event of the view model. /// </summary> /// <remarks> /// This updates the edited <see cref="InstallableFile"/> in the list view. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">An <see cref="EventArgs{InstallableFile}"/> describing the event arguments.</param> private void FileEdited(object sender, EventArgs <InstallableFile> e) { InstallableFile fliFile = e.Argument; ListViewItem lviFile = null; for (Int32 i = lvwInstallableFiles.Items.Count - 1; i >= 0; i--) { if (lvwInstallableFiles.Items[i].Tag == fliFile) { lviFile = lvwInstallableFiles.Items[i]; break; } } lviFile.SubItems["Source"].Text = fliFile.Source; lviFile.SubItems["Destination"].Text = fliFile.Destination; lviFile.SubItems["Priority"].Text = fliFile.Priority.ToString(); }
/// <summary> /// Unparses the given <see cref="InstallableFile"/>. /// </summary> /// <remarks> /// This method can be overidden to provide game-specific or newer-version unparsing. /// </remarks> /// <param name="p_iflFile">The <see cref="InstallableFile"/> for which to generate XML.</param> /// <returns>The XML representation of the given <see cref="InstallableFile"/>.</returns> protected virtual XElement UnparseInstallableFile(InstallableFile p_iflFile) { XElement xelFile = null; if (p_iflFile.IsFolder) { xelFile = new XElement("folder"); } else { xelFile = new XElement("file"); } xelFile.Add(new XAttribute("source", p_iflFile.Source)); xelFile.Add(new XAttribute("destination", p_iflFile.Destination)); xelFile.Add(new XAttribute("alwaysInstall", UnparseBoolean(p_iflFile.AlwaysInstall))); xelFile.Add(new XAttribute("installIfUsable", UnparseBoolean(p_iflFile.InstallIfUsable))); xelFile.Add(new XAttribute("priority", p_iflFile.Priority.ToString())); return(xelFile); }
/// <summary> /// Unparses the given <see cref="InstallableFile"/>. /// </summary> /// <remarks> /// This method can be overidden to provide game-specific or newer-version unparsing. /// </remarks> /// <param name="p_iflFile">The <see cref="InstallableFile"/> for which to generate XML.</param> /// <returns>The XML representation of the given <see cref="InstallableFile"/>.</returns> protected virtual XElement UnparseInstallableFile(InstallableFile p_iflFile) { XElement xelFile = null; if (p_iflFile.IsFolder) xelFile = new XElement("folder"); else xelFile = new XElement("file"); xelFile.Add(new XAttribute("source", p_iflFile.Source)); xelFile.Add(new XAttribute("destination", p_iflFile.Destination)); xelFile.Add(new XAttribute("alwaysInstall", UnparseBoolean(p_iflFile.AlwaysInstall))); xelFile.Add(new XAttribute("installIfUsable", UnparseBoolean(p_iflFile.InstallIfUsable))); xelFile.Add(new XAttribute("priority", p_iflFile.Priority.ToString())); return xelFile; }
/// <summary> /// Deletes the given <see cref="InstallableFile"/> from the list. /// </summary> /// <param name="p_iflArgument">The <see cref="InstallableFile"/> to delete.</param> private void DeleteInstallableFile(InstallableFile p_iflArgument) { InstallableFiles.Remove(p_iflArgument); FileDeleted(this, new EventArgs <InstallableFile>(p_iflArgument)); }
public InstallableFileVM(InstallableFile p_iflInstallableFile) { InstallableFile = p_iflInstallableFile ?? new InstallableFile(null, null, false, 0, false, false); Reset(); }
/// <summary> /// Passes the given <see cref="InstallableFile"/> to the editor view model /// to be edited. /// </summary> /// <param name="p_iflArgument">The <see cref="InstallableFile"/> to be edited.</param> private void EditInstallableFile(InstallableFile p_iflArgument) { InstallableFileEditorVM.InstallableFile = p_iflArgument; }
/// <summary> /// Adds the given <see cref="InstallableFile"/> to the list view. /// </summary> /// <param name="p_iflFile">The <see cref="InstallableFile"/> to add to the list view.</param> protected void AddInstallableFile(InstallableFile p_iflFile) { ListViewItem lviFile = new ListViewItem(p_iflFile.Source); lviFile.SubItems[0].Name = "Source"; lviFile.SubItems.Add(p_iflFile.Destination); lviFile.SubItems[1].Name = "Destination"; lviFile.SubItems.Add(p_iflFile.Priority.ToString()); lviFile.SubItems[2].Name = "Priority"; lviFile.Tag = p_iflFile; lvwInstallableFiles.Items.Add(lviFile); }
/// <summary> /// Deletes the given <see cref="InstallableFile"/> from the list. /// </summary> /// <param name="p_iflArgument">The <see cref="InstallableFile"/> to delete.</param> private void DeleteInstallableFile(InstallableFile p_iflArgument) { InstallableFiles.Remove(p_iflArgument); FileDeleted(this, new EventArgs<InstallableFile>(p_iflArgument)); }
/// <summary> /// Passes the a new <see cref="InstallableFile"/> to the editor view model /// to be edited. /// </summary> /// <param name="p_iflArgument">Ignored.</param> private void AddInstallableFile(InstallableFile p_iflArgument) { InstallableFileEditorVM.InstallableFile = null; }
/// <summary> /// Passes the given <see cref="InstallableFile"/> to the editor view model /// to be edited. /// </summary> /// <param name="p_iflArgument">The <see cref="InstallableFile"/> to be edited.</param> private void EditInstallableFile(InstallableFile p_iflArgument) { InstallableFileEditorVM.InstallableFile = p_iflArgument; }
/// <summary> /// Installs the given <see cref="InstallableFile"/>, and activates any /// plugins it encompasses as requested. /// </summary> /// <param name="p_ilfFile">The file to install.</param> /// <param name="p_booActivate">Whether or not to activate the given file, if it is a plugin.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFile(InstallableFile p_ilfFile, bool p_booActivate) { string strSource = p_ilfFile.Source; string strDest = p_ilfFile.Destination; ItemMessage = "Installing " + (String.IsNullOrEmpty(strDest) ? strSource : strDest); if (p_ilfFile.IsFolder) { if (!InstallFolderFromMod(p_ilfFile)) return false; //if the destination length is greater than 0, then nothing in // this folder is directly in the Data folder as so cannot be // activated if (strDest.Length == 0) { List<string> lstFiles = Mod.GetFileList(strSource, true); ItemMessage = "Activating " + (String.IsNullOrEmpty(strDest) ? strSource : strDest); ItemProgress = 0; ItemProgressMaximum = lstFiles.Count; string strDirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(); if (!strSource.EndsWith(strDirectorySeparatorChar) && !strSource.EndsWith("/")) strSource += strDirectorySeparatorChar; foreach (string strFile in lstFiles) { string strNewFileName = GameMode.GetModFormatAdjustedPath(Mod.Format, strFile.Substring(strSource.Length, strFile.Length - strSource.Length)); if (Installers.PluginManager != null) if (Installers.PluginManager.IsActivatiblePluginFile(strNewFileName)) Installers.PluginManager.SetPluginActivation(strNewFileName, p_booActivate); if (Status == TaskStatus.Cancelling) return false; StepItemProgress(); } } } else { ItemProgress = 0; ItemProgressMaximum = 2; Installers.FileInstaller.InstallFileFromMod(strSource, GameMode.GetModFormatAdjustedPath(Mod.Format, strDest), false); SaveXMLInstalledFiles(strSource, GameMode.GetModFormatAdjustedPath(Mod.Format, strDest)); StepItemProgress(); string strPluginPath = GameMode.GetModFormatAdjustedPath(Mod.Format, String.IsNullOrEmpty(strDest) ? strSource : strDest); if (Installers.PluginManager != null) if (Installers.PluginManager.IsActivatiblePluginFile(strPluginPath)) Installers.PluginManager.SetPluginActivation(strPluginPath, p_booActivate); StepItemProgress(); } return true; }
/// <summary> /// Passes the a new <see cref="InstallableFile"/> to the editor view model /// to be edited. /// </summary> /// <param name="p_iflArgument">Ignored.</param> private void AddInstallableFile(InstallableFile p_iflArgument) { InstallableFileEditorVM.InstallableFile = null; }
/// <summary> /// Recursively copies all files and folders from one location to another. /// </summary> /// <param name="p_ilfFile">The folder to install.</param> /// <returns><c>false</c> if the user cancelled the install; /// <c>true</c> otherwise.</returns> protected bool InstallFolderFromMod(InstallableFile p_ilfFile) { List<string> lstModFiles = Mod.GetFileList(p_ilfFile.Source, true); ItemProgress = 0; ItemProgressMaximum = lstModFiles.Count; String strFrom = p_ilfFile.Source.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).ToLowerInvariant(); if (!strFrom.EndsWith(Path.DirectorySeparatorChar.ToString())) strFrom += Path.DirectorySeparatorChar; String strTo = p_ilfFile.Destination.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if ((strTo.Length > 0) && (!strTo.EndsWith(Path.DirectorySeparatorChar.ToString()))) strTo += Path.DirectorySeparatorChar; String strMODFile = null; for (Int32 i = 0; i < lstModFiles.Count; i++) { if (Status == TaskStatus.Cancelling) return false; strMODFile = lstModFiles[i]; string strNewFileName = strMODFile.Substring(strFrom.Length, strMODFile.Length - strFrom.Length); Installers.FileInstaller.InstallFileFromMod(strMODFile, GameMode.GetModFormatAdjustedPath(Mod.Format, Path.Combine(strTo, strNewFileName)), false); SaveXMLInstalledFiles(strMODFile, GameMode.GetModFormatAdjustedPath(Mod.Format, Path.Combine(strTo, strNewFileName))); StepItemProgress(); } return true; }
public InstallableFileEditorVM(InstallableFile p_iflInstallableFile, IList <VirtualFileSystemItem> p_lstFileSystemItems) { InstallableFile = p_iflInstallableFile; FileSystemItems = p_lstFileSystemItems; Errors = new ErrorContainer(); }