mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 改进 Windows 端第三方同步盘检测 Fix https://github.com/siyuan-note/siyuan/issues/7777
This commit is contained in:
parent
b4395bfca4
commit
e94be5f59c
2 changed files with 83 additions and 5 deletions
|
|
@ -393,7 +393,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") ||
|
return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") ||
|
||||||
-1 < absPathLower.indexOf("google drive") || -1 < absPathLower.indexOf("pcloud")
|
-1 < absPathLower.indexOf("google drive") || -1 < absPathLower.indexOf("pcloud") ||
|
||||||
|
-1 < absPathLower.indexOf("坚果云")
|
||||||
}
|
}
|
||||||
|
|
||||||
const isICloudPath = (absPath) => {
|
const isICloudPath = (absPath) => {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -251,11 +252,24 @@ func IsCloudDrivePath(workspaceAbsPath string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Contains(absPathLower, "onedrive") || strings.Contains(absPathLower, "dropbox") ||
|
if isKnownCloudDrivePath(absPathLower) {
|
||||||
strings.Contains(absPathLower, "google drive") || strings.Contains(absPathLower, "pcloud")
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func isICloudPath(workspaceAbsPath string) (ret bool) {
|
if existAvailabilityStatus(workspaceAbsPath) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isKnownCloudDrivePath(workspaceAbsPathLower string) bool {
|
||||||
|
return strings.Contains(workspaceAbsPathLower, "onedrive") || strings.Contains(workspaceAbsPathLower, "dropbox") ||
|
||||||
|
strings.Contains(workspaceAbsPathLower, "google drive") || strings.Contains(workspaceAbsPathLower, "pcloud") ||
|
||||||
|
strings.Contains(workspaceAbsPathLower, "坚果云")
|
||||||
|
}
|
||||||
|
|
||||||
|
func isICloudPath(workspaceAbsPathLower string) (ret bool) {
|
||||||
if !gulu.OS.IsDarwin() {
|
if !gulu.OS.IsDarwin() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +281,7 @@ func isICloudPath(workspaceAbsPath string) (ret bool) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(workspaceAbsPath, strings.ToLower(path)) {
|
if strings.HasPrefix(workspaceAbsPathLower, strings.ToLower(path)) {
|
||||||
ret = true
|
ret = true
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
@ -275,3 +289,66 @@ func isICloudPath(workspaceAbsPath string) (ret bool) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func existAvailabilityStatus(workspaceAbsPath string) bool {
|
||||||
|
if !gulu.OS.IsWindows() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
dataAbsPath := filepath.Join(workspaceAbsPath, "data")
|
||||||
|
|
||||||
|
// 改进 Windows 端第三方同步盘检测 https://github.com/siyuan-note/siyuan/issues/7777
|
||||||
|
|
||||||
|
ps := `
|
||||||
|
function Get-MetaData {
|
||||||
|
[CmdletBinding()][OutputType([object])]
|
||||||
|
param([ValidateNotNullOrEmpty()][string]$File)
|
||||||
|
|
||||||
|
chcp 65001
|
||||||
|
$folderPath = Split-Path $File
|
||||||
|
$filePath = Split-Path $File -Leaf
|
||||||
|
|
||||||
|
try{
|
||||||
|
$shell = New-Object -ComObject Shell.Application
|
||||||
|
$folderObj = $shell.NameSpace($folderPath)
|
||||||
|
$fileObj = $folderObj.ParseName($filePath)
|
||||||
|
|
||||||
|
$value = $folderObj.GetDetailsOf($fileObj, 303)
|
||||||
|
echo $value
|
||||||
|
}finally{
|
||||||
|
if($shell){
|
||||||
|
[System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$shell) | out-null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-MetaData -File "` + dataAbsPath + "\""
|
||||||
|
cmd := exec.Command("powershell", "-nologo", "-noprofile", "-command", ps)
|
||||||
|
gulu.CmdAttr(cmd)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(string(out), "\n")
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
for _, line := range lines {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if strings.Contains(strings.ToLower(line), "active code page") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" != line {
|
||||||
|
buf.WriteString(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out = buf.Bytes()
|
||||||
|
|
||||||
|
status := strings.ToLower(strings.TrimSpace(string(out)))
|
||||||
|
if strings.Contains(status, "sync") || strings.Contains(status, "同步") ||
|
||||||
|
strings.Contains(status, "available") || strings.Contains(status, "可用") {
|
||||||
|
logging.LogErrorf("data [%s] third party sync status [%s]", dataAbsPath, status)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue