Skip to content

Commit

Permalink
Perform theme copy natively without recursive-copy (#901)
Browse files Browse the repository at this point in the history
There's some sort of issue with recursive-copy's interaction with Electron's ASAR-patched fs module.
  • Loading branch information
apetresc authored Sep 4, 2022
1 parent 003d60c commit a339b0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"pikaday": "^1.8.0",
"preact": "^10.4.0",
"react-markdown": "^8.0.3",
"recursive-copy": "^2.0.10",
"remark-breaks": "^3.0.2",
"rimraf": "^3.0.2",
"uuid": "^7.0.3",
Expand Down
15 changes: 10 additions & 5 deletions src/components/drawers/PreferencesDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import * as remote from '@electron/remote'
import {h, Component} from 'preact'
import classNames from 'classnames'
import {join} from 'path'
import copy from 'recursive-copy'
import rimraf from 'rimraf'
import {v4 as uuid} from 'uuid'
import natsort from 'natsort'

import i18n from '../../i18n.js'
import sabaki from '../../modules/sabaki.js'
import {showOpenDialog, showMessageBox} from '../../modules/dialog.js'
import {noop, isWritableDirectory} from '../../modules/helper.js'
import {
copyFolderSync,
noop,
isWritableDirectory
} from '../../modules/helper.js'
import * as gtplogger from '../../modules/gtplogger.js'
import Drawer from './Drawer.js'

Expand Down Expand Up @@ -449,12 +452,14 @@ class ThemesTab extends Component {

let id = uuid()

copy(result[0], join(setting.themesDirectory, id), err => {
if (err) return showMessageBox(t('Installation failed.'), 'error')
try {
copyFolderSync(result[0], join(setting.themesDirectory, id))

setting.loadThemes()
setting.set('theme.current', id)
})
} catch (err) {
return showMessageBox(t('Installation failed.'), 'error')
}
}

setting.events.on(sabaki.window.id, 'change', ({key, value}) => {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import {join} from 'path'

let id = 0

Expand Down Expand Up @@ -142,6 +143,17 @@ export function isWritableDirectory(path) {
}
}

export function copyFolderSync(from, to) {
fs.mkdirSync(to)
fs.readdirSync(from).forEach(element => {
if (fs.lstatSync(join(from, element)).isFile()) {
fs.copyFileSync(join(from, element), join(to, element))
} else {
copyFolderSync(join(from, element), join(to, element))
}
})
}

export function getScore(board, areaMap, {komi = 0, handicap = 0} = {}) {
let score = {
area: [0, 0],
Expand Down

0 comments on commit a339b0c

Please sign in to comment.