Skip to content

Commit c8bb774

Browse files
committed
New Version: 2.6
1 parent c0382f9 commit c8bb774

File tree

3 files changed

+59
-39
lines changed

3 files changed

+59
-39
lines changed

KenshiModTool/KenshiModTool.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<UseWPF>true</UseWPF>
7-
<Version>2.5</Version>
8-
<AssemblyVersion>2.5</AssemblyVersion>
7+
<Version>2.6</Version>
8+
<AssemblyVersion>2.6</AssemblyVersion>
99
<Configurations>Debug;Release;Standalone;SelfContained</Configurations>
1010
</PropertyGroup>
1111

@@ -40,6 +40,8 @@
4040

4141
<ItemGroup>
4242
<PackageReference Include="Autoupdater.NET.Official" Version="1.6.0" />
43+
<PackageReference Include="Gameloop.Vdf" Version="0.6.2" />
44+
<PackageReference Include="Gameloop.Vdf.JsonConverter" Version="0.2.1" />
4345
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.4.0" />
4446
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.4.0" />
4547
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />

KenshiModTool/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<TextBlock Margin="0,5,0,0" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center" FontWeight="Bold"><Run Text="Check for Updates" /></TextBlock>
102102
</StackPanel>
103103
</Button>
104-
<Button ToolTip="This feature will generate a report on active mods, not intented for players yet." VerticalAlignment="Top" Click="IndexActiveMods">
104+
<Button ToolTip="This feature will generate a report on active mods, not intented for players yet." VerticalAlignment="Top" Click="IndexActiveMods" Visibility="Hidden">
105105
<StackPanel Orientation="Vertical" Width="100">
106106
<Image Source="{StaticResource Save}" Width="16" Height="16" />
107107
<TextBlock Margin="0,5,0,0" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center" FontWeight="Bold"><Run Text="Index Mods" /></TextBlock>

KenshiModTool/MainWindow.xaml.cs

+54-36
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using Core;
33
using Core.Kenshi_Data.Enums;
44
using Core.Models;
5+
using Gameloop.Vdf;
6+
using Gameloop.Vdf.JsonConverter;
7+
using Gameloop.Vdf.Linq;
58
using KenshiModTool.Model;
69
using Microsoft.AppCenter.Crashes;
710
using Microsoft.Win32;
@@ -45,6 +48,8 @@ public MainWindow()
4548
try
4649
{
4750
InitializeComponent();
51+
52+
4853
AutoUpdater.DownloadPath = Environment.CurrentDirectory;
4954
string jsonPath = Path.Combine(Environment.CurrentDirectory, "updateSettings.json");
5055
AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
@@ -66,9 +71,8 @@ public MainWindow()
6671
lsView.ContextMenuOpening += LsView_ContextMenuOpening;
6772

6873
LoadService.Setup();
69-
74+
SteamGameDetection();
7075
AskGamePathIfRequired();
71-
AskSteamPathIfRequired();
7276
LoadService.SaveConfig();
7377

7478
LoadModList();
@@ -158,8 +162,51 @@ public void SetDropAction(object sender, DragEventArgs e)
158162

159163
#region Environment Functions
160164

165+
public void SteamGameDetection()
166+
{
167+
if (string.IsNullOrEmpty(LoadService.config.GamePath))
168+
{
169+
var process = System.Diagnostics.Process.GetProcessesByName("steam");
170+
171+
if (process.Length >0)
172+
{
173+
var steamrunning = process.FirstOrDefault().MainModule.FileName;
174+
175+
var libFolder = Path.Combine(Path.GetDirectoryName(steamrunning), "steamapps", "libraryfolders.vdf");
176+
var vdfObjct = VdfConvert.Deserialize(File.ReadAllText(libFolder));
177+
178+
var obj = vdfObjct.Value as VObject;
179+
for (int i = 0; i < obj.Count; i++)
180+
{
181+
if (obj.ContainsKey(i.ToString()))
182+
{
183+
184+
var exists = ((obj[i.ToString()] as VObject)["apps"] as VObject).ContainsKey("233860");
185+
if (exists)
186+
{
187+
var path = (obj[i.ToString()] as VObject)["path"].ToString();
188+
189+
LoadService.config.GamePath = Path.Combine(path, "steamapps\\common\\Kenshi");
190+
LoadService.config.SteamModsPath = Path.Combine(path, "steamapps\\workshop\\content\\233860");
191+
}
192+
}
193+
}
194+
}
195+
else
196+
{
197+
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you using Steam Version?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
198+
if (messageBoxResult == MessageBoxResult.Yes)
199+
{
200+
MessageBox.Show("Open Steam before running KMM", "Steam not running");
201+
}
202+
else
203+
LoadService.config.SteamModsPath = "NONE";
204+
}
205+
}
206+
}
161207
public void AskGamePathIfRequired()
162208
{
209+
163210
if (string.IsNullOrEmpty(LoadService.config.GamePath))
164211
{
165212
var dialog = new CommonOpenFileDialog();
@@ -176,39 +223,6 @@ public void AskGamePathIfRequired()
176223
}
177224
}
178225

179-
public void AskSteamPathIfRequired()
180-
{
181-
if (LoadService.config.SteamModsPath == "NONE")
182-
{
183-
LoadService.config.SteamModsPath = "NONE";
184-
return;
185-
}
186-
187-
if (string.IsNullOrEmpty(LoadService.config.SteamModsPath))
188-
{
189-
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you using Steam Version?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
190-
if (messageBoxResult == MessageBoxResult.Yes)
191-
{
192-
var dialog = new CommonOpenFileDialog();
193-
dialog.IsFolderPicker = true;
194-
dialog.Title = Directory.Exists("C:\\Program Files (x86)\\Steam\\steamapps\\workshop\\content\\233860") ? "Is this Kenshi Mod Folder (STEAM) P.s. 233860 is the id from kenshi ?" : "You need to select Kenshi Steam Folder, it's your steam folder + \"Steam\\steamapps\\workshop\\content\\233860";
195-
dialog.InitialDirectory = "C:\\Program Files (x86)\\Steam\\steamapps\\workshop\\content\\233860";
196-
CommonFileDialogResult result = dialog.ShowDialog();
197-
198-
try
199-
{
200-
LoadService.config.SteamModsPath = dialog.FileName;
201-
}
202-
catch (Exception)
203-
{
204-
LoadService.config.SteamModsPath = "NONE";
205-
}
206-
}
207-
else
208-
LoadService.config.SteamModsPath = "NONE";
209-
}
210-
}
211-
212226
#endregion Environment Functions
213227

214228
#region Search
@@ -494,7 +508,11 @@ void WriteUrl(string title, string Value, bool local = false)
494508

495509
public void SaveModList_Click(object sender, RoutedEventArgs e)
496510
{
497-
511+
if (!Directory.Exists(Path.Combine(LoadService.config.GamePath, "data")))
512+
{
513+
MessageBox.Show(ConstantMessages.GameFolderNotConfiguredCorrectly, "List not saved!");
514+
return;
515+
}
498516
if (File.Exists(Path.Combine(LoadService.config.GamePath, "data", "mods.cfg")))
499517
File.Copy(Path.Combine(LoadService.config.GamePath, "data", "mods.cfg"), Path.Combine(LoadService.config.GamePath, "data", "mods.cfg.backup"), true);
500518

0 commit comments

Comments
 (0)