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();
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 ----------------------------------------------------------------------------------------------------------------------------------------------------------
@ -50,7 +61,8 @@ namespace skyscraper8.UI.MonoGame
catch (Exception e)
{
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();
}
@ -63,7 +75,8 @@ namespace skyscraper8.UI.MonoGame
catch (Exception e)
{
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()
{
Directory = "dummy_object_storage"
@ -84,7 +97,7 @@ namespace skyscraper8.UI.MonoGame
}
else
{
localLogger.Log(PluginLogLevel.Info,"It isn't -> Creating object storage...");
localLogger.Log(PluginLogLevel.Info, "It isn't -> Creating object storage...");
try
{
handles.ObjectStorage = objectStorageFactory.CreateObjectStorage();
@ -93,17 +106,18 @@ namespace skyscraper8.UI.MonoGame
{
string objectStorageName = connectionManager.GetName(objectStorageFactory);
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.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
{
handles.DataStorage.Ping();
@ -118,7 +132,7 @@ namespace skyscraper8.UI.MonoGame
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
{
handles.ObjectStorage.Ping();
@ -140,56 +154,59 @@ namespace skyscraper8.UI.MonoGame
IGpsReceiverFactory gpsReceiverFactory = GpsManager.GetGpsReceiverFactoryById(gpsReceiverId);
GpsManager.AutoconfigureGpsReceiverFactory(gpsReceiverFactory);
localLogger.Log(PluginLogLevel.Info,"Instantiating the GPS receiver...");
localLogger.Log(PluginLogLevel.Info, "Instantiating the GPS receiver...");
handles.Gps = gpsReceiverFactory.CreateGpsReceiver();
localLogger.Log(PluginLogLevel.Info,"Starting the GPS receiver...");
localLogger.Log(PluginLogLevel.Info, "Starting the GPS receiver...");
handles.Gps.Start();
//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();
localLogger.Log(PluginLogLevel.Info,"Checking for the default LNB types...");
localLogger.Log(PluginLogLevel.Info, "Checking for the default LNB types...");
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();
localLogger.Log(PluginLogLevel.Info,"Checking for the default dish types...");
localLogger.Log(PluginLogLevel.Info, "Checking for the default dish types...");
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();
//LOAD TUNER --------------------------------------------------------------------------------------------------------------------------------------------------------------------
localLogger.Log(PluginLogLevel.Info,"Chcking the Tuner Factory classes...");
localLogger.Log(PluginLogLevel.Info, "Chcking the Tuner Factory classes...");
TunerFactoryConnectionManager tunerFactoryConnectionManager = TunerFactoryConnectionManager.GetInstance();
handles.AllTunerFactories = tunerFactoryConnectionManager.GetKnownFactories();
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");
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);
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
{
handles.StreamReader = bootingTuner.Value.CreateStreamReader();
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();
}
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();
}
@ -203,12 +220,14 @@ namespace skyscraper8.UI.MonoGame
if (!checkForDvbExEx)
{
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)
{
localLogger.Log(PluginLogLevel.Error,"Oh dear, it failed.");
localLogger.Log(PluginLogLevel.Error, "Oh dear, it failed.");
errors.Enqueue(
"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. " +
@ -218,16 +237,15 @@ namespace skyscraper8.UI.MonoGame
}
foreach (TunerMetadata foundTuner in foundTuners)
{
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);
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);
continue;
}
@ -240,7 +258,7 @@ namespace skyscraper8.UI.MonoGame
bool mac = handles.StreamReader.GetMAC(macBuffer);
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);
}
else
@ -257,7 +275,8 @@ namespace skyscraper8.UI.MonoGame
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))
{
handles.DataStorage.UiTunerGetConfiguration(foundTuner);
@ -268,7 +287,7 @@ namespace skyscraper8.UI.MonoGame
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();
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);
switch (qualification)
{
case QualificationToolResultEnum.Good:
break;
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;
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;
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;
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;
}
SkyscraperGame game = new SkyscraperGame(handles,errors);
game.Run();
}
}
}