From fddc11679c964fa9513f441ede3ee8e1bfa722bc Mon Sep 17 00:00:00 2001 From: Das Date: Wed, 20 Sep 2023 21:40:37 +0200 Subject: [PATCH] -added additonal checks -added/fixed ability to change game path + path gets automatically saved & selected now (thanks to szaamerik) -document folder is now 'dynamic' and not 'static' anymore (not everyone has it on C: drive, also thanks to szaamerik) ---Wheel Swap (replace)--- -fixed tool outputing multiple textures -fixed wheel texture not getting renamed properly --- ForzaModelTool/ForzaModelTool.csproj | 2 +- ForzaModelTool/MainWindow.xaml.cs | 48 +++++++++++----------- ForzaModelTool/Views/ModelSwapView.xaml.cs | 10 +++++ ForzaModelTool/Views/WheelSwapView.xaml.cs | 33 +++++++++++---- 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/ForzaModelTool/ForzaModelTool.csproj b/ForzaModelTool/ForzaModelTool.csproj index af8d3c0..e9f1210 100644 --- a/ForzaModelTool/ForzaModelTool.csproj +++ b/ForzaModelTool/ForzaModelTool.csproj @@ -7,7 +7,7 @@ true app.manifest stare.ico - 2.0.0 + 2.1.0 diff --git a/ForzaModelTool/MainWindow.xaml.cs b/ForzaModelTool/MainWindow.xaml.cs index f84df72..09377a2 100644 --- a/ForzaModelTool/MainWindow.xaml.cs +++ b/ForzaModelTool/MainWindow.xaml.cs @@ -12,6 +12,7 @@ public partial class MainWindow : Window public static bool validPath; public static string GamePath; public static string rawPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Forza Model Tool\"; + public static string curPath; public MainWindow() { @@ -34,9 +35,9 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) { TXT_GamePath.Text = File.ReadAllText(rawPath + @"\Path.txt"); GamePath = File.ReadAllText(rawPath + @"\Path.txt"); + curPath = GamePath; TXT_NoPath.Visibility = Visibility.Hidden; - // call the path button func to populate the list bc I was too lazy to analyze whats going on in the code lmao - BTN_Path_Click(new object(), new RoutedEventArgs()); + validPath = true; } } } @@ -64,33 +65,32 @@ private void MinButton_Click(object sender, RoutedEventArgs e) //click on path button > select game path, if wrong throws error message, if correct move on public void BTN_Path_Click(object sender, RoutedEventArgs e) { - //Pop-up to select Folder, yoinked from YT - if (TXT_GamePath.Text == "") - { - FolderBrowserDialog dialog = new(); - dialog.ShowDialog(); - GamePath = dialog.SelectedPath; - } + FolderBrowserDialog dialog = new(); + DialogResult result = dialog.ShowDialog(); + GamePath = dialog.SelectedPath; - //if game path includes ForzaHorizon5.exe or not - if (File.Exists(GamePath + "\\ForzaHorizon5.exe")) + if (result == System.Windows.Forms.DialogResult.OK) { - validPath = true; - TXT_GamePath.Text = new FileInfo(GamePath).FullName; - TXT_NoPath.Visibility = Visibility.Hidden; - //BTN_Path.IsEnabled = false; + //if game path includes ForzaHorizon5.exe or not + if (File.Exists(GamePath + "\\ForzaHorizon5.exe")) + { + validPath = true; + TXT_GamePath.Text = new FileInfo(GamePath).FullName; + TXT_NoPath.Visibility = Visibility.Hidden; - if (!File.Exists(rawPath + @"\Path.txt")) - using (File.Create(rawPath + @"\Path.txt")) { } // Prevent crash from "file in use" + if (!File.Exists(rawPath + @"\Path.txt")) + using (File.Create(rawPath + @"\Path.txt")) { } // Prevent crash from "file in use" - File.WriteAllText(rawPath + @"\Path.txt", GamePath); - } - else - { - System.Windows.MessageBox.Show("Path is wrong or not selected.", "Error", MessageBoxButton.OK, (MessageBoxImage)MessageBoxIcon.Error); - validPath = false; - TXT_NoPath.Visibility = Visibility.Visible; + File.WriteAllText(rawPath + @"\Path.txt", GamePath); + } + else + { + System.Windows.MessageBox.Show("Path is wrong or not selected.", "Error", MessageBoxButton.OK, (MessageBoxImage)MessageBoxIcon.Error); + validPath = false; + TXT_NoPath.Visibility = Visibility.Visible; + } } + else GamePath = curPath; } // view switching (from szaamerik) diff --git a/ForzaModelTool/Views/ModelSwapView.xaml.cs b/ForzaModelTool/Views/ModelSwapView.xaml.cs index 42be33d..1cbcb41 100644 --- a/ForzaModelTool/Views/ModelSwapView.xaml.cs +++ b/ForzaModelTool/Views/ModelSwapView.xaml.cs @@ -59,6 +59,16 @@ public void CarLists() LST_TargetCar.Items.Add(Path.GetFileNameWithoutExtension(car)); } } + + if (MainWindow.curPath != GamePath) + { + LST_DonorCar.Items.Clear(); + LST_TargetCar.Items.Clear(); + + MainWindow.curPath = GamePath; + + CarLists(); + } } //looks in GamePath + CarName.zip from list for .modelbin, lists all in new dropdown list diff --git a/ForzaModelTool/Views/WheelSwapView.xaml.cs b/ForzaModelTool/Views/WheelSwapView.xaml.cs index c59de02..f0ee153 100644 --- a/ForzaModelTool/Views/WheelSwapView.xaml.cs +++ b/ForzaModelTool/Views/WheelSwapView.xaml.cs @@ -94,6 +94,13 @@ public void CarList() foreach (string car in Cars) LST_DonorWheel.Items.Add(Path.GetFileNameWithoutExtension(car)); } + + if (MainWindow.curPath != GamePath) + { + LST_DonorWheel.Items.Clear(); + MainWindow.curPath = GamePath; + CarList(); + } } // if list empty, fill wheel list (aftermarket wheels) @@ -106,6 +113,13 @@ public void WheelList() foreach (string wheel in Wheels) LST_TargetWheel.Items.Add(Path.GetFileNameWithoutExtension(wheel)); } + + if (MainWindow.curPath != GamePath) + { + LST_TargetWheel.Items.Clear(); + MainWindow.curPath = GamePath; + WheelList(); + } } // populate wheel variant list (some cars have wheels with different depths aka variants) @@ -158,6 +172,8 @@ private void Swapper(bool bChecked) bool foundTexture = false; bool textureError = false; + MainWindow.FolderCheck(); + // if add-on checkbox checked, create wheel zip with car name, else create wheel zip of selected car wheel renamed to target wheel if (bChecked) { @@ -255,8 +271,8 @@ private void Swapper(bool bChecked) foreach (ZipArchiveEntry entry in archive.Entries) if (entry.FullName.Contains("_wheellf_ao", StringComparison.OrdinalIgnoreCase)) { - archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{entry.Name}", true); foundTexture = true; + archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true); break; } @@ -269,17 +285,18 @@ private void Swapper(bool bChecked) foreach (ZipArchiveEntry entry in archive.Entries) if (entry.FullName.Contains(LST_DonorWheel.SelectedItem.ToString() + "_wheellf_ao", StringComparison.OrdinalIgnoreCase)) { - archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true); foundTexture = true; + archive.GetEntry(entry.FullName).ExtractToFile($"{ExportWPath}{"\\"}{TexturePath}{"\\"}{LST_TargetWheel.SelectedItem}{"_wheelLF_AO.swatchbin"}", true); break; } } } + break; } if (!foundTexture) { - MessageBox.Show("Texture was not found.", "Missing Texture", MessageBoxButton.OK, MessageBoxImage.Error); textureError = true; + MessageBox.Show("Texture was not found.", "Missing Texture", MessageBoxButton.OK, MessageBoxImage.Error); } // if texture file found, create + move zip to \media\Stripped\MediaOverride\RC0\Cars\_library\scene\wheels @@ -288,7 +305,7 @@ private void Swapper(bool bChecked) if (!Directory.Exists(GamePathMediaOW)) Directory.CreateDirectory(GamePathMediaOW); - if (!File.Exists($"{ExportWPath}{".zip"}")) + if (!File.Exists($"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}")) { ZipFile.CreateFromDirectory(ExportWPath, $"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}"); MessageBox.Show($"{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}{".zip"}" + " was successfully created!", ":)"); @@ -301,6 +318,7 @@ private void Swapper(bool bChecked) if (result == MessageBoxResult.Yes) { //move + overwrite created target zip to '\media\Stripped\MediaOverride\RC0\Cars\_library\scene\wheels' + ZipFile.CreateFromDirectory(ExportWPath, $"{ExportWPath}{".zip"}"); File.Move($"{ExportWPath}{".zip"}", $"{GamePathMediaOW}{"\\"}{LST_TargetWheel.SelectedItem}{".zip"}", true); MessageBox.Show($"{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}{".zip"}" + " was successfully created!", ":)"); } @@ -312,11 +330,12 @@ private void Swapper(bool bChecked) } } } - // delete leftover folders/files - if (Directory.Exists(ExportCPath)) - Directory.Delete(ExportCPath, true); } } + + // delete leftover folders/files + if (Directory.Exists($"{rawPath}{"Wheel Swap\\"}{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}")) + Directory.Delete($"{rawPath}{"Wheel Swap\\"}{Path.GetFileNameWithoutExtension(LST_TargetWheel.SelectedItem.ToString())}", true); } } }