Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
- Interpolated strings
- Typo in "ModDirectoryCondition"
- Using Visual Studio "Run Code Cleanup"
  • Loading branch information
Aehrraid committed Dec 23, 2020
1 parent e47e5b3 commit 2feb581
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 103 deletions.
4 changes: 2 additions & 2 deletions DigglesModManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
<Compile Include="Model\ModConfig.cs" />
<Compile Include="Model\ModDirectory.cs" />
<Compile Include="Model\ModDirectoryType.cs" />
<Compile Include="Model\ModDirectroyCondition.cs" />
<Compile Include="Model\ModDirectroyConditionType.cs" />
<Compile Include="Model\ModDirectoryCondition.cs" />
<Compile Include="Model\ModDirectoryConditionType.cs" />
<Compile Include="Model\ModLinks.cs" />
<Compile Include="Model\ModTranslationString.cs" />
<Compile Include="Model\ModSettingsVariable.cs" />
Expand Down
55 changes: 28 additions & 27 deletions FormMain.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using DigglesModManager.Model;
using DigglesModManager.Properties;
using DigglesModManager.Service;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using DigglesModManager.Model;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DigglesModManager
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public FormMain()
if (correctDirectory)
{
ResetStatusNote();
ReadMods();
ReadMods();
}
else
{
Expand Down Expand Up @@ -108,7 +108,7 @@ private void setCheckOfLanguageInMenu(bool check)
menuItem.Checked = check;
if (check)
menuItem.CheckState = CheckState.Checked;
else
else
menuItem.CheckState = CheckState.Unchecked;

}
Expand All @@ -125,7 +125,7 @@ private void ReadMods()
_moddingService.ReadModsFromFiles(_activeMods, _progressBarManipulator);

//read mods
var modDirectories = (new DirectoryInfo(Paths.ModPath + "\\" + Paths.ModDirectoryName)).GetDirectories();
var modDirectories = (new DirectoryInfo($"{Paths.ModPath}\\{Paths.ModDirectoryName}")).GetDirectories();
foreach (var modInfo in modDirectories)
{
if (!_activeMods.Exists(mod => mod.ModDirectoryName.Equals(modInfo.Name)))
Expand Down Expand Up @@ -163,7 +163,7 @@ private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (!this.moddingServiceRunning)
if (!moddingServiceRunning)
{
//find settings file
int selectedIndex = installedModsListBox.SelectedIndex;
Expand Down Expand Up @@ -255,34 +255,35 @@ private void setUIToModdingState(bool moddingState)

var buttonsEnabled = !moddingState;
// Refresh Button
this.refreshButton.Enabled = buttonsEnabled;
refreshButton.Enabled = buttonsEnabled;
// Arrow Buttons
this.installModButton.Enabled = buttonsEnabled;
this.uninstallModButton.Enabled = buttonsEnabled;
this.moveUpButton.Enabled = buttonsEnabled;
this.moveDownButton.Enabled = buttonsEnabled;
installModButton.Enabled = buttonsEnabled;
uninstallModButton.Enabled = buttonsEnabled;
moveUpButton.Enabled = buttonsEnabled;
moveDownButton.Enabled = buttonsEnabled;
// Mod Settings Buttons
this.moddingServiceRunning = moddingState;
moddingServiceRunning = moddingState;
if (buttonsEnabled)
{
this.listBox2_SelectedIndexChanged(null, null);
listBox2_SelectedIndexChanged(null, null);
}
else
{
this.modSettingsButton.Enabled = false;
this.modSettingsMenuButton.Enabled = false;
modSettingsButton.Enabled = false;
modSettingsMenuButton.Enabled = false;
}
// Lets Mod Buttons
this.letsModButton.Enabled = buttonsEnabled;
this.letsModMenuButton.Enabled = buttonsEnabled;
letsModButton.Enabled = buttonsEnabled;
letsModMenuButton.Enabled = buttonsEnabled;
}

private void button_mod_Click(object sender, EventArgs e)
{
// set user interface into the modding state (disable buttons etc)
this.setUIToModdingState(true);
setUIToModdingState(true);
// Modding in second task to avoid UI freeze
Task.Factory.StartNew(() => {
Task.Factory.StartNew(() =>
{
SetMessage(Resources.PleaseWait, Color.Black);
//get file count of all active mods
var fileCount = 0;
Expand Down Expand Up @@ -318,7 +319,7 @@ private void button_mod_Click(object sender, EventArgs e)
{
SetMessage(Resources.Error, Color.Red);
Helpers.ShowMessage(Resources.ModdingService_ErrorMessage, Resources.Error);
}
}
else if (warning)
{
SetMessage(Resources.Warning, Color.Orange);
Expand All @@ -329,7 +330,7 @@ private void button_mod_Click(object sender, EventArgs e)
SetMessage(Resources.ModdingSuccessful, Color.Green);
}
// set user interface into normal state (enable buttons etc)
this.setUIToModdingState(false);
setUIToModdingState(false);
});
}

Expand All @@ -353,7 +354,7 @@ private void modSettingsMenuButton_Click(object sender, EventArgs e)
{
button_mod_settings_Click(sender, e);
}

private void changeLanguage(string language)
{
setCheckOfLanguageInMenu(false);
Expand Down
12 changes: 6 additions & 6 deletions FormModSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using DigglesModManager.Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DigglesModManager.Model;

namespace DigglesModManager
{
Expand All @@ -20,9 +20,9 @@ public FormModSettings(Mod mod, string language)
InitializeComponent(Math.Max(173, mod.Config.SettingsVariables.Count * 23 + 12));
FormBorderStyle = FormBorderStyle.FixedSingle;

Name = _mod.ToString() + " - Settings";
Name = $"{_mod} - Settings";
Text = Name;

var i = 0;
if (_mod.Config != null)
{
Expand All @@ -43,9 +43,9 @@ private void BuildVariableRow(int i, ModSettingsVariable variable, string langua
{
AutoSize = true,
Location = new Point(12, height),
Name = variable.ID + "_label",
Name = $"{variable.ID}_label",
TabIndex = i + 3,
Text = variable.Name(language) + @":"
Text = $"{variable.Name(language)}:"
};
Controls.Add(label);

Expand Down
4 changes: 2 additions & 2 deletions Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using DigglesModManager.Properties;
using System.Diagnostics;
using System.Windows.Forms;
using DigglesModManager.Properties;

namespace DigglesModManager
{
Expand Down
10 changes: 5 additions & 5 deletions Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class Log

private static void LogToErrorFile(string text)
{
var writer = new StreamWriter(Paths.ExePath + "\\" + Paths.ErrorLogFileName, true, Encoding.Default);
writer.WriteLine(DateTime.Now + " - " + text);
var writer = new StreamWriter($"{Paths.ExePath}\\{Paths.ErrorLogFileName}", true, Encoding.Default);
writer.WriteLine($"{DateTime.Now} - {text}");
writer.Flush();
writer.Close();
}

private static void LogToErrorFile(string type, string message, FileInfo fileInfo, int line)
{
LogToErrorFile(type + " in \"" + fileInfo.FullName + "\" at line " + line + ": " + message);
LogToErrorFile($"{type} in \"{fileInfo.FullName}\" at line {line}: {message}");
}

public static void Error(string message)
{
LogToErrorFile(ERROR + " " + message);
LogToErrorFile($"{ERROR} {message}");
}

public static void Error(string message, FileInfo fileInfo, int line)
Expand All @@ -34,7 +34,7 @@ public static void Error(string message, FileInfo fileInfo, int line)

public static void Warning(string message)
{
LogToErrorFile(WARNING + " " + message);
LogToErrorFile($"{WARNING} {message}");
}

public static void Warning(string message, FileInfo fileInfo, int line)
Expand Down
10 changes: 5 additions & 5 deletions Mod.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using DigglesModManager.Model;
using DigglesModManager.Properties;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using DigglesModManager.Properties;

namespace DigglesModManager
{
Expand All @@ -16,7 +16,7 @@ public class Mod : IToolTipDisplayer, IComparable
public DirectoryInfo ModDirectoryInfo { get; private set; }

public ModConfig Config { get; private set; }

public string ToolTipText { get; private set; }
public string Author { get; private set; }

Expand All @@ -31,7 +31,7 @@ public Mod(string modDirectory, Dictionary<string, object> oldSettings)
{
ModDirectoryName = modDirectory;
// the last backslash is important for path cutting!
ModDirectoryInfo = new DirectoryInfo(Paths.ModPath + "\\" + Paths.ModDirectoryName + "\\" + ModDirectoryName + "\\");
ModDirectoryInfo = new DirectoryInfo($"{Paths.ModPath}\\{Paths.ModDirectoryName}\\{ModDirectoryName}\\");
FileCount = ModDirectoryInfo.GetFiles("*", SearchOption.AllDirectories).Length;

//get description
Expand Down Expand Up @@ -122,11 +122,11 @@ public string GetToolTipText()
}
if (!Author.Equals(""))
{
toolTip += " Author: " + Author;
toolTip += $" Author: {Author}";
}
else if (!string.IsNullOrEmpty(Config.Author))
{
toolTip += " Author: " + Config.Author;
toolTip += $" Author: {Config.Author}";
}

return toolTip;
Expand Down
4 changes: 2 additions & 2 deletions Model/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace DigglesModManager.Model
{
Expand Down
2 changes: 1 addition & 1 deletion Model/ModDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string Path
/// </summary>
[DefaultValue(null)]
[JsonProperty(PropertyName = "condition", Required = Required.Default, DefaultValueHandling = DefaultValueHandling.Populate)]
public ModDirectroyCondition Condition { get; set; }
public ModDirectoryCondition Condition { get; set; }

}
}
24 changes: 12 additions & 12 deletions Model/ModDirectroyCondition.cs → Model/ModDirectoryCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace DigglesModManager.Model
{
public class ModDirectroyCondition
public class ModDirectoryCondition
{
/// <summary>
/// The type of the directory condition. [REQUIRED]
/// </summary>
[JsonProperty(PropertyName = "type", Required = Required.Always)]
public ModDirectroyConditionType Type { get; set; }
public ModDirectoryConditionType Type { get; set; }

/// <summary>
/// ID of the variable or mod that has to be checked. [REQUIRED]
Expand All @@ -27,37 +27,37 @@ public class ModDirectroyCondition
[JsonProperty(PropertyName = "value", Required = Required.Default, DefaultValueHandling = DefaultValueHandling.Populate)]
public object Value { get; set; }

public bool isTrue(Mod mod, List<Mod> activeMods)
public bool IsTrue(Mod mod, List<Mod> activeMods)
{
switch (Type)
{
case ModDirectroyConditionType.Mod:
case ModDirectoryConditionType.Mod:
foreach (var activeMod in activeMods)
{
if (activeMod.ModDirectoryName.Equals(this.Id))
if (activeMod.ModDirectoryName.Equals(Id))
{
return true;
}
}
//no warning, because the existence of a mod is checked.
break;
case ModDirectroyConditionType.Variable:
if (this.Value == null)
case ModDirectoryConditionType.Variable:
if (Value == null)
{
Log.Warning(mod.ModDirectoryName + ": Variable with ID \"" + this.Id + "\" needs a value.");
Log.Warning($"{mod.ModDirectoryName}: Variable with ID \"{Id}\" needs a value.");
break;
}
foreach (var modVariable in mod.Config.SettingsVariables)
{
if (modVariable.ID.Equals(this.Id))
if (modVariable.ID.Equals(Id))
{
return modVariable.Value.Equals(this.Value);
return modVariable.Value.Equals(Value);
}
}
Log.Warning(mod.ModDirectoryName + ": Variable with ID \"" + this.Id + "\" not found");
Log.Warning($"{mod.ModDirectoryName}: Variable with ID \"{Id}\" not found");
break;
default:
Log.Warning(mod.ModDirectoryName + ": Unhandled ModDirectroyConditionType \"" + Type + "\"");
Log.Warning($"{mod.ModDirectoryName}: Unhandled ModDirectroyConditionType \"{Type}\"");
break;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DigglesModManager.Model
{
public enum ModDirectroyConditionType
public enum ModDirectoryConditionType
{
Mod, Variable
}
Expand Down
4 changes: 2 additions & 2 deletions Model/ModSettingsVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ModSettingsVariable
/// <summary>
/// The human readanle name of the variable. [REQUIRED]
/// </summary>
[JsonProperty(PropertyName="name", Required = Required.Always)]
[JsonProperty(PropertyName = "name", Required = Required.Always)]
private ModTranslationString NameTranslation { get; set; }

public string Name(string language)
Expand All @@ -41,7 +41,7 @@ public string Description(string language)
/// <summary>
/// The data-type of the variable. Can be bool, int.. [REQUIRED]
/// </summary>
[JsonConverter(typeof(StringEnumConverter)), JsonProperty(PropertyName="type", Required = Required.Always)]
[JsonConverter(typeof(StringEnumConverter)), JsonProperty(PropertyName = "type", Required = Required.Always)]
public ModVariableType Type { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Paths
public static string ModPath = ExePath; //dyn: ExePath | local: @"D:\Projekte\DigglesMods\DigglesModManager"
public static string ModDirectoryName = "Mods";
public static string[] DigglesExecutableNames = { "Diggles.exe", "Wiggles.exe" };
public static string DataPath = ExePath + "\\Data";
public static string DataPath = $"{ExePath}\\Data";

//.dm
public static string RestoreFileName = "restore.dm";
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Main()
{
Helpers.ShowErrorMessage(Resources.FormMain_CouldNotFindFile.Replace("FILENAME", e.FileName));
}

}
}
}
Loading

2 comments on commit 2feb581

@Aehrraid
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cech12 Hab mal ein bisschen durchgefegt :)

@cech12
Copy link
Member

@cech12 cech12 commented on 2feb581 Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meine schönen "this"-Verweise xD
Review aber bestanden :D

Please sign in to comment.