pinggy 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { exec, execSync } from "child_process";
4
+ import os from "os";
5
+ import CLIPrinter from "./printer.js";
6
+ import { promisify } from "util";
7
+
8
+ const execAsync = promisify(exec);
9
+
10
+ const DLLS = ["vcruntime140.dll", "vcruntime140_1.dll", "msvcp140.dll"];
11
+
12
+ const PATHS = ["C:\\Windows\\System32", "C:\\Windows\\SysWOW64"];
13
+
14
+ // Registry keys for different VC++ Redistributable versions
15
+ const REGISTRY_KEYS = [
16
+ "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X64",
17
+ "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X86",
18
+ "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X64",
19
+ "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X86",
20
+ ];
21
+
22
+ /**
23
+ * Check if VC++ Redistributable DLLs exist
24
+ */
25
+ function checkDLLs() {
26
+ return DLLS.every((dll) =>
27
+ PATHS.some((p) => {
28
+ try {
29
+ return fs.existsSync(path.join(p, dll));
30
+ } catch {
31
+ return false;
32
+ }
33
+ }),
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Check Windows Registry for VC++ Redistributable installation
39
+ */
40
+ function checkRegistry() {
41
+ if (os.platform() !== "win32") return false;
42
+
43
+ try {
44
+ for (const key of REGISTRY_KEYS) {
45
+ const cmd = `reg query "${key}" /v Installed 2>nul`;
46
+ const result = execSync(cmd, { encoding: "utf8" });
47
+
48
+ if (result.includes("0x1")) {
49
+ return true;
50
+ }
51
+ }
52
+ } catch {
53
+ // Registry check failed, fall back to DLL check
54
+ }
55
+
56
+ return false;
57
+ }
58
+
59
+ function getVCRedistVersion() {
60
+ if (os.platform() !== "win32") return null;
61
+
62
+ try {
63
+ for (const key of REGISTRY_KEYS) {
64
+ const cmd = `reg query "${key}" /v Version 2>nul`;
65
+ const result = execSync(cmd, { encoding: "utf8" });
66
+
67
+ const match = result.match(/Version\s+REG_SZ\s+(\S+)/);
68
+ if (match) {
69
+ return match[1];
70
+ }
71
+ }
72
+ } catch {
73
+ // Ignore errors
74
+ }
75
+
76
+ return null;
77
+ }
78
+
79
+ /**
80
+ * Main detection function
81
+ */
82
+ export function hasVCRedist() {
83
+ if (os.platform() !== "win32") {
84
+ return true; // Not Windows, assume OK
85
+ }
86
+
87
+ if (checkRegistry()) {
88
+ return true;
89
+ }
90
+
91
+ if (checkDLLs()) {
92
+ return true;
93
+ }
94
+
95
+ return false;
96
+ }
97
+
98
+ export function getVCRedistStatus() {
99
+ if (os.platform() !== "win32") {
100
+ return {
101
+ required: false,
102
+ installed: true,
103
+ version: null,
104
+ method: "non-windows",
105
+ };
106
+ }
107
+
108
+ const registryInstalled = checkRegistry();
109
+ const dllsPresent = checkDLLs();
110
+ const version = getVCRedistVersion();
111
+
112
+ return {
113
+ required: true,
114
+ installed: registryInstalled || dllsPresent,
115
+ version,
116
+ registryCheck: registryInstalled,
117
+ dllCheck: dllsPresent,
118
+ method: registryInstalled ? "registry" : dllsPresent ? "dll" : "none",
119
+ };
120
+ }
121
+
122
+ /**
123
+ * Open download page in browser
124
+ */
125
+ export async function openDownloadPage() {
126
+ if (process.platform !== "win32") {
127
+ return;
128
+ }
129
+ const url =
130
+ "https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170";
131
+
132
+ // Use cmd.exe explicitly for better compatibility
133
+ const command = `cmd.exe /c start "" "${url}"`;
134
+
135
+ try {
136
+ await execAsync(command);
137
+ CLIPrinter.info("\nOpening Microsoft download page in your browser...");
138
+ CLIPrinter.info(
139
+ "Please install the Visual C++ Runtime and restart this application.\n",
140
+ );
141
+ } catch (err) {
142
+ CLIPrinter.info("\nUnable to open your browser automatically.");
143
+ CLIPrinter.info(
144
+ "Please visit the following page to download the runtime:\n",
145
+ );
146
+ CLIPrinter.info(url + "\n");
147
+ }
148
+ }
149
+
150
+
151
+ /**
152
+ * Get error message
153
+ */
154
+ export function getVCRedistMessage() {
155
+ const status = getVCRedistStatus();
156
+
157
+ if (!status.required || status.installed) {
158
+ return null;
159
+ }
160
+
161
+ return {
162
+ error: true,
163
+ message:
164
+ "Missing Microsoft Visual C++ Runtime. This application requires the Microsoft Visual C++ Runtime to run on Windows.\n" +
165
+ "Please download and install it using the link below, then restart this application.\n",
166
+ };
167
+ }