Skip to content

Commit

Permalink
fix(main): 纠正缓存目录位置
Browse files Browse the repository at this point in the history
Rocket1184#128
抄的

(2333
  • Loading branch information
KoishiMoe committed Apr 27, 2022
1 parent e9ec62c commit dffdff5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/api/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Cache {
constructor(path, configPath) {
if (typeof path === 'string') {
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
fs.mkdirSync(path, {recursive: true});
} else if (!fs.statSync(path).isDirectory()) {
throw new Error(`[Cache] '${path}' was taken by unknown file. Please remove it manually.`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const BaseURL = 'https://music.163.com';
const client = new Client();

const dataPath = app.getPath('userData');
const cachePath = app.getPath('cache');
const CachePath = {
all: dataPath,
music: path.join(dataPath, 'musicCache')
music: path.join(cachePath, 'electron-netease-cloud-music' ,'musicCache')
};
const musicCache = new Cache(CachePath.music, dataPath);
migrate();
Expand Down
6 changes: 6 additions & 0 deletions src/main/api/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ function clearLegacyLyricCache() {
});
}

function clearLegacyMusicCache() {
const dataPath = app.getPath('userData');
fs.rmSync(path.join(dataPath, 'musicCache'), {recursive: true, force: true});
}

export default function migrate() {
clearLegacyLyricCache();
clearLegacyMusicCache();
}

0 comments on commit dffdff5

Please sign in to comment.