Skip to content

Commit 3caadb5

Browse files
committed
Common/Installer: Warn for blocked updates, force update check when mods need it, generate support info file
1 parent 3663660 commit 3caadb5

8 files changed

Lines changed: 133 additions & 18 deletions

File tree

‎ModAPI.Common/CommonStrings.Designer.cs‎

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

‎ModAPI.Common/CommonStrings.resx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,25 @@ If you continue to get this message, or the game is not installed from Steam, th
167167
<data name="SteamDownloadedButNotLaunchedTitle" xml:space="preserve">
168168
<value>Steam installation not completed</value>
169169
</data>
170+
<data name="UpdateCheckDisabledNotice" xml:space="preserve">
171+
<value>The Launcher Kit has been configured to skip checking for updates. You may be missing new features and bug fixes, and may be unable to use newer mods.
172+
173+
Outdated versions of the Launcher Kit are unsupported. If you cannot use automatic updates, for example, because this computer does not have an internet connection, please periodically check https://launcherkit.sporecommunity.com for the latest updates.
174+
175+
Would you like to automatically check for updates?</value>
176+
</data>
177+
<data name="UpdateCheckDisabledNoticeTitle" xml:space="preserve">
178+
<value>Launcher Kit Updates Disabled</value>
179+
</data>
170180
<data name="UpdateCheckFailed" xml:space="preserve">
171181
<value>The Launcher Kit could not connect to the update service. Try again in a few minutes, or check https://launcherkit.sporecommunity.com/support for help.</value>
172182
</data>
173183
<data name="UpdateCheckFailedTitle" xml:space="preserve">
174184
<value>Launcher Kit Update</value>
175185
</data>
186+
<data name="UpdateUnrecognized" xml:space="preserve">
187+
<value>The Launcher Kit must be updated manually. Please visit https://launcherkit.sporecommunity.com/support for more information.</value>
188+
</data>
176189
<data name="UpdatingDllsDialog" xml:space="preserve">
177190
<value>ModAPI DLLs are updating to version </value>
178191
</data>

‎ModAPI.Common/SupportInfo.cs‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static class SupportInfo
3434
/// By default, this is "%programdata%\Spore ModAPI Launcher Kit".
3535
/// The path will NOT have a trailing slash.
3636
/// </summary>
37-
public static String LauncherKitPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
37+
public static string LauncherKitPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
3838

3939

4040

@@ -120,7 +120,7 @@ private static DialogResult ShowMessageBox(string message, string title, bool sh
120120
}
121121

122122
// Append LK info
123-
message += $"\nLauncher Kit version: {LauncherKitVersionString}\nModAPI DLLs Version: {ModAPIDllsVersionString}";
123+
message += $"\nLauncher Kit version: {LauncherKitVersionString}\nModAPI DLLs version: {ModAPIDllsVersionString}";
124124
if (showPaths)
125125
{
126126
message += $"\nLauncher Kit path: {LauncherKitPath}";
@@ -156,5 +156,28 @@ public static DialogResult ShowError(string message, string title, bool showGame
156156
return ShowMessageBox(message, title, showGameInfo, showPaths, buttons, MessageBoxIcon.Error);
157157
}
158158

159+
160+
161+
/// <summary>
162+
/// Writes a text file containing support information.
163+
/// This includes the game version, game paths, Launcher Kit version, ModAPI DLLs version, and Launcher Kit path.
164+
/// </summary>
165+
public static void WriteSupportInfoFile(string path)
166+
{
167+
string[] text =
168+
{
169+
$"Spore version: {GameFullVersionInfoString}",
170+
$"Spore path: {SporePath.GetSporebinEP1Path()}",
171+
$"Spore Core data path: {SporePath.GetDataPath(SporePath.Game.Spore)}",
172+
$"Spore C&C data path: {SporePath.GetDataPath(SporePath.Game.CreepyAndCute)}",
173+
$"Spore GA data path: {SporePath.GetDataPath(SporePath.Game.GalacticAdventures)}",
174+
$"Launcher Kit version: {LauncherKitVersionString}",
175+
$"ModAPI DLLs version: {ModAPIDllsVersionString}",
176+
$"Launcher Kit path: {LauncherKitPath}",
177+
};
178+
179+
File.WriteAllLines(path, text);
180+
}
181+
159182
}
160183
}

‎ModAPI.Common/Update/UpdateManager.cs‎

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,34 @@ public static Version CurrentDllsBuild
4747
if (versions.Count() > 0)
4848
{
4949
Version minVer = versions.Min();
50-
return new Version(minVer.Major, minVer.Minor, minVer.Build, 0);
50+
return new Version(minVer.Major, minVer.Minor, minVer.Build, 0); // revision must be 0 for update checking purposes, as we use revision to indicate whether the DLL is for disc/download/combined versions
5151
}
5252
else
5353
return new Version(999, 999, 999, 999);
5454
}
5555
}
56+
public static bool IsUpdateCheckDisabled => File.Exists(UpdaterBlockPath);
5657

5758
public static void CheckForUpdates()
5859
{
60+
// Create appdata folder if it doesn't exist
61+
Directory.CreateDirectory(AppDataPath);
62+
63+
// Write support info file to appdata folder
64+
SupportInfo.WriteSupportInfoFile(Path.Combine(AppDataPath, "support.info"));
65+
66+
// Make sure game is not running before running any Launcher Kit apps
5967
if ((Process.GetProcessesByName("SporeApp").Length > 0) || (Process.GetProcessesByName("SporeApp_ModAPIFix").Length > 0))
6068
{
6169
SupportInfo.ShowWarning(CommonStrings.GameAlreadyRunning, CommonStrings.GameAlreadyRunningTitle, true, false);
6270
Process.GetCurrentProcess().Kill();
6371
}
6472

65-
if (!Directory.Exists(AppDataPath))
66-
Directory.CreateDirectory(AppDataPath);
67-
68-
File.WriteAllText(Path.Combine(AppDataPath, "path.info"), Directory.GetParent(Assembly.GetEntryAssembly().Location).ToString());
69-
73+
// Delete old updater exe if present
7074
if (File.Exists(UpdaterDestPath))
75+
{
7176
File.Delete(UpdaterDestPath);
77+
}
7278

7379
if (File.Exists(LastUpdateCheckTimePath))
7480
{
@@ -79,20 +85,35 @@ public static void CheckForUpdates()
7985
LastUpdateDateTimeFormat,
8086
CultureInfo.InvariantCulture);
8187

88+
// If it's been less than an hour since last update check, don't check again
8289
if ((DateTime.Now - lastUpdateCheckDateTime).TotalHours < 1)
8390
{
8491
return;
8592
}
93+
94+
// If update check is disabled, and it's been more than 30 days since last update check, prompt user to check for updates
95+
if (IsUpdateCheckDisabled && (DateTime.Now - lastUpdateCheckDateTime).TotalDays >= 30)
96+
{
97+
PromptUserUnblockUpdates();
98+
}
8699
}
87100
catch (Exception)
88101
{
89-
File.Delete(LastUpdateCheckTimePath);
102+
ResetLastUpdateCheckTime();
90103
}
91104
}
105+
else if (IsUpdateCheckDisabled)
106+
{
107+
// If update check is disabled, and this is a new install or we force checked for updates, prompt user to check for updates
108+
PromptUserUnblockUpdates();
109+
}
92110

93-
if (File.Exists(UpdaterBlockPath))
111+
// Record current time as last update check time
112+
File.WriteAllText(LastUpdateCheckTimePath, DateTime.Now.ToString(LastUpdateDateTimeFormat));
113+
114+
// Don't check for updates when block file exists
115+
if (IsUpdateCheckDisabled)
94116
{
95-
// don't check for updates when block file exists
96117
return;
97118
}
98119

@@ -254,8 +275,6 @@ public static void CheckForUpdates()
254275
dialog.ShowDialog();
255276
}
256277
}
257-
258-
File.WriteAllText(LastUpdateCheckTimePath, DateTime.Now.ToString(LastUpdateDateTimeFormat));
259278
}
260279
catch (Exception ex)
261280
{
@@ -288,7 +307,31 @@ static void ShowUpdateCheckFailedMessage(List<Exception> exceptions)
288307

289308
static void ShowUnrecognizedUpdateInfoVersionMessage()
290309
{
291-
SupportInfo.ShowInfo("This update to the Spore ModAPI Launcher Kit must be downloaded manually. Please visit https://launcherkit.sporecommunity.com/support for more information.", CommonStrings.UpdateCheckFailedTitle, false, true);
310+
SupportInfo.ShowInfo(CommonStrings.UpdateUnrecognized, CommonStrings.UpdateCheckFailedTitle, false, true);
311+
}
312+
313+
/// <summary>
314+
/// Forces the Launcher Kit to check for updates the next time it is run, skipping the one hour timeout.
315+
/// If updates are blocked, this will also prompt the user to unblock updates on next launch.
316+
/// </summary>
317+
public static void ResetLastUpdateCheckTime()
318+
{
319+
File.Delete(LastUpdateCheckTimePath);
292320
}
321+
322+
/// <summary>
323+
/// Warns the user that update checks are disabled, and prompts them to re-enable.
324+
/// Returns Yes or No depending on whether the user wants to re-enable update checks. If Yes, the update block file is removed.
325+
/// </summary>
326+
static DialogResult PromptUserUnblockUpdates()
327+
{
328+
var result = SupportInfo.ShowInfo(CommonStrings.UpdateCheckDisabledNotice, CommonStrings.UpdateCheckDisabledNoticeTitle, false, false, MessageBoxButtons.YesNo);
329+
if (result == DialogResult.Yes)
330+
{
331+
File.Delete(UpdaterBlockPath);
332+
}
333+
return result;
334+
}
335+
293336
}
294337
}

‎Spore ModAPI Easy Installer/EasyInstaller.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static ResultType TryExecuteInstaller(string inputFile, string modName)
400400
if (modCoreDllsVersion != null && modCoreDllsVersion > UpdateManager.CurrentDllsBuild)
401401
{
402402
SupportInfo.ShowWarning(Strings.OutdatedDllVersion.Replace("$MODNAME$", modName).Replace("$REQUIREDVERSION$", modCoreDllsVersion.ToString()), Strings.OutdatedDllVersionTitle, false, false);
403+
UpdateManager.ResetLastUpdateCheckTime();
403404
return ResultType.ModNotInstalled;
404405
}
405406
// If the version is not specified, continue installing (the value is optional because not all mods use the ModAPI SDK)

‎Spore ModAPI Easy Installer/Strings.Designer.cs‎

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

‎Spore ModAPI Easy Installer/Strings.resx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@
157157
<value>Installation completed</value>
158158
</data>
159159
<data name="OutdatedDllVersion" xml:space="preserve">
160-
<value> cannot be installed, because it requires a newer version of the ModAPI DLLs. Please restart the launcher and allow it to update.
160+
<value>"$MODNAME$" cannot be installed, because it requires a newer version of the ModAPI DLLs. Please restart the launcher and allow it to update.
161161

162162
Required ModAPI DLLs version: $REQUIREDVERSION$ or higher</value>
163163
</data>
164164
<data name="InvalidDllVersion" xml:space="preserve">
165-
<value> cannot be installed, because it specifies an invalid version of the ModAPI DLLs. Please ask the mod developer for help.</value>
165+
<value>"$MODNAME$" cannot be installed, because it specifies an invalid version of the ModAPI DLLs. Please ask the mod developer for help.</value>
166166
</data>
167167
<data name="UnauthorizedAccess" xml:space="preserve">
168168
<value>The Easy Installer does not currently have permission to install or change mods. You may need to right-click the Easy Installer and "Run as Administrator".</value>

‎Spore ModAPI Easy Installer/XmlInstallerWindow.xaml.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ private void PrepareInstaller()
198198
if ((Document.SelectSingleNode("/mod").Attributes["dllsBuild"] != null) && (Version.TryParse(Document.SelectSingleNode("/mod").Attributes["dllsBuild"].Value + ".0", out Version minFeaturesLevel)))
199199
{
200200
if (minFeaturesLevel > UpdateManager.CurrentDllsBuild)
201+
{
202+
UpdateManager.ResetLastUpdateCheckTime();
201203
CyclePage(0, 2);
204+
}
202205
}
203206
else
204207
throw new Exception("This Mod has not specified a valid minimum features level. Please inform the mod's developer of this.");
@@ -283,6 +286,7 @@ private void PrepareInstaller()
283286
}
284287
else
285288
{
289+
UpdateManager.ResetLastUpdateCheckTime();
286290
CyclePage(0, 2);
287291
}
288292
}

0 commit comments

Comments
 (0)