Skip to content

Commit

Permalink
Merge pull request #948 from shananas/master
Browse files Browse the repository at this point in the history
Lua Backend Configure Actual Error Handling
  • Loading branch information
Vladabdf authored Dec 8, 2023
2 parents 761065c + 05516c6 commit 7fcc71f
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 13 deletions.
116 changes: 104 additions & 12 deletions OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,25 +630,117 @@ public SetupWizardViewModel()
if (File.Exists(Path.Combine(PcReleaseLocation, "LuaBackend.toml")))
{
string config = File.ReadAllText(Path.Combine(PcReleaseLocation, "LuaBackend.toml")).Replace("\\", "/").Replace("\\\\", "/");
if (LuaScriptPaths.Contains("kh1") && !config.Contains("mod/kh1/scripts"))
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("\\", "/"));
if (config.Contains("mod/kh1/scripts"))
{
var errorMessage = MessageBox.Show($"Your Lua Backend is already configured to run Lua scripts for KH1 from an OpenKH Mod Manager." +
$" Do you want to change Lua Backend to run scripts for KH1 from this version of OpenKH Mod Manager instead?", "Warning",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);

switch (errorMessage)
{
case MessageBoxResult.Yes:
{
int index = config.IndexOf("scripts", config.IndexOf("[kh1]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/kh1/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts\" , relative = false}]").Replace("\\", "/"));
break;
}
}
}
else
{
int index = config.IndexOf("scripts", config.IndexOf("[kh1]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/kh1/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh1/scripts\" , relative = false}]").Replace("\\", "/"));
}
}
if (LuaScriptPaths.Contains("kh2") && !config.Contains("mod/kh2/scripts"))
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("\\", "/"));
if (config.Contains("mod/kh2/scripts"))
{
var errorMessage = MessageBox.Show($"Your Lua Backend is already configured to run Lua scripts for KH2 from an OpenKH Mod Manager." +
$" Do you want to change Lua Backend to run scripts for KH2 from this version of OpenKH Mod Manager instead?", "Warning",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);

switch (errorMessage)
{
case MessageBoxResult.Yes:
{
int index = config.IndexOf("scripts", config.IndexOf("[kh2]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/kh2/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts\" , relative = false}]").Replace("\\", "/"));
break;
}
}
}
else
{
int index = config.IndexOf("scripts", config.IndexOf("[kh2]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/kh2/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "kh2/scripts\" , relative = false}]").Replace("\\", "/"));
}
}
if (LuaScriptPaths.Contains("bbs") && !config.Contains("mod/bbs/scripts"))
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("\\", "/"));
if (config.Contains("mod/bbs/scripts"))
{
var errorMessage = MessageBox.Show($"Your Lua Backend is already configured to run Lua scripts for BBS from an OpenKH Mod Manager." +
$" Do you want to change Lua Backend to run scripts for BBS from this version of OpenKH Mod Manager instead?", "Warning",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);

switch (errorMessage)
{
case MessageBoxResult.Yes:
{
int index = config.IndexOf("scripts", config.IndexOf("[bbs]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/bbs/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts\" , relative = false}]").Replace("\\", "/"));
break;
}
}
}
else
{
int index = config.IndexOf("scripts", config.IndexOf("[bbs]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/bbs/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "bbs/scripts\" , relative = false}]").Replace("\\", "/"));
}
}
if (LuaScriptPaths.Contains("Recom") && !config.Contains("mod/Recom/scripts"))
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("\\", "/"));
if (config.Contains("mod/Recom/scripts"))
{
var errorMessage = MessageBox.Show($"Your Lua Backend is already configured to run Lua scripts for ReCoM from an OpenKH Mod Manager." +
$" Do you want to change Lua Backend to run scripts for ReCoM from this version of OpenKH Mod Manager instead?", "Warning",
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);

switch (errorMessage)
{
case MessageBoxResult.Yes:
{
int index = config.IndexOf("scripts", config.IndexOf("[recom]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/recom/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts\" , relative = false}]").Replace("\\", "/"));
break;
}
}
}
else
{
int index = config.IndexOf("scripts", config.IndexOf("[recom]"));
config = config.Remove(index, config.IndexOf("]", index) - index + 1);
config = config.Insert(index, "scripts = [{ path = \"scripts/recom/\", relative = true }" +
", {path = \"" + Path.Combine(ConfigurationService.GameModPath, "Recom/scripts\" , relative = false}]").Replace("\\", "/"));
}
}
File.WriteAllText(Path.Combine(PcReleaseLocation, "LuaBackend.toml"), config);
OnPropertyChanged(nameof(IsLuaBackendInstalled));
Expand Down
2 changes: 1 addition & 1 deletion OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
<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.
If you wish to uninstall Lua Backend 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>
Expand Down

0 comments on commit 7fcc71f

Please sign in to comment.