paths.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import * as path from 'path'
  2. import * as fs from 'fs'
  3. import * as os from 'os'
  4. import { app } from 'electron'
  5. import { WE_APP_ID } from '@shared/constants'
  6. import { getConfiguredWorkshopPath } from '../services/config.service'
  7. export function getWorkshopPath(): string {
  8. return getConfiguredWorkshopPath() ?? getDefaultWorkshopPath()
  9. }
  10. export function getDefaultWorkshopPath(): string {
  11. const home = os.homedir()
  12. if (process.platform === 'linux') {
  13. const candidates = [
  14. path.join(home, '.steam', 'steam', 'steamapps', 'workshop', 'content', String(WE_APP_ID)),
  15. path.join(home, '.local', 'share', 'Steam', 'steamapps', 'workshop', 'content', String(WE_APP_ID))
  16. ]
  17. return candidates.find((p) => fs.existsSync(p)) ?? candidates[0]
  18. }
  19. if (process.platform === 'win32') {
  20. const workshopSuffix = path.join('Steam', 'steamapps', 'workshop', 'content', String(WE_APP_ID))
  21. const candidates = [
  22. path.join('C:', 'Program Files (x86)', workshopSuffix),
  23. path.join('C:', 'Program Files', workshopSuffix),
  24. path.join('C:', 'SteamLibrary', 'steamapps', 'workshop', 'content', String(WE_APP_ID)),
  25. path.join(os.homedir(), 'AppData', 'Local', workshopSuffix)
  26. ]
  27. return candidates.find((p) => fs.existsSync(p)) ?? candidates[0]
  28. }
  29. // macOS
  30. return path.join(
  31. home,
  32. 'Library',
  33. 'Application Support',
  34. 'Steam',
  35. 'steamapps',
  36. 'workshop',
  37. 'content',
  38. String(WE_APP_ID)
  39. )
  40. }
  41. export function getDataPath(): string {
  42. return app.getPath('userData')
  43. }
  44. export function getPreviewCachePath(): string {
  45. return path.join(getDataPath(), 'preview-cache')
  46. }
  47. /** Where a downloaded prebuilt engine lives, outside the app's own data so the AppImage and .deb share it */
  48. export function getLwePrebuiltDir(): string {
  49. const dataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share')
  50. return path.join(dataHome, 'linux-wallpaperengine-kde')
  51. }
  52. export function getLweManifestPath(): string {
  53. return path.join(getDataPath(), 'lwe-install-manifest.json')
  54. }
  55. export function getThumbnailsPath(): string {
  56. return path.join(getDataPath(), 'thumbnails')
  57. }