From dfc9e4688d4c177db6175981f8f0aa99f3242605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=B1=E9=A2=A8=E8=B0=B7=E3=82=AA=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A3=E3=83=B3?= Date: Fri, 20 Sep 2024 01:08:15 +0900 Subject: [PATCH] feat: enable resource hack for main window --- views/utils/ship-img.es | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/views/utils/ship-img.es b/views/utils/ship-img.es index fc83b7a55..8bf2dbd36 100644 --- a/views/utils/ship-img.es +++ b/views/utils/ship-img.es @@ -1,4 +1,39 @@ +/* global config */ import { padStart } from 'lodash' +import * as remote from '@electron/remote' +import path from 'path-extra' +import fs from 'fs-extra' +import url from 'url' + +const getCachePath = (pathname = '') => { + const dir = config.get('poi.misc.cache.path', remote.getGlobal('DEFAULT_CACHE_PATH')) + return path.join(dir, pathname) +} + +const findHackFilePath = (pathname = '') => { + const originFilePath = getCachePath(path.join('KanColle', pathname)) + const sp = originFilePath.split('.') + const ext = sp.pop() + sp.push('hack') + if (ext) { + sp.push(ext) + } + const hackedFilePath = sp.join('.') + try { + fs.accessSync(hackedFilePath, fs.constants.R_OK) + return hackedFilePath + } catch (e) { + try { + fs.accessSync(originFilePath, fs.constants.R_OK) + return originFilePath + } catch (e) { + return undefined + } + } +} + +const pathToFileURL = (filePath = '') => + url.pathToFileURL(filePath.split(path.sep).join(path.posix.sep)) export const shipImgType = [ 'banner', @@ -62,6 +97,10 @@ function create(id, seed) { } function join(ip, base, version) { + const hackedPath = findHackFilePath(base) + if (hackedPath) { + return pathToFileURL(hackedPath).href + } if (!ip) { return base }