Skip to content

Commit

Permalink
Support software update #23
Browse files Browse the repository at this point in the history
  • Loading branch information
anon5r committed Feb 22, 2022
1 parent d6874c7 commit cc1964a
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 13 deletions.
6 changes: 6 additions & 0 deletions KsGameLauncher/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@
<setting name="Language" serializeAs="String">
<value>system</value>
</setting>
<setting name="UpdateCheckInterval" serializeAs="String">
<value>0</value>
</setting>
<setting name="UpdateCheckIntervalUnit" serializeAs="String">
<value>0</value>
</setting>
</KsGameLauncher.Properties.Settings>
<KonaStaGameLauncher.Properties.Settings>
<setting name="appInfoURL" serializeAs="String">
Expand Down
53 changes: 47 additions & 6 deletions KsGameLauncher/Forms/OptionsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 72 additions & 5 deletions KsGameLauncher/Forms/OptionsForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KsGameLauncher.Utils;
using KsGameLauncher.Structures;
using System;
using System.Diagnostics;
using System.Windows.Forms;
Expand All @@ -24,15 +25,15 @@ public OptionsForm()
private void OptionsForm_Load(object sender, EventArgs e)
{
Icon = Properties.Resources.appIcon;
string[] items = {
string[] menuSizes = {
// Normal
Properties.Strings.ContextMenuSize_Text_Normal,
// Large
Properties.Strings.ContextMenuSize_Text_Large
};
comboBox_ContextMenuSize.Items.Clear();
comboBox_ContextMenuSize.Items.AddRange(items);
// Language
comboBox_ContextMenuSize.Items.AddRange(menuSizes);
// Languages
Language currentLang = (string.IsNullOrEmpty(Properties.Settings.Default.Language)
|| Properties.Settings.Default.Language == Properties.Resources.DefaultLanguage)
? Languages.GetLanguage(Properties.Resources.DefaultLanguage)
Expand All @@ -47,13 +48,48 @@ private void OptionsForm_Load(object sender, EventArgs e)
Debug.WriteLine(String.Format("[OPTION:Load] Language comboBox selectedIndex: {0}", comboBox_Languages.Items.IndexOf(currentLang)));
#endif

// Check update
int[] updateIntervalsDays = { 1, 3, 7, 14 }; // None, everyday, 3 days, 7 days, 2 weeks
comboBox_CheckInterval.Items.Clear();
comboBox_CheckInterval.Items.Add(new CheckInterval(0, CheckInterval.UnitType.None));
for (int i = 0; i < updateIntervalsDays.Length; i++)
{
CheckInterval check = new CheckInterval(updateIntervalsDays[i], CheckInterval.UnitType.Days);
comboBox_CheckInterval.Items.Add(check);
}
#if DEBUG
for (int i = 0; i < updateIntervalsDays.Length; i++)
{
CheckInterval check = new CheckInterval(updateIntervalsDays[i], CheckInterval.UnitType.Minutes);
comboBox_CheckInterval.Items.Add(check);
}
#endif



// Default values
checkBox_UseProxy.Checked = Properties.Settings.Default.UseProxy;
checkBox_Notification.Checked = Properties.Settings.Default.EnableNotification;
checkBox_ConfirmExit.Checked = Properties.Settings.Default.ShowConfirmExit;
checkBox_DisplayInstalledGamesOnly.Checked = Properties.Settings.Default.ShowOnlyInstalledGames;
checkBox_RegisterCustomURI.Checked = Properties.Settings.Default.RegisterCustomURI;
comboBox_ContextMenuSize.SelectedIndex = Properties.Settings.Default.ContextMenuSize;
int intervalSelectedIndex = 0;
if (Properties.Settings.Default.UpdateCheckInterval > 0)
{
int settingInterval = Properties.Settings.Default.UpdateCheckInterval;
CheckInterval.UnitType settingUnit = Properties.Settings.Default.UpdateCheckIntervalUnit;
for (int i = 0; i < comboBox_CheckInterval.Items.Count; i++)
{
CheckInterval intervalItem = (CheckInterval)comboBox_CheckInterval.Items[i];
if (intervalItem.Interval == settingInterval && intervalItem.Unit == settingUnit)
{
intervalSelectedIndex = i;
break;
}
}
}
comboBox_CheckInterval.SelectedIndex = intervalSelectedIndex;

// String
Text = Properties.Strings.OptionsWindowTitle;
Expand All @@ -66,6 +102,8 @@ private void OptionsForm_Load(object sender, EventArgs e)
linkLabel_OpenProxySettings.Text = Properties.Strings.OptionsProxySettingsLink;
button_Save.Text = Properties.Strings.ButtonSave;
button_SyncAppInfo.Text = Properties.Strings.SynchWithServerButton;
label_CheckAutoUpdateInterval.Text = Properties.Strings.CheckAutoUpdate;
button_ManualCheck.Text = Properties.Strings.ManualUpdateCheckButton;

checkBox_RegisterCustomURI.Text = (checkBox_RegisterCustomURI.Checked)
? Properties.Strings.ShortcutLaunchCheckboxDisable
Expand Down Expand Up @@ -104,17 +142,38 @@ private void Button_Save_Click(object sender, EventArgs e)
restartApp = true;
}

// AutoUpdate settings
CheckInterval selectedInterval = (CheckInterval)comboBox_CheckInterval.Items[comboBox_CheckInterval.SelectedIndex];
#if DEBUG
Debug.WriteLine(String.Format("[OPTION:Save] AutoUpdateCheck.Interval before changes: {0}", Properties.Settings.Default.UpdateCheckInterval));
Debug.WriteLine(String.Format("[OPTION:Save] AutoUpdateCheck.Interval before unit: {0}", Properties.Settings.Default.UpdateCheckIntervalUnit));
Debug.WriteLine(String.Format("[OPTION:Save] AutoUpdateCheck.Interval selected: {0}", selectedInterval.Interval));
Debug.WriteLine(String.Format("[OPTION:Save] AutoUpdateCheck.Interval unit: {0}", selectedInterval.Unit));
#endif
// need to update thread interval
bool reloadAutoUpdate = false;
if (Properties.Settings.Default.UpdateCheckInterval != selectedInterval.Interval
|| Properties.Settings.Default.UpdateCheckIntervalUnit != selectedInterval.Unit)
reloadAutoUpdate = true;


// Save settings
Properties.Settings.Default.UseProxy = checkBox_UseProxy.Checked;
Properties.Settings.Default.EnableNotification = checkBox_Notification.Checked;
Properties.Settings.Default.ShowConfirmExit = checkBox_ConfirmExit.Checked;
Properties.Settings.Default.ShowOnlyInstalledGames = checkBox_DisplayInstalledGamesOnly.Checked;
Properties.Settings.Default.ContextMenuSize = comboBox_ContextMenuSize.SelectedIndex;
Properties.Settings.Default.Language = ((Language)comboBox_Languages.Items[comboBox_Languages.SelectedIndex]).ID;
Properties.Settings.Default.Language = selectedLang.ID;
Properties.Settings.Default.UpdateCheckInterval = selectedInterval.Interval;
Properties.Settings.Default.UpdateCheckIntervalUnit = selectedInterval.Unit;
Properties.Settings.Default.Save();

if (needsUpdateGames)
Program.mainContext.LoadGamesMenu(); // Re-load menu
Program.mainContext.LoadGamesMenu(); // Reload menu

if (reloadAutoUpdate)
UpdateChecker.UpdateInterval(selectedInterval.Interval, selectedInterval.Unit);


if (restartApp)
{
Expand Down Expand Up @@ -203,5 +262,13 @@ private void CheckBox_RegisterCustomURI_Click(object sender, EventArgs e)
checkBox_RegisterCustomURI.Checked = true;
}
}

private void Button_ManualCheck_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show(Properties.Strings.ConfirmToExecuteCheckManualUpdate,
Properties.Strings.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
if (result == DialogResult.Yes)
AppUtil.CheckUpdate();
}
}
}
2 changes: 2 additions & 0 deletions KsGameLauncher/KsGameLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Structures\CheckInterval.cs" />
<Compile Include="Structures\InternetShortcut.cs" />
<Compile Include="Exceptions\InvalidFormatException.cs" />
<Compile Include="Utils\AppUtil.cs" />
<Compile Include="Utils\UpdateChecker.cs" />
<Compile Include="Utils\Common.cs" />
<Compile Include="Utils\Crypt.cs" />
<Compile Include="Utils\GameRegistry.cs" />
Expand Down
7 changes: 5 additions & 2 deletions KsGameLauncher/MainContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using AutoUpdaterDotNET;

namespace KsGameLauncher
{
Expand Down Expand Up @@ -29,7 +28,11 @@ public MainContext(MainForm _form) : base()
CreateNotificationIcon();


AutoUpdater.Start(Properties.Resources.UpdateXML, typeof(Program).Assembly);
if (Properties.Settings.Default.UpdateCheckInterval > 0)
Utils.UpdateChecker.CreateUpdateCheker(Properties.Settings.Default.UpdateCheckInterval,
Properties.Settings.Default.UpdateCheckIntervalUnit);
else
Utils.AppUtil.CheckUpdate();
}

~MainContext()
Expand Down
13 changes: 13 additions & 0 deletions KsGameLauncher/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions KsGameLauncher/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,11 @@
&lt;string&gt;ja-JP&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="UpdateCheckInterval" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="UpdateCheckIntervalUnit" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit cc1964a

Please sign in to comment.