chore: convert Dalamud to file-scoped namespaces

This commit is contained in:
goat 2022-10-29 15:23:22 +02:00
parent b093323acc
commit 987ff8dc8f
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
368 changed files with 55081 additions and 55450 deletions

View file

@ -6,68 +6,67 @@ using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using Newtonsoft.Json;
namespace Dalamud.Support
namespace Dalamud.Support;
/// <summary>
/// Class responsible for sending feedback.
/// </summary>
internal static class BugBait
{
private const string BugBaitUrl = "https://kiko.goats.dev/feedback";
/// <summary>
/// Class responsible for sending feedback.
/// Send feedback to Discord.
/// </summary>
internal static class BugBait
/// <param name="plugin">The plugin to send feedback about.</param>
/// <param name="isTesting">Whether or not the plugin is a testing plugin.</param>
/// <param name="content">The content of the feedback.</param>
/// <param name="reporter">The reporter name.</param>
/// <param name="includeException">Whether or not the most recent exception to occur should be included in the report.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(PluginManifest plugin, bool isTesting, string content, string reporter, bool includeException)
{
private const string BugBaitUrl = "https://kiko.goats.dev/feedback";
if (content.IsNullOrWhitespace())
return;
/// <summary>
/// Send feedback to Discord.
/// </summary>
/// <param name="plugin">The plugin to send feedback about.</param>
/// <param name="isTesting">Whether or not the plugin is a testing plugin.</param>
/// <param name="content">The content of the feedback.</param>
/// <param name="reporter">The reporter name.</param>
/// <param name="includeException">Whether or not the most recent exception to occur should be included in the report.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(PluginManifest plugin, bool isTesting, string content, string reporter, bool includeException)
var model = new FeedbackModel
{
if (content.IsNullOrWhitespace())
return;
Content = content,
Reporter = reporter,
Name = plugin.InternalName,
Version = isTesting ? plugin.TestingAssemblyVersion?.ToString() : plugin.AssemblyVersion.ToString(),
DalamudHash = Util.GetGitHash(),
};
var model = new FeedbackModel
{
Content = content,
Reporter = reporter,
Name = plugin.InternalName,
Version = isTesting ? plugin.TestingAssemblyVersion?.ToString() : plugin.AssemblyVersion.ToString(),
DalamudHash = Util.GetGitHash(),
};
if (includeException)
{
model.Exception = Troubleshooting.LastException == null ? "Was included, but none happened" : Troubleshooting.LastException?.ToString();
}
var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await Util.HttpClient.PostAsync(BugBaitUrl, postContent);
response.EnsureSuccessStatusCode();
if (includeException)
{
model.Exception = Troubleshooting.LastException == null ? "Was included, but none happened" : Troubleshooting.LastException?.ToString();
}
private class FeedbackModel
{
[JsonProperty("content")]
public string? Content { get; set; }
var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await Util.HttpClient.PostAsync(BugBaitUrl, postContent);
[JsonProperty("name")]
public string? Name { get; set; }
response.EnsureSuccessStatusCode();
}
[JsonProperty("dhash")]
public string? DalamudHash { get; set; }
private class FeedbackModel
{
[JsonProperty("content")]
public string? Content { get; set; }
[JsonProperty("version")]
public string? Version { get; set; }
[JsonProperty("name")]
public string? Name { get; set; }
[JsonProperty("reporter")]
public string? Reporter { get; set; }
[JsonProperty("dhash")]
public string? DalamudHash { get; set; }
[JsonProperty("exception")]
public string? Exception { get; set; }
}
[JsonProperty("version")]
public string? Version { get; set; }
[JsonProperty("reporter")]
public string? Reporter { get; set; }
[JsonProperty("exception")]
public string? Exception { get; set; }
}
}

View file

@ -12,119 +12,118 @@ using Dalamud.Utility;
using Newtonsoft.Json;
using Serilog;
namespace Dalamud.Support
namespace Dalamud.Support;
/// <summary>
/// Class responsible for printing troubleshooting information to the log.
/// </summary>
public static class Troubleshooting
{
/// <summary>
/// Class responsible for printing troubleshooting information to the log.
/// Gets the most recent exception to occur.
/// </summary>
public static class Troubleshooting
public static Exception? LastException { get; private set; }
/// <summary>
/// Log the last exception in a parseable format to serilog.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
{
/// <summary>
/// Gets the most recent exception to occur.
/// </summary>
public static Exception? LastException { get; private set; }
LastException = exception;
/// <summary>
/// Log the last exception in a parseable format to serilog.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
var fixedContext = context?.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
try
{
LastException = exception;
var fixedContext = context?.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
try
var payload = new ExceptionPayload
{
var payload = new ExceptionPayload
{
Context = fixedContext,
When = DateTime.Now,
Info = exception.ToString(),
};
Context = fixedContext,
When = DateTime.Now,
Info = exception.ToString(),
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"LASTEXCEPTION:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print exception.");
}
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"LASTEXCEPTION:{encodedPayload}");
}
/// <summary>
/// Log troubleshooting information in a parseable format to Serilog.
/// </summary>
internal static void LogTroubleshooting()
catch (Exception ex)
{
var startInfo = Service<DalamudStartInfo>.Get();
var configuration = Service<DalamudConfiguration>.Get();
var interfaceManager = Service<InterfaceManager>.GetNullable();
var pluginManager = Service<PluginManager>.GetNullable();
try
{
var payload = new TroubleshootingPayload
{
LoadedPlugins = pluginManager?.InstalledPlugins?.Select(x => x.Manifest)?.OrderByDescending(x => x.InternalName).ToArray(),
DalamudVersion = Util.AssemblyVersion,
DalamudGitHash = Util.GetGitHash(),
GameVersion = startInfo.GameVersion.ToString(),
Language = startInfo.Language.ToString(),
BetaKey = configuration.DalamudBetaKey,
DoPluginTest = configuration.DoPluginTest,
LoadAllApiLevels = pluginManager?.LoadAllApiLevels == true,
InterfaceLoaded = interfaceManager?.IsReady ?? false,
HasThirdRepo = configuration.ThirdRepoList is { Count: > 0 },
ForcedMinHook = EnvironmentConfiguration.DalamudForceMinHook,
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"TROUBLESHOOTING:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print troubleshooting.");
}
}
private class ExceptionPayload
{
public DateTime When { get; set; }
public string Info { get; set; }
public string? Context { get; set; }
}
private class TroubleshootingPayload
{
public LocalPluginManifest[] LoadedPlugins { get; set; }
public string DalamudVersion { get; set; }
public string DalamudGitHash { get; set; }
public string GameVersion { get; set; }
public string Language { get; set; }
public bool DoDalamudTest => false;
public string? BetaKey { get; set; }
public bool DoPluginTest { get; set; }
public bool LoadAllApiLevels { get; set; }
public bool InterfaceLoaded { get; set; }
public bool ForcedMinHook { get; set; }
public List<ThirdPartyRepoSettings> ThirdRepo => new();
public bool HasThirdRepo { get; set; }
Log.Error(ex, "Could not print exception.");
}
}
/// <summary>
/// Log troubleshooting information in a parseable format to Serilog.
/// </summary>
internal static void LogTroubleshooting()
{
var startInfo = Service<DalamudStartInfo>.Get();
var configuration = Service<DalamudConfiguration>.Get();
var interfaceManager = Service<InterfaceManager>.GetNullable();
var pluginManager = Service<PluginManager>.GetNullable();
try
{
var payload = new TroubleshootingPayload
{
LoadedPlugins = pluginManager?.InstalledPlugins?.Select(x => x.Manifest)?.OrderByDescending(x => x.InternalName).ToArray(),
DalamudVersion = Util.AssemblyVersion,
DalamudGitHash = Util.GetGitHash(),
GameVersion = startInfo.GameVersion.ToString(),
Language = startInfo.Language.ToString(),
BetaKey = configuration.DalamudBetaKey,
DoPluginTest = configuration.DoPluginTest,
LoadAllApiLevels = pluginManager?.LoadAllApiLevels == true,
InterfaceLoaded = interfaceManager?.IsReady ?? false,
HasThirdRepo = configuration.ThirdRepoList is { Count: > 0 },
ForcedMinHook = EnvironmentConfiguration.DalamudForceMinHook,
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"TROUBLESHOOTING:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print troubleshooting.");
}
}
private class ExceptionPayload
{
public DateTime When { get; set; }
public string Info { get; set; }
public string? Context { get; set; }
}
private class TroubleshootingPayload
{
public LocalPluginManifest[] LoadedPlugins { get; set; }
public string DalamudVersion { get; set; }
public string DalamudGitHash { get; set; }
public string GameVersion { get; set; }
public string Language { get; set; }
public bool DoDalamudTest => false;
public string? BetaKey { get; set; }
public bool DoPluginTest { get; set; }
public bool LoadAllApiLevels { get; set; }
public bool InterfaceLoaded { get; set; }
public bool ForcedMinHook { get; set; }
public List<ThirdPartyRepoSettings> ThirdRepo => new();
public bool HasThirdRepo { get; set; }
}
}