Skip to content

Commit

Permalink
refactor: add discord manager
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed May 8, 2023
1 parent efb553e commit 99dbef8
Show file tree
Hide file tree
Showing 8 changed files with 1,645 additions and 1,627 deletions.
116 changes: 59 additions & 57 deletions MHFZ_Overlay/ConfigWindow.xaml.cs

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions MHFZ_Overlay/Core/Class/Application/ApplicationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DiscordRPC;
using MHFZ_Overlay.Core.Class.Discord;
using NLog;
using System;
using System.Collections.Generic;
Expand All @@ -18,7 +19,7 @@ public static void HandleShutdown()
{
//https://stackoverflow.com/a/9050477/18859245
databaseManager.StoreSessionTime(databaseManager.DatabaseStartTime);
ApplicationManager.DiscordRPCCleanup();
DiscordManager.DiscordRPCCleanup();
DisposeNotifyIcon();
logger.Info("Closing overlay");
Environment.Exit(0);
Expand All @@ -35,23 +36,11 @@ public static void DisposeNotifyIcon()
public static void HandleRestart()
{
databaseManager.StoreSessionTime(databaseManager.DatabaseStartTime);
DiscordManager.DiscordRPCCleanup();
DisposeNotifyIcon();
logger.Info("Restarting overlay");
System.Windows.Forms.Application.Restart();
System.Windows.Application.Current.Shutdown();
}

//Dispose client
/// <summary>
/// Cleanups the Discord RPC instance.
/// </summary>
public static void DiscordRPCCleanup()
{
if (MainWindow.discordRPCClient != null)//&& ShowDiscordRPC)
{
MainWindow.discordRPCClient.Dispose();
logger.Info("Disposed Discord RPC");
}
}
}
}
20 changes: 9 additions & 11 deletions MHFZ_Overlay/Core/Class/DataAccessLayer/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public static DatabaseManager GetInstance()
{
if (instance == null)
{
logger.Info("Singleton not found, creating instance.");
instance = new DatabaseManager();
}

logger.Info("Singleton found, returning instance.");
logger.Trace(new StackTrace().ToString());
return instance;
}

Expand Down Expand Up @@ -172,7 +174,7 @@ public bool SetupLocalDatabase(DataLoader dataLoader)
conn.Open();

// Toggle comment this for testing the error handling
ThrowException(conn);
//ThrowException(conn);

CreateDatabaseTables(conn, dataLoader);
CreateDatabaseIndexes(conn);
Expand Down Expand Up @@ -438,18 +440,18 @@ public int InsertQuestData(DataLoader dataLoader, int attempts)
//Gathering/etc
if ((dataLoader.model.ObjectiveType() == 0x0 || dataLoader.model.ObjectiveType() == 0x02 || dataLoader.model.ObjectiveType() == 0x1002) && (dataLoader.model.QuestID() != 23527 && dataLoader.model.QuestID() != 23628 && dataLoader.model.QuestID() != 21731 && dataLoader.model.QuestID() != 21749 && dataLoader.model.QuestID() != 21746 && dataLoader.model.QuestID() != 21750))
{
objectiveImage = MainWindow.GetAreaIconFromID(dataLoader.model.AreaID());
objectiveImage = dataLoader.model.GetAreaIconFromID(dataLoader.model.AreaID());
}
//Tenrou Sky Corridor areas
else if (dataLoader.model.AreaID() == 391 || dataLoader.model.AreaID() == 392 || dataLoader.model.AreaID() == 394 || dataLoader.model.AreaID() == 415 || dataLoader.model.AreaID() == 416)
{
objectiveImage = MainWindow.GetAreaIconFromID(dataLoader.model.AreaID());
objectiveImage = dataLoader.model.GetAreaIconFromID(dataLoader.model.AreaID());

}
//Duremudira Doors
else if (dataLoader.model.AreaID() == 399 || dataLoader.model.AreaID() == 414)
{
objectiveImage = MainWindow.GetAreaIconFromID(dataLoader.model.AreaID());
objectiveImage = dataLoader.model.GetAreaIconFromID(dataLoader.model.AreaID());
}
//Duremudira Arena
else if (dataLoader.model.AreaID() == 398)
Expand All @@ -459,7 +461,7 @@ public int InsertQuestData(DataLoader dataLoader, int attempts)
//Hunter's Road Base Camp
else if (dataLoader.model.AreaID() == 459)
{
objectiveImage = MainWindow.GetAreaIconFromID(dataLoader.model.AreaID());
objectiveImage = dataLoader.model.GetAreaIconFromID(dataLoader.model.AreaID());
}
//Raviente
else if (dataLoader.model.AreaID() == 309 || (dataLoader.model.AreaID() >= 311 && dataLoader.model.AreaID() <= 321) || (dataLoader.model.AreaID() >= 417 && dataLoader.model.AreaID() <= 422) || dataLoader.model.AreaID() == 437 || (dataLoader.model.AreaID() >= 440 && dataLoader.model.AreaID() <= 444))
Expand Down Expand Up @@ -2392,10 +2394,8 @@ private void HandleError(SQLiteTransaction? transaction, Exception ex)
if (transaction != null)
transaction.Rollback();

logger.Error(ex, "An error occurred");

// Handle the exception and show an error message to the user
LoggingManager.PromptForOpeningLogs();
LoggingManager.WriteCrashLog(ex);
}

public void MakeDeserealizedQuestInfoDictionariesFromRunID(SQLiteConnection conn, DataLoader dataLoader, int runID)
Expand Down Expand Up @@ -5495,8 +5495,6 @@ public ZenithSkills GetZenithSkills(long runID)
return zenithSkills;
}



public CaravanSkills GetCaravanSkills(long runID)
{
CaravanSkills caravanSkills = new CaravanSkills();
Expand Down
Loading

0 comments on commit 99dbef8

Please sign in to comment.