private void BuildTreeView() { this.ModTreeView.Items.Clear(); this.NodeTree = new NodeTree(); this.NodeTree.AddNodes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods")); foreach (var rootNode in this.NodeTree.RootNodes) { this.ModTreeView.Items.Add(new ModItem(rootNode)); } }
private void InstallModButton_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "Mod Archive (*.zip)|*.zip", Title = "Install Mod..." }; if ((bool)openFileDialog.ShowDialog()) { try { NodeTree testTree = new NodeTree(this.NodeTree); //note that the elements are not copied //suspose let testTree.RootNodes[0].Childs[0].MainExecutable = "" //then this.NodeTree.RootNodes[0].Childs[0].MainExecutable=="" is true! //be careful var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); // Will always overwrite if target filenames already exist fastZip.ExtractZip( openFileDialog.FileName, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Incoming"), String.Empty); testTree.AddNodes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Incoming")); if (testTree.Count() == this.NodeTree.Count()) { throw new Exception("This archive doesn't contain any nodes."); } IO.CreateHardLinksOfFiles(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Incoming"), System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods")); this.BuildTreeView(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { IO.ClearDirectory(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Incoming")); } } }
public NodeTree(NodeTree NodeTree) { this.NodesDictionary = new Dictionary <string, Node>(NodeTree.NodesDictionary); this.RootNodes = new List <Node>(NodeTree.RootNodes); }