mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-08-05 12:26:24 -04:00
Rename AtomicIO to a FileIO
This commit is contained in:
parent
a889b3e85d
commit
b6cc486990
12
CLI/MCGalaxyCLI_dotnet9.csproj
Normal file
12
CLI/MCGalaxyCLI_dotnet9.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
|
<AssemblyName>MCGalaxyCLI</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MCGalaxy\MCGalaxy_dotnet.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -91,8 +91,7 @@ namespace MCGalaxy.Bots {
|
|||||||
try {
|
try {
|
||||||
using (StreamWriter w = new StreamWriter(tmpPath)) { WriteAll(w, props); }
|
using (StreamWriter w = new StreamWriter(tmpPath)) { WriteAll(w, props); }
|
||||||
|
|
||||||
AtomicIO.TryDelete(path);
|
FileIO.Replace(tmpPath, path);
|
||||||
File.Move(tmpPath, path);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.LogError("Error saving bots to " + path, ex);
|
Logger.LogError("Error saving bots to " + path, ex);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
|
|
||||||
static void DeleteReport(string user) {
|
static void DeleteReport(string user) {
|
||||||
string backup = "extra/reportedbackups/" + user + ".txt";
|
string backup = "extra/reportedbackups/" + user + ".txt";
|
||||||
AtomicIO.TryDelete(backup);
|
FileIO.TryDelete(backup);
|
||||||
File.Move(ReportPath(user), backup);
|
File.Move(ReportPath(user), backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ namespace MCGalaxy {
|
|||||||
public static void ListFor(Player p) {
|
public static void ListFor(Player p) {
|
||||||
p.Message("&HPresets: &f{0}", Presets.Join(pr => pr.Key));
|
p.Message("&HPresets: &f{0}", Presets.Join(pr => pr.Key));
|
||||||
|
|
||||||
string[] files = AtomicIO.TryGetFiles(FOLDER, "*" + FILE_EXTENSION);
|
string[] files = FileIO.TryGetFiles(FOLDER, "*" + FILE_EXTENSION);
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
|
|
||||||
string all = files.Join(f => Path.GetFileNameWithoutExtension(f));
|
string all = files.Join(f => Path.GetFileNameWithoutExtension(f));
|
||||||
|
@ -125,7 +125,7 @@ namespace MCGalaxy.Scripting
|
|||||||
|
|
||||||
|
|
||||||
public static void AutoloadCommands() {
|
public static void AutoloadCommands() {
|
||||||
string[] files = AtomicIO.TryGetFiles(COMMANDS_DLL_DIR, "*.dll");
|
string[] files = FileIO.TryGetFiles(COMMANDS_DLL_DIR, "*.dll");
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
|
|
||||||
foreach (string path in files) { AutoloadCommands(path); }
|
foreach (string path in files) { AutoloadCommands(path); }
|
||||||
@ -178,7 +178,7 @@ namespace MCGalaxy.Scripting
|
|||||||
|
|
||||||
|
|
||||||
public static void AutoloadPlugins() {
|
public static void AutoloadPlugins() {
|
||||||
string[] files = AtomicIO.TryGetFiles(PLUGINS_DLL_DIR, "*.dll");
|
string[] files = FileIO.TryGetFiles(PLUGINS_DLL_DIR, "*.dll");
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
|
|
||||||
// Ensure that plugin files are loaded in a consistent order,
|
// Ensure that plugin files are loaded in a consistent order,
|
||||||
|
@ -123,14 +123,14 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
// Move current files to previous files (by moving instead of copying,
|
// Move current files to previous files (by moving instead of copying,
|
||||||
// can overwrite original the files without breaking the server)
|
// can overwrite original the files without breaking the server)
|
||||||
AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll");
|
FileIO.TryMove(serverDLL, "prev_MCGalaxy_.dll");
|
||||||
AtomicIO.TryMove(serverGUI, "prev_MCGalaxy.exe");
|
FileIO.TryMove(serverGUI, "prev_MCGalaxy.exe");
|
||||||
AtomicIO.TryMove(serverCLI, "prev_MCGalaxyCLI.exe");
|
FileIO.TryMove(serverCLI, "prev_MCGalaxyCLI.exe");
|
||||||
|
|
||||||
// Move update files to current files
|
// Move update files to current files
|
||||||
AtomicIO.TryMove("MCGalaxy_.update", serverDLL);
|
FileIO.TryMove("MCGalaxy_.update", serverDLL);
|
||||||
AtomicIO.TryMove("MCGalaxy.update", serverGUI);
|
FileIO.TryMove("MCGalaxy.update", serverGUI);
|
||||||
AtomicIO.TryMove("MCGalaxyCLI.update", serverCLI);
|
FileIO.TryMove("MCGalaxyCLI.update", serverCLI);
|
||||||
|
|
||||||
Server.Stop(true, "Updating server.");
|
Server.Stop(true, "Updating server.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -145,7 +145,7 @@ namespace MCGalaxy
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void DeleteFiles(params string[] paths) {
|
static void DeleteFiles(params string[] paths) {
|
||||||
foreach (string path in paths) { AtomicIO.TryDelete(path); }
|
foreach (string path in paths) { FileIO.TryDelete(path); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ using System.IO;
|
|||||||
|
|
||||||
namespace MCGalaxy
|
namespace MCGalaxy
|
||||||
{
|
{
|
||||||
/// <summary> Provides utility methods for atomic File I/O operations. </summary>
|
/// <summary> Provides utility methods for File I/O operations. </summary>
|
||||||
public static class AtomicIO
|
public static class FileIO
|
||||||
{
|
{
|
||||||
/// <summary> Attempts to delete a file from disc, if it exists </summary>
|
/// <summary> Attempts to delete a file from disc, if it exists </summary>
|
||||||
/// <returns> true if file was successfully deleted, false if file did not exist to begin with </returns>
|
/// <returns> true if file was successfully deleted, false if file did not exist to begin with </returns>
|
||||||
@ -56,5 +56,12 @@ namespace MCGalaxy
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Replace(string src, string dst) {
|
||||||
|
TryDelete(dst + ".old");
|
||||||
|
|
||||||
|
File.Move(dst, dst + ".old");
|
||||||
|
File.Move(src, dst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user