Skip to content

Commit 8830dd9

Browse files
committed
ModApi.UpdateManager: only check for updates once hourly
1 parent 77ff7fc commit 8830dd9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ModApi.UpdateManager/UpdateManager.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.ComponentModel;
55
using System.Diagnostics;
6+
using System.Globalization;
67
using System.IO;
78
using System.Linq;
89
using System.Net;
@@ -26,6 +27,7 @@ public static class UpdateManager
2627
};
2728
public static string PathPrefix = LauncherKitUpdateUrls.First();
2829
public static string AppDataPath = Environment.ExpandEnvironmentVariables(@"%appdata%\Spore ModAPI Launcher");
30+
public static string UpdaterDateTimePath = Path.Combine(AppDataPath, "updateDateTime.info");
2931
public static string UpdateInfoDestPath = Path.Combine(AppDataPath, "update.info");
3032
public static string UpdaterDestPath = Path.Combine(AppDataPath, "updater.exe");
3133
public static string UpdaterBlockPath = Path.Combine(AppDataPath, "noUpdateCheck.info");
@@ -113,6 +115,26 @@ public static void CheckForUpdates()
113115
if (File.Exists(UpdaterDestPath))
114116
File.Delete(UpdaterDestPath);
115117

118+
if (File.Exists(UpdaterDateTimePath))
119+
{
120+
try
121+
{
122+
string lastUpdateDateTimeString = File.ReadAllText(UpdaterDateTimePath);
123+
DateTime lastUpdateDateTime = DateTime.ParseExact(lastUpdateDateTimeString,
124+
"yyyy-MM-dd HH:mm",
125+
CultureInfo.InvariantCulture);
126+
127+
if ((DateTime.Now - lastUpdateDateTime).TotalHours < 1)
128+
{
129+
return;
130+
}
131+
}
132+
catch (Exception)
133+
{
134+
File.Delete(UpdaterDateTimePath);
135+
}
136+
}
137+
116138
if (!File.Exists(UpdaterBlockPath) && HasInternetConnection())
117139
{
118140
try
@@ -261,6 +283,8 @@ public static void CheckForUpdates()
261283
dialog.ShowDialog();
262284
}
263285
}
286+
287+
File.WriteAllText(UpdaterDateTimePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
264288
}
265289
catch (Exception ex)
266290
{

0 commit comments

Comments
 (0)