Browse Source

Fixed some reccommended code structure stuff

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
4b556b9521
5 changed files with 36 additions and 8 deletions
  1. +1
    -1
      IPA.Injector/ConsoleWindow.cs
  2. +1
    -1
      IPA.Loader/Loader/PluginManager.cs
  3. +32
    -5
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  4. +1
    -1
      IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
  5. +1
    -0
      IPA/Program.cs

+ 1
- 1
IPA.Injector/ConsoleWindow.cs View File

@ -77,7 +77,7 @@ namespace Ipa.Injector.Windows
[DllImport("kernel32.dll", [DllImport("kernel32.dll",
EntryPoint = "CreateFileW", EntryPoint = "CreateFileW",
SetLastError = true, SetLastError = true,
CharSet = CharSet.Auto,
CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall)] CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr CreateFileW( private static extern IntPtr CreateFileW(
string lpFileName, string lpFileName,


+ 1
- 1
IPA.Loader/Loader/PluginManager.cs View File

@ -300,7 +300,7 @@ namespace IPA.Loader
internal class AppInfo 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 extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero); private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
public static string StartupPath public static string StartupPath


+ 32
- 5
IPA.Loader/Logging/Printers/GZFilePrinter.cs View File

@ -13,7 +13,7 @@ namespace IPA.Logging.Printers
/// <summary> /// <summary>
/// A <see cref="LogPrinter"/> abstract class that provides the utilities to write to a GZip file. /// A <see cref="LogPrinter"/> abstract class that provides the utilities to write to a GZip file.
/// </summary> /// </summary>
public abstract class GZFilePrinter : LogPrinter
public abstract class GZFilePrinter : LogPrinter, IDisposable
{ {
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CreateHardLink( static extern bool CreateHardLink(
@ -22,9 +22,6 @@ namespace IPA.Logging.Printers
IntPtr lpSecurityAttributes IntPtr lpSecurityAttributes
); );
[DllImport("Kernel32.dll")]
static extern int GetLastError();
private FileInfo fileInfo; private FileInfo fileInfo;
/// <summary> /// <summary>
/// The <see cref="StreamWriter"/> that writes to the GZip file. /// The <see cref="StreamWriter"/> that writes to the GZip file.
@ -57,7 +54,8 @@ namespace IPA.Logging.Printers
{ {
if (!CreateHardLink(symlink.FullName, fileInfo.FullName, IntPtr.Zero)) 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) catch (Exception e)
@ -104,5 +102,34 @@ namespace IPA.Logging.Printers
zstream.Dispose(); zstream.Dispose();
fstream.Dispose(); fstream.Dispose();
} }
/// <summary>
/// Disposes the file printer.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes the file printer.
/// </summary>
/// <param name="disposing">does nothing</param>
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();
}
}
} }
} }

+ 1
- 1
IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs View File

@ -51,7 +51,7 @@ namespace IPA.Logging.Printers
public override void Print(Logger.Level level, DateTime time, string logName, string message) 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)) 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()));
} }
} }
} }

+ 1
- 0
IPA/Program.cs View File

@ -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 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" }; 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) static void Main(string[] args)
{ {
Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch).Process(); Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch).Process();


Loading…
Cancel
Save