public override string ToString() { if (IsDefault) { return("Empty process"); } var path = string.IsNullOrEmpty(ExecutablePath) ? string.Empty : ExecutablePath.Replace("\\", "/"); return(string.Format("{0}, {1}, {2}", ProcessId, Name, path)); }
public static async Task InstallExtension() { var allowAutoClose = true; Console.WriteLine(); Console.WriteLine($"Viramate Installer v{MyAssembly.GetName().Version}"); if (Environment.GetCommandLineArgs().Contains("--version")) { return; } if (Environment.GetCommandLineArgs().Contains("--update")) { await AutoUpdateInstaller(); } Console.WriteLine("Installing extension. This'll take a moment..."); if (await InstallExtensionFiles(false, null) != InstallResult.Failed) { Console.WriteLine($"Extension id: {ExtensionId}"); string manifestText; using (var s = new StreamReader(OpenResource("nmh.json"), Encoding.UTF8)) manifestText = s.ReadToEnd(); manifestText = manifestText .Replace( "$executable_path$", ExecutablePath.Replace("\\", "\\\\").Replace("\"", "\\\"") ).Replace( "$extension_id$", ExtensionId ); var manifestPath = Path.Combine(MiscPath, "nmh.json"); Directory.CreateDirectory(MiscPath); File.WriteAllText(manifestPath, manifestText); Directory.CreateDirectory(Path.Combine(DataPath, "Help")); foreach (var n in MyAssembly.GetManifestResourceNames()) { if (!n.EndsWith(".gif") && !n.EndsWith(".png")) { continue; } var destinationPath = Path.Combine(DataPath, n.Replace("Viramate.", "").Replace("Help.", "Help\\")); using (var src = MyAssembly.GetManifestResourceStream(n)) using (var dst = File.Open(destinationPath, FileMode.Create)) await src.CopyToAsync(dst); } const string keyName = @"Software\Google\Chrome\NativeMessagingHosts\com.viramate.installer"; using (var key = Registry.CurrentUser.CreateSubKey(keyName)) { Console.WriteLine($"{keyName}\\@ = {manifestPath}"); key.SetValue(null, manifestPath); } try { WebSocketServer.SetupFirewallRule(); } catch (Exception exc) { Console.WriteLine("Failed to install firewall rule: {0}", exc); allowAutoClose = false; } string helpFileText; using (var s = new StreamReader(OpenResource("Help/index.html"), Encoding.UTF8)) helpFileText = s.ReadToEnd(); helpFileText = Regex.Replace( helpFileText, @"\<pre\ id='install_path'>[^<]*\</pre\>", @"<pre id='install_path'>" + DataPath + "</pre>" ); var helpFilePath = Path.Combine(DataPath, "Help", "index.html"); File.WriteAllText(helpFilePath, helpFileText); Console.WriteLine($"Viramate v{ReadManifestVersion(null)} has been installed."); if (!Environment.GetCommandLineArgs().Contains("--nohelp")) { Console.WriteLine("Opening install instructions..."); Process.Start(helpFilePath); } else if (!Debugger.IsAttached && !IsRunningInsideCmd) { Console.WriteLine("Press enter to exit."); return; } if (!Environment.GetCommandLineArgs().Contains("--nodir")) { Console.WriteLine("Waiting, then opening install directory..."); await Task.Delay(2000); Process.Start(DataPath); } } else { await AutoUpdateInstaller(); if (!Debugger.IsAttached && !IsRunningInsideCmd) { Console.WriteLine("Failed to install extension. Press enter to exit."); Console.ReadLine(); } else { Console.WriteLine("Failed to install extension."); } } }