Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1781 split eddi project revised #1815

Merged
merged 8 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CargoMonitor/CargoMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Eddi;
using EddiCore;
using EddiDataDefinitions;
using EddiEvents;
using EddiMissionMonitor;
Expand Down
1 change: 1 addition & 0 deletions CargoMonitor/ConfigurationWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Eddi;
using System.Windows.Controls;
using System.Windows.Data;
using EddiCore;

namespace EddiCargoMonitor
{
Expand Down
1 change: 1 addition & 0 deletions CrimeMonitor/ConfigurationWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using EddiCore;
using Utilities;

namespace EddiCrimeMonitor
Expand Down
1 change: 1 addition & 0 deletions CrimeMonitor/CrimeMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Threading;
using EddiCore;
using EddiStarMapService;
using Utilities;

Expand Down
12 changes: 9 additions & 3 deletions EDDI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EddiInaraResponder", "Inara
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EddiInaraService", "EddiInaraService\EddiInaraService.csproj", "{19AB6841-AA93-4D23-BE6D-4CB6883CDF62}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EddiCore", "EddiCore\EddiCore.csproj", "{28DC25D7-4DFD-4A77-B4FF-B9BADB711ECB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -226,14 +228,18 @@ Global
{19AB6841-AA93-4D23-BE6D-4CB6883CDF62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19AB6841-AA93-4D23-BE6D-4CB6883CDF62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19AB6841-AA93-4D23-BE6D-4CB6883CDF62}.Release|Any CPU.Build.0 = Release|Any CPU
{28DC25D7-4DFD-4A77-B4FF-B9BADB711ECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28DC25D7-4DFD-4A77-B4FF-B9BADB711ECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28DC25D7-4DFD-4A77-B4FF-B9BADB711ECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28DC25D7-4DFD-4A77-B4FF-B9BADB711ECB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_TaskErrorCategory = Message
RESX_AutoCreateNewLanguageFiles = True
RESX_ShowErrorsInErrorList = False
SolutionGuid = {28C2EDB6-0FA0-409F-987C-7A24F542D0CF}
RESX_ShowErrorsInErrorList = False
RESX_AutoCreateNewLanguageFiles = True
RESX_TaskErrorCategory = Message
EndGlobalSection
EndGlobal
19 changes: 14 additions & 5 deletions EDDI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using EddiCore;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
Expand All @@ -8,10 +9,10 @@

namespace Eddi
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static Mutex eddiMutex { get; private set; }

Expand All @@ -32,6 +33,14 @@ public static void Main()
StartRollbar(); // do immediately to initialize error reporting
ApplyAnyOverrideCulture(); // this must be done before any UI is generated

// Start by fetching information from the update server, and handling appropriately
EddiUpgrader.CheckUpgrade();
if (EddiUpgrader.UpgradeRequired)
{
// We are too old to continue; initialize in a "safe mode".
EDDI.Init(true);
}

if (FromVA)
{
// Start with the MainWindow hidden
Expand Down
174 changes: 30 additions & 144 deletions EDDI/EDDI.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using EddiCompanionAppService;
using Eddi;
using EddiCompanionAppService;
using EddiDataDefinitions;
using EddiDataProviderService;
using EddiEvents;
using EddiSpeechService;
using EddiStarMapService;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Utilities;

namespace Eddi
namespace EddiCore
{
/// <summary>
/// Eddi is the controller for all EDDI operations. Its job is to retain the state of the objects such as the commander, the current system, etc.
/// and keep them up-to-date with changes that occur. It also passes on messages to responders to handle as required.
/// </summary>
public class EDDI
/// <summary>
/// Eddi is the controller for all EDDI operations. Its job is to retain the state of the objects such as the commander, the current system, etc.
/// and keep them up-to-date with changes that occur.
/// It also acts as the switchboard for passing events through all parts of the application including both responders and monitors.
/// </summary>
public class EDDI
{
// True if the Speech Responder tab is waiting on a modal dialog window. Accessed by VoiceAttack plugin.
public bool SpeechResponderModalWait { get; set; } = false;
Expand All @@ -50,36 +49,33 @@ static EDDI()
Directory.CreateDirectory(Constants.DATA_DIR);
}

public static void Init(bool safeMode)
{
if (instance == null)
{
lock (instanceLock)
{
if (instance == null)
{
Logging.Debug("No EDDI instance: creating one");
instance = new EDDI(safeMode);
}
}
}
}

// EDDI Instance
public static EDDI Instance
{
get
{
if (instance == null)
{
lock (instanceLock)
{
if (instance == null)
{
Logging.Debug("No EDDI instance: creating one");
instance = new EDDI();
}
}
}
Init(false);
return instance;
}
}
private static EDDI instance;
private static readonly object instanceLock = new object();

// Upgrade information
public bool UpgradeAvailable = false;
public bool UpgradeRequired = false;
public string UpgradeVersion;
public string UpgradeLocation;
public string Motd;
public List<string> ProductionBuilds = new List<string>() { "r131487/r0" };

public List<EDDIMonitor> monitors = new List<EDDIMonitor>();
private ConcurrentBag<EDDIMonitor> activeMonitors = new ConcurrentBag<EDDIMonitor>();
private static readonly object monitorLock = new object();
Expand Down Expand Up @@ -122,20 +118,13 @@ public static EDDI Instance
// The event queue
public ConcurrentQueue<Event> eventQueue { get; private set; } = new ConcurrentQueue<Event>();

private EDDI()
private EDDI(bool safeMode)
{
running = !safeMode;
try
{
Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " starting");

// Start by fetching information from the update server, and handling appropriately
CheckUpgrade();
if (UpgradeRequired)
{
// We are too old to continue; initialize in a "safe mode".
running = false;
}

// Ensure that our primary data structures have something in them. This allows them to be updated from any source
Cmdr = new Commander();

Expand Down Expand Up @@ -252,109 +241,6 @@ public bool ShouldUseTestEndpoints()
#endif
}

/// <summary>
/// Check to see if an upgrade is available and populate relevant variables
/// </summary>
public void CheckUpgrade()
{
// Clear the old values
UpgradeRequired = false;
UpgradeAvailable = false;
UpgradeLocation = null;
UpgradeVersion = null;
Motd = null;

try
{
ServerInfo updateServerInfo = ServerInfo.FromServer(Constants.EDDI_SERVER_URL);
if (updateServerInfo == null)
{
throw new Exception("Failed to contact update server");
}
else
{
EDDIConfiguration configuration = EDDIConfiguration.FromFile();
InstanceInfo info = configuration.Beta ? updateServerInfo.beta : updateServerInfo.production;
string spokenVersion = info.version.Replace(".", $" {Properties.EddiResources.point} ");
Motd = info.motd;
if (updateServerInfo.productionbuilds != null)
{
ProductionBuilds = updateServerInfo.productionbuilds;
}
Utilities.Version minVersion = new Utilities.Version(info.minversion);
if (minVersion > Constants.EDDI_VERSION)
{
// There is a mandatory update available
if (!App.FromVA)
{
string message = String.Format(Properties.EddiResources.mandatory_upgrade, spokenVersion);
SpeechService.Instance.Say(null, message, 0);
}
UpgradeRequired = true;
UpgradeLocation = info.url;
UpgradeVersion = info.version;
return;
}

Utilities.Version latestVersion = new Utilities.Version(info.version);
if (latestVersion > Constants.EDDI_VERSION)
{
// There is an update available
if (!App.FromVA)
{
string message = String.Format(Properties.EddiResources.update_available, spokenVersion);
SpeechService.Instance.Say(null, message, 0);
}
UpgradeAvailable = true;
UpgradeLocation = info.url;
UpgradeVersion = info.version;
}
}
}
catch (Exception ex)
{
SpeechService.Instance.Say(null, Properties.EddiResources.update_server_unreachable, 0);
Logging.Warn("Failed to access " + Constants.EDDI_SERVER_URL, ex);
}
}

[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void Upgrade()
{
try
{
if (UpgradeLocation != null)
{
Logging.Info("Downloading upgrade from " + UpgradeLocation);
SpeechService.Instance.Say(null, Properties.EddiResources.downloading_upgrade, 0);
string updateFile = Net.DownloadFile(UpgradeLocation, @"EDDI-update.exe");
if (updateFile == null)
{
SpeechService.Instance.Say(null, Properties.EddiResources.download_failed, 0);
}
else
{
// Inno setup will attempt to restart this application so register it
NativeMethods.RegisterApplicationRestart(null, RestartFlags.NONE);

Logging.Info("Downloaded update to " + updateFile);
Logging.Info("Path is " + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
File.SetAttributes(updateFile, FileAttributes.Normal);
SpeechService.Instance.Say(null, Properties.EddiResources.starting_upgrade, 0);
Logging.Info("Starting upgrade.");

Process.Start(updateFile, @"/closeapplications /restartapplications /silent /log /nocancel /noicon /dir=""" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"""");
}
}
}
catch (Exception ex)
{
SpeechService.Instance.Say(null, Properties.EddiResources.upgrade_failed, 0);
Logging.Error("Upgrade failed", ex);
}
}

public void Start()
{
if (!started)
Expand Down Expand Up @@ -2623,7 +2509,7 @@ private void setCommanderTitle()
{
if (Cmdr != null)
{
Cmdr.title = Properties.EddiResources.Commander;
Cmdr.title = Eddi.Properties.EddiResources.Commander;
if (CurrentStarSystem != null)
{
if (CurrentStarSystem.Faction?.Allegiance?.invariantName == "Federation" && Cmdr.federationrating != null && Cmdr.federationrating.rank > minFederationRankForTitle)
Expand Down Expand Up @@ -2702,13 +2588,13 @@ public List<EDDIMonitor> findMonitors()
}
catch (FileLoadException flex)
{
string msg = string.Format(Properties.EddiResources.problem_load_monitor_file, dir.FullName);
string msg = string.Format(Eddi.Properties.EddiResources.problem_load_monitor_file, dir.FullName);
Logging.Error(msg, flex);
SpeechService.Instance.Say(null, msg, 0);
}
catch (Exception ex)
{
string msg = string.Format(Properties.EddiResources.problem_load_monitor, $"{file.Name}.\n{ex.Message} {ex.InnerException?.Message ?? ""}");
string msg = string.Format(Eddi.Properties.EddiResources.problem_load_monitor, $"{file.Name}.\n{ex.Message} {ex.InnerException?.Message ?? ""}");
Logging.Error(msg, ex);
SpeechService.Instance.Say(null, msg, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion EDDI/EDDIConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.IO;
using Utilities;

namespace Eddi
namespace EddiCore
{
/// <summary>Configuration for EDDI</summary>
public class EDDIConfiguration : INotifyPropertyChanged
Expand Down
2 changes: 1 addition & 1 deletion EDDI/EDDIMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Windows.Controls;

namespace Eddi
namespace EddiCore
{
/// <summary>
/// The methods required for an EDDI monitor.
Expand Down
2 changes: 1 addition & 1 deletion EDDI/EDDIResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.AddIn.Pipeline;
using System.Windows.Controls;

namespace Eddi
namespace EddiCore
{
/// <summary>
/// The methods required for an EDDI responder.
Expand Down
1 change: 1 addition & 0 deletions EDDI/Eddi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="EddiUpgrader.cs" />
<Compile Include="MarketInfoReader.cs" />
<Compile Include="OutfittingInfoReader.cs" />
<Compile Include="Settings.cs" />
Expand Down
Loading