2022-01-25 21:02:10 +01:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-08-24 13:08:10 +02:00
|
|
|
using System.Collections.Generic;
|
2022-01-25 21:02:10 +01:00
|
|
|
using System.Drawing;
|
2022-08-16 19:32:49 +02:00
|
|
|
using System.Globalization;
|
2022-01-25 21:02:10 +01:00
|
|
|
using System.IO;
|
2022-08-24 13:08:10 +02:00
|
|
|
using System.Linq;
|
2022-01-25 21:02:10 +01:00
|
|
|
using System.Runtime.CompilerServices;
|
2022-08-16 19:32:49 +02:00
|
|
|
using System.Threading.Tasks;
|
2022-01-25 21:02:10 +01:00
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Common;
|
2022-08-24 13:08:10 +02:00
|
|
|
using Microsoft.PowerToys.PreviewHandler.Monaco.Formatters;
|
2022-08-16 19:32:49 +02:00
|
|
|
using Microsoft.PowerToys.PreviewHandler.Monaco.Helpers;
|
2022-01-25 21:02:10 +01:00
|
|
|
using Microsoft.PowerToys.PreviewHandler.Monaco.Properties;
|
|
|
|
|
using Microsoft.Web.WebView2.Core;
|
|
|
|
|
using Microsoft.Web.WebView2.WinForms;
|
|
|
|
|
using Windows.System;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.PreviewHandler.Monaco
|
|
|
|
|
{
|
|
|
|
|
public class MonacoPreviewHandlerControl : FormHandlerControl
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Settings class
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Settings _settings = new Settings();
|
|
|
|
|
|
2022-08-24 13:08:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Formatters applied before rendering the preview
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IReadOnlyCollection<IFormatter> _formatters = new List<IFormatter>
|
|
|
|
|
{
|
|
|
|
|
new JsonFormatter(),
|
|
|
|
|
new XmlFormatter(),
|
|
|
|
|
}.AsReadOnly();
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves if the user already navigated to the index page
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool _hasNavigated;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// WebView2 element
|
|
|
|
|
/// </summary>
|
|
|
|
|
private WebView2 _webView;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// WebView2 Environment
|
|
|
|
|
/// </summary>
|
|
|
|
|
private CoreWebView2Environment _webView2Environment;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loading label
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Label _loading;
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Loading progress bar
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ProgressBar _loadingBar;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Grey background
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Label _loadingBackground;
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Name of the virtual host
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const string VirtualHostName = "PowerToysLocalMonaco";
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// HTML code passed to the file
|
|
|
|
|
/// </summary>
|
|
|
|
|
#nullable enable
|
|
|
|
|
private string? _html;
|
|
|
|
|
#nullable disable
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Id for monaco language
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string _vsCodeLangSet;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The content of the previewing file in base64
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string _base64FileCode;
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
[STAThread]
|
|
|
|
|
public override void DoPreview<T>(T dataSource)
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogTrace();
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
base.DoPreview(dataSource);
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
// Sets background color
|
2022-08-19 19:37:05 +02:00
|
|
|
SetBackground();
|
2022-08-16 19:32:49 +02:00
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
// Starts loading screen
|
2022-08-19 19:37:05 +02:00
|
|
|
InitializeLoadingScreen();
|
2022-01-25 21:02:10 +01:00
|
|
|
|
|
|
|
|
// New webview2 element
|
|
|
|
|
_webView = new WebView2();
|
|
|
|
|
|
|
|
|
|
// Checks if dataSource is a string
|
|
|
|
|
if (!(dataSource is string filePath))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"{nameof(dataSource)} for {nameof(MonacoPreviewHandler)} must be a string but was a '{typeof(T)}'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the file is too big.
|
|
|
|
|
long fileSize = new FileInfo(filePath).Length;
|
|
|
|
|
|
|
|
|
|
if (fileSize < _settings.MaxFileSize)
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Task initializeIndexFileAndSelectedFileTask = new Task(() => { InitializeIndexFileAndSelectedFile(filePath); });
|
|
|
|
|
initializeIndexFileAndSelectedFileTask.Start();
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
InvokeOnControlThread(() =>
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Create WebView2 environment");
|
2022-01-25 21:02:10 +01:00
|
|
|
ConfiguredTaskAwaitable<CoreWebView2Environment>.ConfiguredTaskAwaiter
|
|
|
|
|
webView2EnvironmentAwaiter = CoreWebView2Environment
|
|
|
|
|
.CreateAsync(userDataFolder: System.Environment.GetEnvironmentVariable("USERPROFILE") +
|
|
|
|
|
"\\AppData\\LocalLow\\Microsoft\\PowerToys\\MonacoPreview-Temp")
|
|
|
|
|
.ConfigureAwait(true).GetAwaiter();
|
|
|
|
|
webView2EnvironmentAwaiter.OnCompleted(() =>
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
_loadingBar.Value = 60;
|
|
|
|
|
this.Update();
|
2022-01-25 21:02:10 +01:00
|
|
|
InvokeOnControlThread(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (CoreWebView2Environment.GetAvailableBrowserVersionString() == null)
|
|
|
|
|
{
|
|
|
|
|
throw new WebView2RuntimeNotFoundException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_webView2Environment = webView2EnvironmentAwaiter.GetResult();
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
_loadingBar.Value = 70;
|
|
|
|
|
this.Update();
|
2022-01-25 21:02:10 +01:00
|
|
|
|
|
|
|
|
// Initialize WebView
|
2022-02-21 16:10:55 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _webView.EnsureCoreWebView2Async(_webView2Environment).ConfigureAwait(true);
|
2022-08-16 19:32:49 +02:00
|
|
|
|
|
|
|
|
// Wait until html is loaded
|
|
|
|
|
initializeIndexFileAndSelectedFileTask.Wait();
|
|
|
|
|
|
2022-02-21 16:10:55 +01:00
|
|
|
_webView.CoreWebView2.SetVirtualHostNameToFolderMapping(VirtualHostName, Settings.AssemblyDirectory, CoreWebView2HostResourceAccessKind.Allow);
|
2022-08-16 19:32:49 +02:00
|
|
|
|
|
|
|
|
Logger.LogInfo("Navigates to string of HTML file");
|
|
|
|
|
|
|
|
|
|
_webView.NavigateToString(_html);
|
2022-02-21 16:10:55 +01:00
|
|
|
_webView.NavigationCompleted += WebView2Init;
|
|
|
|
|
_webView.Height = this.Height;
|
|
|
|
|
_webView.Width = this.Width;
|
|
|
|
|
Controls.Add(_webView);
|
2022-08-16 19:32:49 +02:00
|
|
|
_webView.SendToBack();
|
|
|
|
|
_loadingBar.Value = 100;
|
|
|
|
|
this.Update();
|
2022-02-21 16:10:55 +01:00
|
|
|
}
|
2022-08-16 19:32:49 +02:00
|
|
|
catch (NullReferenceException e)
|
2022-02-21 16:10:55 +01:00
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogError("NullReferenceException catched. Skipping exception.", e);
|
2022-02-21 16:10:55 +01:00
|
|
|
}
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
2022-08-16 19:32:49 +02:00
|
|
|
catch (WebView2RuntimeNotFoundException e)
|
2022-01-25 21:02:10 +01:00
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogWarning("WebView2 was not found:");
|
|
|
|
|
Logger.LogWarning(e.Message);
|
2022-02-21 16:10:55 +01:00
|
|
|
Controls.Remove(_loading);
|
2022-08-16 19:32:49 +02:00
|
|
|
Controls.Remove(_loadingBar);
|
|
|
|
|
Controls.Remove(_loadingBackground);
|
2022-02-21 16:10:55 +01:00
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
// WebView2 not installed message
|
|
|
|
|
Label errorMessage = new Label();
|
|
|
|
|
errorMessage.Text = Resources.WebView2_Not_Installed_Message;
|
|
|
|
|
errorMessage.Width = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Width + 10;
|
|
|
|
|
errorMessage.Height = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Height;
|
|
|
|
|
Controls.Add(errorMessage);
|
|
|
|
|
|
|
|
|
|
// Download Link
|
|
|
|
|
Label downloadLink = new LinkLabel();
|
|
|
|
|
downloadLink.Text = Resources.Download_WebView2;
|
|
|
|
|
downloadLink.Click += DownloadLink_Click;
|
|
|
|
|
downloadLink.Top = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Height + 10;
|
|
|
|
|
downloadLink.Width = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Width + 10;
|
|
|
|
|
downloadLink.Height = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Height;
|
|
|
|
|
Controls.Add(downloadLink);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
InvokeOnControlThread(() =>
|
|
|
|
|
{
|
2022-02-21 16:10:55 +01:00
|
|
|
Controls.Remove(_loading);
|
2022-08-16 19:32:49 +02:00
|
|
|
Controls.Remove(_loadingBar);
|
|
|
|
|
Controls.Remove(_loadingBackground);
|
2022-01-25 21:02:10 +01:00
|
|
|
Label text = new Label();
|
|
|
|
|
text.Text = Resources.Exception_Occurred;
|
|
|
|
|
text.Text += e.Message;
|
|
|
|
|
text.Text += "\n" + e.Source;
|
|
|
|
|
text.Text += "\n" + e.StackTrace;
|
|
|
|
|
text.Width = 500;
|
|
|
|
|
text.Height = 10000;
|
|
|
|
|
Controls.Add(text);
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogError(e.Message);
|
2022-01-25 21:02:10 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Resize += FormResize;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("File is too big to display. Showing error message");
|
2022-01-25 21:02:10 +01:00
|
|
|
InvokeOnControlThread(() =>
|
|
|
|
|
{
|
2022-02-21 16:10:55 +01:00
|
|
|
Controls.Remove(_loading);
|
2022-08-16 19:32:49 +02:00
|
|
|
_loadingBar.Dispose();
|
|
|
|
|
Controls.Remove(_loadingBar);
|
|
|
|
|
Controls.Remove(_loadingBackground);
|
2022-01-25 21:02:10 +01:00
|
|
|
Label errorMessage = new Label();
|
2022-08-16 19:32:49 +02:00
|
|
|
errorMessage.Text = Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture);
|
2022-01-25 21:02:10 +01:00
|
|
|
errorMessage.Width = 500;
|
|
|
|
|
errorMessage.Height = 50;
|
|
|
|
|
Controls.Add(errorMessage);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This event sets the height and width of the webview to the size of the form
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void FormResize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_webView.Height = this.Height;
|
|
|
|
|
_webView.Width = this.Width;
|
2022-08-16 19:32:49 +02:00
|
|
|
this.Update();
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This event initializes the webview and sets various settings
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
private void WebView2Init(object sender, CoreWebView2NavigationCompletedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Checks if already navigated
|
|
|
|
|
if (!_hasNavigated)
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Setting WebView2 settings");
|
2022-01-25 21:02:10 +01:00
|
|
|
CoreWebView2Settings settings = (sender as WebView2).CoreWebView2.Settings;
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
// Enable developer tools and context menu for debugging
|
|
|
|
|
settings.AreDefaultContextMenusEnabled = true;
|
|
|
|
|
settings.AreDevToolsEnabled = true;
|
|
|
|
|
#else
|
|
|
|
|
// Disable context menu
|
|
|
|
|
settings.AreDefaultContextMenusEnabled = false;
|
|
|
|
|
|
|
|
|
|
// Disable developer tools
|
|
|
|
|
settings.AreDevToolsEnabled = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Disable script dialogs (like alert())
|
|
|
|
|
settings.AreDefaultScriptDialogsEnabled = false;
|
|
|
|
|
|
|
|
|
|
// Enables JavaScript
|
|
|
|
|
settings.IsScriptEnabled = true;
|
|
|
|
|
|
|
|
|
|
// Disable zoom with ctrl and scroll
|
|
|
|
|
settings.IsZoomControlEnabled = false;
|
|
|
|
|
|
|
|
|
|
// Disable developer menu
|
|
|
|
|
settings.IsBuiltInErrorPageEnabled = false;
|
|
|
|
|
|
|
|
|
|
// Disable status bar
|
|
|
|
|
settings.IsStatusBarEnabled = false;
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Remove loading elements");
|
2022-01-25 21:02:10 +01:00
|
|
|
Controls.Remove(_loading);
|
2022-08-16 19:32:49 +02:00
|
|
|
Controls.Remove(_loadingBar);
|
|
|
|
|
Controls.Remove(_loadingBackground);
|
2022-01-25 21:02:10 +01:00
|
|
|
#if DEBUG
|
|
|
|
|
_webView.CoreWebView2.OpenDevToolsWindow();
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Opened Dev Tools window, because solution was built in debug mode");
|
2022-01-25 21:02:10 +01:00
|
|
|
#endif
|
2022-08-16 19:32:49 +02:00
|
|
|
|
|
|
|
|
_loadingBar.Value = 80;
|
|
|
|
|
this.Update();
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This event cancels every navigation inside the webview
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
private void NavigationStarted(object sender, CoreWebView2NavigationStartingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Prevents navigation if already one done to index.html
|
|
|
|
|
if (_hasNavigated)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = false;
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Stopped navigation from user");
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If it has navigated to index.html it stops further navigations
|
|
|
|
|
if (e.Uri == "about:blank")
|
|
|
|
|
{
|
|
|
|
|
_hasNavigated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
private void SetBackground()
|
|
|
|
|
{
|
|
|
|
|
Logger.LogTrace();
|
|
|
|
|
InvokeOnControlThread(() =>
|
|
|
|
|
{
|
|
|
|
|
this.BackColor = Settings.BackgroundColor;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
private void InitializeLoadingScreen()
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogTrace();
|
2022-01-25 21:02:10 +01:00
|
|
|
InvokeOnControlThread(() =>
|
|
|
|
|
{
|
2022-08-16 19:32:49 +02:00
|
|
|
_loadingBackground = new Label();
|
|
|
|
|
_loadingBackground.BackColor = Settings.BackgroundColor;
|
|
|
|
|
_loadingBackground.Width = this.Width;
|
|
|
|
|
_loadingBackground.Height = this.Height;
|
|
|
|
|
Controls.Add(_loadingBackground);
|
|
|
|
|
_loadingBackground.BringToFront();
|
|
|
|
|
|
|
|
|
|
_loadingBar = new ProgressBar();
|
|
|
|
|
_loadingBar.Width = this.Width - 10;
|
|
|
|
|
_loadingBar.Location = new Point(5, this.Height / 2);
|
|
|
|
|
_loadingBar.Maximum = 100;
|
|
|
|
|
_loadingBar.Value = 10;
|
|
|
|
|
Controls.Add(_loadingBar);
|
|
|
|
|
|
2022-01-25 21:02:10 +01:00
|
|
|
_loading = new Label();
|
|
|
|
|
_loading.Text = Resources.Loading_Screen_Message;
|
|
|
|
|
_loading.Width = this.Width;
|
2022-08-16 19:32:49 +02:00
|
|
|
_loading.Height = 45;
|
|
|
|
|
_loading.Location = new Point(0, _loadingBar.Location.Y - _loading.Height);
|
|
|
|
|
_loading.TextAlign = ContentAlignment.TopCenter;
|
2022-01-25 21:02:10 +01:00
|
|
|
_loading.Font = new Font("MS Sans Serif", 16, FontStyle.Bold);
|
|
|
|
|
_loading.ForeColor = Settings.TextColor;
|
|
|
|
|
Controls.Add(_loading);
|
2022-08-16 19:32:49 +02:00
|
|
|
|
|
|
|
|
_loading.BringToFront();
|
|
|
|
|
_loadingBar.BringToFront();
|
|
|
|
|
|
|
|
|
|
this.Update();
|
2022-01-25 21:02:10 +01:00
|
|
|
});
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogInfo("Loading screen initialized");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeIndexFileAndSelectedFile(string filePath)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo("Starting getting monaco language id out of filetype");
|
|
|
|
|
_vsCodeLangSet = FileHandler.GetLanguage(Path.GetExtension(filePath));
|
|
|
|
|
|
|
|
|
|
using (StreamReader fileReader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo("Starting reading requested file");
|
|
|
|
|
var fileContent = fileReader.ReadToEnd();
|
2022-08-24 13:08:10 +02:00
|
|
|
|
|
|
|
|
if (_settings.TryFormat)
|
|
|
|
|
{
|
|
|
|
|
var formatter = _formatters.SingleOrDefault(f => f.LangSet == _vsCodeLangSet);
|
|
|
|
|
if (formatter != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
fileContent = formatter.Format(fileContent);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"Failed to apply formatting to {filePath}", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 19:32:49 +02:00
|
|
|
fileReader.Close();
|
|
|
|
|
_base64FileCode = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileContent));
|
|
|
|
|
Logger.LogInfo("Reading requested file ended");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prepping index html to load in
|
|
|
|
|
using (StreamReader htmlFileReader = new StreamReader(new FileStream(Settings.AssemblyDirectory + "\\index.html", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo("Starting reading HTML source file");
|
|
|
|
|
_html = htmlFileReader.ReadToEnd();
|
|
|
|
|
htmlFileReader.Close();
|
|
|
|
|
Logger.LogInfo("Reading HTML source file ended");
|
2022-08-24 13:08:10 +02:00
|
|
|
}
|
2022-08-16 19:32:49 +02:00
|
|
|
|
|
|
|
|
_html = _html.Replace("[[PT_LANG]]", _vsCodeLangSet, StringComparison.InvariantCulture);
|
|
|
|
|
_html = _html.Replace("[[PT_WRAP]]", _settings.Wrap ? "1" : "0", StringComparison.InvariantCulture);
|
|
|
|
|
_html = _html.Replace("[[PT_THEME]]", Settings.GetTheme(), StringComparison.InvariantCulture);
|
|
|
|
|
_html = _html.Replace("[[PT_CODE]]", _base64FileCode, StringComparison.InvariantCulture);
|
|
|
|
|
_html = _html.Replace("[[PT_URL]]", VirtualHostName, StringComparison.InvariantCulture);
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void DownloadLink_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
await Launcher.LaunchUriAsync(new Uri("https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section"));
|
2022-08-16 19:32:49 +02:00
|
|
|
Logger.LogTrace();
|
2022-01-25 21:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|