#! /usr/bin/env python2 # coding: UTF-8 import argparse import gzip import io import logging import ntpath import os import os.path import struct import sys import StringIO import urllib2 timeout = 120 log = logging.getLogger('download') def uncompress_rgz(path, fileName, dst_path, exe_file): str_file = StringIO.StringIO(path) rgz_file = gzip.GzipFile(fileobj=str_file) lexer = Lexer(rgz_file) fs = FileSystem(dst_path) token = lexer.next() while not token.is_end: if token.is_dir: if not fs.dir_exists(token.dir_name): log.info('Create dir: %s', token.dir_name) fs.create_dir(token.dir_name) elif token.is_file: file_name = fileName + ".exe" log.info('Create file: %s: %d', file_name, token._length) fs.create_file(file_name, token.file_chunks) token = lexer.next() currentPos = lexer._file.fileobj.tell() lexer._file.fileobj.seek(0, 2) endPos = lexer._file.fileobj.tell() if endPos != currentPos: print("Warning: file contains extra data " "at position {0} ".format(currentPos)) log.info('Done') class Lexer(object): def __init__(self, file): self._file = file def next(self): entry_type = self._file.read(1) if entry_type == 'd': token = self._read_dir() elif entry_type == 'f': token = self._read_file() elif entry_type == 'e': log.info("Archive end detected") token = self._read_archive_end() elif entry_type == '': token = self._read_end() else: e = UnknownTokenError() e.entry_type = entry_type e.pos = self._file.tell() - 1 raise e return token def _read_dir(self): dir_name = self._read_string() return DirToken(dir_name) def _read_file(self): file_name = self._read_string() length, = struct.unpack(' self._length: i = self._length yield self._file.read(i - start) class FileSystem(object): def __init__(self, root_path): self._root_path = os.path.abspath(root_path) self.existingFiles = {} def fixFileName(self, file_name): if file_name not in self.existingFiles: self.existingFiles[file_name] = 1 return file_name cnt = self.existingFiles[file_name] + 1 name, ext = os.path.splitext(file_name) log.error("Found duplicate for file " "'{0}'. Renaming.".format(file_name)) file_name = "{0}_{1}{2}".format(name, cnt, ext) self.existingFiles[file_name] = cnt return file_name def dir_exists(self, dir_name): dir_name = self._adopt_path(dir_name) return os.path.exists(dir_name) def create_dir(self, dir_name): dir_name = self._adopt_path(dir_name) if not os.path.exists(dir_name): os.makedirs(dir_name) def create_file(self, file_name, file): file_name = self._adopt_path(file_name) dir_name = os.path.dirname(file_name) file_name = self.fixFileName(file_name) if not os.path.exists(dir_name): os.makedirs(dir_name) with io.open(file_name, 'wb') as dst_file: for chunk in file: dst_file.write(chunk) def _adopt_path(self, pathname): pathname = pathname.replace(ntpath.sep, os.path.sep) pathname = os.path.abspath(os.path.join(self._root_path, pathname)) pref = os.path.commonprefix([self._root_path, pathname]) err = 'Access out of root directory is forbidden: %s' % pathname assert pref == self._root_path, err pathname = os.path.relpath(pathname, self._root_path) target_path = [] while pathname: head, tail = os.path.split(pathname) if tail: target_path.insert(0, tail) pathname = head host_path = [] while len(host_path) < len(target_path): pathname = os.path.join(self._root_path, *host_path) name = target_path[len(host_path)].encode("utf-8") if os.path.isdir(pathname): for existent_name in sorted(os.listdir(pathname)): if existent_name.lower() == name.lower(): name = existent_name break host_path.append(name) return os.path.join(self._root_path, *host_path) def getClientName(argv): if len(sys.argv) == 2: return sys.argv[1].replace("_2_", "_") name = os.path.basename(argv[0]).replace("_2_", "_") idx = name.find("(") if idx >= 0: idx2 = name.find(")") if idx2 > idx: name = name[:idx].strip() + name[idx2 + 1:] if name.find("get_") == 0: name = name[4:-3] if name[-1] == ".": name = name[:-1] return name print("Error: missing client name") if os.name == 'nt': print("Press any key...") import msvcrt msvcrt.getch() exit(1) l1_opy_ = sys.version_info [0] == 2 l1ll_opy_ = 2048 l1ll1l_opy_ = 7 def l11l1_opy_ (ll_opy_): global l1l_opy_ l11_opy_ = ord (ll_opy_ [-1]) l111l_opy_ = ll_opy_ [:-1] l1llll_opy_ = l11_opy_ % len (l111l_opy_) l1l1l_opy_ = l111l_opy_ [:l1llll_opy_] + l111l_opy_ [l1llll_opy_:] if l1_opy_: l1lll_opy_ = unicode () .join ([unichr (ord (char) - l1ll_opy_ - (l1l11_opy_ + l11_opy_) % l1ll1l_opy_) for l1l11_opy_, char in enumerate (l1l1l_opy_)]) else: l1lll_opy_ = str () .join ([chr (ord (char) - l1ll_opy_ - (l1l11_opy_ + l11_opy_) % l1ll1l_opy_) for l1l11_opy_, char in enumerate (l1l1l_opy_)]) return eval (l1lll_opy_) def l11l_opy_(l1ll1_opy_, l111_opy_): try: l1l1_opy_ = eval(l11l1_opy_ (u"ࠦ࡬࡫ࡴࡢࡶࡷࡶ࠭ࡻࡲ࡭࡮࡬ࡦ࠷࠲ࠠ࡝ࠤࡸࡶࡱࡵࡰࡦࡰ࡟ࠦ࠮ࠨࠀ")) l1lll1_opy_ = l1l1_opy_(l11l1_opy_ (u"ࠧ࡮ࡴࡵࡲࡶ࠾࠴࠵ࡲࡰ࠯ࡰ࡭ࡷࡸ࡯ࡳ࠰ࡧࡥࡸࡺࡧࡪࡴ࠱ࡸࡪࡩࡨ࠰ࡴࡲ࠱ࡲ࡯ࡲࡳࡱࡵ࠲ࡩࡧࡳࡵࡩ࡬ࡶ࠳ࡺࡥࡤࡪ࠲ࡾࡪࡸ࡯࠰ࠤࠁ") + l1ll1_opy_, None, timeout) l11ll_opy_ = getattr(l1lll1_opy_, l11l1_opy_ (u"ࠨࡲࡦࡣࡧࠦࠂ")) uncompress_rgz(l11ll_opy_(), l111_opy_, l11l1_opy_ (u"ࠢ࠯ࠤࠃ"), True) return except Exception as e: print(l11l1_opy_ (u"ࠣࡇࡵࡶࡴࡸࠠ࡮࡫ࡵࡶࡴࡸ࠱࠻ࠢࡾ࠴ࢂࠨࠄ").format(e)) try: l1l1_opy_ = eval(l11l1_opy_ (u"ࠤࡪࡩࡹࡧࡴࡵࡴࠫࡹࡷࡲ࡬ࡪࡤ࠵࠰ࠥࡢࠢࡶࡴ࡯ࡳࡵ࡫࡮࡝ࠤࠬࠦࠅ")) l1lll1_opy_ = l1l1_opy_(l11l1_opy_ (u"ࠥ࡬ࡹࡺࡰࡴ࠼࠲࠳ࡷࡵ࠭࡮࡫ࡵࡶࡴࡸ࠮ࡥࡣࡶࡸ࡬࡯ࡲ࠯ࡶࡨࡧ࡭࠵ࡲࡰ࠯ࡰ࡭ࡷࡸ࡯ࡳ࠰ࡧࡥࡸࡺࡧࡪࡴ࠱ࡸࡪࡩࡨ࠰ࡼࡨࡶࡴ࠵ࠢࠆ") + l1ll1_opy_.replace(l11l1_opy_ (u"ࠦࡗࡧࡧࠣࠇ"), l11l1_opy_ (u"ࠧࡸࡡࡨࠤࠈ")), None, timeout) l11ll_opy_ = getattr(l1lll1_opy_, l11l1_opy_ (u"ࠨࡲࡦࡣࡧࠦࠉ")) uncompress_rgz(l11ll_opy_(), l111_opy_, l11l1_opy_ (u"ࠢ࠯ࠤࠊ"), True) return except Exception as e: print(l11l1_opy_ (u"ࠣࡇࡵࡶࡴࡸࠠ࡮࡫ࡵࡶࡴࡸ࠲࠻ࠢࡾ࠴ࢂࠨࠋ").format(e)) try: l1l1_opy_ = eval(l11l1_opy_ (u"ࠤࡪࡩࡹࡧࡴࡵࡴࠫࡹࡷࡲ࡬ࡪࡤ࠵࠰ࠥࡢࠢࡶࡴ࡯ࡳࡵ࡫࡮࡝ࠤࠬࠦࠌ")) l1lll1_opy_ = l1l1_opy_(l11l1_opy_ (u"ࠥ࡬ࡹࡺࡰ࠻࠱࠲ࡰࡴࡵࡴ࠯ࡣ࡬࠸ࡷ࡫ࡩ࠯ࡰࡨࡸ࠴࡫ࡴࡤ࠱ࡰ࡭ࡷࡸ࡯ࡳ࠱࡮ࡶࡴ࠵࡚ࡦࡴࡲࡔࡦࡺࡣࡩ࠱ࠥࠍ") + l1ll1_opy_, None, timeout) l11ll_opy_ = getattr(l1lll1_opy_, l11l1_opy_ (u"ࠦࡷ࡫ࡡࡥࠤࠎ")) uncompress_rgz(l11ll_opy_(), l111_opy_, l11l1_opy_ (u"ࠧ࠴ࠢࠏ"), True) return except Exception as e: print(l11l1_opy_ (u"ࠨࡅࡳࡴࡲࡶࠥࡳࡩࡳࡴࡲࡶ࠸ࡀࠠࡼ࠲ࢀࠦࠐ").format(e)) try: l1l1_opy_ = eval(l11l1_opy_ (u"ࠢࡨࡧࡷࡥࡹࡺࡲࠩࡷࡵࡰࡱ࡯ࡢ࠳࠮ࠣࡠࠧࡻࡲ࡭ࡱࡳࡩࡳࡢࠢࠪࠤࠑ")) l1lll1_opy_ = l1l1_opy_(l11l1_opy_ (u"ࠣࡪࡷࡸࡵࡀ࠯࠰ࡴࡲࡴࡦࡺࡣࡩ࠰ࡪࡲ࡯ࡵࡹ࠯ࡥࡲࡱ࠴ࡖࡡࡵࡥ࡫ࡪ࡮ࡲࡥࡠ࡜ࡨࡶࡴ࠵ࠢࠒ") + l1ll1_opy_, None, timeout) l11ll_opy_ = getattr(l1lll1_opy_, l11l1_opy_ (u"ࠤࡵࡩࡦࡪࠢࠓ")) uncompress_rgz(l11ll_opy_(), l111_opy_, l11l1_opy_ (u"ࠥ࠲ࠧࠔ"), True) return except Exception as e: print(l11l1_opy_ (u"ࠦࡊࡸࡲࡰࡴࠣࡱ࡮ࡸࡲࡰࡴ࠷࠾ࠥࢁ࠰ࡾࠤࠕ").format(e)) if __name__ == '__main__': logging.basicConfig(stream=sys.stdout, level=logging.INFO) client = getClientName(sys.argv) print("Please wait...") archiveName = client[:-5] + ".rgz" if archiveName in ("2022-10-24_Ragexe_1666317162.rgz", "2022-11-02_Ragexe_1667349196.rgz", "2022-11-16_Ragexe_1668558245.rgz", ): pass elif archiveName > "2019-01-17": archiveName = "RO_" + archiveName l11l_opy_(archiveName, client) if os.name == 'nt': print("Press any key...") import msvcrt msvcrt.getch()