Skip to content

Commit

Permalink
LuaVFS cleanup + changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
gajop committed May 9, 2020
1 parent 078248f commit 08c394f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 39 deletions.
5 changes: 3 additions & 2 deletions doc/changelog.txt
Expand Up @@ -114,9 +114,10 @@ Lua:
- Added VFS.GetArchivePath(string archiveName1) -> string archivePathOnDisk
- Added VFS.GetFileAbsolutePath(string vfsFilePath) -> string filePathOnDisk
- Added VFS.GetArchiveContainingFile(string vfsFilePath) -> string archiveName
! VFS.MapArchive, VFS.UnmapArchive and VFS.UseArchive now take archiveName instead of fileName as the first parameter.
- add a 6th return value (feature->reclaimTime) to GetFeatureResources.
- Add `Spring.UnitFinishCommand(unitID)`, finishes current command. Unlike CMD.REMOVE it works with Repeat/UnitCmdDone
and unlike CommandFallback it works on builtin engine commands.
and unlike CommandFallback it works on builtin engine commands.
- Allow spawning of any CEG from any LUS:
EmitSfx(p, "cegTag") param will emit the CEG with tag="cegTag"
EmitSfx(p, SFX.GLOBAL | cegID) will emit the CEG with id=cegID
Expand Down Expand Up @@ -148,7 +149,7 @@ AI:
skirmishAiCallback_Unit_get{CaptureProgress,BuildProgress,ParalyzeDamage} functions

Misc:
- dedicated server now defaults the `AllowSpectatorJoin` springsetting to false (still true for non-dedi)
- dedicated server now defaults the `AllowSpectatorJoin` springsetting to false (still true for non-dedi)
- Rifle weapontype: remove hardcoded particles
- add MapConvNG executables to official spring builds: https://springrts.com/wiki/MapConvNG
- remove joystick support
Expand Down
49 changes: 12 additions & 37 deletions rts/Lua/LuaVFS.cpp
Expand Up @@ -376,11 +376,11 @@ int LuaVFS::UseArchive(lua_State* L)
const std::string& archiveName = luaL_checkstring(L, 1);
const CArchiveScanner::ArchiveData& archiveData = archiveScanner->GetArchiveData(archiveName);
if (archiveData.IsEmpty())
return 0;
luaL_error(L, "[VFS::%s] archive not found: %s", __func__, archiveName.c_str());

constexpr int funcIndex = 2;
if (!lua_isfunction(L, funcIndex))
return 0;
luaL_error(L, "[VFS::%s] second argument should be a function", __func__);

// block other threads from getting the global until we are done
vfsHandler->GrabLock();
Expand Down Expand Up @@ -413,14 +413,8 @@ int LuaVFS::MapArchive(lua_State* L)

const std::string& archiveName = luaL_checkstring(L, 1);
const CArchiveScanner::ArchiveData& archiveData = archiveScanner->GetArchiveData(archiveName);
if (archiveData.IsEmpty()) {
std::ostringstream buf;
buf << "[" << __func__ << "] archive not found: " << archiveName;

lua_pushboolean(L, false);
lua_pushsstring(L, buf.str());
return 2;
}
if (archiveData.IsEmpty())
luaL_error(L, "[VFS::%s] archive not found: %s", __func__, archiveName.c_str());

if (args >= 2) {
sha512::hex_digest argChecksum;
Expand All @@ -430,26 +424,13 @@ int LuaVFS::MapArchive(lua_State* L)
std::memcpy(argChecksum.data(), lua_tostring(L, 2), std::min(argChecksum.size() - 1, strlen(lua_tostring(L, 2))));
sha512::dump_digest(archiveScanner->GetArchiveSingleChecksumBytes(archiveName), hexChecksum);

if (argChecksum != hexChecksum) {
std::ostringstream buf;

buf << "[" << __func__ << "] incorrect checksum for archive: " << archiveName;
buf << "(got: " << argChecksum.data() << ", expected: " << hexChecksum.data() << ")";

lua_pushboolean(L, false);
lua_pushsstring(L, buf.str());
return 2;
}
if (argChecksum != hexChecksum)
luaL_error(L, "[VFS::%s] incorrect checksum for archive: %s (got: %s, expected: %s)",
__func__, archiveName.c_str(), argChecksum.data(), hexChecksum.data());
}

if (!vfsHandler->AddArchive(archiveName, false)) {
std::ostringstream buf;
buf << "[" << __func__ << "] failed to load archive: " << archiveName;

lua_pushboolean(L, false);
lua_pushsstring(L, buf.str());
return 2;
}
if (!vfsHandler->AddArchive(archiveName, false))
luaL_error(L, "[VFS::%s] failed to load archive: %s", archiveName.c_str());

lua_pushboolean(L, true);
return 1;
Expand All @@ -464,18 +445,12 @@ int LuaVFS::UnmapArchive(lua_State* L)
const std::string& archiveName = luaL_checkstring(L, 1);
const CArchiveScanner::ArchiveData& archiveData = archiveScanner->GetArchiveData(archiveName);
if (archiveData.IsEmpty())
return 0;
luaL_error(L, "[VFS::%s] archive not found: %s", __func__, archiveName.c_str());

LOG("[LuaVFS::%s] archive=%s", __func__, archiveName.c_str());

if (!vfsHandler->RemoveArchive(archiveName)) {
std::ostringstream buf;
buf << "[" << __func__ << "] failed to remove archive: " << archiveName;

lua_pushboolean(L, false);
lua_pushsstring(L, buf.str());
return 2;
}
if (!vfsHandler->RemoveArchive(archiveName))
luaL_error(L, "[VFS::%s] failed to remove archive: %s", __func__, archiveName.c_str());

lua_pushboolean(L, true);
return 1;
Expand Down

0 comments on commit 08c394f

Please sign in to comment.