-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from Xcube-Studio/refactor-new-core-managemen…
…t-style Refactor new core management style
- Loading branch information
Showing
62 changed files
with
1,599 additions
and
1,069 deletions.
There are no files selected for viewing
Submodule FluentLauncher.Localization
updated
10 files
Submodule Natsurainko.FluentCore
updated
7 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
#nullable disable | ||
namespace Natsurainko.FluentLauncher.Experimental.Saves; | ||
|
||
internal record SaveInfo | ||
{ | ||
public string Folder { get; set; } | ||
|
||
public string FolderName { get; set; } | ||
|
||
public string LevelName { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
public bool AllowCommands { get; set; } | ||
|
||
public DateTime LastPlayed { get; set; } | ||
|
||
public long Seed { get; set; } | ||
|
||
public string IconFilePath { get; set; } | ||
|
||
public int GameType { get; set; } | ||
} | ||
|
||
|
49 changes: 49 additions & 0 deletions
49
Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using NbtToolkit.Binary; | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Natsurainko.FluentLauncher.Experimental.Saves; | ||
|
||
internal static class SaveInfoParser | ||
{ | ||
public static async Task<SaveInfo> ParseAsync(string saveFolder) | ||
{ | ||
var saveInfo = new SaveInfo | ||
{ | ||
FolderName = new DirectoryInfo(saveFolder).Name, | ||
Folder = saveFolder | ||
}; | ||
|
||
await Task.Run(() => | ||
{ | ||
var time = DateTime.Now; | ||
using var fileStream = new FileStream(Path.Combine(saveFolder, "level.dat"), FileMode.Open, FileAccess.Read); | ||
using var _nbtReader = new NbtReader(fileStream, NbtCompression.GZip, true); | ||
var rootTag = _nbtReader.ReadRootTag(); | ||
var dataTagCompound = rootTag["Data"].AsTagCompound(); | ||
saveInfo.LevelName = dataTagCompound["LevelName"].AsString(); | ||
saveInfo.AllowCommands = dataTagCompound["allowCommands"].AsBool(); | ||
saveInfo.GameType = dataTagCompound["GameType"].AsInt(); | ||
saveInfo.Version = dataTagCompound["Version"].AsTagCompound()["Name"].AsString(); | ||
if (dataTagCompound.ContainsKey("WorldGenSettings")) | ||
saveInfo.Seed = dataTagCompound["WorldGenSettings"].AsTagCompound()["seed"].AsLong(); | ||
else if (dataTagCompound.ContainsKey("RandomSeed")) | ||
saveInfo.Seed = dataTagCompound["RandomSeed"].AsLong(); | ||
saveInfo.LastPlayed = DateTimeOffset.FromUnixTimeMilliseconds(dataTagCompound["LastPlayed"].AsLong()).ToLocalTime().DateTime; | ||
if (File.Exists(Path.Combine(saveFolder, "icon.png"))) | ||
saveInfo.IconFilePath = Path.Combine(saveFolder, "icon.png"); | ||
var gap = DateTime.Now - time; | ||
}); | ||
|
||
return saveInfo; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Natsurainko.FluentLauncher/Experimental/Saves/SaveManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Natsurainko.FluentLauncher.Experimental.Saves; | ||
|
||
internal class SaveManager | ||
{ | ||
private readonly List<(FileInfo, Exception)> _errorLevelData = []; | ||
|
||
public IReadOnlyList<(FileInfo, Exception)> ErrorLevelData { get; init; } | ||
|
||
public string SavesFolder { get; private set; } | ||
|
||
public SaveManager(string savesFolder) | ||
{ | ||
SavesFolder = savesFolder; | ||
ErrorLevelData = _errorLevelData; | ||
} | ||
|
||
public async IAsyncEnumerable<SaveInfo> EnumerateSavesAsync() | ||
{ | ||
foreach (var dir in Directory.EnumerateDirectories(SavesFolder)) | ||
{ | ||
var levelDataFile = new FileInfo(Path.Combine(dir, "level.dat")); | ||
|
||
if (!levelDataFile.Exists) | ||
continue; | ||
|
||
SaveInfo? saveInfo = default; | ||
|
||
try | ||
{ | ||
saveInfo = await SaveInfoParser.ParseAsync(dir); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_errorLevelData.Add((levelDataFile, ex)); | ||
} | ||
|
||
if (saveInfo != null) | ||
yield return saveInfo; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#nullable disable | ||
namespace Natsurainko.FluentLauncher.Experimental.Servers; | ||
|
||
internal record ServerInfo | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string Address { get; set; } | ||
|
||
public string Icon { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.