Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xADDBx committed Jun 6, 2024
1 parent d17ab2b commit 1f86f18
Show file tree
Hide file tree
Showing 71 changed files with 262 additions and 501 deletions.
26 changes: 15 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,44 @@ csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined
dotnet_naming_rule.constants_rule.severity = suggestion
dotnet_naming_rule.constants_rule.style = upper_camel_case_style
dotnet_naming_rule.constants_rule.style = pascal_case
dotnet_naming_rule.constants_rule.symbols = constants_symbols
dotnet_naming_rule.interface_should_be_begins_with_i_rule.import_to_resharper = True
dotnet_naming_rule.interface_should_be_begins_with_i_rule.resharper_description = interface_should_be_begins_with_i
dotnet_naming_rule.interface_should_be_begins_with_i_rule.resharper_guid = 336fd165-eb04-40c2-ae13-5363789422ca
dotnet_naming_rule.interface_should_be_begins_with_i_rule.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i_rule.style = i_upper_camel_case_style
dotnet_naming_rule.interface_should_be_begins_with_i_rule.style = begins_with_i
dotnet_naming_rule.interface_should_be_begins_with_i_rule.symbols = interface_should_be_begins_with_i_symbols
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.import_to_resharper = True
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.resharper_description = non_field_members_should_be_pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.resharper_guid = bfe4a45b-02bb-4987-9b46-2c7a34bb09e8
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.resharper_style = AaBb, aaBb
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.style = upper_camel_case_style
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case_rule.symbols = non_field_members_should_be_pascal_case_symbols
dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined
dotnet_naming_rule.private_constants_rule.severity = suggestion
dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style
dotnet_naming_rule.private_constants_rule.style = pascal_case
dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols
dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined
dotnet_naming_rule.private_static_readonly_rule.resharper_style = AaBb, _ + aaBb
dotnet_naming_rule.private_static_readonly_rule.severity = suggestion
dotnet_naming_rule.private_static_readonly_rule.style = upper_camel_case_style
dotnet_naming_rule.private_static_readonly_rule.style = pascal_case
dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols
dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined
dotnet_naming_rule.public_fields_rule.resharper_style = AaBb, aaBb
dotnet_naming_rule.public_fields_rule.severity = suggestion
dotnet_naming_rule.public_fields_rule.style = upper_camel_case_style
dotnet_naming_rule.public_fields_rule.style = pascal_case
dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols
dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined
dotnet_naming_rule.static_readonly_rule.severity = suggestion
dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style
dotnet_naming_rule.static_readonly_rule.style = pascal_case
dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols
dotnet_naming_rule.types_should_be_pascal_case_rule.import_to_resharper = True
dotnet_naming_rule.types_should_be_pascal_case_rule.resharper_description = types_should_be_pascal_case
dotnet_naming_rule.types_should_be_pascal_case_rule.resharper_guid = 46acfd3a-c646-4b13-9908-9d4a8e3bc8ac
dotnet_naming_rule.types_should_be_pascal_case_rule.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case_rule.style = upper_camel_case_style
dotnet_naming_rule.types_should_be_pascal_case_rule.style = pascal_case
dotnet_naming_rule.types_should_be_pascal_case_rule.symbols = types_should_be_pascal_case_symbols
dotnet_naming_style.i_upper_camel_case_style.capitalization = pascal_case
dotnet_naming_style.i_upper_camel_case_style.required_prefix = I
Expand Down Expand Up @@ -228,11 +228,11 @@ resharper_show_autodetect_configure_formatting_tip = false
resharper_use_indent_from_vs = false
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_chained_binary_patterns = chop_if_long
csharp_new_line_before_else = true
csharp_new_line_before_else = false
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
csharp_new_line_before_catch = true
csharp_new_line_before_catch = false
csharp_new_line_before_open_brace = none

# Standard properties
Expand All @@ -251,8 +251,12 @@ resharper_redundant_base_qualifier_highlighting = warning
resharper_suggest_var_or_type_built_in_types_highlighting = hint
resharper_suggest_var_or_type_elsewhere_highlighting = none
resharper_suggest_var_or_type_simple_types_highlighting = none
csharp_style_prefer_primary_constructors = true:suggestion

[*.{appxmanifest,asax,ascx,aspx,axaml,axml,build,c,c++,cc,cginc,compute,config,cp,cpp,cs,cshtml,csproj,cu,cuh,cxx,dbml,discomap,dtd,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,htm,html,hxx,inc,inl,ino,ipp,ixx,jsproj,lsproj,master,mpp,mq4,mq5,mqh,njsproj,nuspec,paml,proj,props,razor,resw,resx,skin,StyleCop,targets,tasks,tpp,usf,ush,vb,vbproj,xaml,xamlx,xml,xoml,xsd}]
indent_style = space
indent_size = 4
tab_width = 4
tab_width = 4
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
15 changes: 5 additions & 10 deletions ModKit/DataViewer/ReflectionSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ private void Search(string[] searchTerms, List<Node> todo, int depth, int visitC
}
});
}
}
catch (Exception e) {
} catch (Exception e) {
Mod.Log(depth, $"caught - {e}");
}
node.Matches = foundMatch;
Expand All @@ -199,32 +198,28 @@ private void Search(string[] searchTerms, List<Node> todo, int depth, int visitC
foreach (var child in node.GetItemNodes())
//Main.Log(depth + 1, $"item: {child.Name}");
newTodo.Add(child);
}
catch (Exception e) {
} catch (Exception e) {
Mod.Log(depth, $"caught - {e}");
}
try {
foreach (var child in node.GetComponentNodes())
//Main.Log(depth + 1, $"comp: {child.Name}");
newTodo.Add(child);
}
catch (Exception e) {
} catch (Exception e) {
Mod.Log(depth, $"caught - {e}");
}
try {
foreach (var child in node.GetPropertyNodes())
//Main.Log(depth + 1, $"prop: {child.Name}");
newTodo.Add(child);
}
catch (Exception e) {
} catch (Exception e) {
Mod.Log(depth, $"caught - {e}");
}
try {
foreach (var child in node.GetFieldNodes())
//Main.Log(depth + 1, $"field: {child.Name}");
newTodo.Add(child);
}
catch (Exception e) {
} catch (Exception e) {
Mod.Log(depth, $"caught - {e}");
}
}
Expand Down
18 changes: 6 additions & 12 deletions ModKit/DataViewer/ReflectionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ protected override void UpdateValueImpl() {
if (TryGetParentValue(out var parentValue)) {
_isException = false;
Value = parentValue.GetFieldValue<TParentInst, TNode>(Name);
}
else {
} else {
_isException = true;
Value = default;
}
Expand All @@ -554,8 +553,7 @@ protected override void UpdateValueImpl() {
try {
_isException = false;
Value = parentValue.GetPropertyValue<TParentInst, TNode>(Name);
}
catch {
} catch {
_isException = true;
Value = default;
}
Expand All @@ -573,8 +571,7 @@ protected override void UpdateValueImpl() {
if (TryGetParentValue(out var parentValue)) {
_isException = false;
Value = parentValue.GetFieldValue<TUnderlying, TNode>(Name);
}
else {
} else {
_isException = true;
Value = default;
}
Expand All @@ -589,8 +586,7 @@ protected override void UpdateValueImpl() {
try {
_isException = false;
Value = parentValue.GetPropertyValue<TUnderlying, TNode>(Name);
}
catch {
} catch {
_isException = true;
Value = default;
}
Expand All @@ -608,8 +604,7 @@ protected override void UpdateValueImpl() {
if (TryGetParentValue(out var parentValue)) {
_isException = false;
Value = parentValue.GetFieldValue<TParentInst, TNode>(Name);
}
else {
} else {
_isException = true;
Value = default;
}
Expand All @@ -624,8 +619,7 @@ protected override void UpdateValueImpl() {
try {
_isException = false;
Value = parentValue.GetPropertyValue<TParentInst, TNode>(Name);
}
catch {
} catch {
_isException = true;
Value = default;
}
Expand Down
15 changes: 5 additions & 10 deletions ModKit/DataViewer/ReflectionTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static bool OnDetailGUI(object key, int indent = 50) {
}
reflectionTreeView.OnGUI(false);
return true;
}
else
} else
return false;
}

Expand Down Expand Up @@ -128,8 +127,7 @@ public void OnGUI(bool drawRoot = true, bool collapse = false) {
_startIndex++;
}
if (_startIndex > startIndexUBound) _startIndex = startIndexUBound;
}
else
} else
_startIndex = 0;
}
using (new GUILayout.VerticalScope()) {
Expand Down Expand Up @@ -246,8 +244,7 @@ public void OnGUI(bool drawRoot = true, bool collapse = false) {
if (node.Node.NodeType == NodeType.Root) {
if (node.matches.Count == 0) return false;
Label("Search Results".Cyan().Bold());
}
else
} else
DrawNodePrivate(node.Node, depth, ref toggleState);
if (node.ToggleState != toggleState) Mod.Log(node.ToString());
node.ToggleState = toggleState;
Expand Down Expand Up @@ -338,8 +335,7 @@ private void DrawNodePrivate(Node node, int depth, ref ToggleState expanded) {
text = node.InstType.Name.color(RGBA.yellow);
style = _buttonStyle;
Label(text, _buttonStyle, GUILayout.ExpandWidth(false));
}
else
} else
Label("", ExpandWidth(false));
}
}
Expand All @@ -359,8 +355,7 @@ private void DrawNode(Node node, int depth, bool collapse) {

// children
if (expanded.IsOn()) DrawChildren(node, depth + 1, collapse);
}
catch (Exception) { }
} catch (Exception) { }
}

private void DrawChildren(Node node, int depth, bool collapse, Func<Node, bool>? hoist = null) {
Expand Down
24 changes: 8 additions & 16 deletions ModKit/ModKit/LocalizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public static void Enable() {
IsDefault = _local == null;
}

}
catch (Exception ex) {
} catch (Exception ex) {
Mod.Error("Could not load localization files!");
Mod.Warn(ex.ToString());
}
Expand All @@ -71,8 +70,7 @@ public static void Update() {
FilePath = _localFolderPath + "en";
IsDefault = true;
_local = null;
}
else {
} else {
if (!(_local?.LanguageCode == locale)) {
FilePath = _localFolderPath + Mod.ModKitSettings.uiCultureCode;
_local = Import();
Expand Down Expand Up @@ -116,12 +114,10 @@ public static Language Import(Action<Exception> onError = null) {
lang.HomePage = "https://github.com/cabarius/ToyBox/";
Language.Serialize(lang, FilePath + _fileEnding);
}
}
catch (Exception e) {
} catch (Exception e) {
if (onError != null) {
onError(e);
}
else {
} else {
Mod.Error(e.ToString());
}
}
Expand Down Expand Up @@ -151,8 +147,7 @@ public static bool Export(Action<Exception> onError = null) {
}
if (File.Exists(FilePath + _fileEnding)) {
File.Delete(FilePath + _fileEnding);
}
else {
} else {
_LanguageCache.Add(Mod.ModKitSettings.uiCultureCode);
}
var toSerialize = Mod.ModKitSettings.uiCultureCode == "en" ? _localDefault : _local;
Expand All @@ -162,8 +157,7 @@ public static bool Export(Action<Exception> onError = null) {
foreach (var k in _localDefault.Strings.Keys) {
toSerialize.Strings.Add(k, "");
}
}
else {
} else {
var notToSerialize = Mod.ModKitSettings.uiCultureCode == "en" ? _local : _localDefault;
if (notToSerialize != null) {
foreach (var k in notToSerialize.Strings.Keys) {
Expand All @@ -179,12 +173,10 @@ public static bool Export(Action<Exception> onError = null) {
toSerialize.HomePage = "https://github.com/cabarius/ToyBox/";
Language.Serialize(toSerialize, FilePath + _fileEnding);
return true;
}
catch (Exception e) {
} catch (Exception e) {
if (onError != null) {
onError(e);
}
else {
} else {
Mod.Error(e.ToString());
}
}
Expand Down
3 changes: 1 addition & 2 deletions ModKit/ModKit/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ private void OnGUI(UnityModManager.ModEntry modEntry) {
page.OnGUI(modEntry);
hasPriorPage = true;
}
}
catch (Exception e) {
} catch (Exception e) {
Console.Write($"{e}");
caughtException = e;
}
Expand Down
12 changes: 4 additions & 8 deletions ModKit/ModKit/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void Enable(UnityModManager.ModEntry modEntry, Assembly assembly) {
try {
var patchProcessor = harmonyInstance.CreateClassProcessor(type);
patchProcessor.Patch();
}
catch (Exception e) {
} catch (Exception e) {
Error(e);
}
}
Expand All @@ -99,8 +98,7 @@ public void Enable(UnityModManager.ModEntry modEntry, Assembly assembly) {

process.Log("Raising events: OnEnable()");
for (var i = 0; i < _eventHandlers.Count; i++) _eventHandlers[i].HandleModEnable();
}
catch (Exception e) {
} catch (Exception e) {
Error(e);
Disable(modEntry, true);
throw;
Expand All @@ -123,8 +121,7 @@ public void Disable(UnityModManager.ModEntry modEntry, bool unpatch = false) {
for (var i = _eventHandlers.Count - 1; i >= 0; i--)
try {
_eventHandlers[i].HandleModDisable();
}
catch (Exception e) {
} catch (Exception e) {
Error(e);
}
_eventHandlers = null;
Expand All @@ -142,8 +139,7 @@ public void Disable(UnityModManager.ModEntry modEntry, bool unpatch = false) {
foreach (var patch in patches)
try {
harmonyInstance.Unpatch(method, patch.PatchMethod);
}
catch (Exception e) {
} catch (Exception e) {
Error(e);
}
}
Expand Down
9 changes: 3 additions & 6 deletions ModKit/ModKit/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static void SaveSettings<T>(this ModEntry modEntry, string fileName, T se
settings = JsonConvert.DeserializeObject<T>(text);
//Logger.Log($"read settings: {string.Join(Environment.NewLine, settings)}");
}
}
catch (Exception e) {
} catch (Exception e) {
Mod.Error($"{fileName} resource is not present or is malformed. exception: {e}");
}
if (File.Exists(userPath)) {
Expand All @@ -44,13 +43,11 @@ public static void SaveSettings<T>(this ModEntry modEntry, string fileName, T se
var userSettings = JsonConvert.DeserializeObject<T>(reader.ReadToEnd());
if (userSettings is IUpdatableSettings updatableSettings) updatableSettings?.AddMissingKeys((IUpdatableSettings)settings);
settings = userSettings;
}
catch {
} catch {
Mod.Error("Failed to load user settings. Settings will be rebuilt.");
try {
File.Copy(userPath, userConfigFolder + $"{Path.DirectorySeparatorChar}BROKEN_{fileName}", true);
}
catch {
} catch {
Mod.Error("Failed to archive broken settings.");
}
}
Expand Down
3 changes: 1 addition & 2 deletions ModKit/UI/Glyphs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static void CheckGlyphSupport() {
GUI.skin.font.HasCharacter(DefaultDisclosureEmpty[0]) &&
GUI.skin.font.HasCharacter(DefaultEdit[0])) {
Mod.ModKitSettings.UseDefaultGlyphs = true;
}
else {
} else {
Mod.ModKitSettings.UseDefaultGlyphs = false;
}
Mod.Log($"Glyph Support Check returned: {Mod.ModKitSettings.UseDefaultGlyphs}");
Expand Down
Loading

0 comments on commit 1f86f18

Please sign in to comment.