mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 22:46:06 +02:00
auto reinstall of vc redist when CEF dies in a expected way (#835)
This commit is contained in:
+29
-1
@@ -8,6 +8,7 @@ using NLog;
|
|||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
@@ -104,10 +105,37 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
|
#region Handle CEF Explosion
|
||||||
|
catch (FileNotFoundException e)
|
||||||
|
{
|
||||||
|
logger.Error(e, "Handled Exception, Missing file found in Handle Cef Explosion.");
|
||||||
|
|
||||||
|
var result = MessageBox.Show("VRCX Has encountered an error with the CefSharp backend, \nthis is typically caused by missing files or dependencies\nWould you like to try an autofix and automatically install vc_redist?.", "VRCX CefSharp not found.", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||||
|
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case DialogResult.Yes:
|
||||||
|
logger.Fatal("Handled Exception, User selected auto install of vc_redist.");
|
||||||
|
Update.DownloadInstallRedist();
|
||||||
|
MessageBox.Show(
|
||||||
|
"vc_redist has finished installing, if the issue continues upon next restart, please reinstall reinstall VRCX From GitHub,\nVRCX Will now restart.", "vc_redist installation complete", MessageBoxButtons.OK);
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
AppApi.Instance.RestartApplication();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DialogResult.No:
|
||||||
|
logger.Fatal("Handled Exception, User choose manual.");
|
||||||
|
MessageBox.Show("VRCX will now close, try reinstalling VRCX from Github setup exe as a possible fix.", "VRCX CefSharp not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Fatal(e, "Unhandled Exception, program dying");
|
logger.Fatal(e, "Unhandled Exception, program dying");
|
||||||
MessageBox.Show(e.ToString(), "PLEASE REPORT IN https://vrcx.app/discord", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(e.ToString(), "PLEASE REPORT IN https://vrcx.pypy.moe/discord", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
{
|
{
|
||||||
@@ -55,5 +56,89 @@ namespace VRCX
|
|||||||
MessageBox.Show(e.ToString(), "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(e.ToString(), "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void DownloadInstallRedist()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var filePath = DownloadFile("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||||
|
var installRedist = new Process
|
||||||
|
{
|
||||||
|
StartInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = filePath,
|
||||||
|
Arguments = "/install /quiet /norestart"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
installRedist.Start();
|
||||||
|
installRedist.WaitForExit();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e.ToString(), "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string DownloadFile(string fileUrl)
|
||||||
|
{
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response = client.GetAsync(fileUrl).Result;
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string fileName = GetFileNameFromContentDisposition(response);
|
||||||
|
|
||||||
|
string tempPath = Path.Combine(Path.GetTempPath(), "VRCX");
|
||||||
|
Directory.CreateDirectory(tempPath);
|
||||||
|
|
||||||
|
string filePath = Path.Combine(tempPath, fileName);
|
||||||
|
|
||||||
|
using (FileStream fileStream = File.Create(filePath))
|
||||||
|
{
|
||||||
|
response.Content.CopyToAsync(fileStream).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Failed to download the file. Status code: {response.StatusCode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error downloading the file: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetFileNameFromContentDisposition(HttpResponseMessage response)
|
||||||
|
{
|
||||||
|
string contentDisposition = response.Content.Headers.ContentDisposition?.ToString();
|
||||||
|
if (contentDisposition != null)
|
||||||
|
{
|
||||||
|
int startIndex = contentDisposition.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (startIndex >= 0)
|
||||||
|
{
|
||||||
|
startIndex += "filename=".Length;
|
||||||
|
int endIndex = contentDisposition.IndexOf(";", startIndex);
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
endIndex = contentDisposition.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileName = contentDisposition.Substring(startIndex, endIndex - startIndex).Trim(' ', '"');
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception("Unable to extract file name from content-disposition header.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user