Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some warnings and errors #1894

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions UndertaleModCli/CommandOptions/DumpOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UndertaleModCli;

// ReSharper disable NotNullMemberIsNotInitialized - Properties are applied via reflection.
/// <summary>
/// Cli options for the Dump command
/// </summary>
Expand All @@ -16,7 +15,7 @@ public class DumpOptions
/// <summary>
/// Directory path to where to dump all contents
/// </summary>
public DirectoryInfo? Output { get; set; }
public DirectoryInfo Output { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
Expand All @@ -37,4 +36,4 @@ public class DumpOptions
/// Determines if embedded textures should get dumped
/// </summary>
public bool Textures { get; set; }
}
}
3 changes: 1 addition & 2 deletions UndertaleModCli/CommandOptions/InfoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UndertaleModCli;

// ReSharper disable NotNullMemberIsNotInitialized - Properties are applied via reflection.
/// <summary>
/// Cli options for the Info command
/// </summary>
Expand All @@ -17,4 +16,4 @@ public class InfoOptions
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
7 changes: 3 additions & 4 deletions UndertaleModCli/CommandOptions/LoadOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UndertaleModCli;

// ReSharper disable NotNullMemberIsNotInitialized - Properties are applied via reflection.
/// <summary>
/// Cli options for the Load command
/// </summary>
Expand All @@ -21,12 +20,12 @@ public class LoadOptions
/// <summary>
/// C# string that shall be executed
/// </summary>
public string? Line { get; set; }
public string Line { get; set; }

/// <summary>
/// File path to where to save the modified data file
/// </summary>
public FileInfo? Output { get; set; }
public FileInfo Output { get; set; }

/// <summary>
/// Determines if Cli should be run in interactive mode
Expand All @@ -37,4 +36,4 @@ public class LoadOptions
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
3 changes: 1 addition & 2 deletions UndertaleModCli/CommandOptions/NewOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UndertaleModCli;

// ReSharper disable NotNullMemberIsNotInitialized - Properties are applied via reflection.
/// <summary>
/// Cli options for the New command
/// </summary>
Expand All @@ -27,4 +26,4 @@ public class NewOptions
/// Determines if Cli should print out verbose logs
/// </summary>
public bool Verbose { get; set; } = false;
}
}
5 changes: 2 additions & 3 deletions UndertaleModCli/CommandOptions/ReplaceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UndertaleModCli;

// ReSharper disable NotNullMemberIsNotInitialized - Properties are applied via reflection.
/// <summary>
/// Cli options for the Replace command
/// </summary>
Expand All @@ -16,7 +15,7 @@ public class ReplaceOptions
/// <summary>
/// File path to where to save the modified data file
/// </summary>
public FileInfo? Output { get; set; }
public FileInfo Output { get; set; }

/// <summary>
/// Determines if Cli should print out verbose logs
Expand All @@ -32,4 +31,4 @@ public class ReplaceOptions
/// Equal separated values of embedded texture and the file to replace the embedded texture with.
/// </summary>
public string[] Textures { get; set; }
}
}
4 changes: 2 additions & 2 deletions UndertaleModCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ private void RunCSharpFile(string path)
/// Evaluates and executes given C# code.
/// </summary>
/// <param name="code">The C# string to execute</param>
/// <param name="scriptFile">The path to the script file where <see cref="code"/> was executed from.
/// Leave as null, if it wasn't executed from a script file</param>
/// <param name="scriptFile">The path to the script file where <paramref name="code"/> was loaded from.
/// Leave as null, if it wasn't executed from a script file.</param>
private void RunCSharpCode(string code, string scriptFile = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

isnt scriptfile supposed to be a nullable? or is that disabled for the cli project

{
if (Verbose)
Expand Down
4 changes: 2 additions & 2 deletions UndertaleModLib/Scripting/IScriptInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ bool AreFilesIdentical(string file1, string file2)
Task ClickableSearchOutput(string title, string query, int resultsCount, IDictionary<string, List<(int lineNum, string codeLine)>> resultsDict, bool showInDecompiledView, IEnumerable<string> failedList = null);

/// <summary>
/// Sets <see cref="isFinishedMessageEnabled"/>.
/// Sets whether or not the current script should show a message indicating that it completed.
/// </summary>
/// <param name="isFinishedMessageEnabled">The state to set it to.</param>
/// <param name="isFinishedMessageEnabled">True to enable the finished message; false otherwise.</param>
void SetFinishedMessage(bool isFinishedMessageEnabled);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModLibTests/Models/StringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void TestUnescapeText(string text, string expected)
[InlineData(null, null, false)]
[InlineData("hi", null, false)]
[InlineData(null, "null", false)]
public void TestSearchMatches(string text, string substring, bool expected)
public void TestSearchMatches(string? text, string? substring, bool expected)
{
UndertaleString utString = new UndertaleString(text);

Expand Down
14 changes: 14 additions & 0 deletions UndertaleModTests/GameScriptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ public string DummyString()
{
return "";
}

public Task ClickableSearchOutput(string title, string query, int resultsCount, IOrderedEnumerable<KeyValuePair<string, List<(int lineNum, string codeLine)>>> resultsDict, bool showInDecompiledView, IOrderedEnumerable<string> failedList = null)
{
throw new NotImplementedException();
}

public Task ClickableSearchOutput(string title, string query, int resultsCount, IDictionary<string, List<(int lineNum, string codeLine)>> resultsDict, bool showInDecompiledView, IEnumerable<string> failedList = null)
{
throw new NotImplementedException();
}

public void ChangeSelection(object newSelection, bool inNewTab = false)
{
}
Comment on lines +323 to +335
Copy link
Contributor

Choose a reason for hiding this comment

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

whats the use of these?

}

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public partial class EditGlyphRectangleWindow : Window, INotifyPropertyChanged
private short initShift;
private Canvas canvas;

#pragma warning disable CS0067 // Event is never used (this is actually used)
public event PropertyChangedEventHandler PropertyChanged;
#pragma warning restore CS0067

public EditGlyphRectangleWindow(UndertaleFont font, UndertaleFont.Glyph selectedGlyph)
{
Expand Down
4 changes: 4 additions & 0 deletions UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1416 // Validate platform compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of throwing this into every file, wonder if it makes more sense to put itinto the project.


using Microsoft.Win32;
using System;
using System.Buffers;
Expand Down Expand Up @@ -2710,3 +2712,5 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility
6 changes: 5 additions & 1 deletion UndertaleModTool/Editors/UndertaleShaderEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ICSharpCode.AvalonEdit;
#pragma warning disable CA1416 // Validate platform compatibility

using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -68,3 +70,5 @@ private void TextEditor_LostFocus(object sender, RoutedEventArgs e)
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility
6 changes: 5 additions & 1 deletion UndertaleModTool/Editors/UndertaleSoundEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable CA1416 // Validate platform compatibility

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -180,3 +182,5 @@ private void Stop_Click(object sender, RoutedEventArgs e)
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility
17 changes: 5 additions & 12 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.CodeAnalysis;
#pragma warning disable CA1416 // Validate platform compatibility

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Win32;
Expand Down Expand Up @@ -775,7 +777,6 @@ public async Task<SaveResult> SaveCodeChanges()
return SaveResult.Error;
}

#pragma warning disable CA1416
if (codeEditor.DecompiledChanged || codeEditor.DisassemblyChanged)
{
IsSaving = true;
Expand All @@ -786,7 +787,6 @@ public async Task<SaveResult> SaveCodeChanges()
result = IsSaving ? SaveResult.Error : SaveResult.Saved;
IsSaving = false;
}
#pragma warning restore CA1416

return result;
}
Expand Down Expand Up @@ -1074,10 +1074,8 @@ private async Task LoadFile(string filename, bool preventClose = false, bool onl
? "Tile sets"
: "Backgrounds & Tile sets";

#pragma warning disable CA1416
UndertaleCodeEditor.gettext = null;
UndertaleCodeEditor.gettextJSON = null;
#pragma warning restore CA1416
}

dialog.Hide();
Expand Down Expand Up @@ -1272,9 +1270,7 @@ private async Task SaveFile(string filename, bool suppressDebug = false)
Data.ToolInfo.CurrentMD5 = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant();
}

#pragma warning disable CA1416
UndertaleCodeEditor.gettextJSON = null;
#pragma warning restore CA1416

Dispatcher.Invoke(() =>
{
Expand Down Expand Up @@ -2477,7 +2473,6 @@ public void OpenCodeEntry(string name, int lineNum, UndertaleCodeEditor.CodeEdit
{
Focus();

#pragma warning disable CA1416
if (Selected == code)
{
var codeEditor = FindVisualChild<UndertaleCodeEditor>(DataEditor);
Expand Down Expand Up @@ -2512,7 +2507,6 @@ public void OpenCodeEntry(string name, int lineNum, UndertaleCodeEditor.CodeEdit
UndertaleCodeEditor.EditorTab = editorTab;
UndertaleCodeEditor.ChangeLineNumber(lineNum, editorTab);
}
#pragma warning restore CA1416

HighlightObject(code);
ChangeSelection(code, inNewTab);
Expand Down Expand Up @@ -2744,21 +2738,18 @@ public string PromptLoadFile(string defaultExt, string filter)
return dlg.ShowDialog() == true ? dlg.FileName : null;
}

#pragma warning disable CA1416
public string PromptChooseDirectory()
{
VistaFolderBrowserDialog folderBrowser = new VistaFolderBrowserDialog();
// vista dialog doesn't suffix the folder name with "/", so we're fixing it here.
return folderBrowser.ShowDialog() == true ? folderBrowser.SelectedPath + "/" : null;
}

#pragma warning disable CA1416
public void PlayInformationSound()
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
System.Media.SystemSounds.Asterisk.Play();
}
#pragma warning restore CA1416

public void ScriptMessage(string message)
{
Expand Down Expand Up @@ -4078,3 +4069,5 @@ public DescriptionView(string heading, string description)
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility
2 changes: 1 addition & 1 deletion UndertaleModTool/MessageBoxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static MessageBoxResult ShowQuestion(this Window window, string messageBo
/// <param name="messageBoxText">A <see cref="string"/> that specifies the text to display.</param>
/// <param name="icon">The <see cref="MessageBoxImage"/> to display.</param>
/// <param name="title">A <see cref="string"/> that specifies the title bar caption to display.</param>
/// <returns><see cref="MessageBoxResult.Yes"/>, <see cref="MessageBoxResult.No"/> or <see cref="MessageBoxResult.Cancel"/> depending on the users' answer.
/// <returns><see cref="MessageBoxResult.Yes"/>, <see cref="MessageBoxResult.No"/> or <see cref="MessageBoxResult.Cancel"/> depending on the users' answer.</returns>
public static MessageBoxResult ShowQuestionWithCancel(this Window window, string messageBoxText, MessageBoxImage icon = MessageBoxImage.Question, string title = "UndertaleModTool")
{
return ShowCore(window, messageBoxText, title, MessageBoxButton.YesNoCancel, icon);
Expand Down
8 changes: 6 additions & 2 deletions UndertaleModTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable CA1416 // Validate platform compatibility

using System;
using System.Collections.Generic;
using log4net;
using System.Diagnostics;
Expand All @@ -21,7 +23,7 @@ public static string GetExecutableDirectory()
}

// https://stackoverflow.com/questions/1025843/merging-dlls-into-a-single-exe-with-wpf
[STAThreadAttribute]
[STAThread]
public static void Main()
{
try
Expand Down Expand Up @@ -59,3 +61,5 @@ private static void GlobalThreadExceptionHandler(object sender, System.Threading
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility
3 changes: 2 additions & 1 deletion UndertaleModTool/ScriptingFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System.IO.Pipes;
using System.Threading.Tasks;

namespace UndertaleModTool
{
Expand All @@ -29,7 +30,7 @@ public bool RunUMTScript(string path)
ScriptError(path + " does not exist!");
return false;
}
RunScript(path);
RunScript(path).GetAwaiter().GetResult();
if (!ScriptExecutionSuccess)
ScriptError("An error of type \"" + ScriptErrorType + "\" occurred. The error is:\n\n" + ScriptErrorMessage, ScriptErrorType);
return ScriptExecutionSuccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ EnsureDataLoaded();

if (Data.IsVersionAtLeast(2, 3))
{
bool x = RunUMTScript(Path.Combine(ExePath, "Scripts", "Helper Scripts", "ConvertFrom17to16_for_2.3.csx"));
bool x = await RunUMTScript(Path.Combine(ExePath, "Scripts", "Helper Scripts", "ConvertFrom17to16_for_2.3.csx"));
if (x == false)
ScriptError("ConvertFrom17to16_for_2.3.csx failed!");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//Need to test this, once I do then I can obsolete the other two scripts
if (Data.IsVersionAtLeast(2, 3))
{
bool x = RunUMTScript(Path.Combine(ExePath, "Scripts", "Helper Scripts", "ConvertFrom17to16_for_2.3.csx"));
bool x = await RunUMTScript(Path.Combine(ExePath, "Scripts", "Helper Scripts", "ConvertFrom17to16_for_2.3.csx"));
if (x == false)
ScriptError("ConvertFrom17to16_for_2.3.csx failed!");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,6 @@ public static async Task<Dictionary<string, List<object>>> GetUnreferencedObject
{
UndertaleResourceReferenceMethodsMap.data = data;

var ver = (data.GeneralInfo.Major, data.GeneralInfo.Minor, data.GeneralInfo.Release);
colinator27 marked this conversation as resolved.
Show resolved Hide resolved

Dictionary<string, List<object>> outDict = new();

List<(IList, string)> assetLists = new();
Expand Down
6 changes: 5 additions & 1 deletion UndertaleModTool/Windows/TextInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable CA1416 // Validate platform compatibility

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
Expand Down Expand Up @@ -179,3 +181,5 @@ private void textCopyMenu_Opening(object sender, CancelEventArgs e)
}
}
}

#pragma warning restore CA1416 // Validate platform compatibility