files.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const fs = require('fs');
  2. const path = require('path');
  3. const tiny = require("@peterpanhihi/tiny");
  4. const getFilesIn = require('get-files-in')
  5. const globalVariables = require('../lib/globalVars');
  6. const Language = require("@shypes/language-translator");
  7. const settings = require("settings-store");
  8. Language.setActiveLang(settings.value("Lang"))
  9. module.exports = {
  10. getCurrentDirectoryBase: () => {
  11. return path.basename(process.cwd());
  12. },
  13. directoryExists: (filePath) => {
  14. return fs.existsSync(filePath);
  15. },
  16. writeIpAddress: (value) => {
  17. const data = {
  18. ipAddress: value
  19. }
  20. try {
  21. fs.writeFileSync('./data/options.json', JSON.stringify(data))
  22. } catch (err) {
  23. console.log(err)
  24. }
  25. },
  26. loadPackageList: () => {
  27. try {
  28. const packageList = JSON.parse(fs.readFileSync('./data/xiaomiPackageRemovalList.json', 'utf8'));
  29. return packageList
  30. } catch (err) {
  31. console.log(err)
  32. }
  33. },
  34. renameLocalApk: async (apkList) => {
  35. return new Promise(function (resolve, reject) {
  36. for (let e of apkList) {
  37. a = tiny(e)
  38. fs.rename(e, a, function (err) {
  39. if (err) console.log('ERROR: ' + err);
  40. });
  41. }
  42. resolve(x / y);
  43. }).catch(err => NaN)
  44. },
  45. getListOfAPk: (path) => {
  46. const result = getFilesIn(path, matchFiletypes = ["apk"], checkSubDirectories = false)
  47. return result
  48. },
  49. getLanguageFiles: () => {
  50. const result = getFilesIn('./lang/', matchFiletypes = ["json"], checkSubDirectories = false)
  51. return result
  52. },
  53. }