Пример #1
0
    def download(self, osname, arch, jname):
        farch = {'x86': '32', 'x64': '64'}.get(arch)
        info = self[osname][farch][jname]
        url = info['url']
        version = info['version']

        path = self.path / f'{jname}-{arch}/{version}'

        up = urlparse(url)  # type: ParseResult
        sha1_hash = info['sha1']
        name, ext = os.path.splitext(os.path.basename(up.path))

        with mktemp(ext, name + ".") as tpath:
            if not fetch(url, tpath):
                return False

            file_sha1_hash = calc_sha1_hash(tpath)
            if sha1_hash != file_sha1_hash:
                return False

            with lzma.open(tpath) as fp:
                zf = zipfile.ZipFile(fp, 'r')
                path.mkdir(parents=True, exist_ok=True)
                zf.extractall(path)

        return True
Пример #2
0
def build_launcher():
    DIST_FOLDER = Path('dist')
    LAUNCHER_DIR = (DIST_FOLDER / "launcher")

    json.loads((LAUNCHER_DIR / "options.txt").read_text())

    prev_hash = calc_sha1_hash(DIST_FOLDER / "SM-RE.exe")

    argv, sys.argv = sys.argv = ['...', 'bdist_exe']
    try:
        runpy.run_path("setup.py")
    finally:
        sys.argv = argv

    next_hash = calc_sha1_hash(DIST_FOLDER / "SM-RE.exe")

    if prev_hash != next_hash:
        shutil.copy((DIST_FOLDER / "SM-RE.exe"), LAUNCHER_DIR)
        return Path(shutil.make_archive("launcher", "zip", LAUNCHER_DIR))
    else:
        raise Exception("failure compile")
Пример #3
0
    def _check(self, path):
        obj_hash = self.info['hash']
        obj_size = self.info['size']

        if not path.exists():
            return False

        if path.stat().st_size != obj_size:
            return False

        if calc_sha1_hash(path) != obj_hash.lower():
            return False

        return True
Пример #4
0
    def sequence(self):
        result_set = {True}

        if not self.path.exists():
            self.path.mkdir(parents=True, exist_ok=True)

        donefile = self.path / 'modpack.done'
        if self.is_fresh or not donefile.exists():
            if donefile.exists():
                donefile.unlink()
            self._download_files()
            donefile.touch()

        keepmods = self.path / 'keepmods'
        if not keepmods.is_dir():
            keepmods.mkdir(exist_ok=True)

        has_keepmods = False
        mods = self.path / 'mods'
        for src in keepmods.rglob("**/*"):  # type: Path
            has_keepmods = True
            dst: Path = mods / src.relative_to(keepmods)
            if src.stat().st_size == 0:
                if dst.exists():
                    dst.unlink()
            elif not dst.exists() or calc_sha1_hash(src) != calc_sha1_hash(
                    dst):
                if not dst.parent.exists():
                    dst.parent.mkdir(exist_ok=True, parents=True)

                shutil.copy(str(src), str(dst))

        if has_keepmods:
            result_set.add("has_keepmods")

        return result_set
Пример #5
0
def minecraft_build(mc_version, forge_version, path_lib: Path,
                    url_builder) -> MojangMinecraftJson:
    mm = MojangMinecraftPackage(Path(os.environ["APPDATA"]) / '.minecraft')
    name = f'{mc_version}-{forge_version}'

    release_time = current_time()
    modpack_version_info = {
        'id': name,
        'inheritsFrom': name,
        'releaseTime': release_time,
        'time': release_time,
        'type': 'release',
    }

    mc_pack = mm.build(name, modpack_version_info)
    mc_lib_path = mc_pack.path / 'libraries'
    for library in mc_pack['libraries']:
        if library.get('url') or library.get('serverreq') or library.get(
                'clientreq'):
            download = MavenDownload(
                MavenDownload._get_maven_download(library, library['name']))

            source = mc_pack.path / download.path
            if not source.exists():
                print("warning", source, "missing")
                raise Exception(source)

            rpath = source.relative_to(mc_lib_path)
            target = path_lib / rpath
            target.parent.mkdir(parents=True, exist_ok=True)

            shutil.copy(source, target)

            file_sha1_hash = calc_sha1_hash(target)
            file_size = target.stat().st_size

            artifact = library.setdefault('downloads',
                                          {}).setdefault('artifact', {})
            artifact.update({
                'sha1': file_sha1_hash,
                'size': file_size,
                'path': str(rpath.as_posix()),
                'url': url_builder(target),
            })

    return mc_pack
Пример #6
0
def build_files(path: Path, url_builder):
    files = []
    for file in path.glob("**/*"):  # type: Path
        if file.is_file():
            file_size = file.stat().st_size
            file_sha1_hash = calc_sha1_hash(file)
            file_info = {
                'url': url_builder(file),
                'path': file.relative_to(path).as_posix(),
                'sha1': file_sha1_hash,
                'size': file_size,
            }

            files.append(file_info)

    return {
        'files': files,
    }