我有一个名为 backup.lua 的文件,程序应该经常写入该文件以备份其状态,以防万一发生故障。问题是该程序在第一轮中将 backup.lua 文件写入完全正常,但在其他任何时候它都拒绝写入该文件。
我尝试在程序仍处于打开状态时删除该文件,但 Windows 告诉我该文件正在被程序“CrysisWarsDedicatedServer.exe”使用。我已经告诉宿主Lua函数关闭backup.lua文件,为什么它关闭后不让我随意修改文件?
我在互联网上找不到任何东西(谷歌实际上试图更正我的搜索),该项目的二级程序员也不知道。所以我想知道你们中是否有人知道我们在这里做错了什么?
主机功能代码:
function ServerBackup(todo)
local write, read;
if todo=="write" then
write = true;
else
read = true;
end
if (write) then
local source = io.open(Root().."Mods/Infinity/System/Read/backup.lua", "w");
System.Log(TeamInstantAction:GetTeamScore(2).." for 2, and for 1: "..TeamInstantAction:GetTeamScore(1))
System.LogAlways("[System] Backing up serverdata to file 'backup.lua'");
source:write("--[[ The server is dependent on this file; editing it will lead to serious problems.If there is a problem with this file, please re-write it by accessing the backup system ingame.--]]");
source:write("Backup = {};Backup.Time = '"..os.date("%H:%M").."';Backup.Date = '"..os.date("%d/%m/%Y").."';");
source:write(XFormat("TeamInstantAction:SetTeamScore(2, %d);TeamInstantAction:SetTeamScore(1, %d);TeamInstantAction:UpdateScores();",TeamInstantAction:GetTeamScore(2), TeamInstantAction:GetTeamScore(1) ));
source:close();
for i,player in pairs(g_gameRules.game:GetPlayers() or {}) do
if (IsModerator(player)) then
CMPlayer(player, "[!backup] Completed server backup.");
end
end
end
--local source = io.open(Root().."Mods/Infinity/System/Read/backup.lua", "r"); Can the file be open here and by the Lua scriptloader too?
if (read) then
System.LogAlways("[System] Restoring serverdata from file 'backup.lua'");
--source:close();
Backup = {};
Script.LoadScript(Root().."Mods/Infinity/System/Read/backup.lua");
if not Backup or #Backup < 1 then
System.LogAlways("[System] Error restoring serverdata from file 'backup.lua'");
end
end
end
谢谢大家:)。
编辑:
尽管文件现在已正常写入磁盘,但系统无法读取转储文件。