diff --git a/IPA.Injector/ConsoleWindow.cs b/IPA.Injector/ConsoleWindow.cs
index 1121d765..e854ed27 100644
--- a/IPA.Injector/ConsoleWindow.cs
+++ b/IPA.Injector/ConsoleWindow.cs
@@ -77,7 +77,7 @@ namespace Ipa.Injector.Windows
[DllImport("kernel32.dll",
EntryPoint = "CreateFileW",
SetLastError = true,
- CharSet = CharSet.Auto,
+ CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr CreateFileW(
string lpFileName,
diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs
index a63bb5da..8c66acdc 100644
--- a/IPA.Loader/Loader/PluginManager.cs
+++ b/IPA.Loader/Loader/PluginManager.cs
@@ -300,7 +300,7 @@ namespace IPA.Loader
internal class AppInfo
{
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false)]
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = false)]
private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
public static string StartupPath
diff --git a/IPA.Loader/Logging/Printers/GZFilePrinter.cs b/IPA.Loader/Logging/Printers/GZFilePrinter.cs
index cfe46747..7761f852 100644
--- a/IPA.Loader/Logging/Printers/GZFilePrinter.cs
+++ b/IPA.Loader/Logging/Printers/GZFilePrinter.cs
@@ -13,7 +13,7 @@ namespace IPA.Logging.Printers
///
/// A abstract class that provides the utilities to write to a GZip file.
///
- public abstract class GZFilePrinter : LogPrinter
+ public abstract class GZFilePrinter : LogPrinter, IDisposable
{
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CreateHardLink(
@@ -22,9 +22,6 @@ namespace IPA.Logging.Printers
IntPtr lpSecurityAttributes
);
- [DllImport("Kernel32.dll")]
- static extern int GetLastError();
-
private FileInfo fileInfo;
///
/// The that writes to the GZip file.
@@ -57,7 +54,8 @@ namespace IPA.Logging.Printers
{
if (!CreateHardLink(symlink.FullName, fileInfo.FullName, IntPtr.Zero))
{
- Logger.log.Error($"Hardlink creation failed {GetLastError()}");
+ var error = Marshal.GetLastWin32Error();
+ Logger.log.Error($"Hardlink creation failed ({error})");
}
}
catch (Exception e)
@@ -104,5 +102,34 @@ namespace IPA.Logging.Printers
zstream.Dispose();
fstream.Dispose();
}
+
+ ///
+ /// Disposes the file printer.
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Disposes the file printer.
+ ///
+ /// does nothing
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ fileWriter.Flush();
+ zstream.Flush();
+ fstream.Flush();
+ fileWriter.Close();
+ zstream.Close();
+ fstream.Close();
+ fileWriter.Dispose();
+ zstream.Dispose();
+ fstream.Dispose();
+ }
+ }
}
}
diff --git a/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
index 63525913..e5a7d00d 100644
--- a/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
+++ b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
@@ -51,7 +51,7 @@ namespace IPA.Logging.Printers
public override void Print(Logger.Level level, DateTime time, string logName, string message)
{
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
- fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper()));
+ fileWriter.WriteLine(string.Format("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper()));
}
}
}
diff --git a/IPA/Program.cs b/IPA/Program.cs
index a3e63b05..b6ae36a2 100644
--- a/IPA/Program.cs
+++ b/IPA/Program.cs
@@ -32,6 +32,7 @@ namespace IPA
public static ArgumentFlag ArgStart = new ArgumentFlag("--start", "-s") { DocString = "uses value as arguments to start the game after the patch/unpatch", ValueString = "ARGUMENTS" };
public static ArgumentFlag ArgLaunch = new ArgumentFlag("--launch", "-l") { DocString = "uses positional parameters as arguments to start the game after patch/unpatch" };
+ [STAThread]
static void Main(string[] args)
{
Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch).Process();