fix regression issue with wine drive name mangling
This commit is contained in:
parent
c376266090
commit
5bc1ad5926
@ -1009,7 +1009,16 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPath = GenerateLogPath(basegame.Value, basepath.Value, EventParser.Configuration.GameDirectory, game, logfile.Value);
|
var logInfo = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BaseGameDirectory = basegame.Value,
|
||||||
|
BasePathDirectory = basepath.Value,
|
||||||
|
GameDirectory = EventParser.Configuration.GameDirectory ?? "",
|
||||||
|
ModDirectory = game ?? "",
|
||||||
|
LogFile = logfile.Value,
|
||||||
|
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||||
|
};
|
||||||
|
LogPath = GenerateLogPath(logInfo);
|
||||||
|
|
||||||
if (!File.Exists(LogPath) && ServerConfig.GameLogServerUrl == null)
|
if (!File.Exists(LogPath) && ServerConfig.GameLogServerUrl == null)
|
||||||
{
|
{
|
||||||
@ -1027,37 +1036,37 @@ namespace IW4MAdmin
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateLogPath(string baseGameDirectory, string basePathDirectory, string gameDirectory, string modDirectory, string logFile)
|
public static string GenerateLogPath(LogPathGeneratorInfo logInfo)
|
||||||
{
|
{
|
||||||
string logPath;
|
string logPath;
|
||||||
string workingDirectory = basePathDirectory;
|
string workingDirectory = logInfo.BasePathDirectory;
|
||||||
|
|
||||||
bool baseGameIsDirectory = !string.IsNullOrWhiteSpace(baseGameDirectory) &&
|
bool baseGameIsDirectory = !string.IsNullOrWhiteSpace(logInfo.BaseGameDirectory) &&
|
||||||
baseGameDirectory.IndexOfAny(Utilities.DirectorySeparatorChars) != -1;
|
logInfo.BaseGameDirectory.IndexOfAny(Utilities.DirectorySeparatorChars) != -1;
|
||||||
|
|
||||||
bool baseGameIsRelative = baseGameDirectory.FixDirectoryCharacters()
|
bool baseGameIsRelative = logInfo.BaseGameDirectory.FixDirectoryCharacters()
|
||||||
.Equals(gameDirectory?.FixDirectoryCharacters() ?? "", StringComparison.InvariantCultureIgnoreCase);
|
.Equals(logInfo.GameDirectory.FixDirectoryCharacters(), StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
|
||||||
// we want to see if base game is provided and it 'looks' like a directory
|
// we want to see if base game is provided and it 'looks' like a directory
|
||||||
if (baseGameIsDirectory && !baseGameIsRelative)
|
if (baseGameIsDirectory && !baseGameIsRelative)
|
||||||
{
|
{
|
||||||
workingDirectory = baseGameDirectory;
|
workingDirectory = logInfo.BaseGameDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(modDirectory))
|
if (string.IsNullOrWhiteSpace(logInfo.ModDirectory))
|
||||||
{
|
{
|
||||||
logPath = Path.Combine(workingDirectory, gameDirectory ?? "", logFile);
|
logPath = Path.Combine(workingDirectory, logInfo.GameDirectory, logInfo.LogFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logPath = Path.Combine(workingDirectory, modDirectory, logFile);
|
logPath = Path.Combine(workingDirectory, logInfo.ModDirectory, logInfo.LogFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix wine drive name mangling
|
// fix wine drive name mangling
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (!logInfo.IsWindows)
|
||||||
{
|
{
|
||||||
logPath = Regex.Replace($"{Path.DirectorySeparatorChar}{logPath}", @"[A-Z]:/", "");
|
logPath = $"{Path.DirectorySeparatorChar}{Regex.Replace(logPath, @"[A-Z]:(\/|\\)", "")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return logPath.FixDirectoryCharacters();
|
return logPath.FixDirectoryCharacters();
|
||||||
|
45
Application/Misc/LogPathGeneratorInfo.cs
Normal file
45
Application/Misc/LogPathGeneratorInfo.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace IW4MAdmin.Application.Misc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// dto class for handling log path generation
|
||||||
|
/// </summary>
|
||||||
|
public class LogPathGeneratorInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// directory under the paths where data comes from by default
|
||||||
|
/// <remarks>fs_basegame</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public string BaseGameDirectory { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// base game root path
|
||||||
|
/// <remarks>fs_basepath</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public string BasePathDirectory { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// overide game directory
|
||||||
|
/// <remarks>plugin driven</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public string GameDirectory { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// game director
|
||||||
|
/// <remarks>fs_game</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public string ModDirectory { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// log file name
|
||||||
|
/// <remarks>g_log</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public string LogFile { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// indicates if running on windows
|
||||||
|
/// </summary>
|
||||||
|
public bool IsWindows { get; set; } = true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using IW4MAdmin;
|
using IW4MAdmin;
|
||||||
|
using IW4MAdmin.Application.Misc;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace ApplicationTests
|
namespace ApplicationTests
|
||||||
@ -10,7 +11,13 @@ namespace ApplicationTests
|
|||||||
public void Test_GenerateLogPath_Basic()
|
public void Test_GenerateLogPath_Basic()
|
||||||
{
|
{
|
||||||
string expected = "C:\\Game\\main\\log.log";
|
string expected = "C:\\Game\\main\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("", "C:\\Game", "main", null, "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
@ -19,25 +26,47 @@ namespace ApplicationTests
|
|||||||
public void Test_GenerateLogPath_WithMod()
|
public void Test_GenerateLogPath_WithMod()
|
||||||
{
|
{
|
||||||
string expected = "C:\\Game\\mods\\mod\\log.log";
|
string expected = "C:\\Game\\mods\\mod\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("", "C:\\Game", "main", "mods\\mod", "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main",
|
||||||
|
ModDirectory = "mods\\mod",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_GenerateLogPath_WithBasePath()
|
public void Test_GenerateLogPath_WithBaseGame()
|
||||||
{
|
{
|
||||||
string expected = "C:\\GameAlt\\main\\log.log";
|
string expected = "C:\\GameAlt\\main\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("C:\\GameAlt", "C:\\Game", "main", null, "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BaseGameDirectory = "C:\\GameAlt",
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_GenerateLogPath_WithBasePathAndMod()
|
public void Test_GenerateLogPath_WithBaseGameAndMod()
|
||||||
{
|
{
|
||||||
string expected = "C:\\GameAlt\\mods\\mod\\log.log";
|
string expected = "C:\\GameAlt\\mods\\mod\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("C:\\GameAlt", "C:\\Game", "main", "mods\\mod", "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BaseGameDirectory = "C:\\GameAlt",
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main",
|
||||||
|
ModDirectory = "mods\\mod",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
@ -46,7 +75,14 @@ namespace ApplicationTests
|
|||||||
public void Test_GenerateLogPath_InvalidBasePath()
|
public void Test_GenerateLogPath_InvalidBasePath()
|
||||||
{
|
{
|
||||||
string expected = "C:\\Game\\main\\log.log";
|
string expected = "C:\\Game\\main\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("game", "C:\\Game", "main", null, "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BaseGameDirectory = "game",
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
@ -55,7 +91,13 @@ namespace ApplicationTests
|
|||||||
public void Test_GenerateLogPath_BadSeparators()
|
public void Test_GenerateLogPath_BadSeparators()
|
||||||
{
|
{
|
||||||
string expected = "C:\\Game\\main\\folder\\log.log";
|
string expected = "C:\\Game\\main\\folder\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("", "C:/Game", "main/folder", null, "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BasePathDirectory = "C:/Game",
|
||||||
|
GameDirectory = "main/folder",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
@ -64,7 +106,30 @@ namespace ApplicationTests
|
|||||||
public void Test_GenerateLogPath_RelativeBasePath()
|
public void Test_GenerateLogPath_RelativeBasePath()
|
||||||
{
|
{
|
||||||
string expected = "C:\\Game\\main\\folder\\log.log";
|
string expected = "C:\\Game\\main\\folder\\log.log";
|
||||||
string generated = IW4MServer.GenerateLogPath("main\\folder", "C:\\Game", "main\\folder", null, "log.log");
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BaseGameDirectory = "main\\folder",
|
||||||
|
BasePathDirectory = "C:\\Game",
|
||||||
|
GameDirectory = "main\\folder",
|
||||||
|
LogFile = "log.log"
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info);
|
||||||
|
|
||||||
|
Assert.AreEqual(expected, generated);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_GenerateLogPath_FixWineDriveMangling()
|
||||||
|
{
|
||||||
|
string expected = "/opt/server/game/log.log";
|
||||||
|
var info = new LogPathGeneratorInfo()
|
||||||
|
{
|
||||||
|
BasePathDirectory = "Z:\\opt\\server",
|
||||||
|
GameDirectory = "game",
|
||||||
|
LogFile = "log.log",
|
||||||
|
IsWindows = false
|
||||||
|
};
|
||||||
|
string generated = IW4MServer.GenerateLogPath(info).Replace('\\', '/');
|
||||||
|
|
||||||
Assert.AreEqual(expected, generated);
|
Assert.AreEqual(expected, generated);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user