Skip to content

Commit

Permalink
v2.6.1: Fix adding of mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibowl committed Jul 16, 2020
1 parent 1689e18 commit 01b21cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kccacheproxy",
"productName": "KCCacheProxy",
"version": "2.6.0",
"version": "2.6.1",
"description": "KanColle caching proxy",
"main": "src/electron/index.js",
"scripts": {
Expand Down
39 changes: 21 additions & 18 deletions src/electron/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
const { remote, ipcRenderer, shell } = require ("electron")
const { join, basename } = require("path")
const { join } = require("path")
const { readFileSync, existsSync } = require("fs-extra")
const fetch = require("node-fetch")

Expand Down Expand Up @@ -571,6 +571,17 @@ function updateHelp(toUpdate) {
if (helpSequence.has("mainHit") && helpSequence.has("versionHit"))
document.getElementById("loading").style = "display: none;"
}

function getModPath() {
return config.mods.length > 0 ? join(config.mods[config.mods.length - 1].path, "..") : undefined
}
function getImgCachePath() {
let cachePath = config.cacheLocation
if (config.cacheLocation == undefined || config.cacheLocation == "default")
cachePath = join(remote.app.getPath("userData"), "ProxyData", "cache")
cachePath = join(cachePath, "kcs2", "img")
return cachePath
}
for (const type of ["importCache", "reloadCache", "checkVersion", "prepatch"])
document.getElementById(type).onclick = () => ipcRenderer.send(type)

Expand Down Expand Up @@ -640,18 +651,18 @@ document.getElementById("addMod").onclick = async () => {
title: "Select a mod metadata file",
filters: [{
name: "Mod metadata",
defaultPath: config.mods.length > 0 ? join(config.mods[config.mods.length - 1], "..") : undefined,
defaultPath: getModPath(),
extensions: ["mod.json"]
}],
properties: ["openFile"]
})
if (response.canceled) return

if (config.mods.includes(response.filePaths[0])) {
if (config.mods.map(m => m.path).includes(response.filePaths[0])) {
addLog("error", new Date(), "Already added")
return
}
config.mods.push(response.filePaths[0])
config.mods.push({ path: response.filePaths[0] })
ipcRenderer.send("setConfig", config)
ipcRenderer.send("reloadModCache")
updateHidden()
Expand All @@ -661,11 +672,7 @@ document.getElementById("reloadMods").onclick = () => {
ipcRenderer.send("reloadModCache")
}
document.getElementById("extractSpritesheet").onclick = async () => {
let cachePath = config.cacheLocation
if (config.cacheLocation == undefined || config.cacheLocation == "default")
cachePath = join(remote.app.getPath("userData"), "ProxyData", "cache")
cachePath = join(cachePath, "kcs2", "img")

const cachePath = getImgCachePath()
const source = await remote.dialog.showOpenDialog({
title: "Select a spritesheet",
defaultPath: cachePath,
Expand All @@ -679,19 +686,15 @@ document.getElementById("extractSpritesheet").onclick = async () => {

const target = await remote.dialog.showOpenDialog({
title: "Select a folder to extract to",
defaultPath: config.mods.length > 0 ? join(config.mods[config.mods.length - 1], "..") : undefined,
defaultPath: getModPath(),
properties: ["openDirectory"]
})
if (target.canceled) return

ipcRenderer.send("extractSpritesheet", source.filePaths[0], target.filePaths[0])
}
document.getElementById("outlines").onclick = async () => {
let cachePath = config.cacheLocation
if (config.cacheLocation == undefined || config.cacheLocation == "default")
cachePath = join(remote.app.getPath("userData"), "ProxyData", "cache")
cachePath = join(cachePath, "kcs2", "img")

const cachePath = getImgCachePath()
const source = await remote.dialog.showOpenDialog({
title: "Select a spritesheet",
defaultPath: cachePath,
Expand All @@ -705,7 +708,7 @@ document.getElementById("outlines").onclick = async () => {

const target = await remote.dialog.showSaveDialog({
title: "Select a location to save outlines to",
defaultPath: config.mods.length > 0 ? join(config.mods[config.mods.length - 1], "..", basename(source.filePaths[0])) : undefined,
defaultPath: getModPath(),
filters: [{
name: "Images",
extensions: ["png"]
Expand All @@ -718,14 +721,14 @@ document.getElementById("outlines").onclick = async () => {
document.getElementById("importExternalMod").onclick = async () => {
const source = await remote.dialog.showOpenDialog({
title: "Select cache folder to import from",
defaultPath: config.mods.length > 0 ? join(config.mods[config.mods.length - 1], "..") : undefined,
defaultPath: getModPath(),
properties: ["openDirectory"]
})
if (source.canceled) return

const target = await remote.dialog.showOpenDialog({
title: "Select a folder to export to",
defaultPath: config.mods.length > 0 ? join(config.mods[config.mods.length - 1], "..") : undefined,
defaultPath: getModPath(),
properties: ["openDirectory"]
})
if (target.canceled) return
Expand Down

0 comments on commit 01b21cf

Please sign in to comment.