Skip to content

Commit 53603d7

Browse files
committed
Spore ModAPI Uninstaller: allow users to uninstall mods with config
1 parent 2ffb9f1 commit 53603d7

File tree

9 files changed

+108
-61
lines changed

9 files changed

+108
-61
lines changed

Spore ModAPI Easy Installer/EasyInstaller.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ static void Main()
106106

107107

108108
var cmdArgs = Environment.GetCommandLineArgs();
109-
if ((cmdArgs.Length == 3) && bool.TryParse(cmdArgs[2], out bool configResult))
109+
if ((cmdArgs.Length == 4) && bool.TryParse(cmdArgs[2], out bool configResult) && bool.TryParse(cmdArgs[3], out bool uninstall))
110110
{
111111
string modName = cmdArgs[1];
112112
//MessageBox.Show(modName, "modName");
113113

114114
if (configResult)
115115
{
116-
Thread thread = GetXmlInstaller(modName, configResult, true, out XmlInstallerWindow win);
116+
Thread thread = GetXmlInstaller(modName, configResult, uninstall, true, out XmlInstallerWindow win);
117117
thread.Join();
118118
}
119119
}
@@ -558,7 +558,7 @@ static ResultType TryExecuteInstaller(string inputFile, string modName)
558558

559559
/*XmlInstallerWindow win = */
560560
//bool installCancelled = false;
561-
Thread installerThread = GetXmlInstaller(modName, false, true, out XmlInstallerWindow win);
561+
Thread installerThread = GetXmlInstaller(modName, false, false, true, out XmlInstallerWindow win);
562562
//_showXmlInstaller = true;//Thread showThread = new Thread(() => xmlWin.Show());// xmlWin.Dispatcher.Invoke(new Action(() => xmlWin.Show())));
563563
/*showThread.SetApartmentState(ApartmentState.STA);
564564
showThread.Start();
@@ -664,13 +664,13 @@ public static void DeleteFolder(string path)
664664
public static bool RevealXmlInstaller = false;
665665

666666
//[STAThread]
667-
static Thread GetXmlInstaller(string modName, bool configure, bool show, out XmlInstallerWindow win)
667+
static Thread GetXmlInstaller(string modName, bool configure, bool uninstall, bool show, out XmlInstallerWindow win)
668668
{
669669
XmlInstallerWindow xmlWin = null;
670670
Thread thread = new Thread(() =>
671671
{
672672
//MessageBox.Show(modName, "modName");
673-
xmlWin = new XmlInstallerWindow(modName, configure);
673+
xmlWin = new XmlInstallerWindow(modName, configure, uninstall);
674674
if (show)// && (!xmlWin.IsVisible))
675675
{
676676
xmlWin.ShowDialog(); //.Show();

Spore ModAPI Easy Installer/XmlInstallerWindow.xaml.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public partial class XmlInstallerWindow : DecoratableWindow
4747
List<string> enabledList = new List<string>();
4848
string enabledListPath = string.Empty;
4949
bool _isConfigurator = false;
50+
bool _isUninstallingOnly = false;
5051
int _activeComponentCount = 0;
5152
CircleEase _ease = new CircleEase()
5253
{
@@ -62,7 +63,7 @@ public partial class XmlInstallerWindow : DecoratableWindow
6263

6364
public static string SporeDataPath = SporePath.MoveToData(SporePath.Game.Spore, SporePath.GetRealParent(PathDialogs.ProcessSpore()));
6465

65-
public XmlInstallerWindow(string modName, bool configure)
66+
public XmlInstallerWindow(string modName, bool configure, bool uninstall)
6667
{
6768
InitializeComponent();
6869
//LauncherSettings.Load();
@@ -78,10 +79,19 @@ public XmlInstallerWindow(string modName, bool configure)
7879
ModConfigPath = Path.Combine(Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString(), "ModConfigs", ModName); // Settings.ProgramDataPath + @"\ModConfig\" + modName + @"\";
7980
//if (!Directory.Exists())
8081
_isConfigurator = configure;
82+
_isUninstallingOnly = uninstall;
8183
if (_isConfigurator)
8284
{
8385
LoadingPanel.Visibility = Visibility.Collapsed;
8486
RevealInstaller();
87+
88+
if (_isUninstallingOnly)
89+
{
90+
Dispatcher.Invoke(new Action(() =>
91+
{
92+
StartUninstallationButton_Click(StartUninstallationButton, null);
93+
}));
94+
}
8595
}
8696
else
8797
{
@@ -1037,6 +1047,11 @@ await Task.Run(() =>
10371047
await Task.Run(() => DeleteFolder(ModConfigPath));
10381048
CyclePage(0, 1);
10391049
_installerState = 2;
1050+
1051+
if (_isUninstallingOnly)
1052+
{
1053+
Close();
1054+
}
10401055
//Process.GetCurrentProcess().Kill();
10411056
}
10421057
catch (Exception ex)

Spore ModAPI Easy Uninstaller/EasyUninstaller.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,26 @@ static void Main()
5858
}
5959
}
6060

61-
public static void UninstallMods(List<ModConfiguration> mods)
61+
public static void UninstallMods(Dictionary<ModConfiguration, bool> mods)
6262
{
6363
List<ModConfiguration> successfulMods = new List<ModConfiguration>();
6464

6565
try
6666
{
67-
foreach (ModConfiguration mod in mods)
67+
foreach (var mod in mods)
6868
{
69-
RemoveModFiles(mod);
70-
71-
Mods.RemoveMod(mod);
72-
73-
successfulMods.Add(mod);
69+
if (mod.Value)
70+
{
71+
ExecuteConfigurator(mod.Key, true);
72+
}
73+
else
74+
{
75+
RemoveModFiles(mod.Key);
76+
}
77+
78+
Mods.RemoveMod(mod.Key);
79+
80+
successfulMods.Add(mod.Key);
7481
}
7582
}
7683
catch (UnauthorizedAccessException)
@@ -193,19 +200,14 @@ private static string ConvertToArgument(string path)
193200
}
194201
}
195202

196-
public static void ExecuteConfigurator(ModConfiguration mod)
203+
public static void ExecuteConfigurator(ModConfiguration mod, bool uninstall)
197204
{
198-
199-
200-
201-
202-
203205
if (mod.ConfiguratorPath.ToLowerInvariant().EndsWith("xml"))
204206
{
205207
string path = Path.Combine(
206208
Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString()
207209
, "Spore ModAPI Easy Installer.exe");
208-
string args = "\"" + mod.Name + "\"" + " true";
210+
string args = "\"" + mod.Name + "\"" + " true " + uninstall.ToString();
209211
//MessageBox.Show(path + "\n\n" + args, "process information");
210212
var process = Process.Start(path, args);
211213
}
@@ -216,12 +218,6 @@ public static void ExecuteConfigurator(ModConfiguration mod)
216218
throw new Exception(Strings.ConfiguratorDoesNotExist);
217219
}
218220

219-
220-
221-
222-
223-
224-
225221
var process = Process.Start(new ProcessStartInfo()
226222
{
227223
UseShellExecute = false, // we need this to execute a temp file

Spore ModAPI Easy Uninstaller/Properties/Resources.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Spore ModAPI Easy Uninstaller/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,7 @@
121121
<data name="ConfigIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
122122
<value>..\Resources\config_24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123123
</data>
124+
<data name="NoConfigIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
125+
<value>..\Resources\no-config.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126+
</data>
124127
</root>

Spore ModAPI Easy Uninstaller/Spore ModAPI Easy Uninstaller.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<ItemGroup>
104104
<Content Include="Easy Uninstaller Icon Red.ico" />
105105
<Content Include="Easy Uninstaller Icon.ico" />
106+
<Content Include="Resources\no-config.png" />
106107
<None Include="Resources\config_24.png" />
107108
</ItemGroup>
108109
<ItemGroup>

Spore ModAPI Easy Uninstaller/UninstallerForm.Designer.cs

Lines changed: 19 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Spore ModAPI Easy Uninstaller/UninstallerForm.cs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public UninstallerForm()
2222

2323
// create header row
2424

25-
this.dataGridView1.Rows.Add(new object[] { false, "Installed Mods"});
25+
this.dataGridView1.Rows.Add(new object[] { false, "Installed Mods" });
2626
this.dataGridView1.Rows[0].DefaultCellStyle.ApplyStyle(dataGridView1.ColumnHeadersDefaultCellStyle);
2727
this.dataGridView1.Rows[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
2828
this.dataGridView1.Rows[0].Cells[2].Value = Strings.InstalledMods;
@@ -47,10 +47,7 @@ public void AddMod(ModConfiguration mod)
4747
int index = this.dataGridView1.Rows.Add(new object[] { false, mod, mod.DisplayName });
4848

4949
if (GetConfiguratorPath(index) != null)
50-
this.dataGridView1.Rows[index].Cells[0].ReadOnly = true;
51-
//this.dataGridView1.Rows[index].Cells[2].Value = mod.DisplayName;
52-
53-
//this.dataGridView1.Rows[index].Cells[0].Tag = mod;
50+
this.dataGridView1.Rows[index].Cells[3].ReadOnly = true;
5451
}
5552

5653
private void btnCancel_Click(object sender, EventArgs e)
@@ -60,7 +57,7 @@ private void btnCancel_Click(object sender, EventArgs e)
6057

6158
private void dataGridView_CellDoubleClick(Object sender, DataGridViewCellEventArgs e)
6259
{
63-
if (e.RowIndex != 0 && GetConfiguratorPath(e.RowIndex) != null)
60+
if (e.RowIndex != 0 && e.ColumnIndex == 3 && GetConfiguratorPath(e.RowIndex) != null)
6461
{
6562
// execute configurator and close uninstaller
6663
ExecuteConfigurator(GetModConfiguration(e.RowIndex));
@@ -73,7 +70,7 @@ private void dataGridView_CellDoubleClick(Object sender, DataGridViewCellEventAr
7370

7471
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
7572
{
76-
if (e.RowIndex != 0 && GetConfiguratorPath(e.RowIndex) != null && e.ColumnIndex == 0)
73+
if (e.RowIndex != 0 && e.ColumnIndex == 3 && GetConfiguratorPath(e.RowIndex) != null)
7774
{
7875
// execute configurator and close uninstaller
7976
ExecuteConfigurator(GetModConfiguration(e.RowIndex));
@@ -96,10 +93,7 @@ private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventA
9693
bool value = (bool)this.dataGridView1.Rows[0].Cells[0].Value;
9794
for (int i = 1; i < this.dataGridView1.RowCount; i++)
9895
{
99-
if (GetConfiguratorPath(i) == null)
100-
{
101-
this.dataGridView1.Rows[i].Cells[0].Value = value;
102-
}
96+
this.dataGridView1.Rows[i].Cells[0].Value = value;
10397
}
10498
}
10599
else
@@ -126,15 +120,15 @@ private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventA
126120

127121
private void btnUninstall_Click(object sender, EventArgs e)
128122
{
129-
var list = new List<ModConfiguration>();
123+
var list = new Dictionary<ModConfiguration, bool>();
130124

131125
foreach (DataGridViewRow row in this.dataGridView1.Rows)
132126
{
133127
if (((bool)row.Cells[0].Value) && (row.Cells[1].Value is ModConfiguration conf))
134-
list.Add(conf);
135-
/*else
136-
MessageBox.Show("COULD NOT READ MOD FROM DATAGRID CELL THING");*/
137-
}//list.Add(new ModConfiguration(row.Cells[1].Value.ToString()));
128+
{
129+
list.Add(conf, (GetConfiguratorPath(row.Index) != null));
130+
}
131+
}
138132

139133
if (list.Count > 0)
140134
{
@@ -143,31 +137,47 @@ private void btnUninstall_Click(object sender, EventArgs e)
143137
if (result == DialogResult.Yes)
144138
{
145139
EasyUninstaller.UninstallMods(list);
146-
147140
this.Close();
148-
149141
}
150142
}
151-
152143
}
153144

154145
private void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
155146
{
156147
// if (e.ColumnIndex == this.dataGridView1.Columns["ConfiguratorColumn"].Index)
157-
if (e.ColumnIndex == 0 && e.RowIndex > 0)
148+
if (e.ColumnIndex == 3)
158149
{
159-
if (GetConfiguratorPath(e.RowIndex) != null)
150+
if (e.RowIndex > 0)
160151
{
161-
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
162-
163152
var w = Properties.Resources.ConfigIcon.Width;
164153
var h = Properties.Resources.ConfigIcon.Height;
165154
var x = e.CellBounds.Left + (e.CellBounds.Width - w) / 2;
166155
var y = e.CellBounds.Top + (e.CellBounds.Height - h) / 2;
167156

168-
e.Graphics.DrawImage(Properties.Resources.ConfigIcon, new Rectangle(x, y, w, h));
157+
Bitmap image = Properties.Resources.NoConfigIcon;
158+
if (GetConfiguratorPath(e.RowIndex) != null)
159+
{
160+
image = Properties.Resources.ConfigIcon;
161+
}
162+
163+
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
164+
e.Graphics.DrawImage(image, new Rectangle(x, y, w, h));
169165
e.Handled = true;
166+
}
167+
else
168+
{
169+
SolidBrush brush = new SolidBrush(e.CellStyle.BackColor);
170+
foreach (DataGridViewRow selectedRow in this.dataGridView1.SelectedRows)
171+
{
172+
if (selectedRow.Index == 0)
173+
{
174+
brush = new SolidBrush(e.CellStyle.SelectionBackColor);
175+
}
176+
}
170177

178+
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
179+
e.Graphics.FillRectangle(brush, e.CellBounds);
180+
e.Handled = true;
171181
}
172182
}
173183
}
@@ -186,7 +196,7 @@ private void ExecuteConfigurator(ModConfiguration mod)
186196
{
187197
try
188198
{
189-
EasyUninstaller.ExecuteConfigurator(mod);
199+
EasyUninstaller.ExecuteConfigurator(mod, false);
190200
this.Close();
191201
}
192202
catch (Exception ex)

0 commit comments

Comments
 (0)