/// <summary> /// Initializes the Node environment. /// </summary> public static async Task InitializeAsync() { var mutex = new AsyncLock(); using (await mutex.LockAsync()) { var node_modules = Path.Combine(ExecutionPath, "node_modules"); var log_file = Path.Combine(ExecutionPath, "log.txt"); if (!Directory.Exists(node_modules) || !File.Exists(log_file) || (Directory.Exists(node_modules) && Directory.GetDirectories(node_modules).Length < 235)) { if (Directory.Exists(ExecutionPath)) Directory.Delete(ExecutionPath, true); Directory.CreateDirectory(ExecutionPath); var tasks = new List<Task> { SaveResourceFileAsync(ExecutionPath, "WebLinter.Node.node_modules.7z", "node_modules.7z"), SaveResourceFileAsync(ExecutionPath, "WebLinter.Node.7z.exe", "7z.exe"), SaveResourceFileAsync(ExecutionPath, "WebLinter.Node.7z.dll", "7z.dll"), SaveResourceFileAsync(ExecutionPath, "WebLinter.Node.prepare.cmd", "prepare.cmd"), SaveResourceFileAsync(ExecutionPath, "WebLinter.Node.server.js", "server.js"), }; await Task.WhenAll(tasks.ToArray()); ProcessStartInfo start = new ProcessStartInfo { WorkingDirectory = ExecutionPath, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, FileName = "cmd.exe", Arguments = "/c prepare.cmd" }; Process p = Process.Start(start); await p.WaitForExitAsync(); // If this file is written, then the initialization was successful. using (var writer = new StreamWriter(log_file)) { await writer.WriteAsync(DateTime.Now.ToLongDateString()); } } } }
internal Releaser(AsyncLock toRelease) { m_toRelease = toRelease; }