Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Valve VDF change
Browse files Browse the repository at this point in the history
  • Loading branch information
malware-dev committed Sep 7, 2021
1 parent 242d575 commit c65350f
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 200 deletions.
8 changes: 4 additions & 4 deletions Source/DocGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDKWhitelistExtractor", "MDKWhitelistExtractor\MDKWhitelistExtractor.csproj", "{02E93D45-C296-49F4-BEF2-3D5429549917}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SteamAndSE", "SteamAndSE\SteamAndSE.shproj", "{9E28967B-803C-4CF2-9A9C-B8135C85266B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocGen2", "DocGen2\DocGen2.csproj", "{76F6E75A-EA20-4BA8-8FA5-A1E713BFAFF4}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Mixin.SteamAndSE", "Mixin.SteamAndSE\Mixin.SteamAndSE.shproj", "{9E28967B-803C-4CF2-9A9C-B8135C85266B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SteamAndSE\SteamAndSE.projitems*{76f6e75a-ea20-4ba8-8fa5-a1e713bfaff4}*SharedItemsImports = 4
SteamAndSE\SteamAndSE.projitems*{9e28967b-803c-4cf2-9a9c-b8135c85266b}*SharedItemsImports = 13
Mixin.SteamAndSE\Mixin.SteamAndSE.projitems*{76f6e75a-ea20-4ba8-8fa5-a1e713bfaff4}*SharedItemsImports = 4
Mixin.SteamAndSE\Mixin.SteamAndSE.projitems*{9e28967b-803c-4cf2-9a9c-b8135c85266b}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion Source/DocGen2/DocGen2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="..\SteamAndSE\SteamAndSE.projitems" Label="Shared" />
<Import Project="..\Mixin.SteamAndSE\Mixin.SteamAndSE.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion Source/MDK/MDKPackage.GeneratedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class MDKPackage
/// <summary>
/// The current package version
/// </summary>
public static readonly Version Version = new Version("1.4.8");
public static readonly Version Version = new Version("1.4.9");

/// <summary>
/// The required IDE version
Expand Down
2 changes: 1 addition & 1 deletion Source/MDK/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="MDK.Morten Aune Lyrstad.e02b602e-3099-44a5-88c6-cb30cab978f6" Version="1.4.8" Language="en-US" Publisher="Morten Aune Lyrstad" />
<Identity Id="MDK.Morten Aune Lyrstad.e02b602e-3099-44a5-88c6-cb30cab978f6" Version="1.4.9" Language="en-US" Publisher="Morten Aune Lyrstad" />
<DisplayName>MDK/SE</DisplayName>
<Description xml:space="preserve">A toolkit to help with ingame script (programmable block) development for Keen Software House's space sandbox Space Engineers.

Expand Down
1 change: 1 addition & 0 deletions Source/MDKServices/DTEExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;

Expand Down
22 changes: 19 additions & 3 deletions Source/MDKServices/HealthAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using System.Runtime.InteropServices;

namespace Malware.MDKServices
{
Expand All @@ -31,13 +32,28 @@ public class HealthAnalysis
/// <returns></returns>
public static Task<HealthAnalysis[]> AnalyzeAsync(Solution solution, HealthAnalysisOptions options) => System.Threading.Tasks.Task.WhenAll(solution.Projects.Cast<Project>().Select(project => System.Threading.Tasks.Task.Run(() => Analyze(project, options))));

// ReSharper disable once InconsistentNaming
private const int RPC_E_SERVERCALL_RETRYLATER = unchecked((int)0x8001010A);

static HealthAnalysis Analyze(Project project, HealthAnalysisOptions options)
{
options.Echo?.Invoke("Analyzing project...");
if (!project.IsLoaded())
while (true)
{
options.Echo?.Invoke("Project is not loaded.");
return new HealthAnalysis(project, null, options);
try
{
if (!project.IsLoaded())
{
options.Echo?.Invoke("Project is not loaded.");
return new HealthAnalysis(project, null, options);
}

break;
}
catch (COMException ce) when (ce.HResult == RPC_E_SERVERCALL_RETRYLATER)
{
System.Threading.Thread.Sleep(500);
}
}

var projectInfo = MDKProjectProperties.Load(project.FullName, project.Name, options.Echo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ partial class MDKProjectProperties
/// <summary>
/// The current package version this utility assembly targets
/// </summary>
public static readonly Version TargetPackageVersion = new Version("1.4.8");
public static readonly Version TargetPackageVersion = new Version("1.4.9");
}
}
93 changes: 86 additions & 7 deletions Source/Mixin.SteamAndSE/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,112 @@ public string GetInstallFolder(string subfolderName, string verificationFilePath
return null;
}
var configPath = Path.Combine(basePath, @"steamapps\libraryfolders.vdf");
string configuration;
Dictionary<string, object> configuration;
try
{
configuration = File.ReadAllText(configPath);
configuration = ReadVdf(configPath);
}
catch (Exception)
{
return null;
}

if (!configuration.ContainsKey("libraryfolders"))
return null;

configuration = (Dictionary<string, object>)configuration["libraryfolders"];
int n = 1;
var basePaths = new List<string>
{
basePath
};

var matches = Regex.Matches(configuration, @"""\d+""[ \t]+""([^""]+)""", RegexOptions.Singleline);
foreach (Match match in matches)
basePaths.Add(match.Groups[1].Value);
string path;
while (true)
{
var key = n.ToString();
n++;
if (!configuration.ContainsKey(key))
break;
var folder = (Dictionary<string, object>)configuration[key];
path = (string)folder["path"];
basePaths.Add(path);
}

// Search through the potential base path, returning the first path which contains the desired
// verification file.
var path = basePaths.Select(p => Path.Combine(p, "SteamApps", "common", subfolderName))
path = basePaths.Select(p => Path.Combine(p, "SteamApps", "common", subfolderName))
.FirstOrDefault(p => File.Exists(Path.Combine(p, verificationFilePath)));

if (path != null && !path.EndsWith("\\"))
path += "\\";
return path;
}

private Dictionary<string, object> ReadVdf(string configPath)
{
var lines = File.ReadAllLines(configPath);
int pos = 0;
return ReadVdfObject(lines, ref pos, false);
}

private Dictionary<string, object> ReadVdfObject(string[] lines, ref int pos, bool nested)
{
if (nested)
{
if (pos >= lines.Length && !Regex.IsMatch(lines[pos], @"\A\s*{\s*\z", RegexOptions.Singleline))
throw new InvalidDataException("Steam .vdf file format failure");
pos++;
}

var obj = new Dictionary<string, object>();
while (true)
{
if (nested)
{
if (pos < lines.Length && Regex.IsMatch(lines[pos], @"\A\s*}\s*\z", RegexOptions.Singleline))
{
pos++;
return obj;
}
}

var part = ReadVdfLine(lines, ref pos);
if (part == null)
break;
if (part.Value.Value == null)
{
obj[Unquote(part.Value.Key)] = ReadVdfObject(lines, ref pos, true);
continue;
}

obj[Unquote(part.Value.Key)] = Unquote(part.Value.Value);
}
if (nested)
throw new InvalidDataException("Steam .vdf file format failure");
return obj;
}

private string Unquote(string value)
{
return value.Substring(1, value.Length - 2).Replace("\\\"", "\"");
}

private static KeyValuePair<string, string>? ReadVdfLine(string[] lines, ref int pos)
{
if (pos >= lines.Length)
return null;
var matches = Regex.Matches(lines[pos], @"\s*(""[^""\\]*(?:\\.[^""\\]*)*"")", RegexOptions.Singleline);
switch (matches.Count)
{
case 1:
pos++;
return new KeyValuePair<string, string>(matches[0].Groups[1].Value, null);
case 2:
pos++;
return new KeyValuePair<string, string>(matches[0].Groups[1].Value, matches[1].Groups[1].Value);
default:
return null;
}
}
}
}
56 changes: 0 additions & 56 deletions Source/SteamAndSE/SpaceEngineers.cs

This file was deleted.

98 changes: 0 additions & 98 deletions Source/SteamAndSE/Steam.cs

This file was deleted.

15 changes: 0 additions & 15 deletions Source/SteamAndSE/SteamAndSE.projitems

This file was deleted.

Loading

0 comments on commit c65350f

Please sign in to comment.