<template>
  <div>
    <!-- 用于更新静态文件 -->
  </div>
</template>

<script>
const Store = require('electron-store')
const localStore = new Store()

const fs = require('fs-extra')
const fc = require('filecompare')
const path = require('path')

const updateFiles = [
  {
    from: path.join(__static, 'pos', 'MisPos.dll'),
    to: path.join(localStore.get('softposPath') || '', 'MisPos.dll')
  }
//   {
//     from: path.join(__static, 'pos', 'test.txt'),
//     to: path.join(localStore.get('softposPath'), 'test.txt')
//   }
]

export default {
  created () {
    this.updateFile()
  },
  methods: {
    updateFile () {
      updateFiles.forEach(item => {
        let fromExist = fs.existsSync(item.from)
        let toExist = fs.existsSync(item.to)
        if (!fromExist || !toExist) return

        // 比较文件
        fc(item.from, item.to, (isEqual) => {
          if (!isEqual) {
            this.$log.info(`更新文件 ${item.to}`)
            // 替换文件
            fs.copySync(item.from, item.to)
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
