Skip to content

Commit 607ab4b

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

File tree

10 files changed

+112
-61
lines changed

10 files changed

+112
-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: 20 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,21 +200,20 @@ 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);
213+
if (uninstall)
214+
{
215+
process.WaitForExit();
216+
}
211217
}
212218
else
213219
{
@@ -216,12 +222,6 @@ public static void ExecuteConfigurator(ModConfiguration mod)
216222
throw new Exception(Strings.ConfiguratorDoesNotExist);
217223
}
218224

219-
220-
221-
222-
223-
224-
225225
var process = Process.Start(new ProcessStartInfo()
226226
{
227227
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>
8 KB
Loading

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.

0 commit comments

Comments
 (0)