Merge branch 'main' into webSupport
This commit is contained in:
commit
d3c313e8a4
18 changed files with 448 additions and 342 deletions
|
|
@ -173,28 +173,6 @@ namespace Server
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string EnsureDirectory(string dir)
|
||||
{
|
||||
var path = Path.Combine(Core.BaseDirectory, dir);
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(FileInfo fi)
|
||||
{
|
||||
var dir = fi.DirectoryName;
|
||||
if (dir != null)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(DirectoryInfo di)
|
||||
{
|
||||
Directory.CreateDirectory(di.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeCache
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace Server
|
|||
{
|
||||
var path = Path.Combine(savePath, name);
|
||||
|
||||
AssemblyHandler.EnsureDirectory(path);
|
||||
PathUtility.EnsureDirectory(path);
|
||||
|
||||
string binPath = Path.Combine(path, $"{name}.bin");
|
||||
using var bin = new BinaryFileWriter(binPath, true);
|
||||
|
|
@ -54,7 +54,7 @@ namespace Server
|
|||
{
|
||||
var path = Path.Combine(savePath, name);
|
||||
|
||||
AssemblyHandler.EnsureDirectory(path);
|
||||
PathUtility.EnsureDirectory(path);
|
||||
|
||||
string binPath = Path.Combine(path, $"{name}.bin");
|
||||
|
||||
|
|
|
|||
|
|
@ -169,6 +169,28 @@ namespace Server
|
|||
return str;
|
||||
}
|
||||
|
||||
public static string TrimMultiline(this string str, string lineSeparator = "\n")
|
||||
{
|
||||
var parts = str.Split(lineSeparator);
|
||||
for (var i = 0; i < parts.Length; i++)
|
||||
{
|
||||
parts[i] = parts[i].Trim();
|
||||
}
|
||||
|
||||
return string.Join(lineSeparator, parts);
|
||||
}
|
||||
|
||||
public static string IndentMultiline(this string str, string indent = "\t", string lineSeparator = "\n")
|
||||
{
|
||||
var parts = str.Split(lineSeparator);
|
||||
for (var i = 0; i < parts.Length; i++)
|
||||
{
|
||||
parts[i] = $"{indent}{parts[i]}";
|
||||
}
|
||||
|
||||
return string.Join(lineSeparator, parts);
|
||||
}
|
||||
|
||||
public static List<string> Wrap(this string value, int perLine, int maxLines)
|
||||
{
|
||||
if ((value = value?.Trim() ?? "").Length <= 0)
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ namespace Server
|
|||
}
|
||||
|
||||
#if DEBUG_TIMERS
|
||||
tw.WriteLine("\nStack Traces:");
|
||||
tw.WriteLine($"{Environment.NewLine}Stack Traces:");
|
||||
foreach (var kvp in DelayCallTimer._stackTraces)
|
||||
{
|
||||
tw.WriteLine(kvp.Value);
|
||||
|
|
|
|||
67
Projects/Server/Utilities/PathUtility.cs
Normal file
67
Projects/Server/Utilities/PathUtility.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: PathUtility.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class PathUtility
|
||||
{
|
||||
public static string EnsureDirectory(string dir)
|
||||
{
|
||||
var path = GetFullPath(dir, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this FileInfo fi)
|
||||
{
|
||||
var dir = GetFullPath(fi.DirectoryName, Core.BaseDirectory);
|
||||
if (dir != null)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this DirectoryInfo di)
|
||||
{
|
||||
var file = GetFullPath(di.FullName, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(file);
|
||||
}
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath) =>
|
||||
GetFullPath(relativeOrAbsolutePath, Core.BaseDirectory);
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath, string basePath) =>
|
||||
relativeOrAbsolutePath switch
|
||||
{
|
||||
null => null,
|
||||
"" => basePath,
|
||||
_ => Path.IsPathRooted(relativeOrAbsolutePath)
|
||||
? relativeOrAbsolutePath
|
||||
: Path.GetFullPath(relativeOrAbsolutePath, basePath)
|
||||
};
|
||||
|
||||
public static string EnsureRandomPath(string basePath)
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[8];
|
||||
Utility.RandomBytes(bytes);
|
||||
return EnsureDirectory(Path.Combine(basePath, bytes.ToHexString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1331,28 +1331,6 @@ namespace Server
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T Max<T>(T val, T max) where T : IComparable<T> => val.CompareTo(max) > 0 ? val : max;
|
||||
|
||||
public static string TrimMultiline(this string str, string lineSeparator = "\n")
|
||||
{
|
||||
var parts = str.Split(lineSeparator);
|
||||
for (var i = 0; i < parts.Length; i++)
|
||||
{
|
||||
parts[i] = parts[i].Trim();
|
||||
}
|
||||
|
||||
return string.Join(lineSeparator, parts);
|
||||
}
|
||||
|
||||
public static string IndentMultiline(this string str, string indent = "\t", string lineSeparator = "\n")
|
||||
{
|
||||
var parts = str.Split(lineSeparator);
|
||||
for (var i = 0; i < parts.Length; i++)
|
||||
{
|
||||
parts[i] = $"{indent}{parts[i]}";
|
||||
}
|
||||
|
||||
return string.Join(lineSeparator, parts);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Tidy<T>(this List<T> list) where T : ISerializable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Server
|
|||
|
||||
var path = Path.Combine(savePath, typeName);
|
||||
|
||||
AssemblyHandler.EnsureDirectory(path);
|
||||
PathUtility.EnsureDirectory(path);
|
||||
|
||||
string idxPath = Path.Combine(path, $"{typeName}.idx");
|
||||
string tdbPath = Path.Combine(path, $"{typeName}.tdb");
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ namespace Server
|
|||
private static readonly ConcurrentQueue<Item> _decayQueue = new();
|
||||
|
||||
private static string _tempSavePath; // Path to the temporary folder for the save
|
||||
private static string _savePath; // Path to "Saves" folder
|
||||
private static bool _enableSaveStats;
|
||||
|
||||
public const bool DirtyTrackingEnabled = false;
|
||||
|
|
@ -130,6 +129,8 @@ namespace Server
|
|||
internal static List<Type> MobileTypes { get; } = new();
|
||||
internal static List<Type> GuildTypes { get; } = new();
|
||||
|
||||
public static string SavePath { get; private set; }
|
||||
|
||||
public static WorldState WorldState { get; private set; }
|
||||
public static bool Saving => WorldState == WorldState.Saving;
|
||||
public static bool Running => WorldState is not WorldState.Loading and not WorldState.Initial;
|
||||
|
|
@ -141,10 +142,12 @@ namespace Server
|
|||
|
||||
public static void Configure()
|
||||
{
|
||||
var tempSavePath = ServerConfiguration.GetOrUpdateSetting("world.tempSavePath", "temp");
|
||||
_tempSavePath = Path.Combine(Core.BaseDirectory, tempSavePath);
|
||||
var tempSavePath = ServerConfiguration.GetSetting("world.tempSavePath", "temp");
|
||||
_tempSavePath = PathUtility.GetFullPath(tempSavePath);
|
||||
|
||||
var savePath = ServerConfiguration.GetOrUpdateSetting("world.savePath", "Saves");
|
||||
_savePath = Path.Combine(Core.BaseDirectory, savePath);
|
||||
SavePath = PathUtility.GetFullPath(savePath);
|
||||
|
||||
_enableSaveStats = ServerConfiguration.GetOrUpdateSetting("world.enableSaveStats", false);
|
||||
|
||||
// Mobiles & Items
|
||||
|
|
@ -256,7 +259,7 @@ namespace Server
|
|||
logger.Information("Loading world");
|
||||
var watch = Stopwatch.StartNew();
|
||||
|
||||
Persistence.Load(_savePath);
|
||||
Persistence.Load(SavePath);
|
||||
EventSink.InvokeWorldLoad();
|
||||
|
||||
ProcessSafetyQueues();
|
||||
|
|
@ -344,7 +347,7 @@ namespace Server
|
|||
|
||||
var timestamp = Utility.GetTimeStamp();
|
||||
var saveStatsPath = Path.Combine(Core.BaseDirectory, $"Logs/Saves/Save-Stats-{timestamp}.log");
|
||||
AssemblyHandler.EnsureDirectory(saveStatsPath);
|
||||
PathUtility.EnsureDirectory(saveStatsPath);
|
||||
|
||||
using var op = new StreamWriter(saveStatsPath, true);
|
||||
|
||||
|
|
@ -388,7 +391,7 @@ namespace Server
|
|||
{
|
||||
Exception exception = null;
|
||||
|
||||
var tempPath = Path.Combine(_tempSavePath, Utility.GetTimeStamp());
|
||||
var tempPath = PathUtility.EnsureRandomPath(_tempSavePath);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -417,8 +420,8 @@ namespace Server
|
|||
{
|
||||
try
|
||||
{
|
||||
EventSink.InvokeWorldSavePostSnapshot(_savePath, tempPath);
|
||||
Directory.Move(tempPath, _savePath);
|
||||
EventSink.InvokeWorldSavePostSnapshot(SavePath, tempPath);
|
||||
Directory.Move(tempPath, SavePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue