Skip to content

Commit

Permalink
Merge pull request #859 from shananas/AutoUpdate
Browse files Browse the repository at this point in the history
Auto Update toggle added to info menu in Mod Manager.
  • Loading branch information
Vladabdf authored Sep 1, 2023
2 parents 6d5f6f7 + 555ee62 commit f072592
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
10 changes: 10 additions & 0 deletions OpenKh.Tools.ModsManager/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private class Config
public int RegionId { get; internal set; }
public bool PanaceaInstalled { get; internal set; }
public bool DevView { get; internal set; }
public bool AutoUpdateMods { get; internal set; }
public bool isEGSVersion { get; internal set; } = true;
public bool kh1 { get; internal set; }
public bool kh2 { get; internal set; } = true;
Expand Down Expand Up @@ -282,6 +283,15 @@ public static bool DevView
_config.Save(ConfigPath);
}
}
public static bool AutoUpdateMods
{
get => _config.AutoUpdateMods;
set
{
_config.AutoUpdateMods = value;
_config.Save(ConfigPath);
}
}
public static bool IsEGSVersion
{
get => _config.isEGSVersion;
Expand Down
28 changes: 23 additions & 5 deletions OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Xe.Tools;
Expand Down Expand Up @@ -41,6 +38,7 @@ public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState
private bool _pc;
private bool _panaceaInstalled;
private bool _devView;
private bool _autoUpdateMods = false;
private string _launchGame = "kh2";
private List<string> _supportedGames = new List<string>()
{
Expand Down Expand Up @@ -118,6 +116,15 @@ public bool DevView
ConfigurationService.DevView = DevView;
OnPropertyChanged(nameof(PatchVisible));
}
}
public bool AutoUpdateMods
{
get => _autoUpdateMods;
set
{
_autoUpdateMods = value;
ConfigurationService.AutoUpdateMods = _autoUpdateMods;
}
}
public bool PanaceaInstalled
{
Expand Down Expand Up @@ -226,7 +233,9 @@ public MainViewModel()
if (_supportedGames.Contains(ConfigurationService.LaunchGame) && PC)
_launchGame = ConfigurationService.LaunchGame;
else
ConfigurationService.LaunchGame = _launchGame;
ConfigurationService.LaunchGame = _launchGame;

AutoUpdateMods = ConfigurationService.AutoUpdateMods;

Log.OnLogDispatch += (long ms, string tag, string message) =>
_debuggingWindow.Log(ms, tag, message);
Expand Down Expand Up @@ -848,7 +857,16 @@ private async Task FetchUpdates()

Application.Current.Dispatcher.Invoke(() =>
mod.UpdateCount = modUpdate.UpdateCount);
}
}
if (AutoUpdateMods)
{
foreach (var mod in ModsList)
{
if (mod.UpdateCount > 0)
await ModsService.Update(mod.Source);
}
ReloadModsList();
}
}

private async Task UpdateOpenkhAsync()
Expand Down
1 change: 1 addition & 0 deletions OpenKh.Tools.ModsManager/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</MenuItem>
<MenuItem Header="_Settings">
<MenuItem Header="Run _wizard" Command="{Binding WizardCommand}" InputGestureText="Alt+W"/>
<MenuItem Header="Auto Update Mods" IsCheckable="True" ToolTip="When enabled Mod Manager will automatically update all mods on startup." IsChecked="{Binding AutoUpdateMods}"/>
</MenuItem>
<MenuItem Header="_Info">
<MenuItem IsEnabled="False">
Expand Down

0 comments on commit f072592

Please sign in to comment.