Refactored Startup in that MonoGame thingy.

This commit is contained in:
feyris-tan 2025-08-12 22:13:09 +02:00
parent 2b67f56e9c
commit 05857b9004

View File

@ -20,7 +20,18 @@ namespace skyscraper8.UI.MonoGame
SkyscraperHandleCollection handles = new SkyscraperHandleCollection(); SkyscraperHandleCollection handles = new SkyscraperHandleCollection();
Queue<string> errors = new Queue<string>(); Queue<string> errors = new Queue<string>();
localLogger.Log(PluginLogLevel.Info,"Starting up..."); PerformStartup(localLogger, handles, errors);
SkyscraperGame game = new SkyscraperGame(handles,errors);
localLogger.Log(PluginLogLevel.Info,"Entering MonoGame loop...");
game.Run();
}
private static void PerformStartup(PluginLogger localLogger, SkyscraperHandleCollection handles, Queue<string> errors)
{
localLogger.Log(PluginLogLevel.Info, "Starting up...");
//LOAD STORAGE ---------------------------------------------------------------------------------------------------------------------------------------------------------- //LOAD STORAGE ----------------------------------------------------------------------------------------------------------------------------------------------------------
@ -50,10 +61,11 @@ namespace skyscraper8.UI.MonoGame
catch (Exception e) catch (Exception e)
{ {
localLogger.Log(PluginLogLevel.Error, "Failed to start the data storage factory: {0}", e.Message); localLogger.Log(PluginLogLevel.Error, "Failed to start the data storage factory: {0}", e.Message);
errors.Enqueue(String.Format("Could not load the data storage factory.\nThe following went wrong:\n\n{0}\n\n", e.Message)); errors.Enqueue(String.Format("Could not load the data storage factory.\nThe following went wrong:\n\n{0}\n\n",
e.Message));
dataStorageFactory = new InMemoryScraperStorageFactory(); dataStorageFactory = new InMemoryScraperStorageFactory();
} }
ObjectStorageFactory objectStorageFactory; ObjectStorageFactory objectStorageFactory;
try try
{ {
@ -63,17 +75,18 @@ namespace skyscraper8.UI.MonoGame
catch (Exception e) catch (Exception e)
{ {
localLogger.Log(PluginLogLevel.Error, "Failed to start the object storage factory: {0}", e.Message); localLogger.Log(PluginLogLevel.Error, "Failed to start the object storage factory: {0}", e.Message);
errors.Enqueue(String.Format("Could not load the object storage factory.\nThe following went wrong:\n\n{0}\n\n", e.Message)); errors.Enqueue(String.Format("Could not load the object storage factory.\nThe following went wrong:\n\n{0}\n\n",
e.Message));
objectStorageFactory = new FilesystemScraperStorageFactory() objectStorageFactory = new FilesystemScraperStorageFactory()
{ {
Directory = "dummy_object_storage" Directory = "dummy_object_storage"
}; };
} }
localLogger.Log(PluginLogLevel.Info, "Creating Data Storage..."); localLogger.Log(PluginLogLevel.Info, "Creating Data Storage...");
handles.DataStorage = dataStorageFactory.CreateDataStorage(); handles.DataStorage = dataStorageFactory.CreateDataStorage();
localLogger.Log(PluginLogLevel.Info, "Checking whether the data storage and the object storage are the same..."); localLogger.Log(PluginLogLevel.Info, "Checking whether the data storage and the object storage are the same...");
bool equivalentStorages = objectStorageFactory.IsEquivalent(dataStorageFactory); bool equivalentStorages = objectStorageFactory.IsEquivalent(dataStorageFactory);
@ -84,7 +97,7 @@ namespace skyscraper8.UI.MonoGame
} }
else else
{ {
localLogger.Log(PluginLogLevel.Info,"It isn't -> Creating object storage..."); localLogger.Log(PluginLogLevel.Info, "It isn't -> Creating object storage...");
try try
{ {
handles.ObjectStorage = objectStorageFactory.CreateObjectStorage(); handles.ObjectStorage = objectStorageFactory.CreateObjectStorage();
@ -93,17 +106,18 @@ namespace skyscraper8.UI.MonoGame
{ {
string objectStorageName = connectionManager.GetName(objectStorageFactory); string objectStorageName = connectionManager.GetName(objectStorageFactory);
localLogger.Log(PluginLogLevel.Error, "Failed to start the object storage factory: {0}", e.Message); localLogger.Log(PluginLogLevel.Error, "Failed to start the object storage factory: {0}", e.Message);
errors.Enqueue(String.Format("Could not load {1}.\nThe following went wrong:\n\n{0}\n\n", e.Message, objectStorageName)); errors.Enqueue(String.Format("Could not load {1}.\nThe following went wrong:\n\n{0}\n\n", e.Message,
objectStorageName));
} }
} }
localLogger.Log(PluginLogLevel.Info,"Reporting UI Version to the storages..."); localLogger.Log(PluginLogLevel.Info, "Reporting UI Version to the storages...");
handles.DataStorage?.UiSetVersion(2); handles.DataStorage?.UiSetVersion(2);
handles.ObjectStorage?.UiSetVersion(2); handles.ObjectStorage?.UiSetVersion(2);
localLogger.Log(PluginLogLevel.Info,"Testing whether the data storage is responding..."); localLogger.Log(PluginLogLevel.Info, "Testing whether the data storage is responding...");
try try
{ {
handles.DataStorage.Ping(); handles.DataStorage.Ping();
@ -118,7 +132,7 @@ namespace skyscraper8.UI.MonoGame
brokenStorageName, e.Message)); brokenStorageName, e.Message));
} }
localLogger.Log(PluginLogLevel.Info,"Please wait while I test whether the object storage is responding..."); localLogger.Log(PluginLogLevel.Info, "Please wait while I test whether the object storage is responding...");
try try
{ {
handles.ObjectStorage.Ping(); handles.ObjectStorage.Ping();
@ -140,56 +154,59 @@ namespace skyscraper8.UI.MonoGame
IGpsReceiverFactory gpsReceiverFactory = GpsManager.GetGpsReceiverFactoryById(gpsReceiverId); IGpsReceiverFactory gpsReceiverFactory = GpsManager.GetGpsReceiverFactoryById(gpsReceiverId);
GpsManager.AutoconfigureGpsReceiverFactory(gpsReceiverFactory); GpsManager.AutoconfigureGpsReceiverFactory(gpsReceiverFactory);
localLogger.Log(PluginLogLevel.Info,"Instantiating the GPS receiver..."); localLogger.Log(PluginLogLevel.Info, "Instantiating the GPS receiver...");
handles.Gps = gpsReceiverFactory.CreateGpsReceiver(); handles.Gps = gpsReceiverFactory.CreateGpsReceiver();
localLogger.Log(PluginLogLevel.Info,"Starting the GPS receiver..."); localLogger.Log(PluginLogLevel.Info, "Starting the GPS receiver...");
handles.Gps.Start(); handles.Gps.Start();
//LOAD BASE DATA -------------------------------------------------------------------------------------------------------------------------------------------------------------- //LOAD BASE DATA --------------------------------------------------------------------------------------------------------------------------------------------------------------
localLogger.Log(PluginLogLevel.Info,"Querying the storage for known satellite positions..."); localLogger.Log(PluginLogLevel.Info, "Querying the storage for known satellite positions...");
handles.SatellitePositions = handles.DataStorage.UiSatellitesListAll(); handles.SatellitePositions = handles.DataStorage.UiSatellitesListAll();
localLogger.Log(PluginLogLevel.Info,"Checking for the default LNB types..."); localLogger.Log(PluginLogLevel.Info, "Checking for the default LNB types...");
EquipmentUtilities.InsertDefaultLnbTypes(handles.DataStorage); EquipmentUtilities.InsertDefaultLnbTypes(handles.DataStorage);
localLogger.Log(PluginLogLevel.Info,"Querying the storage for known LNB types..."); localLogger.Log(PluginLogLevel.Info, "Querying the storage for known LNB types...");
handles.LnbTypes = handles.DataStorage.UiLnbTypesListAll(); handles.LnbTypes = handles.DataStorage.UiLnbTypesListAll();
localLogger.Log(PluginLogLevel.Info,"Checking for the default dish types..."); localLogger.Log(PluginLogLevel.Info, "Checking for the default dish types...");
EquipmentUtilities.InsertDefaultDishTypes(handles.DataStorage); EquipmentUtilities.InsertDefaultDishTypes(handles.DataStorage);
localLogger.Log(PluginLogLevel.Info,"Querying the storage for known Dish types..."); localLogger.Log(PluginLogLevel.Info, "Querying the storage for known Dish types...");
handles.DishTypes = handles.DataStorage.UiDishTypesListAll(); handles.DishTypes = handles.DataStorage.UiDishTypesListAll();
//LOAD TUNER -------------------------------------------------------------------------------------------------------------------------------------------------------------------- //LOAD TUNER --------------------------------------------------------------------------------------------------------------------------------------------------------------------
localLogger.Log(PluginLogLevel.Info,"Chcking the Tuner Factory classes..."); localLogger.Log(PluginLogLevel.Info, "Chcking the Tuner Factory classes...");
TunerFactoryConnectionManager tunerFactoryConnectionManager = TunerFactoryConnectionManager.GetInstance(); TunerFactoryConnectionManager tunerFactoryConnectionManager = TunerFactoryConnectionManager.GetInstance();
handles.AllTunerFactories = tunerFactoryConnectionManager.GetKnownFactories(); handles.AllTunerFactories = tunerFactoryConnectionManager.GetKnownFactories();
int tunerFactory = handles.Ini.ReadValue("startup", "tunerFactory", 0); int tunerFactory = handles.Ini.ReadValue("startup", "tunerFactory", 0);
KeyValuePair<TunerFactoryIdAttribute, ITunerFactory> bootingTuner = handles.AllTunerFactories.First(x => x.Key.Id == tunerFactory); KeyValuePair<TunerFactoryIdAttribute, ITunerFactory> bootingTuner =
handles.AllTunerFactories.First(x => x.Key.Id == tunerFactory);
bool isNoTuner = bootingTuner.Key.DisplayName.Equals("No tuner"); bool isNoTuner = bootingTuner.Key.DisplayName.Equals("No tuner");
if (isNoTuner) if (isNoTuner)
{ {
errors.Enqueue("Please not that Skyscraper is currently configured to not use a Tuner Factory Class. This will work, but functionality will be severely limited. Please configure a Tuner Factory Class in order to get the best experience."); errors.Enqueue(
"Please not that Skyscraper is currently configured to not use a Tuner Factory Class. This will work, but functionality will be severely limited. Please configure a Tuner Factory Class in order to get the best experience.");
} }
localLogger.Log(PluginLogLevel.Info,"Applying the tuner factory class configuration..:"); localLogger.Log(PluginLogLevel.Info, "Applying the tuner factory class configuration..:");
TunerFactoryConnectionManager.ConfigureFactoryFromIni(bootingTuner, handles.Ini); TunerFactoryConnectionManager.ConfigureFactoryFromIni(bootingTuner, handles.Ini);
List<TunerMetadata> foundTuners = new List<TunerMetadata>(); List<TunerMetadata> foundTuners = new List<TunerMetadata>();
localLogger.Log(PluginLogLevel.Info,"Please wait while the Tuner Factory class code is being executed..."); localLogger.Log(PluginLogLevel.Info, "Please wait while the Tuner Factory class code is being executed...");
try try
{ {
handles.StreamReader = bootingTuner.Value.CreateStreamReader(); handles.StreamReader = bootingTuner.Value.CreateStreamReader();
try try
{ {
localLogger.Log(PluginLogLevel.Info,"Trying to see whether the tuner factory works..."); localLogger.Log(PluginLogLevel.Info, "Trying to see whether the tuner factory works...");
handles.StreamReader.CheckForDVB(); handles.StreamReader.CheckForDVB();
} }
catch (BadImageFormatException e) catch (BadImageFormatException e)
{ {
errors.Enqueue("The configured tuner factory is not suitable for the current processor architecture. Tuning won't work, therefore functionality will be severely limited. Please configure a Tuner Factory Class suitable for this processor architecture in order to get the best experience. If you need to run crazycat69's StreamReader.dll on 64-bit machines, try RemoteStreamReader."); errors.Enqueue(
"The configured tuner factory is not suitable for the current processor architecture. Tuning won't work, therefore functionality will be severely limited. Please configure a Tuner Factory Class suitable for this processor architecture in order to get the best experience. If you need to run crazycat69's StreamReader.dll on 64-bit machines, try RemoteStreamReader.");
handles.StreamReader = new NullTunerFactory().CreateStreamReader(); handles.StreamReader = new NullTunerFactory().CreateStreamReader();
} }
@ -203,12 +220,14 @@ namespace skyscraper8.UI.MonoGame
if (!checkForDvbExEx) if (!checkForDvbExEx)
{ {
if (!isNoTuner) if (!isNoTuner)
localLogger.Log(PluginLogLevel.Error, String.Format("{0} has failed. Tuning won't be possible!", nameof(handles.StreamReader.CheckForDVBExEx))); localLogger.Log(PluginLogLevel.Error,
String.Format("{0} has failed. Tuning won't be possible!",
nameof(handles.StreamReader.CheckForDVBExEx)));
} }
} }
catch (Exception e) catch (Exception e)
{ {
localLogger.Log(PluginLogLevel.Error,"Oh dear, it failed."); localLogger.Log(PluginLogLevel.Error, "Oh dear, it failed.");
errors.Enqueue( errors.Enqueue(
"Please not that the Tuner Factory class code failed to execute. " + "Please not that the Tuner Factory class code failed to execute. " +
"This won't stop the program from working, but functionality will be severely limited. " + "This won't stop the program from working, but functionality will be severely limited. " +
@ -216,18 +235,17 @@ namespace skyscraper8.UI.MonoGame
"The following went wrong:\n" + e.Message); "The following went wrong:\n" + e.Message);
handles.StreamReader = new NullTunerFactory().CreateStreamReader(); handles.StreamReader = new NullTunerFactory().CreateStreamReader();
} }
foreach (TunerMetadata foundTuner in foundTuners) foreach (TunerMetadata foundTuner in foundTuners)
{ {
handles.StreamReader.StopDVB(); handles.StreamReader.StopDVB();
localLogger.Log(PluginLogLevel.Info,String.Format("Starting tuner {0}", foundTuner.Name)); localLogger.Log(PluginLogLevel.Info, String.Format("Starting tuner {0}", foundTuner.Name));
bool startDvbEx = handles.StreamReader.StartDvbEx(foundTuner.Index); bool startDvbEx = handles.StreamReader.StartDvbEx(foundTuner.Index);
if (!startDvbEx) if (!startDvbEx)
{ {
localLogger.Log(PluginLogLevel.Error,String.Format("Failed to start {0}", foundTuner.Name)); localLogger.Log(PluginLogLevel.Error, String.Format("Failed to start {0}", foundTuner.Name));
Thread.Sleep(1000); Thread.Sleep(1000);
continue; continue;
} }
@ -240,7 +258,7 @@ namespace skyscraper8.UI.MonoGame
bool mac = handles.StreamReader.GetMAC(macBuffer); bool mac = handles.StreamReader.GetMAC(macBuffer);
if (!mac) if (!mac)
{ {
localLogger.Log(PluginLogLevel.Error,String.Format("Failed to read MAC Address of {0}", foundTuner.Name)); localLogger.Log(PluginLogLevel.Error, String.Format("Failed to read MAC Address of {0}", foundTuner.Name));
Thread.Sleep(1000); Thread.Sleep(1000);
} }
else else
@ -257,7 +275,8 @@ namespace skyscraper8.UI.MonoGame
continue; continue;
} }
localLogger.Log(PluginLogLevel.Info, String.Format("Querying storage for configuration of {0}...", foundTuner.Name)); localLogger.Log(PluginLogLevel.Info,
String.Format("Querying storage for configuration of {0}...", foundTuner.Name));
if (handles.DataStorage.UiTunerTestFor(foundTuner)) if (handles.DataStorage.UiTunerTestFor(foundTuner))
{ {
handles.DataStorage.UiTunerGetConfiguration(foundTuner); handles.DataStorage.UiTunerGetConfiguration(foundTuner);
@ -268,7 +287,7 @@ namespace skyscraper8.UI.MonoGame
handles.Tuners.Add(foundTuner); handles.Tuners.Add(foundTuner);
} }
localLogger.Log(PluginLogLevel.Info,"Checking the engine Version..."); localLogger.Log(PluginLogLevel.Info, "Checking the engine Version...");
string engineProductName = handles.StreamReader.GetEngineName(); string engineProductName = handles.StreamReader.GetEngineName();
Version engineVersion = handles.StreamReader.GetEngineVersion(); Version engineVersion = handles.StreamReader.GetEngineVersion();
@ -281,29 +300,33 @@ namespace skyscraper8.UI.MonoGame
} }
} }
localLogger.Log(PluginLogLevel.Info,"Qualifying the engine..."); localLogger.Log(PluginLogLevel.Info, "Qualifying the engine...");
QualificationToolResultEnum qualification = QualificationTool.QualifyTunerFactory(engineProductName, engineVersion); QualificationToolResultEnum qualification = QualificationTool.QualifyTunerFactory(engineProductName, engineVersion);
switch (qualification) switch (qualification)
{ {
case QualificationToolResultEnum.Good: case QualificationToolResultEnum.Good:
break; break;
case QualificationToolResultEnum.Bad: case QualificationToolResultEnum.Bad:
errors.Enqueue(String.Format("You are using {0}, Version {1}\nThis version is known to cause issues with skyscraper. You can continue using it, but if it causes issues, you're on your own.", engineProductName, engineVersion)); errors.Enqueue(String.Format(
"You are using {0}, Version {1}\nThis version is known to cause issues with skyscraper. You can continue using it, but if it causes issues, you're on your own.",
engineProductName, engineVersion));
break; break;
case QualificationToolResultEnum.Unknown: case QualificationToolResultEnum.Unknown:
errors.Enqueue(String.Format("You are using {0}, Version {1}\nThis version has not been tested with skyscraper, and might cause some issues. Consider submitting a copy of this version to the author.", engineProductName, engineVersion)); errors.Enqueue(String.Format(
"You are using {0}, Version {1}\nThis version has not been tested with skyscraper, and might cause some issues. Consider submitting a copy of this version to the author.",
engineProductName, engineVersion));
break; break;
case QualificationToolResultEnum.PossibleIssues: case QualificationToolResultEnum.PossibleIssues:
errors.Enqueue(String.Format("You are using {0}, Version {1}\nThis version will work, but might have minor issues in some edge cases.", engineProductName, engineVersion)); errors.Enqueue(String.Format(
"You are using {0}, Version {1}\nThis version will work, but might have minor issues in some edge cases.",
engineProductName, engineVersion));
break; break;
default: default:
errors.Enqueue(String.Format("You are using {0}, Version {1}\nThe Qualification said \"{2}\", but this status is not implemented.\n Possibly your skyscraper Version and your testdrid Version mismatch?", engineProductName, engineVersion, qualification.ToString())); errors.Enqueue(String.Format(
"You are using {0}, Version {1}\nThe Qualification said \"{2}\", but this status is not implemented.\n Possibly your skyscraper Version and your testdrid Version mismatch?",
engineProductName, engineVersion, qualification.ToString()));
break; break;
} }
SkyscraperGame game = new SkyscraperGame(handles,errors);
game.Run();
} }
} }
} }