diff --git a/OpenRA.Launcher/ConfigureModsDialog.Designer.cs b/OpenRA.Launcher/ConfigureModsDialog.Designer.cs index 22d144e5aa..37aa1c4f1e 100644 --- a/OpenRA.Launcher/ConfigureModsDialog.Designer.cs +++ b/OpenRA.Launcher/ConfigureModsDialog.Designer.cs @@ -33,13 +33,22 @@ this.installButton = new System.Windows.Forms.Button(); this.installModDialog = new System.Windows.Forms.OpenFileDialog(); this.treeView1 = new System.Windows.Forms.TreeView(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.addButton = new System.Windows.Forms.Button(); + this.removeButton = new System.Windows.Forms.Button(); + this.listView1 = new System.Windows.Forms.ListView(); + this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); + this.label1 = new System.Windows.Forms.Label(); + this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); + this.label2 = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // // cancelButton // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(275, 227); + this.cancelButton.Location = new System.Drawing.Point(446, 477); this.cancelButton.Name = "cancelButton"; this.cancelButton.Size = new System.Drawing.Size(75, 23); this.cancelButton.TabIndex = 0; @@ -50,7 +59,7 @@ // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.Location = new System.Drawing.Point(194, 227); + this.okButton.Location = new System.Drawing.Point(365, 477); this.okButton.Name = "okButton"; this.okButton.Size = new System.Drawing.Size(75, 23); this.okButton.TabIndex = 1; @@ -59,7 +68,8 @@ // // installButton // - this.installButton.Location = new System.Drawing.Point(12, 227); + this.installButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.installButton.Location = new System.Drawing.Point(12, 477); this.installButton.Name = "installButton"; this.installButton.Size = new System.Drawing.Size(116, 23); this.installButton.TabIndex = 2; @@ -74,17 +84,121 @@ // // treeView1 // - this.treeView1.Location = new System.Drawing.Point(12, 12); + this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.treeView1.Location = new System.Drawing.Point(3, 23); this.treeView1.Name = "treeView1"; - this.treeView1.Size = new System.Drawing.Size(175, 209); + this.tableLayoutPanel1.SetRowSpan(this.treeView1, 2); + this.treeView1.Size = new System.Drawing.Size(233, 212); this.treeView1.TabIndex = 3; + this.treeView1.Enter += new System.EventHandler(this.treeView1_Enter); + this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeViewSelect); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.treeView1, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.addButton, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.removeButton, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.listView1, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.propertyGrid1, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.label2, 2, 0); + this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 4; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(509, 459); + this.tableLayoutPanel1.TabIndex = 4; + // + // addButton + // + this.addButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.addButton.Location = new System.Drawing.Point(242, 103); + this.addButton.Name = "addButton"; + this.addButton.Size = new System.Drawing.Size(24, 23); + this.addButton.TabIndex = 5; + this.addButton.Text = "+"; + this.addButton.UseVisualStyleBackColor = true; + this.addButton.Click += new System.EventHandler(this.ActivateMod); + // + // removeButton + // + this.removeButton.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.removeButton.Location = new System.Drawing.Point(242, 132); + this.removeButton.Name = "removeButton"; + this.removeButton.Size = new System.Drawing.Size(24, 23); + this.removeButton.TabIndex = 6; + this.removeButton.Text = "-"; + this.removeButton.UseVisualStyleBackColor = true; + this.removeButton.Click += new System.EventHandler(this.DeactivateMod); + // + // listView1 + // + this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick; + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1}); + this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.listView1.FullRowSelect = true; + this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.listView1.Location = new System.Drawing.Point(272, 23); + this.listView1.MultiSelect = false; + this.listView1.Name = "listView1"; + this.tableLayoutPanel1.SetRowSpan(this.listView1, 2); + this.listView1.Size = new System.Drawing.Size(234, 212); + this.listView1.TabIndex = 8; + this.listView1.TileSize = new System.Drawing.Size(10, 10); + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.SelectedIndexChanged += new System.EventHandler(this.ListViewSelect); + this.listView1.Enter += new System.EventHandler(this.ListViewSelect); + // + // label1 + // + this.label1.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(96, 3); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(47, 13); + this.label1.TabIndex = 10; + this.label1.Text = "All Mods"; + // + // propertyGrid1 + // + this.tableLayoutPanel1.SetColumnSpan(this.propertyGrid1, 3); + this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill; + this.propertyGrid1.Location = new System.Drawing.Point(3, 241); + this.propertyGrid1.Name = "propertyGrid1"; + this.propertyGrid1.PropertySort = System.Windows.Forms.PropertySort.NoSort; + this.propertyGrid1.Size = new System.Drawing.Size(503, 215); + this.propertyGrid1.TabIndex = 9; + this.propertyGrid1.ToolbarVisible = false; + // + // label2 + // + this.label2.Anchor = System.Windows.Forms.AnchorStyles.None; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(356, 3); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(66, 13); + this.label2.TabIndex = 11; + this.label2.Text = "Active Mods"; // // ConfigureModsDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(362, 262); - this.Controls.Add(this.treeView1); + this.ClientSize = new System.Drawing.Size(533, 512); + this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.installButton); this.Controls.Add(this.okButton); this.Controls.Add(this.cancelButton); @@ -94,6 +208,8 @@ this.Name = "ConfigureModsDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Configure Mods"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); } @@ -105,5 +221,13 @@ private System.Windows.Forms.Button installButton; private System.Windows.Forms.OpenFileDialog installModDialog; private System.Windows.Forms.TreeView treeView1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Button addButton; + private System.Windows.Forms.Button removeButton; + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.PropertyGrid propertyGrid1; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; } } \ No newline at end of file diff --git a/OpenRA.Launcher/ConfigureModsDialog.cs b/OpenRA.Launcher/ConfigureModsDialog.cs index 37a7d7f243..a6b2d68350 100644 --- a/OpenRA.Launcher/ConfigureModsDialog.cs +++ b/OpenRA.Launcher/ConfigureModsDialog.cs @@ -1,27 +1,30 @@ -using System; +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Linq; -using System.Text; using System.Windows.Forms; namespace OpenRA.Launcher { - struct Mod - { - public string Title; - public string Version; - public string Author; - public string Description; - public string Requires; - public bool Standalone; - } - public partial class ConfigureModsDialog : Form { - string[] activeMods; + List activeMods; + + public List ActiveMods + { + get { return activeMods; } + } + Dictionary allMods; public ConfigureModsDialog(string[] activeMods) { @@ -29,19 +32,21 @@ namespace OpenRA.Launcher Util.UacShield(installButton); - this.activeMods = activeMods; + this.activeMods = new List(activeMods); + listView1.Items.AddRange(activeMods.Select(x => new ListViewItem(x)).ToArray()); + RefreshMods(); } Mod GetMetadata(string mod) { var response = UtilityProgram.Call("-i", mod); - Mod m = new Mod(); - if (response.IsError) return m; + if (response.IsError) return null; string[] lines = response.ResponseLines; - + string title = "", version = "", author = "", description = "", requires = ""; + bool standalone = false; foreach (string line in lines) { string s = line.Trim(' ', '\r', '\n'); @@ -51,29 +56,29 @@ namespace OpenRA.Launcher switch (s.Substring(0, i)) { case "Title": - m.Title = value; + title = value; break; case "Version": - m.Version = value; + version = value; break; case "Author": - m.Author = value; + author = value; break; case "Description": - m.Description = value; + description = value; break; case "Requires": - m.Requires = value; + requires = value; break; case "Standalone": - m.Standalone = bool.Parse(value); + standalone = bool.Parse(value); break; default: break; } } - return m; + return new Mod(title, version, author, description, requires, standalone); } void RefreshMods() @@ -99,6 +104,7 @@ namespace OpenRA.Launcher void RefreshModTree(TreeView treeView, string[] modList) { + treeView.Nodes.Clear(); Dictionary nodes; nodes = modList.Where(x => allMods[x].Standalone).ToDictionary(x => x, x => new TreeNode(x)); string[] rootMods = modList.Where(x => allMods[x].Standalone).ToArray(); @@ -148,5 +154,111 @@ namespace OpenRA.Launcher treeView.Invalidate(); } + + void TreeViewSelect(object sender, TreeViewEventArgs e) + { + SelectMod(e.Node.Text); + } + + void ListViewSelect(object sender, EventArgs e) + { + if (listView1.SelectedItems.Count > 0) + SelectMod(listView1.SelectedItems[0].Text); + else + SelectMod(""); + } + + void treeView1_Enter(object sender, EventArgs e) + { + if (treeView1.SelectedNode != null) + SelectMod(treeView1.SelectedNode.Text); + else + SelectMod(""); + } + + void SelectMod(string mod) + { + if (!allMods.ContainsKey(mod)) + propertyGrid1.SelectedObject = null; + else + propertyGrid1.SelectedObject = allMods[mod]; + } + + void ActivateMod(object sender, EventArgs e) + { + if (treeView1.SelectedNode == null) return; + string mod = treeView1.SelectedNode.Text; + if (!allMods.ContainsKey(mod)) return; + if (activeMods.Contains(mod)) return; + + Mod m = allMods[mod]; + Stack toAdd = new Stack(); + toAdd.Push(mod); + while (!string.IsNullOrEmpty(m.Requires)) + { + string r = m.Requires; + if (!allMods.ContainsKey(r)) + { + MessageBox.Show(string.Format("A requirement for the mod \"{0}\" is missing. Please install \"{1}\" or the game may not run properly.", mod, r)); + return; + } + if (!activeMods.Contains(r)) + toAdd.Push(r); + mod = r; + m = allMods[mod]; + } + + while (toAdd.Count > 0) + activeMods.Add(toAdd.Pop()); + + listView1.Items.Clear(); + listView1.Items.AddRange(activeMods.Select(x => new ListViewItem(x)).ToArray()); + } + + void DeactivateMod(object sender, EventArgs e) + { + if (listView1.SelectedItems.Count < 1) return; + string mod = listView1.SelectedItems[0].Text; + List toRemove = new List(); + + Stack nodes = new Stack(); + nodes.Push(mod); + string currentNode; + while (nodes.Count > 0) + { + currentNode = nodes.Pop(); + toRemove.Add(currentNode); + foreach (string n in activeMods.Where(x => allMods[x].Requires == currentNode)) + nodes.Push(n); + } + + listView1.SuspendLayout(); + foreach (string s in toRemove) + { + listView1.Items.Remove(listView1.Items.OfType().Where(x => x.Text == s).SingleOrDefault()); + activeMods.Remove(s); + } + listView1.ResumeLayout(); + } + } + + class Mod + { + public string Title { get; private set; } + public string Version { get; private set; } + public string Author { get; private set; } + public string Description { get; private set; } + public string Requires { get; private set; } + public bool Standalone { get; private set; } + + public Mod(string title, string version, string author, string description, string requires, bool standalone) + { + Title = title; + Version = version; + Author = author; + Description = description; + Requires = requires; + Standalone = standalone; + } } } diff --git a/OpenRA.Launcher/InstallPackagesDialog.Designer.cs b/OpenRA.Launcher/InstallPackagesDialog.Designer.cs new file mode 100644 index 0000000000..5b318b388b --- /dev/null +++ b/OpenRA.Launcher/InstallPackagesDialog.Designer.cs @@ -0,0 +1,131 @@ +namespace OpenRA.Launcher +{ + partial class InstallPackagesDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.cancelButton = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.radioButton1 = new System.Windows.Forms.RadioButton(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(280, 89); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(218, 163); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 1; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(109, 163); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(103, 23); + this.button2.TabIndex = 2; + this.button2.Text = "Continue..."; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // radioButton1 + // + this.radioButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.radioButton1.AutoSize = true; + this.radioButton1.Checked = true; + this.radioButton1.Location = new System.Drawing.Point(16, 113); + this.radioButton1.Name = "radioButton1"; + this.radioButton1.Size = new System.Drawing.Size(138, 17); + this.radioButton1.TabIndex = 3; + this.radioButton1.TabStop = true; + this.radioButton1.Text = "Download From Internet"; + this.radioButton1.UseVisualStyleBackColor = true; + // + // radioButton2 + // + this.radioButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(16, 136); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(96, 17); + this.radioButton2.TabIndex = 4; + this.radioButton2.TabStop = true; + this.radioButton2.Text = "Install From CD"; + this.radioButton2.UseVisualStyleBackColor = true; + // + // folderBrowserDialog1 + // + this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer; + this.folderBrowserDialog1.ShowNewFolderButton = false; + // + // InstallPackagesDialog + // + this.AcceptButton = this.button2; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(305, 198); + this.Controls.Add(this.radioButton2); + this.Controls.Add(this.radioButton1); + this.Controls.Add(this.button2); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "InstallPackagesDialog"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Install Mod Files"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.RadioButton radioButton1; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; + } +} \ No newline at end of file diff --git a/OpenRA.Launcher/InstallPackagesDialog.cs b/OpenRA.Launcher/InstallPackagesDialog.cs new file mode 100644 index 0000000000..6cb099edc6 --- /dev/null +++ b/OpenRA.Launcher/InstallPackagesDialog.cs @@ -0,0 +1,52 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.IO; +using System.Windows.Forms; + +namespace OpenRA.Launcher +{ + public partial class InstallPackagesDialog : Form + { + string mod; + public InstallPackagesDialog(string mod) + { + InitializeComponent(); + Util.UacShield(button2); + this.mod = mod; + if (mod == "cnc") radioButton2.Enabled = false; + label1.Text = string.Format("In order to play OpenRA with the mod \"{0}\", you must install the original game files. " + + "These can either be downloaded or for some mods be installed from a CD copy of the original game. " + + "Please select your choice below and click continue", mod); + } + + private void button2_Click(object sender, EventArgs e) + { + UtilityProgramResponse response = null; + if (radioButton1.Checked) + response = UtilityProgram.CallWithAdmin("--download-packages", mod); + + if (radioButton2.Checked) + { + if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) + response = UtilityProgram.CallWithAdmin(string.Format("--install-{0}-packages", mod), + folderBrowserDialog1.SelectedPath + Path.DirectorySeparatorChar); + } + + if (response.IsError) + DialogResult = DialogResult.No; + else + DialogResult = DialogResult.OK; + + Close(); + } + } +} diff --git a/OpenRA.Launcher/InstallPackagesDialog.resx b/OpenRA.Launcher/InstallPackagesDialog.resx new file mode 100644 index 0000000000..c3fe8f176d --- /dev/null +++ b/OpenRA.Launcher/InstallPackagesDialog.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/OpenRA.Launcher/MainForm.Designer.cs b/OpenRA.Launcher/MainForm.Designer.cs index 19724a9431..e45ec296c1 100644 --- a/OpenRA.Launcher/MainForm.Designer.cs +++ b/OpenRA.Launcher/MainForm.Designer.cs @@ -59,6 +59,7 @@ this.launchButton.TabIndex = 1; this.launchButton.Text = "Launch OpenRA"; this.launchButton.UseVisualStyleBackColor = true; + this.launchButton.Click += new System.EventHandler(this.LaunchGame); // // tableLayoutPanel1 // @@ -107,6 +108,7 @@ // configGameButton // this.configGameButton.Anchor = System.Windows.Forms.AnchorStyles.None; + this.configGameButton.Enabled = false; this.configGameButton.Location = new System.Drawing.Point(51, 239); this.configGameButton.Name = "configGameButton"; this.configGameButton.Size = new System.Drawing.Size(192, 50); diff --git a/OpenRA.Launcher/MainForm.cs b/OpenRA.Launcher/MainForm.cs index 06cb431cca..c0583211cd 100644 --- a/OpenRA.Launcher/MainForm.cs +++ b/OpenRA.Launcher/MainForm.cs @@ -1,12 +1,18 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.Diagnostics; using System.IO; +using System.Linq; +using System.Windows.Forms; namespace OpenRA.Launcher { @@ -25,13 +31,50 @@ namespace OpenRA.Launcher else currentMods = response.Response.Split(','); + UpdateModLabel(); + } + + void UpdateModLabel() + { label1.Text = string.Format("Current Mods: {0}", currentMods.Length > 0 ? string.Join(",", currentMods) : "ra"); } - private void ConfigureMods(object sender, EventArgs e) + void ConfigureMods(object sender, EventArgs e) { var d = new ConfigureModsDialog(currentMods); - d.ShowDialog(); + if (d.ShowDialog() != DialogResult.OK) + return; + + currentMods = d.ActiveMods.ToArray(); + + UpdateModLabel(); + } + + void LaunchGame(object sender, EventArgs e) + { + string[] officialMods = { "ra", "cnc" }; + + bool allOk = true; + foreach(string s in officialMods) + if (currentMods.Contains(s)) + allOk = CheckAndInstallPackages(s); + + if (!allOk) return; + + Process p = new Process(); + p.StartInfo.FileName = "OpenRA.Game.exe"; + p.StartInfo.Arguments = "Game.Mods=" + string.Join(",", currentMods); + p.Start(); + } + + bool CheckAndInstallPackages(string mod) + { + string packageDir = "mods" + Path.DirectorySeparatorChar + mod + Path.DirectorySeparatorChar + "packages"; + if (Directory.Exists(packageDir) && + Directory.GetFiles(packageDir, "*.mix").Length > 0) return true; + var dialog = new InstallPackagesDialog(mod); + if (dialog.ShowDialog() != DialogResult.OK) return false; + return true; } } } diff --git a/OpenRA.Launcher/MainForm.resx b/OpenRA.Launcher/MainForm.resx index dd11766961..a37d048e55 100644 --- a/OpenRA.Launcher/MainForm.resx +++ b/OpenRA.Launcher/MainForm.resx @@ -165,7 +165,7 @@ XTesb3QPLh88M+QwdP6m681Lt7xuXbu94vbgcOjwnZHokdE77DtTd1PuvriXeW/h/sYH6AdFD6UeVjxS fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+ tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/ - 6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALEgAACxIB0t1+/AAAAAZiS0dEAP8A/wD/oL2n + 6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALEAAACxABrSO9dQAAAAZiS0dEAP8A/wD/oL2n kwAAAAd0SU1FB9oKFAwuMM5+jWQAABigSURBVHhe7V0JeBRVtu6tunrNvpCk093ZE8Lq7jiOzLznMj5l 1HHX5+e4v3n6XGeeKKMOjiggIIIIioAKI4hsiiAooMgmi2yyL7LJJoo4EAjp7v/9p5LM9Nevk05C0i1S 9/vOV9VVt+69deqce/9z7rm3DQY96RzQOaBzQOeAzoGEcMDhcIxOSMV6pToHEs0Bq9XqpgIgKys7LdFt diff --git a/OpenRA.Launcher/OpenRA.Launcher.csproj b/OpenRA.Launcher/OpenRA.Launcher.csproj index 32999baa70..5a3b1b29bf 100644 --- a/OpenRA.Launcher/OpenRA.Launcher.csproj +++ b/OpenRA.Launcher/OpenRA.Launcher.csproj @@ -48,6 +48,12 @@ ConfigureModsDialog.cs + + Form + + + InstallPackagesDialog.cs + Form @@ -72,6 +78,9 @@ ConfigureModsDialog.cs + + InstallPackagesDialog.cs + MainForm.cs diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs new file mode 100644 index 0000000000..d11df03dc4 --- /dev/null +++ b/OpenRA.Utility/Command.cs @@ -0,0 +1,179 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Threading; +using ICSharpCode.SharpZipLib.Zip; +using OpenRA.FileFormats; + +namespace OpenRA.Utility +{ + static class Command + { + public static void ListMods(string _) + { + foreach (var m in Mod.AllMods) + Console.WriteLine(m.Key); + } + + public static void ListModInfo(string modList) + { + string[] mods = modList.Split(','); + foreach (var m in mods) + { + var mod = Mod.AllMods + .Where(x => x.Key.Equals(m)) + .Select(x => x.Value) + .FirstOrDefault(); + if (mod == null) + { + Console.WriteLine("Error: Mod `{0}` is not installed or could not be found.", m); + return; + } + + Console.WriteLine("{0}:", m); + Console.WriteLine(" Title: {0}", mod.Title); + Console.WriteLine(" Version: {0}", mod.Version); + Console.WriteLine(" Author: {0}", mod.Author); + Console.WriteLine(" Description: {0}", mod.Description); + Console.WriteLine(" Requires: {0}", mod.RequiresMods == null ? "" : string.Join(",", mod.RequiresMods)); + Console.WriteLine(" Standalone: {0}", mod.Standalone.ToString()); + } + } + + public static void InstallRAMusic(string path) + { + Util.ExtractPackagesFromMix(path, string.Format("mods{0}ra{0}packages", Path.DirectorySeparatorChar), + "MAIN.MIX", "scores.mix"); + Console.WriteLine("Done"); + } + + public static void InstallCncMusic(string path) + { + if (!Directory.Exists(path)) { Console.WriteLine("Error: Path {0} does not exist", path); return; } + string scoresMixPath = path + Path.DirectorySeparatorChar + "SCORES.MIX"; + if (!File.Exists(scoresMixPath)) { Console.WriteLine("Error: Could not find SCORES.MIX in path {0}", path); return; } + + File.Copy(scoresMixPath, string.Format("mods{0}cnc{0}packages{0}scores.mix", Path.DirectorySeparatorChar), true); + + Console.WriteLine("Done"); + } + + public static void DownloadPackages(string argValue) + { + string[] args = argValue.Split(','); + string mod = ""; + string destPath = Path.GetTempPath(); + + if (args.Length >= 1) + mod = args[0]; + if (args.Length >= 2) + destPath = args[1]; + + string destFile = string.Format("{0}{1}{2}-packages.zip", destPath, Path.DirectorySeparatorChar, mod); + + if (File.Exists(destFile)) + { + Console.WriteLine("Downloaded file already exists, using it instead."); + Util.ExtractPackagesFromZip(mod, destPath); + return; + } + + WebClient wc = new WebClient(); + wc.DownloadProgressChanged += DownloadProgressChanged; + wc.DownloadFileCompleted += DownloadFileCompleted; + Console.WriteLine("Downloading {0}-packages.zip to {1}", mod, destPath); + wc.DownloadFileAsync( + new Uri(string.Format("http://open-ra.org/get-dependency.php?file={0}-packages", mod)), + destFile, + new string[] { mod, destPath }); + + while (wc.IsBusy) + Thread.Sleep(500); + } + + static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) + { + if (e.Error != null) + { + Console.WriteLine("Error: {0}", e.Error.Message); + return; + } + + Console.WriteLine("Download Completed"); + string[] modAndDest = (string[])e.UserState; + Util.ExtractPackagesFromZip(modAndDest[0], modAndDest[1]); + } + + static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) + { + Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); + } + + public static void InstallRAPackages(string path) + { + Util.ExtractPackagesFromMix(path, "mods{0}ra{0}packages".F(Path.DirectorySeparatorChar), "MAIN.MIX", + "conquer.mix", "russian.mix", "allies.mix", "sounds.mix", "scores.mix", + "snow.mix", "interior.mix", "temperat.mix"); + var redalertMixPath = "{0}{1}INSTALL{1}REDALERT.MIX".F(path, Path.DirectorySeparatorChar); + if (!File.Exists(redalertMixPath)) { Console.WriteLine("Error: REDALERT.MIX could not be found on the CD"); return; } + Console.WriteLine("Copying REDALERT.MIX"); + File.Copy(redalertMixPath, "mods{0}ra{0}packages{0}redalert.mix".F(Path.DirectorySeparatorChar)); + Console.WriteLine("Done"); + } + + public static void InstallCncPackages(string path) + { + Console.WriteLine("Error: NotI"); + } + + public static void Settings(string argValue) + { + string[] args = argValue.Split(','); + + if (args.Length < 2) { return; } + + string settingsFile = args[0] + Path.DirectorySeparatorChar + "settings.yaml"; + List settingsYaml = MiniYaml.FromFile(settingsFile); + Queue settingKey = new Queue(args[1].Split('.')); + + string s = settingKey.Dequeue(); + MiniYaml n = settingsYaml.Where(x => x.Key == s).Select(x => x.Value).FirstOrDefault(); + + if (n == null) + { + Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); + return; + } + + while (settingKey.Count > 0) + { + s = settingKey.Dequeue(); + if (!n.NodesDict.TryGetValue(s, out n)) + { + Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); + return; + } + } + + Console.WriteLine(n.Value); + } + + public static void InstallMod(string zipFile) + { + if (!File.Exists(zipFile)) { Console.WriteLine("Error: Could not find {0}", zipFile); return; } + new ZipInputStream(File.OpenRead(zipFile)).ExtractZip("mods"); + } + } +} diff --git a/OpenRA.Utility/OpenRA.Utility.csproj b/OpenRA.Utility/OpenRA.Utility.csproj index 56984716ef..723bc9d1fb 100644 --- a/OpenRA.Utility/OpenRA.Utility.csproj +++ b/OpenRA.Utility/OpenRA.Utility.csproj @@ -1,4 +1,4 @@ - + Debug @@ -50,8 +50,10 @@ + + diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 9146d7a35a..a474b811ca 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -11,12 +11,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Net; using System.Security.Principal; -using System.Threading; -using ICSharpCode.SharpZipLib.Zip; -using OpenRA.FileFormats; namespace OpenRA.Utility { @@ -36,22 +31,22 @@ namespace OpenRA.Utility static void Main(string[] args) { argCallbacks = new Dictionary(); - argCallbacks.Add("--list-mods", ListMods); - argCallbacks.Add("-l", ListMods); - argCallbacks.Add("--mod-info", ListModInfo); - argCallbacks.Add("-i", ListModInfo); - argCallbacks.Add("--install-ra-music", InstallRAMusic); - argCallbacks.Add("--install-cnc-music", InstallCncMusic); - argCallbacks.Add("--download-packages", DownloadPackages); - argCallbacks.Add("--install-ra-packages", InstallRAPackages); - argCallbacks.Add("--install-cnc-packages", InstallCncPackages); - argCallbacks.Add("--settings-value", Settings); - argCallbacks.Add("--install-mod", InstallMod); + argCallbacks.Add("--list-mods", Command.ListMods); + argCallbacks.Add("-l", Command.ListMods); + argCallbacks.Add("--mod-info", Command.ListModInfo); + argCallbacks.Add("-i", Command.ListModInfo); + argCallbacks.Add("--install-ra-music", Command.InstallRAMusic); + argCallbacks.Add("--install-cnc-music", Command.InstallCncMusic); + argCallbacks.Add("--download-packages", Command.DownloadPackages); + argCallbacks.Add("--install-ra-packages", Command.InstallRAPackages); + argCallbacks.Add("--install-cnc-packages", Command.InstallCncPackages); + argCallbacks.Add("--settings-value", Command.Settings); + argCallbacks.Add("--install-mod", Command.InstallMod); WindowsIdentity id = WindowsIdentity.GetCurrent(); WindowsPrincipal p = new WindowsPrincipal(id); if (p.IsInRole(WindowsBuiltInRole.Administrator)) - Console.SetOut(new StreamWriter(File.OpenWrite("output.txt"))); + Console.SetOut(new StreamWriter(File.Create("output.txt"))); if (args.Length == 0) { PrintUsage(); return; } var arg = SplitArgs(args[0]); @@ -79,215 +74,5 @@ namespace OpenRA.Utility Console.WriteLine(" --settings-value=SUPPORTDIR,KEY Get value of KEY in SUPPORTDIR/settings.yaml"); Console.WriteLine(" --install-mod=ZIPFILE Install a mod from ZIPFILE"); } - - static void ListMods(string _) - { - foreach (var m in Mod.AllMods) - Console.WriteLine(m.Key); - } - - static void ListModInfo(string modList) - { - string[] mods = modList.Split(','); - foreach (var m in mods) - { - var mod = Mod.AllMods - .Where(x => x.Key.Equals(m)) - .Select(x => x.Value) - .FirstOrDefault(); - if (mod == null) - { - Console.WriteLine("Error: Mod `{0}` is not installed or could not be found.", m); - return; - } - - Console.WriteLine("{0}:", m); - Console.WriteLine(" Title: {0}", mod.Title); - Console.WriteLine(" Version: {0}", mod.Version); - Console.WriteLine(" Author: {0}", mod.Author); - Console.WriteLine(" Description: {0}", mod.Description); - Console.WriteLine(" Requires: {0}", mod.RequiresMods == null ? "" : string.Join(",", mod.RequiresMods)); - Console.WriteLine(" Standalone: {0}", mod.Standalone.ToString()); - } - } - - static void InstallRAMusic(string path) - { - ExtractPackagesFromMix(path, string.Format("mods{0}ra{0}packages", Path.DirectorySeparatorChar), - "MAIN.MIX", "scores.mix"); - Console.WriteLine("Done"); - } - - static void InstallCncMusic(string path) - { - if (!Directory.Exists(path)) { Console.WriteLine("Error: Path {0} does not exist", path); return; } - string scoresMixPath = path + Path.DirectorySeparatorChar + "SCORES.MIX"; - if (!File.Exists(scoresMixPath)) { Console.WriteLine("Error: Could not find SCORES.MIX in path {0}", path); return; } - - File.Copy(scoresMixPath, string.Format("mods{0}cnc{0}packages{0}scores.mix", Path.DirectorySeparatorChar), true); - - Console.WriteLine("Done"); - } - - static void DownloadPackages(string argValue) - { - string[] args = argValue.Split(','); - string mod = ""; - string destPath = Path.GetTempPath(); - - if (args.Length >= 1) - mod = args[0]; - if (args.Length >= 2) - destPath = args[1]; - - string destFile = string.Format("{0}{1}{2}-packages.zip", destPath, Path.DirectorySeparatorChar, mod); - - if (File.Exists(destFile)) - { - Console.WriteLine ("Downloaded file already exists, using it instead."); - ExtractPackagesFromZip(mod, destPath); - return; - } - - WebClient wc = new WebClient(); - wc.DownloadProgressChanged += DownloadProgressChanged; - wc.DownloadFileCompleted += DownloadFileCompleted; - Console.WriteLine("Downloading {0}-packages.zip to {1}", mod, destPath); - wc.DownloadFileAsync( - new Uri(string.Format("http://open-ra.org/get-dependency.php?file={0}-packages", mod)), - destFile, - new string[] { mod, destPath }); - - while (wc.IsBusy) - Thread.Sleep(500); - } - - static void ExtractPackagesFromMix(string srcPath, string destPath, string mix, params string[] packages) - { - if (!Directory.Exists(srcPath)) { Console.WriteLine("Error: Path {0} does not exist", srcPath); return; } - FileSystem.Mount(srcPath); - if (!FileSystem.Exists(mix)) { Console.WriteLine("Error: Could not find {1} in path {0}", srcPath, mix); return; } - FileSystem.Mount(mix); - - if (!Directory.Exists(destPath)) - Directory.CreateDirectory(destPath); - - foreach(string s in packages) - { - var destFile = "{0}{1}{2}".F(destPath, Path.DirectorySeparatorChar, s); - using (var sourceStream = FileSystem.Open(s)) - using (var destStream = File.Create(destFile)) - { - Console.WriteLine("Extracting {0}", s); - destStream.Write(sourceStream.ReadAllBytes()); - } - } - } - - static void ExtractPackagesFromZip(string mod, string dest) - { - string filepath = string.Format("{0}{1}{2}-packages.zip", dest, Path.DirectorySeparatorChar, mod); - string modPackageDir = string.Format("mods{0}{1}{0}packages{0}", Path.DirectorySeparatorChar, mod); - - if (!Directory.Exists(modPackageDir)) - Directory.CreateDirectory(modPackageDir); - - using (var z = new ZipInputStream(File.OpenRead(filepath))) - { - ZipEntry entry; - while ((entry = z.GetNextEntry()) != null) - { - if (!entry.IsFile) continue; - - Console.WriteLine ("Extracting {0}", entry.Name); - using (var f = File.Create(modPackageDir + entry.Name)) - { - int bufSize = 2048; - byte[] buf = new byte[bufSize]; - while ((bufSize = z.Read(buf, 0, buf.Length)) > 0) - { - f.Write(buf, 0, bufSize); - } - } - } - } - - Console.WriteLine ("Done"); - } - - static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) - { - if (e.Error != null) - { - Console.WriteLine("Error: {0}", e.Error.Message); - return; - } - - Console.WriteLine("Download Completed"); - string[] modAndDest = (string[])e.UserState; - ExtractPackagesFromZip(modAndDest[0], modAndDest[1]); - } - - static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); - } - - static void InstallRAPackages(string path) - { - ExtractPackagesFromMix(path, "mods{0}ra{0}packages".F(Path.DirectorySeparatorChar), "MAIN.MIX", - "conquer.mix", "russian.mix", "allies.mix", "sounds.mix", "scores.mix", - "snow.mix", "interior.mix", "temperat.mix"); - var redalertMixPath = "{0}{1}INSTALL{1}REDALERT.MIX".F(path, Path.DirectorySeparatorChar); - if (!File.Exists(redalertMixPath)) { Console.WriteLine ("Error: REDALERT.MIX could not be found on the CD"); return; } - Console.WriteLine ("Copying REDALERT.MIX"); - File.Copy(redalertMixPath, "mods{0}ra{0}packages{0}redalert.mix".F(Path.DirectorySeparatorChar)); - Console.WriteLine ("Done"); - } - - static void InstallCncPackages(string path) - { - Console.WriteLine ("Error: NotI"); - } - - static void Settings(string argValue) - { - string[] args = argValue.Split(','); - - if (args.Length < 2) { return; } - - string settingsFile = args[0] + Path.DirectorySeparatorChar + "settings.yaml"; - List settingsYaml = MiniYaml.FromFile(settingsFile); - Queue settingKey = new Queue(args[1].Split('.')); - - string s = settingKey.Dequeue(); - MiniYaml n = settingsYaml.Where(x => x.Key == s).Select(x => x.Value).FirstOrDefault(); - - if (n == null) - { - Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); - return; - } - - while (settingKey.Count > 0) - { - s = settingKey.Dequeue(); - if (!n.NodesDict.TryGetValue(s, out n)) - { - Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); - return; - } - } - - Console.WriteLine(n.Value); - } - - static void InstallMod(string zipFile) - { - if (!File.Exists(zipFile)) { Console.WriteLine("Error: Could not find {0}", zipFile); return; } - using (var zipStream = new ZipInputStream(File.OpenRead(zipFile))) - { - } - } } } diff --git a/OpenRA.Utility/Util.cs b/OpenRA.Utility/Util.cs new file mode 100644 index 0000000000..9007681fdb --- /dev/null +++ b/OpenRA.Utility/Util.cs @@ -0,0 +1,75 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.IO; +using ICSharpCode.SharpZipLib.Zip; +using OpenRA.FileFormats; + +namespace OpenRA.Utility +{ + static class Util + { + public static void ExtractPackagesFromMix(string srcPath, string destPath, string mix, params string[] packages) + { + if (!Directory.Exists(srcPath)) { Console.WriteLine("Error: Path {0} does not exist", srcPath); return; } + FileSystem.Mount(srcPath); + if (!FileSystem.Exists(mix)) { Console.WriteLine("Error: Could not find {1} in path {0}", srcPath, mix); return; } + FileSystem.Mount(mix); + + if (!Directory.Exists(destPath)) + Directory.CreateDirectory(destPath); + + foreach (string s in packages) + { + var destFile = "{0}{1}{2}".F(destPath, Path.DirectorySeparatorChar, s); + using (var sourceStream = FileSystem.Open(s)) + using (var destStream = File.Create(destFile)) + { + Console.WriteLine("Extracting {0}", s); + destStream.Write(sourceStream.ReadAllBytes()); + } + } + } + + public static void ExtractPackagesFromZip(string mod, string dest) + { + string filepath = string.Format("{0}{1}{2}-packages.zip", dest, Path.DirectorySeparatorChar, mod); + string modPackageDir = string.Format("mods{0}{1}{0}packages{0}", Path.DirectorySeparatorChar, mod); + + if (!Directory.Exists(modPackageDir)) + Directory.CreateDirectory(modPackageDir); + + new ZipInputStream(File.OpenRead(filepath)).ExtractZip(modPackageDir); + + + Console.WriteLine("Done"); + } + + public static void ExtractZip(this ZipInputStream z, string destPath) + { + ZipEntry entry; + while ((entry = z.GetNextEntry()) != null) + { + if (!entry.IsFile) continue; + + Console.WriteLine("Extracting {0}", entry.Name); + using (var f = File.Create(destPath + Path.DirectorySeparatorChar + entry.Name)) + { + int bufSize = 2048; + byte[] buf = new byte[bufSize]; + while ((bufSize = z.Read(buf, 0, buf.Length)) > 0) + f.Write(buf, 0, bufSize); + } + } + z.Close(); + } + } +}