Skip to content

Commit

Permalink
Use separate map and mod downloaders
Browse files Browse the repository at this point in the history
Also gives each of them a new separate cache directory, so there is no
risk of name collision.

Signed-off-by: Igor Kotrasinski <[email protected]>
  • Loading branch information
Wesmania committed Jan 19, 2018
1 parent 6780204 commit ecf3715
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/client/_clientwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def __init__(self, *args, **kwargs):
# Handy reference to the User object representing the logged-in user.
self.me = User(self.players)

self.map_downloader = PreviewDownloader(util.CACHE_DIR, MAP_PREVIEW_ROOT)
self.map_downloader = PreviewDownloader(util.MAP_PREVIEW_DIR, MAP_PREVIEW_ROOT)
self.mod_downloader = PreviewDownloader(util.MOD_PREVIEW_DIR, None)

# Qt model for displaying active games.
self.game_model = GameModel(self.me, self.map_downloader, self.gameset)
Expand Down
2 changes: 1 addition & 1 deletion src/modvault/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def update(self, dic):
if img:
self.setIcon(util.THEME.icon(img, False))
else:
self.parent.client.map_downloader.download_preview(name, self._map_dl_request, self.thumbstr)
self.parent.client.mod_downloader.download_preview(name, self._map_dl_request, self.thumbstr)
self.updateVisibility()

def _on_mod_downloaded(self, modname, result):
Expand Down
30 changes: 8 additions & 22 deletions src/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def developer():
# This contains cached data downloaded while communicating with the lobby - at the moment, mostly map preview pngs.
CACHE_DIR = os.path.join(APPDATA_DIR, "cache")

MAP_PREVIEW_DIR = os.path.join(CACHE_DIR, "map_previews")
MOD_PREVIEW_DIR = os.path.join(CACHE_DIR, "mod_previews")

# This contains cached data downloaded for FA extras
EXTRA_DIR = os.path.join(APPDATA_DIR, "extra")

Expand Down Expand Up @@ -114,29 +117,12 @@ def developer():
logger.info('PERSONAL_DIR final: ' + PERSONAL_DIR)

# Ensure Application data directories exist
if not os.path.isdir(APPDATA_DIR):
os.makedirs(APPDATA_DIR)

if not os.path.isdir(PERSONAL_DIR):
os.makedirs(PERSONAL_DIR)

if not os.path.isdir(LUA_DIR):
os.makedirs(LUA_DIR)

if not os.path.isdir(CACHE_DIR):
os.makedirs(CACHE_DIR)

if not os.path.isdir(THEME_DIR):
os.makedirs(THEME_DIR)

if not os.path.isdir(REPLAY_DIR):
os.makedirs(REPLAY_DIR)

if not os.path.isdir(LOG_DIR):
os.makedirs(LOG_DIR)

if not os.path.isdir(EXTRA_DIR):
os.makedirs(EXTRA_DIR)
for data_dir in [APPDATA_DIR, PERSONAL_DIR, LUA_DIR, CACHE_DIR,
MAP_PREVIEW_DIR, MOD_PREVIEW_DIR, THEME_DIR, REPLAY_DIR,
LOG_DIR, EXTRA_DIR]:
if not os.path.isdir(data_dir):
os.makedirs(data_dir)

from PyQt5 import QtWidgets
from PyQt5.uic import *
Expand Down

0 comments on commit ecf3715

Please sign in to comment.