Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › zig › WindowsSdk › MsvcLibDir › findViaCOM Private Function findViaCOM Doc Source Private Function std.zig.WindowsSdk.MsvcLibDir.findViaCOM
fn findViaCOM (
gpa : Allocator ,
io : Io ,
registry : *Registry ,
arch : std .Target .Cpu .Arch ,
environ_map : *const Environ .Map ,
) error Params File zig/WindowsSdk.zig: 819
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881 fn findViaCOM (
gpa : Allocator ,
io : Io ,
registry : *Registry ,
arch : std .Target .Cpu .Arch ,
environ_map : *const Environ .Map ,
) error { OutOfMemory , PathNotFound }![]const u8 {
// Typically `%PROGRAMDATA%\Microsoft\VisualStudio\Packages\_Instances`
// This will contain directories with names of instance IDs like 80a758ca,
// which will contain `state.json` files that have the version and
// installation directory.
var instances_dir = try findInstancesDir (gpa , io , registry , environ_map );
defer instances_dir .close (io );
var state_subpath_buf : [Dir .max_name_bytes + 32 ]u8 = undefined ;
var latest_version_lib_dir : std .ArrayList (u8 ) = .empty ;
errdefer latest_version_lib_dir .deinit (gpa );
var latest_version : u64 = 0 ;
var instances_dir_it = instances_dir .iterateAssumeFirstIteration ();
while (instances_dir_it .next (io ) catch return error .PathNotFound ) |entry | {
if (entry .kind != .directory ) continue ;
var writer : Writer = .fixed (&state_subpath_buf );
writer .writeAll (entry .name ) catch unreachable ;
writer .writeByte (Dir .path .sep ) catch unreachable ;
writer .writeAll ("state.json" ) catch unreachable ;
const json_contents = instances_dir .readFileAlloc (io , writer .buffered (), gpa , .limited (std .math .maxInt (usize ))) catch continue ;
defer gpa .free (json_contents );
var parsed = std .json .parseFromSlice (std .json .Value , gpa , json_contents , .{}) catch continue ;
defer parsed .deinit ();
if (parsed .value != .object ) continue ;
const catalog_info = parsed .value .object .get ("catalogInfo" ) orelse continue ;
if (catalog_info != .object ) continue ;
const product_version_value = catalog_info .object .get ("buildVersion" ) orelse continue ;
if (product_version_value != .string ) continue ;
const product_version_text = product_version_value .string ;
const parsed_version = parseVersionQuad (product_version_text ) catch continue ;
// We want to end up with the most recent version installed
if (parsed_version <= latest_version ) continue ;
const installation_path = parsed .value .object .get ("installationPath" ) orelse continue ;
if (installation_path != .string ) continue ;
const lib_dir_path = libDirFromInstallationPath (gpa , io , installation_path .string , arch ) catch |err | switch (err ) {
error .OutOfMemory => |e | return e ,
error .PathNotFound => continue ,
};
defer gpa .free (lib_dir_path );
latest_version_lib_dir .clearRetainingCapacity ();
try latest_version_lib_dir .appendSlice (gpa , lib_dir_path );
latest_version = parsed_version ;
}
if (latest_version_lib_dir .items .len == 0 ) return error .PathNotFound ;
return latest_version_lib_dir .toOwnedSlice (gpa );
}
Intended to be equivalent to ISetupConfiguration.EnumInstances: https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.setup.configuration but without the use of COM in order to avoid a dependency on ole32.dll
The logic in this function is intended to match what ISetupConfiguration does under-the-hood, as verified using Procmon.