UWUVCI-AIO-WPF/UWUVCI AIO WPF/UI/Windows/IMG_Message - Kopieren - Kopieren - Kopieren.xaml.cs
ZestyTS 3f2e32756c Added Null Propagation to this.Owner.GetType()
On the rare occassion when downloading different bases, the whole application would crash out. I've been able to figure out that it's in the DownloadWait.xaml.cs specifically on the "this.Owner.GetType()" check. After adding the null propgation, I haven't received the issue since, so I've gone ahead and applied the fix everywhere for consistency and to err on the side of caution.
2020-09-30 08:32:34 -07:00

151 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations;
namespace UWUVCI_AIO_WPF.UI.Windows
{
/// <summary>
/// Interaktionslogik für IMG_Message.xaml
/// </summary>
public partial class LOGSHOW : Window, IDisposable
{
private static readonly string tempPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "bin", "temp");
private static readonly string toolsPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "bin", "Tools");
string copy = "";
string pat = "";
BitmapImage bitmap = new BitmapImage();
public LOGSHOW(string path)
{
try
{
if (this.Owner?.GetType() != typeof(MainWindow))
{
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}
catch (Exception)
{
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
pat = String.Copy(path);
InitializeComponent();
if (Directory.Exists(System.IO.Path.Combine(tempPath, "image"))) Directory.Delete(System.IO.Path.Combine(tempPath, "image"), true);
Directory.CreateDirectory(System.IO.Path.Combine(tempPath, "image"));
if (path == "Added via Config")
{
File.WriteAllBytes(System.IO.Path.Combine(tempPath, "image", "log." + (FindResource("mvm") as MainViewModel).GameConfiguration.TGALog.extension), (FindResource("mvm") as MainViewModel).GameConfiguration.TGALog.ImgBin);
pat = System.IO.Path.Combine(tempPath, "image", "log." + (FindResource("mvm") as MainViewModel).GameConfiguration.TGALog.extension);
}
if (new FileInfo(pat).Extension.Contains("tga"))
{
using (Process conv = new Process())
{
conv.StartInfo.UseShellExecute = false;
conv.StartInfo.CreateNoWindow = true;
conv.StartInfo.FileName = System.IO.Path.Combine(toolsPath, "tga2png.exe");
conv.StartInfo.Arguments = $"-i \"{pat}\" -o \"{System.IO.Path.Combine(tempPath, "image")}\"";
conv.Start();
conv.WaitForExit();
foreach (string sFile in Directory.GetFiles(System.IO.Path.Combine(tempPath, "image"), "*.png"))
{
copy = sFile;
}
}
}
else
{
copy = pat;
}
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(copy, UriKind.Absolute);
image.EndInit();
image.Freeze();
img.Source = image;
if(path == "Added via Config")
{
File.Delete(pat);
}
}
public void Dispose()
{
}
private void Canc_Click(object sender, RoutedEventArgs e)
{
bitmap.UriSource = null;
this.Close();
}
private void wind_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
(FindResource("mvm") as MainViewModel).mw.Topmost = true;
}
private void wind_Closed(object sender, EventArgs e)
{
(FindResource("mvm") as MainViewModel).mw.Topmost = false;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MainViewModel mvm = FindResource("mvm") as MainViewModel;
switch (mvm.GameConfiguration.Console)
{
case GameBaseClassLibrary.GameConsoles.NDS:
case GameBaseClassLibrary.GameConsoles.NES:
case GameBaseClassLibrary.GameConsoles.SNES:
case GameBaseClassLibrary.GameConsoles.MSX:
(mvm.Thing as OtherConfigs).clearImages(3);
break;
case GameBaseClassLibrary.GameConsoles.GBA:
(mvm.Thing as GBA).clearImages(3);
break;
case GameBaseClassLibrary.GameConsoles.WII:
if(mvm.test == GameBaseClassLibrary.GameConsoles.GCN)
{
(mvm.Thing as GCConfig).clearImages(3);
}
else
{
(mvm.Thing as WiiConfig).clearImages(3);
}
break;
case GameBaseClassLibrary.GameConsoles.N64:
(mvm.Thing as N64Config).clearImages(3);
break;
case GameBaseClassLibrary.GameConsoles.TG16:
(mvm.Thing as TurboGrafX).clearImages(3);
break;
}
this.Close();
}
}
}