Skip to content

Commit

Permalink
Storage (#117)
Browse files Browse the repository at this point in the history
* Update InfoService.java

* Update UsageService.java

* Update InfoService.java

* Update InfoService.java

* Update pom.xml

* rework storage
  • Loading branch information
AntonyLeons authored Mar 17, 2024
1 parent baf14d4 commit 7833aae
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/dev/leons/ward/services/UsageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ private int getRam() {
private int getStorage() {
FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();

// Calculate total storage and free storage
long totalStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getTotalSpace).sum();
long freeStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getFreeSpace).sum();
// Calculate total storage and free storage for all drives
long totalStorage = 0;
long freeStorage = 0;
for (OSFileStore fileStore : fileSystem.getFileStores()) {
totalStorage += fileStore.getTotalSpace();
freeStorage += fileStore.getFreeSpace();
}

// Handle possible division by zero
if (totalStorage == 0) {
return 0; // or handle in a way suitable for your application
}

// Calculate storage usage percentage
// Calculate total storage usage percentage for all drives
return (int) Math.round(((double) (totalStorage - freeStorage) / totalStorage) * 100);
}

Expand Down

0 comments on commit 7833aae

Please sign in to comment.