Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a uninstall button for Lua Backend #947

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions OpenKh.Tools.ModsManager/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ private class Config
public bool DevView { get; internal set; } = false;
public bool AutoUpdateMods { get; internal set; }
public bool isEGSVersion { get; internal set; } = true;
public bool Extractkh1 { get; internal set; }
public bool Extractkh2 { get; internal set; } = true;
public bool Extractbbs { get; internal set; }
public bool Extractrecom { get; internal set; }
public List<string> GamesToExtract { get; internal set; } = new List<string> { "kh2" };
public string LaunchGame { get; internal set; } = "kh2";

public void Save(string fileName)
Expand Down Expand Up @@ -336,37 +333,65 @@ public static bool IsEGSVersion
}
public static bool Extractkh1
{
get => _config.Extractkh1;
get => _config.GamesToExtract.Contains("kh1");
set
{
_config.Extractkh1 = value;
if (value)
{
_config.GamesToExtract.Add("kh1");
}
else
{
_config.GamesToExtract.Remove("kh1");
}
_config.Save(ConfigPath);
}
}
public static bool Extractkh2
{
get => _config.Extractkh2;
get => _config.GamesToExtract.Contains("kh2");
set
{
_config.Extractkh2 = value;
if (value)
{
_config.GamesToExtract.Add("kh2");
}
else
{
_config.GamesToExtract.Remove("kh2");
}
_config.Save(ConfigPath);
}
}
public static bool Extractbbs
{
get => _config.Extractbbs;
get => _config.GamesToExtract.Contains("bbs");
set
{
_config.Extractbbs = value;
if (value)
{
_config.GamesToExtract.Add("bbs");
}
else
{
_config.GamesToExtract.Remove("bbs");
}
_config.Save(ConfigPath);
}
}
public static bool Extractrecom
{
get => _config.Extractrecom;
get => _config.GamesToExtract.Contains("Recom");
set
{
_config.Extractrecom = value;
if (value)
{
_config.GamesToExtract.Add("Recom");
}
else
{
_config.GamesToExtract.Remove("Recom");
}
_config.Save(ConfigPath);
}
}
Expand Down
95 changes: 55 additions & 40 deletions OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ public class SetupWizardViewModel : BaseNotifyPropertyChanged
private string _pcReleaseLanguage;
private string _gameDataLocation;
private bool _isEGSVersion;
private bool _Extractkh2 = ConfigurationService.Extractkh2;
private bool _Extractkh1 = ConfigurationService.Extractkh1;
private bool _Extractbbs = ConfigurationService.Extractbbs;
private bool _Extractrecom = ConfigurationService.Extractrecom;
private List<string> LuaScriptPaths = new List<string>();
private bool _overrideGameDataFound = false;

private Xceed.Wpf.Toolkit.WizardPage _wizardPageAfterIntro;
public Xceed.Wpf.Toolkit.WizardPage WizardPageAfterIntro
Expand Down Expand Up @@ -211,6 +208,8 @@ public string PcReleaseLocation
OnPropertyChanged(nameof(PanaceaNotInstalledVisibility));
OnPropertyChanged(nameof(IsGameSelected));
OnPropertyChanged(nameof(IsGameDataFound));
OnPropertyChanged(nameof(LuaBackendFoundVisibility));
OnPropertyChanged(nameof(LuaBackendNotFoundVisibility));
}
}
public bool IsEGSVersion
Expand All @@ -223,39 +222,23 @@ public bool IsEGSVersion
}
public bool Extractkh1
{
get => _Extractkh1;
set
{
_Extractkh1 = value;
ConfigurationService.Extractkh1 = value;
}
get => ConfigurationService.Extractkh1;
set => ConfigurationService.Extractkh1 = value;
}
public bool Extractkh2
{
get => _Extractkh2;
set
{
_Extractkh2 = value;
ConfigurationService.Extractkh2 = value;
}
get => ConfigurationService.Extractkh2;
set => ConfigurationService.Extractkh2 = value;
}
public bool Extractbbs
{
get => _Extractbbs;
set
{
_Extractbbs = value;
ConfigurationService.Extractbbs = value;
}
get => ConfigurationService.Extractbbs;
set => ConfigurationService.Extractbbs = value;
}
public bool Extractrecom
{
get => _Extractrecom;
set
{
_Extractrecom = value;
ConfigurationService.Extractrecom = value;
}
get => ConfigurationService.Extractrecom;
set => ConfigurationService.Extractrecom = value;
}
public bool LuaConfigkh1
{
Expand Down Expand Up @@ -317,6 +300,19 @@ public bool LuaConfigrecom
}
}
}
public bool OverrideGameDataFound
{
get => _overrideGameDataFound;
set
{
_overrideGameDataFound = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsGameDataFound));
OnPropertyChanged(nameof(GameDataNotFoundVisibility));
OnPropertyChanged(nameof(GameDataFoundVisibility));
}

}
public string PcReleaseLanguage
{
get => _pcReleaseLanguage;
Expand Down Expand Up @@ -352,7 +348,8 @@ public string GameDataLocation
(GameEdition == EpicGames && (GameService.FolderContainsUniqueFile("kh2", Path.Combine(GameDataLocation, "kh2")) ||
GameService.FolderContainsUniqueFile("kh1", Path.Combine(GameDataLocation, "kh1")) ||
File.Exists(Path.Combine(GameDataLocation, "bbs", "message")) ||
File.Exists(Path.Combine(GameDataLocation, "Recom", "SYS")))));
File.Exists(Path.Combine(GameDataLocation, "Recom", "SYS"))))||
OverrideGameDataFound);
public Visibility GameDataNotFoundVisibility => !IsGameDataFound ? Visibility.Visible : Visibility.Collapsed;
public Visibility GameDataFoundVisibility => IsGameDataFound ? Visibility.Visible : Visibility.Collapsed;
public Visibility ProgressBarVisibility => IsNotExtracting ? Visibility.Collapsed : Visibility.Visible;
Expand All @@ -362,11 +359,20 @@ public string GameDataLocation
public int RegionId { get; set; }
public bool IsLuaBackendInstalled
{
get => File.Exists(Path.Combine(PcReleaseLocation, "LuaBackend.dll")) &&
File.Exists(Path.Combine(PcReleaseLocation, "lua54.dll")) &&
File.Exists(Path.Combine(PcReleaseLocation, "LuaBackend.toml"));
get
{
if (PcReleaseLocation != null)
{
return File.Exists(Path.Combine(PcReleaseLocation, "LuaBackend.dll")) &&
File.Exists(Path.Combine(PcReleaseLocation, "lua54.dll")) &&
File.Exists(Path.Combine(PcReleaseLocation, "LuaBackend.toml"));
}
else
return false;
}
}
public RelayCommand InstallLuaBackendCommand { get; set; }
public RelayCommand RemoveLuaBackendCommand { get; set; }
public Visibility LuaBackendFoundVisibility => IsLuaBackendInstalled ? Visibility.Visible : Visibility.Collapsed;
public Visibility LuaBackendNotFoundVisibility => IsLuaBackendInstalled ? Visibility.Collapsed : Visibility.Visible;
public RelayCommand InstallPanaceaCommand { get; }
Expand Down Expand Up @@ -595,22 +601,22 @@ public SetupWizardViewModel()
if (LuaScriptPaths.Contains("kh1"))
{
int index = config.IndexOf("true }", config.IndexOf("[kh1]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("kh2"))
{
int index = config.IndexOf("true }", config.IndexOf("[kh2]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("bbs"))
{
int index = config.IndexOf("true }", config.IndexOf("[bbs]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("Recom"))
{
int index = config.IndexOf("true }", config.IndexOf("[recom]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts\" , relative = false}").Replace("\\", "/"));
}
File.WriteAllText(Path.Combine(PcReleaseLocation, "LuaBackend.toml"), config);
File.Delete(DownPath);
Expand All @@ -627,22 +633,22 @@ public SetupWizardViewModel()
if (LuaScriptPaths.Contains("kh1") && !config.Contains("mod/kh1/scripts"))
{
int index = config.IndexOf("true }", config.IndexOf("[kh1]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("kh2") && !config.Contains("mod/kh2/scripts"))
{
int index = config.IndexOf("true }", config.IndexOf("[kh2]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("bbs") && !config.Contains("mod/bbs/scripts"))
{
int index = config.IndexOf("true }", config.IndexOf("[bbs]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts\" , relative = false}").Replace("\\", "/"));
}
if (LuaScriptPaths.Contains("Recom") && !config.Contains("mod/Recom/scripts"))
{
int index = config.IndexOf("true }", config.IndexOf("[recom]")) + 6;
config = config.Insert(index, ", {path = " + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts , relative = false}").Replace("\\", "/"));
config = config.Insert(index, ", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts\" , relative = false}").Replace("\\", "/"));
}
File.WriteAllText(Path.Combine(PcReleaseLocation, "LuaBackend.toml"), config);
OnPropertyChanged(nameof(IsLuaBackendInstalled));
Expand All @@ -651,6 +657,15 @@ public SetupWizardViewModel()
}
}
});
RemoveLuaBackendCommand = new RelayCommand(_ =>
{
File.Delete(Path.Combine(PcReleaseLocation, "LuaBackend.dll"));
File.Delete(Path.Combine(PcReleaseLocation, "lua54.dll"));
File.Delete(Path.Combine(PcReleaseLocation, "LuaBackend.toml"));
OnPropertyChanged(nameof(IsLuaBackendInstalled));
OnPropertyChanged(nameof(LuaBackendFoundVisibility));
OnPropertyChanged(nameof(LuaBackendNotFoundVisibility));
});
}

private async Task ExtractGameData(string isoLocation, string gameDataLocation)
Expand Down
9 changes: 9 additions & 0 deletions OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<TextBlock Margin="0 0 0 3" Visibility="{Binding ExtractionCompleteVisibility}">
The extraction of the game's data succeded!
</TextBlock>
<TextBlock Margin="0 0 0 3" Visibility="{Binding PcReleaseConfigVisibility}" TextWrapping="Wrap">
<Run Foreground="Red">WARNING</Run>
If you do not extract a games data only Lua Scripts will function properly. Only check the box below if you will only be installing Lua Scripts in Mods Manager.
</TextBlock>
<CheckBox IsChecked="{Binding OverrideGameDataFound}" Content="Skip Game Extraction" Visibility="{Binding PcReleaseConfigVisibility}" Margin="0 0 0 4"/>
</StackPanel>
</xctk:WizardPage>
<xctk:WizardPage
Expand Down Expand Up @@ -281,6 +286,10 @@
</StackPanel>
<Button Margin="0 0 0 6" Content="Install and Configure Lua Backend" HorizontalAlignment="Left" Width="200" Command="{Binding InstallLuaBackendCommand}" CommandParameter="false" Visibility="{Binding LuaBackendNotFoundVisibility}"/>
<Button Margin="0 0 0 6" Content="Configure Lua Backend" HorizontalAlignment="Left" Width="200" Command="{Binding InstallLuaBackendCommand}" CommandParameter="true" Visibility="{Binding LuaBackendFoundVisibility}"/>
<TextBlock Margin="0 2 0 10" Visibility="{Binding LuaBackendFoundVisibility}" TextWrapping="Wrap">
If you wish to reinstall Lua Backend to fix scripts not loading and the configure button did not work or just to uninstall completely press the button below.
</TextBlock>
<Button Margin="0 0 0 6" Content="Uninstall Lua Backend" HorizontalAlignment="Left" Width="200" Command="{Binding RemoveLuaBackendCommand}" Visibility="{Binding LuaBackendFoundVisibility}"/>
</StackPanel>
</xctk:WizardPage>
<xctk:WizardPage
Expand Down
Loading