- {{$utils.prettyBytes(drive.size.free, 1)}} left
+ {{drive.size.free && $utils.prettyBytes(drive.size.free, 1)}} left
-
+
{
+ const options = {type: 'raw', stopOnError: false}
+ trammelGetSize(path, options, (error, size) => {
+ if (error) {reject(error)}
+ resolve(size)
+ })
+ })
+}
+
+async function getDirSizeOnDisk (dir) {
+ return new Promise((resolve, reject) => {
+ let paths = getFilesRecursively(dir)
+ let totalSize = 0
+ let promises = []
+ paths.forEach(path => {
+ promises.push(new Promise((resolve) => {
+ fswin.ntfs.getCompressedSize(path, (size) => {
+ resolve(size)
+ })
+ }))
+ })
+
+ Promise.allSettled(promises)
+ .then((data) => {
+ data.forEach(promise => {
+ totalSize += promise.value
+ })
+ resolve(totalSize)
+ })
+ })
+}
+
+function getFilesRecursively (dir) {
+ let files = []
+
+ const walk = (dir) => {
+ const filesInDirectory = fs.readdirSync(dir)
+ for (const file of filesInDirectory) {
+ const absolute = PATH.join(dir, file)
+ try {
+ if (fs.statSync(absolute).isDirectory()) {
+ walk(absolute)
+ }
+ else {
+ files.push(absolute)
+ }
+ }
+ catch (error) {}
+ }
+ }
+ walk(dir)
+
+ return files
+}
+
+module.exports = {
+ getDirSize,
+ getDirSizeOnDisk
+}
\ No newline at end of file
diff --git a/src/utils/navigatorCore.js b/src/utils/navigatorCore.js
index a3ea0cf3..5b1daa84 100644
--- a/src/utils/navigatorCore.js
+++ b/src/utils/navigatorCore.js
@@ -264,6 +264,32 @@ function shouldFetchExtraStats (path) {
return isExtraStatsEmpty && !isExtraStatsFetchInProgress && isExtraStatsForCurrentDir
}
+function getAttributes (dirItemData) {
+ if (utils.platform === 'win32') {
+ return fsWin.getAttributesSync(dirItemData.path)
+ }
+ // TODO: FINISH
+ else if (utils.platform === 'linux') {
+ return {}
+ }
+ else if (utils.platform === 'darwin') {
+ return 0
+ }
+}
+
+function getSizeOnDisk (dirItemData) {
+ if (utils.platform === 'win32') {
+ return fsWin.ntfs.getCompressedSizeSync(dirItemData.path)
+ }
+ // TODO: FINISH
+ else if (utils.platform === 'linux') {
+ return {}
+ }
+ else if (utils.platform === 'darwin') {
+ return 0
+ }
+}
+
/**
* @param {string} path
* @param {string} nameBase
@@ -302,6 +328,8 @@ async function fetchDirItemData (path, nameBase, itemHeight) {
dirItemData.stat = await getStat(path)
// if (isObjectEmpty(dirItemData.stat)) {throw Error('inaccessible item')}
// console.log(dirItemData.path, isObjectEmpty(dirItemData.stat))
+ dirItemData.attributes = getAttributes(dirItemData)
+ dirItemData.sizeOnDisk = getSizeOnDisk(dirItemData)
dirItemData.isHidden = isHidden(dirItemData)
dirItemData.isInaccessible = isObjectEmpty(dirItemData.stat)
dirItemData.isWin32Shortcut = await isFile(dirItemData, dirItemData.stat) && nameBase.endsWith('.lnk')
diff --git a/src/utils/storageInfo.js b/src/utils/storageInfo.js
index e60dc591..d75fe1c6 100644
--- a/src/utils/storageInfo.js
+++ b/src/utils/storageInfo.js
@@ -7,9 +7,12 @@
import utils from './utils'
import * as fsManager from './fsManager.js'
+const fs = require('fs')
const PATH = require('path')
const sysInfo = require('systeminformation')
const diskusage = require('diskusage')
+const fsInfo = require('./fsInfo.js')
+const appPaths = require('../appPaths.js')
let state = {
extraDeviceData: [],
@@ -34,8 +37,10 @@ let state = {
export async function getStorageDevices () {
try {
let blockDevices = await getBlockDevices()
+ let oneDrive = await getOneDrive()
let storageDevices = [
...blockDevices,
+ ...oneDrive
]
state.previousDriveList = [...state.driveList]
state.driveList = blockDevices
@@ -55,6 +60,28 @@ function handleDriveListChange () {
}
}
+async function getOneDrive () {
+ let path = appPaths.oneDrive
+ if (path) {
+ let oneDriveItemList = await fs.promises.readdir(path)
+ let size = await fsInfo.getDirSize(path)
+ let sizeOnDisk = await fsInfo.getDirSizeOnDisk(path)
+ let formattedSizeOnDisk = utils.prettyBytes(sizeOnDisk, 1)
+ let formattedSizeTotal = utils.prettyBytes(size, 1)
+ return [{
+ type: 'cloud',
+ path,
+ mount: path,
+ infoSummary: `Used: ${formattedSizeTotal} • Locally: ${formattedSizeOnDisk}`,
+ titleSummary: 'OneDrive',
+ isEmpty: oneDriveItemList.length === 0
+ }]
+ }
+ else {
+ return []
+ }
+}
+
export async function fetchBlockDevicesExtraData () {
try {
getBlockDevicesExtraData()
diff --git a/src/utils/utils.js b/src/utils/utils.js
index a5d348d5..b174b24e 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -35,6 +35,38 @@ export default {
? PATH.join(__dirname, relativePath)
: PATH.join(relativePath)
},
+ getDriveIcon (drive) {
+ if (drive.type === 'cloud') {
+ return {
+ icon: 'mdi-cloud-outline',
+ size: '22px'
+ }
+ }
+ else if (['rom', 'cd'].includes(drive.type)) {
+ return {
+ icon: 'fas fa-compact-disc',
+ size: '20px'
+ }
+ }
+ else if (drive.type === 'removable') {
+ return {
+ icon: 'fab fa-usb',
+ size: '20px'
+ }
+ }
+ else if (drive.type === 'network') {
+ return {
+ icon: 'mdi-folder-network-outline',
+ size: '22px'
+ }
+ }
+ else {
+ return {
+ icon: 'far fa-hdd',
+ size: '20px'
+ }
+ }
+ },
openLink (link) {
electron.shell.openExternal(link)
},