mirror of
https://github.com/H-uru/korman.git
synced 2025-07-14 02:27:36 -04:00
Re-fix the TPotS launching race condition.
This was fixed in H-uru/libhsplasma#242 originally, but Win32 APIs seem to have terrible performance without user mode buffering, which negatively impacted PRP loading in other tools, such as PRP Shop. Therefore, the fix was reverted in H-uru/libhsplasma#246. This fixes the race condition closer to the point of impact using the Win32 stream introduced by H-uru/libhsplasma#264.
This commit is contained in:
@ -208,7 +208,7 @@ if(korman_BUILD_HSPLASMA)
|
|||||||
korman_add_external_project(HSPlasma
|
korman_add_external_project(HSPlasma
|
||||||
GIT_REPOSITORY "https://github.com/H-uru/libhsplasma.git"
|
GIT_REPOSITORY "https://github.com/H-uru/libhsplasma.git"
|
||||||
# Be sure to increase this as the feature set used by Korman increases
|
# Be sure to increase this as the feature set used by Korman increases
|
||||||
GIT_TAG 4a1fd38dca471008de62209cc89616351161a843
|
GIT_TAG 6fa56d979163af8602cd6212449a07400a14b532
|
||||||
# We can only do shallow checkouts if the above is a branch or tag.
|
# We can only do shallow checkouts if the above is a branch or tag.
|
||||||
GIT_SHALLOW FALSE
|
GIT_SHALLOW FALSE
|
||||||
CMAKE_CACHE_ARGS
|
CMAKE_CACHE_ARGS
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from PyHSPlasma import *
|
from PyHSPlasma import *
|
||||||
import shutil
|
import shutil
|
||||||
@ -55,6 +56,28 @@ def die(*args, **kwargs):
|
|||||||
sys.stdout.write("DIE\n")
|
sys.stdout.write("DIE\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def open_vault_stream(vault_path, fm):
|
||||||
|
stream_type = globals().get("hsWindowsStream", "hsFileStream")
|
||||||
|
write("DBG: Opened '{}' stream with provider '{}'", vault_path, stream_type.__name__)
|
||||||
|
|
||||||
|
encrypted = plEncryptedStream.IsFileEncrypted(vault_path)
|
||||||
|
encryption_type = plEncryptedStream.kEncAuto if fm in {fmRead, fmReadWrite} else plEncryptedStream.kEncXtea
|
||||||
|
|
||||||
|
backing_stream = stream_type().open(vault_path, fm)
|
||||||
|
if encrypted:
|
||||||
|
enc_stream = plEncryptedStream().open(backing_stream, fm, encryption_type)
|
||||||
|
output_stream = enc_stream
|
||||||
|
else:
|
||||||
|
output_stream = backing_stream
|
||||||
|
try:
|
||||||
|
yield output_stream
|
||||||
|
finally:
|
||||||
|
if encrypted:
|
||||||
|
enc_stream.close()
|
||||||
|
backing_stream.flush()
|
||||||
|
backing_stream.close()
|
||||||
|
|
||||||
def write(*args, **kwargs):
|
def write(*args, **kwargs):
|
||||||
assert args
|
assert args
|
||||||
if len(args) == 1 and not kwargs:
|
if len(args) == 1 and not kwargs:
|
||||||
@ -112,7 +135,8 @@ def find_player_vault(cwd, name):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
store = plVaultStore()
|
store = plVaultStore()
|
||||||
store.Import(str(vault_dat))
|
with open_vault_stream(vault_dat, fmRead) as stream:
|
||||||
|
store.Import(stream)
|
||||||
|
|
||||||
# First node is the Player node...
|
# First node is the Player node...
|
||||||
playerNode = store[store.firstNodeID]
|
playerNode = store[store.firstNodeID]
|
||||||
@ -135,7 +159,9 @@ def main():
|
|||||||
backup_vault_dat(vault_path)
|
backup_vault_dat(vault_path)
|
||||||
vault_prev_autolink = set_link_chronicle(vault_store, args.age)
|
vault_prev_autolink = set_link_chronicle(vault_store, args.age)
|
||||||
write("DBG: Saving vault...")
|
write("DBG: Saving vault...")
|
||||||
vault_store.Export(str(vault_path))
|
|
||||||
|
with open_vault_stream(vault_path, fmCreate) as stream:
|
||||||
|
vault_store.Export(stream)
|
||||||
|
|
||||||
# Update init file for this schtuff...
|
# Update init file for this schtuff...
|
||||||
init_path = args.cwd.joinpath("init", "net_age.fni")
|
init_path = args.cwd.joinpath("init", "net_age.fni")
|
||||||
@ -154,9 +180,6 @@ def main():
|
|||||||
# the stale vault...
|
# the stale vault...
|
||||||
del vault_store
|
del vault_store
|
||||||
|
|
||||||
# Sigh...
|
|
||||||
time.sleep(1.0)
|
|
||||||
|
|
||||||
# EXE args
|
# EXE args
|
||||||
plasma_args = [str(executable), "-iinit", "To_Dni"]
|
plasma_args = [str(executable), "-iinit", "To_Dni"]
|
||||||
else:
|
else:
|
||||||
@ -174,18 +197,16 @@ def main():
|
|||||||
finally:
|
finally:
|
||||||
# Restore sp vault, if needed.
|
# Restore sp vault, if needed.
|
||||||
if args.version == "pvPots":
|
if args.version == "pvPots":
|
||||||
# Path of the Shell seems to have some sort of weird racing with the vault.dat around
|
|
||||||
# shutdown. This delay helps somewhat in that regard.
|
|
||||||
time.sleep(1.0)
|
|
||||||
|
|
||||||
vault_store = plVaultStore()
|
vault_store = plVaultStore()
|
||||||
vault_store.Import(str(vault_path))
|
with open_vault_stream(vault_path, fmRead) as stream:
|
||||||
|
vault_store.Import(stream)
|
||||||
new_prev_autolink = set_link_chronicle(vault_store, vault_prev_autolink, args.age)
|
new_prev_autolink = set_link_chronicle(vault_store, vault_prev_autolink, args.age)
|
||||||
if new_prev_autolink != args.age:
|
if new_prev_autolink != args.age:
|
||||||
write("DBG: ***Not*** resaving the vault!")
|
write("DBG: ***Not*** resaving the vault!")
|
||||||
else:
|
else:
|
||||||
write("DBG: Resaving vault...")
|
write("DBG: Resaving vault...")
|
||||||
vault_store.Export(str(vault_path))
|
with open_vault_stream(vault_path, fmCreate) as stream:
|
||||||
|
vault_store.Export(stream)
|
||||||
|
|
||||||
# All good!
|
# All good!
|
||||||
write("DONE")
|
write("DONE")
|
||||||
|
Reference in New Issue
Block a user