Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Private Function

findFromInstallationFolder

Private Function
std.zig.WindowsSdk.Installation.findFromInstallationFolder
fn findFromInstallationFolder(
        gpa: Allocator,
        registry: *Registry,
        version_key_name: []const u16,
    ) error

Params

File

zig/WindowsSdk.zig:544
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
    fn findFromInstallationFolder(
        gpa: Allocator,
        registry: *Registry,
        version_key_name: []const u16,
    ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation {
        const key_name = try std.mem.concat(gpa, u16, &.{ L("Microsoft\\Microsoft SDKs\\Windows\\"), version_key_name });
        defer gpa.free(key_name);

        const key = registry.tryOpenSoftwareKeyWithPrecedence(switch (is_32_bit) {
            true => &.{
                .{ .root = .local_machine },
                .{ .root = .current_user },
            },
            false => &.{
                .{ .root = .local_machine, .wow64 = .wow64_32 },
                .{ .root = .current_user, .wow64 = .wow64_32 },
                .{ .root = .local_machine, .wow64 = .native },
                .{ .root = .current_user, .wow64 = .native },
            },
        }, key_name) catch {
            return error.InstallationNotFound;
        };
        defer key.close();

        const path: []const u8 = path: {
            const path_w_maybe_with_trailing_slash = key.getString(gpa, .{ .name = L("InstallationFolder") }, .wtf16) catch |err| switch (err) {
                error.NotAString,
                error.ValueNameNotFound,
                error.StringNotFound,
                => return error.InstallationNotFound,

                error.OutOfMemory => |e| return e,
            };
            defer gpa.free(path_w_maybe_with_trailing_slash);

            if (!std.fs.path.isAbsoluteWindowsWtf16(path_w_maybe_with_trailing_slash)) {
                return error.InstallationNotFound;
            }

            const path_w = std.mem.trimEnd(u16, path_w_maybe_with_trailing_slash, L("\\/"));
            break :path try std.unicode.wtf16LeToWtf8Alloc(gpa, path_w);
        };
        errdefer gpa.free(path);

        const version: []const u8 = version: {
            // Microsoft doesn't include the .0 in the ProductVersion key
            const version_without_0 = key.getString(gpa, .{ .name = L("ProductVersion") }, .wtf16) catch |err| switch (err) {
                error.NotAString,
                error.ValueNameNotFound,
                error.StringNotFound,
                => return error.InstallationNotFound,

                error.OutOfMemory => |e| return e,
            };
            defer gpa.free(version_without_0);

            if (version_without_0.len + ".0".len > product_version_max_length) {
                return error.VersionTooLong;
            }

            var version: std.array_list.Managed(u8) = try .initCapacity(gpa, version_without_0.len + 2);
            errdefer version.deinit();

            try std.unicode.wtf16LeToWtf8ArrayList(&version, version_without_0);
            try version.appendSlice(".0");

            break :version try version.toOwnedSlice();
        };
        errdefer gpa.free(version);

        return .{ .path = path, .version = version };
    }