mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
🎨 Prompt when the user attempts to create a workspace in the root directory of the disk https://github.com/siyuan-note/siyuan/issues/15976
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
33216b093d
commit
dbf5a3e198
1 changed files with 48 additions and 0 deletions
|
|
@ -383,6 +383,24 @@
|
||||||
}
|
}
|
||||||
const initPath = result.filePaths[0]
|
const initPath = result.filePaths[0]
|
||||||
|
|
||||||
|
if (isPartitionRootPath(initPath)) {
|
||||||
|
let msg = '⚠️ Do not create the workspace in the partition root path, please create a new folder as the workspace'
|
||||||
|
if (isChinese(currentLang)) {
|
||||||
|
msg = '⚠️ 请勿在分区根路径上创建工作空间,请新建一个文件夹作为工作空间'
|
||||||
|
}
|
||||||
|
alert(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isWorkspaceDir(initPath) && !isEmptyDir(initPath)) {
|
||||||
|
let msg = '⚠️ This folder contains other files, please create a new folder as the workspace'
|
||||||
|
if (isChinese(currentLang)) {
|
||||||
|
msg = '⚠️ 该文件夹包含了其他文件,请新建一个文件夹作为工作空间'
|
||||||
|
}
|
||||||
|
alert(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (isICloudPath(initPath)) {
|
if (isICloudPath(initPath)) {
|
||||||
let msg = '⚠️ This folder is under the iCloud sync path, please change another path'
|
let msg = '⚠️ This folder is under the iCloud sync path, please change another path'
|
||||||
if (isChinese(currentLang)) {
|
if (isChinese(currentLang)) {
|
||||||
|
|
@ -417,6 +435,36 @@
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isPartitionRootPath = (absPath) => {
|
||||||
|
const path = require('path')
|
||||||
|
const parsedPath = path.parse(absPath)
|
||||||
|
return parsedPath.root === absPath
|
||||||
|
}
|
||||||
|
|
||||||
|
const isEmptyDir = (absPath) => {
|
||||||
|
const fs = require('fs')
|
||||||
|
let files;
|
||||||
|
try {
|
||||||
|
files = fs.readdirSync(absPath)
|
||||||
|
} catch (err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return 0 === files.length
|
||||||
|
}
|
||||||
|
|
||||||
|
const isWorkspaceDir = (absPath) => {
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const conf = path.join(absPath, 'conf', 'conf.json');
|
||||||
|
let data;
|
||||||
|
try {
|
||||||
|
data = fs.readFileSync(conf, 'utf8');
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return data.includes('kernelVersion');
|
||||||
|
}
|
||||||
|
|
||||||
const isCloudDrivePath = (absPath) => {
|
const isCloudDrivePath = (absPath) => {
|
||||||
const absPathLower = absPath.toLowerCase()
|
const absPathLower = absPath.toLowerCase()
|
||||||
return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") ||
|
return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue