1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 21:30:12 +00:00
msfs-popout-panel-manager/Orchestration/HelpOrchestrator.cs

139 lines
4.9 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using AutoUpdaterDotNET;
using MSFSPopoutPanelManager.Shared;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace MSFSPopoutPanelManager.Orchestration
{
public class HelpOrchestrator : ObservableObject
{
public void OpenGettingStarted()
{
Process.Start(new ProcessStartInfo("https://github.com/hawkeye-stan/msfs-popout-panel-manager/blob/master/GETTING_STARTED.md") { UseShellExecute = true });
}
public void OpenUserGuide()
{
Process.Start(new ProcessStartInfo("https://github.com/hawkeye-stan/msfs-popout-panel-manager#msfs-pop-out-panel-manager") { UseShellExecute = true });
}
public void OpenLatestDownloadGitHub()
{
Process.Start(new ProcessStartInfo("https://github.com/hawkeye-stan/msfs-popout-panel-manager/releases") { UseShellExecute = true });
}
public void OpenLatestDownloadFligthsimTo()
{
Process.Start(new ProcessStartInfo("https://flightsim.to/file/35759/msfs-pop-out-panel-manager") { UseShellExecute = true });
}
public void OpenLicense()
{
Process.Start("notepad.exe", "LICENSE");
}
public void OpenVersionInfo()
{
Process.Start("notepad.exe", "VERSION.md");
}
public void OpenDataFolder()
{
Process.Start("explorer.exe", Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MSFS Pop Out Panel Manager"));
}
public bool HasOrphanAppCache()
{
2024-02-28 02:44:21 +00:00
var appLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var srcPath = Path.Combine(appLocal, @"temp\.net\MSFSPopoutPanelManager");
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
var di = new DirectoryInfo(srcPath);
2023-07-12 22:41:31 +00:00
if (di.Exists)
return di.GetDirectories().Length > 1;
return false;
}
2024-02-28 02:44:21 +00:00
public void DownloadVccLibrary()
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var target = "https://aka.ms/vs/17/release/vc_redist.x64.exe";
2023-07-12 22:41:31 +00:00
try
{
2024-02-28 02:44:21 +00:00
var psi = new ProcessStartInfo
{
UseShellExecute = true,
FileName = target
};
2023-07-12 22:41:31 +00:00
Process.Start(psi);
}
2024-02-28 02:44:21 +00:00
catch
{
// ignored
}
2023-07-12 22:41:31 +00:00
}
public void DeleteAppCache()
{
2024-02-28 02:44:21 +00:00
var appLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var srcPath = Path.Combine(appLocal, @"temp\.net\MSFSPopoutPanelManager");
2023-07-12 22:41:31 +00:00
try
{
var currentAppPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location);
2024-02-28 02:44:21 +00:00
if (currentAppPath == null)
throw new ApplicationException("Unable to determine POPM application path.");
2023-07-12 22:41:31 +00:00
var dir = new DirectoryInfo(srcPath);
var subDirs = dir.GetDirectories();
foreach (var subDir in subDirs)
{
if (subDir.FullName.ToLower().Trim() != currentAppPath.FullName.ToLower().Trim())
{
Directory.Delete(subDir.FullName, true);
}
}
}
catch (Exception ex)
{
FileLogger.WriteLog("Delete app cache exception: " + ex.Message, StatusMessageType.Error);
}
}
public void RollBackUpdate()
{
var userProfileBackupPath = Path.Combine(FileIo.GetUserDataFilePath(), "Backup-previous-version", "userprofiledata.json");
var appSettingBackupPath = Path.Combine(FileIo.GetUserDataFilePath(), "Backup-previous-version", "appsettingdata.json");
var userProfilePath = Path.Combine(FileIo.GetUserDataFilePath(), "userprofiledata.json");
var appSettingPath = Path.Combine(FileIo.GetUserDataFilePath(), "appsettingdata.json");
if (File.Exists(userProfileBackupPath))
File.Copy(userProfileBackupPath, userProfilePath, true);
if (File.Exists(appSettingBackupPath))
File.Copy(appSettingBackupPath, appSettingPath, true);
AutoUpdater.InstalledVersion = new Version("1.0.0.0");
AutoUpdater.Synchronous = true;
AutoUpdater.AppTitle = "MSFS Pop Out Panel Manager";
AutoUpdater.RunUpdateAsAdmin = false;
AutoUpdater.UpdateFormSize = new System.Drawing.Size(1024, 660);
AutoUpdater.UpdateMode = Mode.ForcedDownload;
AutoUpdater.Start("https://raw.githubusercontent.com/hawkeye-stan/msfs-popout-panel-manager/master/rollback.xml");
}
public bool IsRollBackUpdateEnabled()
{
var appSettingBackupPath = Path.Combine(FileIo.GetUserDataFilePath(), "Backup-previous-version", "appsettingdata.json");
return File.Exists(appSettingBackupPath);
}
}
}