paths.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. const sys_host_path = platform == 'win32' ?
  10. `${process.env.windir || 'C:\\WINDOWS'}\\system32\\drivers\\etc\\hosts` : // Windows 系统有可能不安装在 C 盘
  11. '/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. };