mirror of
https://github.com/4sval/FModel.git
synced 2026-08-24 10:24:32 -05:00
added keylogger lmfao i gotta steal your leaks sorry
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using FModel.Methods.MessageBox;
|
||||
using FModel.Methods.Utilities;
|
||||
using System.Windows;
|
||||
|
||||
namespace FModel
|
||||
@@ -11,6 +12,7 @@ namespace FModel
|
||||
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
string errorMessage = string.Format("An unhandled exception occurred: {0}", e.Exception.Message);
|
||||
DebugHelper.WriteException(e.Exception, "thrown in App.xaml.cs by OnDispatcherUnhandledException");
|
||||
DarkMessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -346,11 +346,13 @@
|
||||
<Compile Include="Methods\Utilities\AESUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\AssetsUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\ChallengesUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\DebugHelper.cs" />
|
||||
<Compile Include="Methods\Utilities\EndpointsUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\FoldersUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\FormsUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\ImagesUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\ListBoxUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\Logger.cs" />
|
||||
<Compile Include="Methods\Utilities\MBoxesUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\PAKsUtility.cs" />
|
||||
<Compile Include="Methods\Utilities\TasksUtility.cs" />
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Icon="Logo.ico"
|
||||
Loaded="Window_Loaded"
|
||||
UseLayoutRounding="True" Closed="Window_Closed">
|
||||
UseLayoutRounding="True">
|
||||
<Window.CommandBindings>
|
||||
<CommandBinding Command="{x:Static commands:FModel_Commands.OpenSettings}" Executed="MI_Settings_Click"/>
|
||||
<CommandBinding Command="{x:Static commands:FModel_Commands.OpenSearch}" Executed="MI_Search_Click"/>
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace FModel
|
||||
{
|
||||
FModelVersionLabel.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString().Substring(0, 5);
|
||||
|
||||
DebugHelper.WriteLine("AutoUpdater: Checking for updates");
|
||||
AutoUpdater.CheckForUpdateEvent += UIHelper.AutoUpdaterOnCheckForUpdateEvent;
|
||||
AutoUpdater.Start("https://dl.dropbox.com/s/3kv2pukqu6tj1r0/FModel.xml?dl=0");
|
||||
|
||||
@@ -44,6 +45,8 @@ namespace FModel
|
||||
FProp.Default.Upgrade();
|
||||
FProp.Default.FUpdateSettings = false;
|
||||
FProp.Default.Save();
|
||||
|
||||
DebugHelper.WriteLine("User settings copied from previous version");
|
||||
}
|
||||
|
||||
await Task.Run(() =>
|
||||
@@ -56,13 +59,10 @@ namespace FModel
|
||||
}).ContinueWith(TheTask =>
|
||||
{
|
||||
TasksUtility.TaskCompleted(TheTask.Exception);
|
||||
Dispatcher.InvokeAsync(() => AvalonEdit.SetAEConfig());
|
||||
Program.StartTimer.Stop();
|
||||
DebugHelper.WriteLine("Startup time: {0} ms", Program.StartTimer.ElapsedMilliseconds);
|
||||
});
|
||||
|
||||
AvalonEdit.SetAEConfig();
|
||||
}
|
||||
private void Window_Closed(object sender, System.EventArgs e)
|
||||
{
|
||||
FProp.Default.Save();
|
||||
}
|
||||
|
||||
#region BUTTON EVENTS
|
||||
|
||||
@@ -12,10 +12,11 @@ namespace FModel.Methods.AESManager
|
||||
private static readonly string AESManager_PATH = FProp.Default.FOutput_Path + "\\FAESManager.xml";
|
||||
private static List<AESInfosEntry> _oldAESEntriesList;
|
||||
|
||||
public static void SetDynamicKeys(bool reaload = false)
|
||||
public static void SetDynamicKeys(bool reload = false)
|
||||
{
|
||||
if (FProp.Default.ReloadAES || reaload)
|
||||
if (FProp.Default.ReloadAES || reload)
|
||||
{
|
||||
DebugHelper.WriteLine("Loading AES keys");
|
||||
if (!File.Exists(AESManager_PATH))
|
||||
{
|
||||
AESEntries.AESEntriesList = new List<AESInfosEntry>();
|
||||
@@ -76,7 +77,10 @@ namespace FModel.Methods.AESManager
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("AES keys not loaded, this isn't an error");
|
||||
KeysManager.Deserialize();
|
||||
}
|
||||
|
||||
FWindow.FMain.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using FModel.Methods.Utilities;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using FProp = FModel.Properties.Settings;
|
||||
@@ -12,6 +13,7 @@ namespace FModel.Methods.AESManager
|
||||
|
||||
public static void Serialize(string PAKName, string PAKKey)
|
||||
{
|
||||
DebugHelper.WriteLine("FAESManager: Serializing " + PAKName + " with " + PAKKey);
|
||||
AESEntries.AESEntriesList.Add(new AESInfosEntry
|
||||
{
|
||||
ThePAKName = PAKName,
|
||||
@@ -23,6 +25,7 @@ namespace FModel.Methods.AESManager
|
||||
{
|
||||
if (File.Exists(AESManager_PATH))
|
||||
{
|
||||
DebugHelper.WriteLine("FAESManager: Deserializing");
|
||||
List<AESInfosEntry> outputList;
|
||||
using (var fileStream = new FileStream(AESManager_PATH, FileMode.Open))
|
||||
{
|
||||
@@ -30,6 +33,8 @@ namespace FModel.Methods.AESManager
|
||||
}
|
||||
AESEntries.AESEntriesList = outputList;
|
||||
}
|
||||
else
|
||||
DebugHelper.WriteLine("FAESManager: Deserializing but " + AESManager_PATH + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using FModel.Methods.Utilities;
|
||||
using RestSharp;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -41,6 +42,7 @@ namespace FModel.Methods.BackupsManager
|
||||
MenuItem ClickedBackup = sender as MenuItem;
|
||||
if (BackupsFromDropbox != null && BackupsFromDropbox.Any())
|
||||
{
|
||||
Stopwatch timer = Stopwatch.StartNew();
|
||||
foreach (BackupInfosEntry Backup in BackupsFromDropbox)
|
||||
{
|
||||
string BackupFileName = Backup.TheFileName;
|
||||
@@ -59,11 +61,17 @@ namespace FModel.Methods.BackupsManager
|
||||
|
||||
if (new FileInfo(path).Length > 0) //HENCE WE CHECK THE LENGTH
|
||||
{
|
||||
timer.Stop();
|
||||
DebugHelper.WriteLine("Dropbox: Downloaded " + BackupFileName + " in " + timer.ElapsedMilliseconds + "ms");
|
||||
|
||||
new UpdateMyProcessEvents($"\\Backups\\{BackupFileName} successfully downloaded", "Success").Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Delete(path); //WE DELETE THE EMPTY FILE CREATED
|
||||
|
||||
timer.Stop();
|
||||
DebugHelper.WriteLine("Dropbox: Error while downloading " + BackupFileName + ", spent " + timer.ElapsedMilliseconds + "ms");
|
||||
new UpdateMyProcessEvents($"Error while downloading {BackupFileName}", "Error").Update();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using FProp = FModel.Properties.Settings;
|
||||
@@ -21,6 +20,7 @@ namespace FModel.Methods.PAKs
|
||||
string AutoPath = GetGameFiles();
|
||||
if (!string.IsNullOrEmpty(AutoPath))
|
||||
{
|
||||
DebugHelper.WriteLine("Auto .PAK files detection at " + AutoPath);
|
||||
new UpdateMyConsole(".PAK files path detected at ", CColors.White).Append();
|
||||
new UpdateMyConsole(AutoPath, CColors.Blue, true).Append();
|
||||
|
||||
@@ -38,9 +38,12 @@ namespace FModel.Methods.PAKs
|
||||
{
|
||||
if (!PAKsUtility.IsPAKLocked(new FileInfo(Pak)))
|
||||
{
|
||||
if (PAKsUtility.GetPAKVersion(Pak) == 8)
|
||||
uint pVersion = PAKsUtility.GetPAKVersion(Pak);
|
||||
if (pVersion == 8)
|
||||
{
|
||||
string PAKGuid = PAKsUtility.GetPAKGuid(Pak);
|
||||
DebugHelper.WriteLine("Registering " + Pak + " with GUID " + PAKGuid);
|
||||
|
||||
PAKEntries.PAKEntriesList.Add(new PAKInfosEntry(Pak, PAKGuid, string.Equals(PAKGuid, "0-0-0-0") ? false : true));
|
||||
FWindow.FMain.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
@@ -51,10 +54,16 @@ namespace FModel.Methods.PAKs
|
||||
FWindow.FMain.MI_LoadOnePAK.Items.Add(MI_Pak);
|
||||
});
|
||||
}
|
||||
else { new UpdateMyProcessEvents($"Unsupported .PAK Version for {Path.GetFileName(Pak)}", "Error").Update(); }
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine(Path.GetFileName(Pak) + " file version is " + pVersion + " instead of 8");
|
||||
new UpdateMyProcessEvents($"Unsupported .PAK Version for {Path.GetFileName(Pak)}", "Error").Update();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine(Path.GetFileName(Pak) + " is locked by another process.");
|
||||
|
||||
new UpdateMyConsole(Path.GetFileName(Pak), CColors.Blue).Append();
|
||||
new UpdateMyConsole(" is locked by another process.", CColors.White, true).Append();
|
||||
}
|
||||
@@ -81,7 +90,10 @@ namespace FModel.Methods.PAKs
|
||||
{
|
||||
if (DatFileExists())
|
||||
{
|
||||
string jsonData = File.ReadAllText($@"{GetEpicDirectory()}\UnrealEngineLauncher\LauncherInstalled.dat");
|
||||
string path = $@"{GetEpicDirectory()}\UnrealEngineLauncher\LauncherInstalled.dat";
|
||||
string jsonData = File.ReadAllText(path);
|
||||
DebugHelper.WriteLine("EPIC .dat file at " + path);
|
||||
|
||||
if (AssetsUtility.IsValidJson(jsonData))
|
||||
{
|
||||
JToken games = JsonConvert.DeserializeObject<JToken>(jsonData);
|
||||
@@ -94,13 +106,16 @@ namespace FModel.Methods.PAKs
|
||||
{
|
||||
if (string.Equals(game["AppName"].Value<string>(), "Fortnite"))
|
||||
{
|
||||
DebugHelper.WriteLine(game["AppVersion"] + " found in .dat file");
|
||||
return $@"{game["InstallLocation"].Value<string>()}\FortniteGame\Content\Paks";
|
||||
}
|
||||
}
|
||||
DebugHelper.WriteLine("Fortnite not found in .dat file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DebugHelper.WriteLine("EPIC .dat file not found");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
49
FModel/Methods/Utilities/DebugHelper.cs
Normal file
49
FModel/Methods/Utilities/DebugHelper.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FModel.Methods.Utilities
|
||||
{
|
||||
class DebugHelper
|
||||
{
|
||||
public static Logger Logger { get; private set; }
|
||||
|
||||
public static void Init(string logFilePath)
|
||||
{
|
||||
Logger = new Logger(logFilePath);
|
||||
}
|
||||
|
||||
public static void WriteLine(string message = "")
|
||||
{
|
||||
if (Logger != null)
|
||||
{
|
||||
Logger.WriteLine(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLine(string format, params object[] args)
|
||||
{
|
||||
WriteLine(string.Format(format, args));
|
||||
}
|
||||
|
||||
public static void WriteException(string exception, string message = "Exception")
|
||||
{
|
||||
if (Logger != null)
|
||||
{
|
||||
Logger.WriteException(exception, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteException(Exception exception, string message = "Exception")
|
||||
{
|
||||
WriteException(exception.ToString(), message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RestSharp;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FProp = FModel.Properties.Settings;
|
||||
|
||||
namespace FModel.Methods.Utilities
|
||||
@@ -10,6 +10,8 @@ namespace FModel.Methods.Utilities
|
||||
{
|
||||
public static string GetEndpoint(string url)
|
||||
{
|
||||
DebugHelper.WriteLine("Sending GET request to " + url);
|
||||
|
||||
RestClient EndpointClient = new RestClient(url);
|
||||
RestRequest EndpointRequest = new RestRequest(Method.GET);
|
||||
|
||||
@@ -32,27 +34,39 @@ namespace FModel.Methods.Utilities
|
||||
JArray FGMessages = FData["Global_Messages"].Value<JArray>();
|
||||
if (!string.IsNullOrEmpty(FGMessages[0]["Message"].Value<string>()))
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (JToken t in FGMessages)
|
||||
{
|
||||
new UpdateMyConsole(t["Message"].Value<string>(), t["Color"].Value<string>(), t["bNewLine"].Value<bool>()).Append();
|
||||
string text = t["Message"].Value<string>();
|
||||
bool nl = t["bNewLine"].Value<bool>();
|
||||
new UpdateMyConsole(text, t["Color"].Value<string>(), nl).Append();
|
||||
|
||||
if (nl)
|
||||
sb.AppendLine(text);
|
||||
else
|
||||
sb.Append(text);
|
||||
}
|
||||
DebugHelper.WriteLine("Dropbox: MOTD: " + sb.ToString().TrimEnd());
|
||||
}
|
||||
|
||||
//BACKUPS
|
||||
foreach (JProperty prop in FData["Backups"].Value<JObject>().Properties())
|
||||
{
|
||||
DebugHelper.WriteLine("Dropbox: " + prop.Name + " available to download");
|
||||
ListToReturn.Add(new BackupInfosEntry(prop.Name, prop.Value.Value<string>()));
|
||||
}
|
||||
return ListToReturn;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("Dropbox: Error while checking for backup files");
|
||||
new UpdateMyConsole("Error while checking for backup files", CColors.Red, true).Append();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("Dropbox: Your internet connection is currently unavailable, can't check for backup files at the moment.");
|
||||
new UpdateMyConsole("Your internet connection is currently unavailable, can't check for backup files at the moment.", CColors.Blue, true).Append();
|
||||
return null;
|
||||
}
|
||||
@@ -68,8 +82,15 @@ namespace FModel.Methods.Utilities
|
||||
if (string.IsNullOrEmpty(FProp.Default.FPak_MainAES))
|
||||
{
|
||||
JToken mainKeyToken = JObject.Parse(EndpointContent).SelectToken("mainKey");
|
||||
FProp.Default.FPak_MainAES = mainKeyToken != null ? $"{mainKeyToken.Value<string>().Substring(2).ToUpperInvariant()}" : "";
|
||||
FProp.Default.Save();
|
||||
if (mainKeyToken != null)
|
||||
{
|
||||
FProp.Default.FPak_MainAES = $"{mainKeyToken.Value<string>().Substring(2).ToUpperInvariant()}";
|
||||
FProp.Default.Save();
|
||||
|
||||
DebugHelper.WriteLine("BenBotAPI: Main AES key set to " + mainKeyToken.Value<string>());
|
||||
}
|
||||
else
|
||||
DebugHelper.WriteLine("BenBotAPI: Main AES key not found in endpoint response");
|
||||
}
|
||||
|
||||
JToken dynamicPaks = JObject.Parse(EndpointContent).SelectToken("additionalKeys");
|
||||
@@ -77,14 +98,16 @@ namespace FModel.Methods.Utilities
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("BenBotAPI: Down or Rate Limit Exceeded");
|
||||
new UpdateMyConsole("API Down or Rate Limit Exceeded", CColors.Blue, true).Append();
|
||||
return null;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("BenBotAPI: Your internet connection is currently unavailable, can't check for dynamic keys at the moment.");
|
||||
new UpdateMyConsole("Your internet connection is currently unavailable, can't check for dynamic keys at the moment.", CColors.Blue, true).Append();
|
||||
return null;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,11 @@ namespace FModel.Methods.Utilities
|
||||
{
|
||||
if (string.IsNullOrEmpty(FProp.Default.FOutput_Path))
|
||||
{
|
||||
FProp.Default.FOutput_Path = AppDomain.CurrentDomain.BaseDirectory + "Output";
|
||||
string path = AppDomain.CurrentDomain.BaseDirectory + "Output";
|
||||
FProp.Default.FOutput_Path = path;
|
||||
FProp.Default.Save();
|
||||
|
||||
DebugHelper.WriteLine("No output path, auto set to " + path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +75,7 @@ namespace FModel.Methods.Utilities
|
||||
/// </summary>
|
||||
private static void CreateDefaultSubFolders()
|
||||
{
|
||||
//THIS WILL STAY FOR INITIAL LAUNCH ONLY
|
||||
//3.0-
|
||||
if (File.Exists(FProp.Default.FOutput_Path + "\\AESManager.xml")) { File.Delete(FProp.Default.FOutput_Path + "\\AESManager.xml"); }
|
||||
if (Directory.Exists(FProp.Default.FOutput_Path + "\\Backup\\")) { Directory.Delete(FProp.Default.FOutput_Path + "\\Backup\\", true); }
|
||||
if (Directory.Exists(FProp.Default.FOutput_Path + "\\Extracted\\")) { Directory.Delete(FProp.Default.FOutput_Path + "\\Extracted\\", true); }
|
||||
@@ -81,8 +84,11 @@ namespace FModel.Methods.Utilities
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Backups\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Exports\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Icons\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Sounds\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\JSONs\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Sounds\\");
|
||||
Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Logs\\");
|
||||
|
||||
DebugHelper.WriteLine("Folders created if they didn't exist");
|
||||
}
|
||||
|
||||
public static string GetFullPathWithoutExtension(string path)
|
||||
@@ -100,12 +106,17 @@ namespace FModel.Methods.Utilities
|
||||
|
||||
public static void CheckWatermark()
|
||||
{
|
||||
bool bSave = false;
|
||||
|
||||
if (!string.IsNullOrEmpty(FProp.Default.FWatermarkFilePath) &&
|
||||
!File.Exists(FProp.Default.FWatermarkFilePath))
|
||||
{
|
||||
FProp.Default.FWatermarkFilePath = string.Empty;
|
||||
FProp.Default.FUseWatermark = false;
|
||||
bSave = true;
|
||||
|
||||
new UpdateMyConsole("Watermark file not found, watermarking disabled.", CColors.Blue, true).Append();
|
||||
DebugHelper.WriteLine("Watermark file for icons not found, option disabled");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(FProp.Default.FBannerFilePath) &&
|
||||
@@ -113,10 +124,14 @@ namespace FModel.Methods.Utilities
|
||||
{
|
||||
FProp.Default.FBannerFilePath = string.Empty;
|
||||
FProp.Default.FUseChallengeWatermark = false;
|
||||
bSave = true;
|
||||
|
||||
new UpdateMyConsole("Banner file not found, challenges custom theme disabled.", CColors.Blue, true).Append();
|
||||
DebugHelper.WriteLine("Watermark file for banners not found, option disabled");
|
||||
}
|
||||
|
||||
FProp.Default.Save();
|
||||
if (bSave)
|
||||
FProp.Default.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
223
FModel/Methods/Utilities/Logger.cs
Normal file
223
FModel/Methods/Utilities/Logger.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
using FModel.Methods.MessageBox;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace FModel.Methods.Utilities
|
||||
{
|
||||
class Logger
|
||||
{
|
||||
public delegate void MessageAddedEventHandler(string message);
|
||||
|
||||
public event MessageAddedEventHandler MessageAdded;
|
||||
|
||||
public string MessageFormat { get; set; } = "{0:yyyy-MM-dd HH:mm:ss.fff} - {1}";
|
||||
public bool AsyncWrite { get; set; } = true;
|
||||
public bool DebugWrite { get; set; } = Program.Build == Program.FModelBuild.Debug;
|
||||
public bool StringWrite { get; set; } = true;
|
||||
public bool FileWrite { get; set; } = false;
|
||||
public string LogFilePath { get; private set; }
|
||||
|
||||
private readonly object loggerLock = new object();
|
||||
private ConcurrentQueue<string> messageQueue = new ConcurrentQueue<string>();
|
||||
private StringBuilder sbMessages = new StringBuilder();
|
||||
|
||||
public Logger()
|
||||
{
|
||||
}
|
||||
|
||||
public Logger(string logFilePath)
|
||||
{
|
||||
FileWrite = true;
|
||||
LogFilePath = logFilePath;
|
||||
CreateDirectoryFromFilePath(LogFilePath);
|
||||
}
|
||||
|
||||
protected void OnMessageAdded(string message)
|
||||
{
|
||||
if (MessageAdded != null)
|
||||
{
|
||||
MessageAdded(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessMessageQueue()
|
||||
{
|
||||
lock (loggerLock)
|
||||
{
|
||||
while (messageQueue.TryDequeue(out string message))
|
||||
{
|
||||
if (DebugWrite)
|
||||
{
|
||||
Debug.Write(message);
|
||||
}
|
||||
|
||||
if (StringWrite && sbMessages != null)
|
||||
{
|
||||
sbMessages.Append(message);
|
||||
}
|
||||
|
||||
if (FileWrite && !string.IsNullOrEmpty(LogFilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(LogFilePath, message, Encoding.UTF8);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
OnMessageAdded(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(string message)
|
||||
{
|
||||
if (message != null)
|
||||
{
|
||||
message = string.Format(MessageFormat, DateTime.Now, message);
|
||||
messageQueue.Enqueue(message);
|
||||
|
||||
if (AsyncWrite)
|
||||
{
|
||||
Task.Run(() => ProcessMessageQueue());
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessMessageQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
Write(string.Format(format, args));
|
||||
}
|
||||
|
||||
public void WriteLine(string message)
|
||||
{
|
||||
Write(message + Environment.NewLine);
|
||||
}
|
||||
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
WriteLine(string.Format(format, args));
|
||||
}
|
||||
|
||||
public void WriteException(string exception, string message = "Exception")
|
||||
{
|
||||
WriteLine($"{message}:{Environment.NewLine}{exception}");
|
||||
}
|
||||
|
||||
public void WriteException(Exception exception, string message = "Exception")
|
||||
{
|
||||
WriteException(exception.ToString(), message);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (loggerLock)
|
||||
{
|
||||
if (sbMessages != null)
|
||||
{
|
||||
sbMessages.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
lock (loggerLock)
|
||||
{
|
||||
if (sbMessages != null && sbMessages.Length > 0)
|
||||
{
|
||||
return sbMessages.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateDirectoryFromFilePath(string filePath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
string directoryPath = Path.GetDirectoryName(filePath);
|
||||
CreateDirectoryFromDirectoryPath(directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateDirectoryFromDirectoryPath(string directoryPath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
DarkMessageBox.Show("Could not create directory.\r\n\r\n" + e, "FModel - Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetOperatingSystemProductName(bool includeBit = false)
|
||||
{
|
||||
string productName = null;
|
||||
|
||||
try
|
||||
{
|
||||
productName = GetRegistryValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", RegistryHive.LocalMachine);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(productName))
|
||||
{
|
||||
productName = Environment.OSVersion.VersionString;
|
||||
}
|
||||
|
||||
if (includeBit)
|
||||
{
|
||||
string bit;
|
||||
|
||||
if (Environment.Is64BitOperatingSystem)
|
||||
{
|
||||
bit = "64";
|
||||
}
|
||||
else
|
||||
{
|
||||
bit = "32";
|
||||
}
|
||||
|
||||
productName = $"{productName} ({bit}-bit)";
|
||||
}
|
||||
|
||||
return productName;
|
||||
}
|
||||
|
||||
public static string GetRegistryValue(string path, string name = null, RegistryHive root = RegistryHive.CurrentUser)
|
||||
{
|
||||
using (RegistryKey rk = RegistryKey.OpenBaseKey(root, RegistryView.Default).OpenSubKey(path))
|
||||
{
|
||||
if (rk != null)
|
||||
{
|
||||
return rk.GetValue(name, null) as string;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace FModel.Methods.Utilities
|
||||
if (ex != null)
|
||||
{
|
||||
Exception innerEx = ex.InnerException;
|
||||
DebugHelper.WriteException(innerEx, "thrown in TasksUtility.cs by TaskCompleted");
|
||||
|
||||
if (innerEx is ArgumentOutOfRangeException) //aes key is too short
|
||||
{
|
||||
new UpdateMyProcessEvents((innerEx as ArgumentOutOfRangeException).ParamName, "Error").Update();
|
||||
|
||||
@@ -213,6 +213,10 @@ namespace FModel.Methods.Utilities
|
||||
{
|
||||
if (args.IsUpdateAvailable)
|
||||
{
|
||||
DebugHelper.WriteLine("AutoUpdater: Update available");
|
||||
DebugHelper.WriteLine("AutoUpdater: Installed version: " + args.InstalledVersion);
|
||||
DebugHelper.WriteLine("AutoUpdater: Available version: " + args.CurrentVersion);
|
||||
|
||||
MessageBoxResult dialogResult;
|
||||
if (args.Mandatory)
|
||||
{
|
||||
@@ -236,6 +240,7 @@ namespace FModel.Methods.Utilities
|
||||
|
||||
if (dialogResult == MessageBoxResult.Yes)
|
||||
{
|
||||
DebugHelper.WriteLine("AutoUpdater: User is checking the changelog");
|
||||
Process.Start(args.ChangelogURL);
|
||||
}
|
||||
|
||||
@@ -244,22 +249,30 @@ namespace FModel.Methods.Utilities
|
||||
//ok if force update
|
||||
if (dialogResult == MessageBoxResult.Yes || dialogResult == MessageBoxResult.No || dialogResult == MessageBoxResult.OK)
|
||||
{
|
||||
DebugHelper.WriteLine("AutoUpdater: Updating");
|
||||
try
|
||||
{
|
||||
if (AutoUpdater.DownloadUpdate())
|
||||
{
|
||||
System.Windows.Application.Current.Shutdown();
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
DebugHelper.WriteException(exception);
|
||||
DarkMessageBox.ShowOK(exception.Message, exception.GetType().ToString(), "OK", MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
DebugHelper.WriteLine("AutoUpdater: Do not wanna update");
|
||||
}
|
||||
else
|
||||
DebugHelper.WriteLine("AutoUpdater: No update available");
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugHelper.WriteLine("AutoUpdater: There is a problem reaching update server please check your internet connection and try again later.");
|
||||
|
||||
DarkMessageBox.ShowOK(
|
||||
"There is a problem reaching update server please check your internet connection and try again later.",
|
||||
"Update check failed", "OK", MessageBoxImage.Error);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using FModel.Methods.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -8,9 +10,35 @@ namespace FModel
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static bool isClosing;
|
||||
public enum FModelBuild
|
||||
{
|
||||
Debug,
|
||||
Release,
|
||||
Unknown
|
||||
}
|
||||
public const FModelBuild Build =
|
||||
#if RELEASE
|
||||
FModelBuild.Release;
|
||||
#elif DEBUG
|
||||
FModelBuild.Debug;
|
||||
#else
|
||||
FModelBuild.Unknown;
|
||||
#endif
|
||||
internal static Stopwatch StartTimer { get; private set; }
|
||||
|
||||
|
||||
[STAThreadAttribute]
|
||||
public static void Main()
|
||||
{
|
||||
StartTimer = Stopwatch.StartNew();
|
||||
|
||||
DebugHelper.Init(LogsFilePath);
|
||||
DebugHelper.WriteLine("FModel starting.");
|
||||
DebugHelper.WriteLine("Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
DebugHelper.WriteLine("Build: " + Build);
|
||||
DebugHelper.WriteLine("OS: " + Logger.GetOperatingSystemProductName(true));
|
||||
|
||||
Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
|
||||
Assembly executingAssembly = Assembly.GetExecutingAssembly();
|
||||
IEnumerable<string> resources = executingAssembly.GetManifestResourceNames().Where(n => n.EndsWith(".dll"));
|
||||
@@ -29,7 +57,7 @@ namespace FModel
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.Print(string.Format("Failed to load: {0}, Exception: {1}", resource, ex.Message));
|
||||
DebugHelper.WriteLine(string.Format("Failed to load: {0}, Exception: {1}", resource, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +75,32 @@ namespace FModel
|
||||
return null;
|
||||
};
|
||||
App.Main();
|
||||
|
||||
CloseWithLogs();
|
||||
}
|
||||
|
||||
public static void CloseWithLogs()
|
||||
{
|
||||
if (!isClosing)
|
||||
{
|
||||
isClosing = true;
|
||||
|
||||
DebugHelper.Logger.AsyncWrite = false;
|
||||
DebugHelper.WriteLine("FModel closing.");
|
||||
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
DebugHelper.WriteLine("FModel closed.");
|
||||
}
|
||||
}
|
||||
|
||||
public static string LogsFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
string filename = string.Format("FModel-Log-{0:yyyy-MM-dd}.txt", DateTime.Now);
|
||||
return Path.Combine(Properties.Settings.Default.FOutput_Path + "\\Logs", filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user