Hopefully fix new SteamLibrary

* Fix value between 0 and 1 being shown as percentage, this is now multiplied by 100
* If CS:GO is not found, it will also return from the function as not to execute the background worker causing an exception
* Using the new libraryfolders.vdf instead of the legacy config.vdf to fetch all libraryfolders. This is controllable via the new preprocessor directive NEWLIBRARYLOCATION
This commit is contained in:
Mathias Lui 2022-11-19 15:43:15 +01:00
parent 986762688a
commit 74be8dafc3
3 changed files with 49 additions and 2 deletions

View file

@ -99,6 +99,7 @@ namespace Damage_Calculator
{
MessageBox.Show("Make sure you have installed CS:GO and Steam correctly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
this.Close();
return;
}
bgWorker.DoWork += BgWorker_DoWork;
@ -1460,7 +1461,7 @@ namespace Damage_Calculator
this.txtWeaponBaseDamagePerMinute.Text = this.selectedWeapon.FireRate < 0 ? "?" : (this.selectedWeapon.BaseDamage * this.selectedWeapon.FireRate).ToString(CultureInfo.InvariantCulture);
this.txtWeaponFireRate.Text = this.selectedWeapon.FireRate.ToString(CultureInfo.InvariantCulture);
this.txtWeaponArmorPenetration.Text = this.selectedWeapon.ArmorPenetration.ToString(CultureInfo.InvariantCulture) + " %";
this.txtWeaponDamageDropoff.Text = Math.Round(1d - this.selectedWeapon.DamageDropoff, 2).ToString(CultureInfo.InvariantCulture) + " %";
this.txtWeaponDamageDropoff.Text = (Math.Round(1d - this.selectedWeapon.DamageDropoff, 2) * 100).ToString(CultureInfo.InvariantCulture) + " %";
this.txtWeaponMaxRange.Text = this.selectedWeapon.MaxBulletRange.ToString(CultureInfo.InvariantCulture);
this.txtWeaponHeadshotModifier.Text = this.selectedWeapon.DamageType != DamageType.Shock ? this.selectedWeapon.HeadshotModifier.ToString(CultureInfo.InvariantCulture) : placeholderText;
this.txtWeaponRunningSpeed.Text = this.selectedWeapon.RunningSpeed.ToString();

View file

@ -94,6 +94,33 @@ namespace SteamShared
if (this.steamPath == null)
return null;
// Usually the config.vdf had "BaseInstallFolder_" entries,
// now it seems that these entries don't exist anymore with reinstalls, and maybe they're not up-to-date anyways?
// Now we try reading the "libraryfolders.vdf", which now also contains the default library location
#if NEWLIBRARYLOCATION
string configFilePath = Path.Combine(this.steamPath, "config", "libraryfolders.vdf");
if (!File.Exists(configFilePath))
return null;
// Fetch all libraries from the config
var configFile = new VDFFile(configFilePath);
IEnumerable<string>? foundSteamLibraries = configFile["libraryfolders"]?.Children.Select(c => c["path"]?.Value)!;
var allLibraries = new List<SteamLibrary>();
if (foundSteamLibraries?.Any() != true)
{
return null;
}
foreach (string foundLib in foundSteamLibraries!)
{
// All paths in the file are escaped
allLibraries.Add(new SteamLibrary(foundLib.Replace("\\\\", "\\")));
}
return allLibraries;
#else
string configFilePath = Path.Combine(this.steamPath, "config\\config.vdf");
if (!File.Exists(configFilePath))
return null;
@ -104,12 +131,15 @@ namespace SteamShared
// List libraries plus default Steam directory, because that's the default library
var allLibraries = new List<SteamLibrary> { new SteamLibrary(this.steamPath) };
foreach(string addLib in additionalSteamLibraries!)
foreach (string addLib in additionalSteamLibraries!)
{
// All paths in the file are escaped
allLibraries.Add(new SteamLibrary(addLib.Replace("\\\\", "\\")));
}
return allLibraries;
#endif
}
public List<SteamGame>? GetInstalledGames()

View file

@ -7,6 +7,22 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants)TRACE;NEWLIBRARYLOCATION</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>$(DefineConstants)TRACE;NEWLIBRARYLOCATION</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DefineConstants>$(DefineConstants)TRACE;NEWLIBRARYLOCATION</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DefineConstants>$(DefineConstants)TRACE;NEWLIBRARYLOCATION</DefineConstants>
</PropertyGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>