Skip to content

Commit

Permalink
Remove 2.0.0.0 folder. Disable update config
Browse files Browse the repository at this point in the history
  • Loading branch information
SoprachevAK committed Apr 21, 2024
1 parent c2c36c5 commit ee38143
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
17 changes: 13 additions & 4 deletions WOTSTAT/res/scripts/client/gui/mods/wot_stat/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Config:
'updateURL': 'https://api.github.com/repos/WOT-STAT/WOTMOD/releases/latest',
'statusURL': 'https://wotstat.info/api',
'lokiURL': 'https://loki.wotstat.info/loki/api/v1/push',
'hideServer': False
'hideServer': False,
'disableCopyToFuture': False,
'disableAutoUpdate': False,
}

def __init__(self, ConfigPath, DefaultParams=None):
Expand All @@ -31,11 +33,18 @@ def __init__(self, ConfigPath, DefaultParams=None):
self.config = json.loads(f.read())
print_log('found new config:')
print_log(self.config)
config_str = '''\n------\n'''.join("%s: %s" % (key, value) for key, value in self.config.items())

message = '''[WotStat] Обнаружена новая конфигурация в файле /mods/configs/wot_stat/config.cfg\n------\n%s''' % config_str
newInit = self.config.get('initBattleURL', None)
newEvent = self.config.get('eventURL', None)
newUpdate = self.config.get('updateURL', None)

BigWorld.callback(5.0, lambda: show_notification(message, message_type=SystemMessages.SM_TYPE.Warning))
if newInit and newInit != self.defaultParams.get('initBattleURL') or \
newEvent and newEvent != self.defaultParams.get('eventURL') or \
newUpdate and newUpdate != self.defaultParams.get('updateURL'):
config_str = '''\n------\n'''.join("%s: %s" % (key, value) for key, value in self.config.items())
message = '''[WotStat] Обнаружена новая конфигурация в файле /mods/configs/wot_stat/config.cfg\n------\n%s''' % config_str

BigWorld.callback(5.0, lambda: show_notification(message, message_type=SystemMessages.SM_TYPE.Warning))
except Exception, e:
print_log('load config error')
print_log(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,46 @@ def num_game_version():


@with_exception_sending
def update_game_version(full_mod_name):
def update_game_version(full_mod_name, mod_name):
gameVersion = num_game_version()
currentMod = os.path.join(os.path.abspath('./mods/'), gameVersion, full_mod_name)

def b(x, y):
return '.'.join(
[str(int(c) + 1 if i == y else 0) if i >= y else c for i, c in enumerate(x.split('.'))])

v = [b(gameVersion, i) for i in range(len(gameVersion.split('.')))]
v = [b(gameVersion, i) for i in range(1, len(gameVersion.split('.')))]

absPath = os.path.abspath('./mods/')
for i in range(len(v)):
p = os.path.join(absPath, v[i])
if not os.path.exists(p):
os.mkdir(p)
filePath = os.path.join(p, full_mod_name)

old_mod_versions = filter(lambda x: x.startswith(mod_name) and x.endswith('.wotmod') and x != full_mod_name, os.listdir(p))
for old_mod in old_mod_versions:
os.remove(os.path.join(p, old_mod))

if not os.path.exists(filePath):
shutil.copyfile(currentMod, filePath)


GH_headers = {'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github+json'}
# TODO: remove this later
# remove 2.0.0.0 mods if exists
v2Path = os.path.join(absPath, '2.0.0.0')
if os.path.exists(v2Path):
mods = filter(lambda x: x.startswith(mod_name) and x.endswith('.wotmod'), os.listdir(v2Path))
for mod in mods:
os.remove(os.path.join(v2Path, mod))
if not os.listdir(v2Path):
os.rmdir(v2Path)
print_log('Remove empty v2.0.0.0 folder')


GH_headers = {
'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github+json'
}


@with_exception_sending
Expand Down
18 changes: 12 additions & 6 deletions WOTSTAT/res/scripts/client/gui/mods/wot_stat/load_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
from .logger.sessionStorage import sessionStorage
from .common.serverLogger import setupLogger, send

MOD_NAME_PREFIX = 'mod.wotStat'

api_server_time = None


def mod_name_version(version):
return 'mod.wotStat_' + version + '.wotmod'
return MOD_NAME_PREFIX + '_' + version + '.wotmod'


def mod_name():
Expand Down Expand Up @@ -99,11 +101,15 @@ def on_status_check_fail(e):
show_notification(t('serverNotResponse'), message_type=SystemMessages.SM_TYPE.ErrorSimple)

get_async(config.get('statusURL'), callback=on_status_check, error_callback=on_status_check_fail)
update_game_version(mod_name())
update_mod_version(config.get('updateURL'), 'mod.wotStat',
config.get('version'),
on_start_update=lambda version: print_log('Found new mod version ' + version),
on_updated=update_end)

if not config.get('disableCopyToFuture'):
update_game_version(mod_name(), MOD_NAME_PREFIX)

if not config.get('disableAutoUpdate'):
update_mod_version(config.get('updateURL'), MOD_NAME_PREFIX,
config.get('version'),
on_start_update=lambda version: print_log('Found new mod version ' + version),
on_updated=update_end)

sessionStorage.on_load_mod()
wotHookEvents.onConnected += on_connected
Expand Down

0 comments on commit ee38143

Please sign in to comment.