 Promise = require 'bluebird'
 path = require 'path'
 async = Promise.coroutine
-fs = Promise.promisifyAll require('fs-extra'), { multiArgs: true }
+fs = require('fs-extra')
 request = Promise.promisifyAll require('request'), { multiArgs: true }
 {Traditionalized} = require './traditionalized'
 dbg.extra('subtitlesAudioResponse')

  i18n['poi-plugin-subtitle-data'].setLocale(locale)
  ___ = i18n["poi-plugin-subtitle-data"].__.bind(i18n["poi-plugin-subtitle-data"])

loadSubtitles = async (_path) ->
  [err] = yield fs.ensureFileAsync _path
  [data] = yield fs.readFileAsync _path
  data = "{}" if not data or data.length is 0
  JSON.parse data

loadBackupSubtitles = async (locale) ->
  abbr = locale[...2]
  if abbr is 'zh'
    [dataBackup] = yield fs.readFileAsync subtitlesBackupPath['zh-CN']
    subtitlesBackup = JSON.parse dataBackup
    if not subtitles['zh-CN']?.version or +subtitles['zh-CN']?.version < +subtitlesBackup?.version or not subtitles['zh-TW']?.version
      data = dataBackup
      subtitles['zh-CN'] = subtitlesBackup
      [err] = yield fs.writeFileAsync subtitlesI18nPath['zh-CN'], data
      # Convert backup subtitle to zh-TW and save
      subtitles['zh-TW'] = {}
      for shipIdOrSth, value of subtitlesBackup

      window.success "#{__('Update Success')}(#{version})",
        stickyFor: 3000
    for lang in langs
      fs.writeFileSync subtitlesI18nPath[lang], JSON.stringify(subtitles[lang], null, '\t')
  catch e
    if e instanceof Error
      console.error "#{e.name}: #{e.message}\n#{e.stack}"
    else
      console.error e
    if locale isnt 'zh-TW'
      fs.writeFileSync subtitlesI18nPath[locale], dataBackup[locale]
      subtitles[locale] = JSON.parse dataBackup[locale]
    # window.warn "语音字幕自动更新失败，请联系有关开发人员，并手动更新插件以更新字幕数据",
    #   stickyFor: 5000
