Module.preRun = Module.preRun || [];
Module.preRun.push(() => {
  for (const path of [
    '/freecad-user',
    '/freecad-user/config',
    '/freecad-user/data',
    '/freecad-user/cache',
    '/freecad-user/temp',
  ]) {
    try {
      FS.mkdir(path)
    } catch (error) {
      if (!FS.analyzePath(path).exists) throw error
    }
  }
  Object.assign(ENV, {
    HOME: '/freecad-user',
    FREECAD_USER_HOME: '/freecad-user',
    FREECAD_USER_DATA: '/freecad-user/data',
    FREECAD_USER_TEMP: '/freecad-user/temp',
    XDG_CONFIG_HOME: '/freecad-user/config',
    XDG_DATA_HOME: '/freecad-user/data',
    XDG_CACHE_HOME: '/freecad-user/cache',
    TMPDIR: '/freecad-user/temp',
  })
})
