paths.js 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. 'use strict'
  6. const path = require('path')
  7. const io = require('./io')
  8. const platform = process.platform
  9. // Windows 系统有可能不安装在 C 盘
  10. const sys_host_path = platform === 'win32' ? `${process.env.windir ||
  11. 'C:\\WINDOWS'}\\system32\\drivers\\etc\\hosts` : '/etc/hosts'
  12. const home_path = io.getUserHome()
  13. const work_path = path.join(home_path, '.SwitchHosts')
  14. const data_path = path.join(work_path, 'data.json')
  15. const preference_path = path.join(work_path, 'preferences.json')
  16. function getCurrentAppPath () {
  17. let a = __dirname.split(path.sep)
  18. // console.log(a);
  19. while (a.length > 0) {
  20. let i = a[a.length - 1]
  21. if (i.endsWith('.app')) {
  22. return a.join(path.sep)
  23. }
  24. a.pop()
  25. }
  26. return null
  27. }
  28. module.exports = {
  29. home_path: home_path
  30. , work_path: work_path
  31. , data_path: data_path
  32. , preference_path: preference_path
  33. , sys_host_path: sys_host_path
  34. // ,current_app_path: getCurrentAppPath()
  35. }