Files
@ d6859ea7177f
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/ViewModels/ViewModelBase.cs - annotation
d6859ea7177f
3.1 KiB
text/x-csharp
Add some sanity checks on min/max concentration and min/max reagents in recipe generation. Also, clear out the search queue when generation has finished so the queue isn't loaded next time. This fixes the start/resume button state when entering the recipe generator after a prior run had finished.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia.Platform;
using DesertPaintCodex.Views;
using ReactiveUI;
namespace DesertPaintCodex.ViewModels
{
public class ViewModelBase : ReactiveObject
{
public ViewModelBase()
{
ShowMessageBoxDialog = new Interaction<MessageBoxViewModel, int>();
}
public void OpenBrowser(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// If no associated application/json MimeType is found xdg-open opens retun error
// but it tries to open it anyway using the console editor (nano, vim, other..)
ShellExec($"xdg-open {url}", waitForExit: false);
}
else
{
using (Process.Start(new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? url : "open",
Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? $"-e {url}" : "",
CreateNoWindow = true,
UseShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
})){}
}
}
private static void ShellExec(string cmd, bool waitForExit = true)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
using var process = Process.Start(
new ProcessStartInfo
{
FileName = "/bin/sh",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}
);
if (waitForExit)
{
process?.WaitForExit();
}
}
public async Task<int> ShowMessageBox(string title, string message, string? optionA = null, string? optionB = null, string? optionC = null)
{
if (string.IsNullOrEmpty(optionA))
{
optionA = "Ok";
}
return await ShowMessageBoxDialog.Handle(new MessageBoxViewModel(title, message, optionA, optionB, optionC));
}
public async Task<bool> ShowYesNoBox(string title, string message)
{
int rawVal = await ShowMessageBox(title, message, "No", "Yes");
return rawVal == 1;
}
public async Task<bool> ShowOkCancelBox(string title, string message)
{
int rawVal = await ShowMessageBox(title, message, "Cancel", "Ok");
return rawVal == 1;
}
public async Task ShowInfoBox(string title, string message)
{
await ShowMessageBox(title, message, "Close");
}
public Interaction<MessageBoxViewModel, int> ShowMessageBoxDialog { get; }
}
}
|