Code Monkey home page Code Monkey logo

Comments (34)

MDNich avatar MDNich commented on June 6, 2024

Renamed to clarify cause

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Oh no I'm sorry there is indeed a storage issue.

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

See if you can run this @frogg

egrep "[Container|Volume] Total Space:" "/tmp/.ath/sysvolname.txt" | awk '{print $4,$5}'

Let me know what is printed

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Ok I have made a potential fix, do try this and let me know if it works for you:

https://www.mediafire.com/file/b431dfoa8mramfi/About+This+Hack.zip/file

from about-this-hack.

frogg avatar frogg commented on June 6, 2024

See if you can run this @frogg

egrep "[Container|Volume] Total Space:" "/tmp/.ath/sysvolname.txt" | awk '{print $4,$5}'

Let me know what is printed

Output: 2.0 TB

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

@MDNich @0xCUB3

Try with a conversion to the same unit (GB) of size on Disk total size and Available total size
(don't copy lines below, github view didn't return editor real edited code)

Not tested (I don't have N TB SSD)

HardwareCollector.swift
...
static func getStorageData() -> [String] {

...
let size = run("egrep "[Container|Volume] Total Space:" | awk '{print $4,$5}' | tr -d '\n'")
var coeffMultDiskSIze = 1.0
switch run("echo "(size)" | awk '{print $2}' | tr -d '\n'") {
case "GB" : coeffMultDiskSIze = 1
case "MB" : coeffMultDiskSIze = 0.1
case "TB" : coeffMultDiskSIze = 10
default : coeffMultDiskSIze = 1
}
let sizeTrimmed = (Double(run("echo "(size)" | awk '{print $1}' | tr -d '\n'"))! * Double(coeffMultDiskSIze))

let available = run("grep \"[Container|Volume] Free Space:\" | awk '{print $4,$5}' | tr -d '\n'")
var coeffMultAvailableSIze = 1.0
    switch run("echo \"\(available)\" | awk '{print $2}' | tr -d '\n'") {
    case "GB"   : coeffMultAvailableSIze = 1
    case "MB"   : coeffMultAvailableSIze = 0.1
    case "TB"   : coeffMultAvailableSIze = 10
    default     : coeffMultAvailableSIze = 1
    }
 let availableTrimmed = (Double(run("echo \"\(available)\" | awk '{print $2}' | tr -d '\n'"))! * Double(coeffMultAvailableSIze))

let percentfree = NSString(format: "%.2f",(availableTrimmed) / sizeTrimmed * 100)

...

Regards

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

I have implemented a similar fix in the mediafire document attached above ; @frogg if you could test that it would be awesome :)

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

@MDNich

with a fake 2 TB HDD (External USB SSD) test with 2 TB forced in code

Capture d’écran 2023-10-10 à 16 24 18

with my real 250 GB (External USB SSD) test with real app. code

Capture d’écran 2023-10-10 à 16 29 06

with a fake 128 MB HDD (External USB SSD) test with 128 MB forced in code

Capture d’écran 2023-10-10 à 16 34 52

...

// let size = run("egrep "[Container|Volume] Total Space:" " + initGlobVar.bootvolnameFilePath + " | awk '{print $4}' | tr -d '\n'")
// let unitsize = run("egrep "[Container|Volume] Total Space:" " + initGlobVar.bootvolnameFilePath + " | awk '{print $5}' | tr -d '\n'")
// let size = "2.0" //test code
// let unitsize = "TB" //test code
let size = "128.0" //test code
let unitsize = "MB" //test code
var coeffMultDiskSize = 1.0
switch unitsize {
case "GB" : coeffMultDiskSize = 1.0
case "MB" : coeffMultDiskSize = 0.001
case "TB" : coeffMultDiskSize = 1000.0
default : coeffMultDiskSize = 1.0
}
let sizeTrimmed = (Double(size)! * coeffMultDiskSize)
print(coeffMultDiskSize)

// let available = run("grep "[Container|Volume] Free Space:" " + initGlobVar.bootvolnameFilePath + " | awk '{print $4}' | tr -d '\n'")
// let unitavailable = run("grep "[Container|Volume] Free Space:" " + initGlobVar.bootvolnameFilePath + " | awk '{print $5}' | tr -d '\n'")
// let available = "227.43" //test code
// let unitavailable = "GB" //test code
let available = "62.73" //test code
let unitavailable = "MB" //test code
var coeffMultAvailableSize = 1.0
switch unitavailable {
case "GB" : coeffMultAvailableSize = 1.0
case "MB" : coeffMultAvailableSize = 0.001
case "TB" : coeffMultAvailableSize = 1000.0
default : coeffMultAvailableSize = 1.0
}
let availableTrimmed = (Double(available)! * coeffMultAvailableSize)
print(coeffMultAvailableSize)

    let percent = (availableTrimmed / sizeTrimmed)
    let percentfree = NSString(format: "%.2f",(availableTrimmed) / sizeTrimmed * 100)

    print("Size: Double(\(sizeTrimmed))")
    print("Available: Double(\(availableTrimmed))")
    print("%: \(percentfree)")
    
    return ["""
    \(name) (\(devicelocation) \(deviceprotocol))
    \(size) \(unitsize) (\(available) \(unitavailable) Available - \(percentfree)%)
    """, String(1 - percent)]
}

Regards

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

@matxpa Have you tried with the app I have uploaded ? Thank you for the rest though.

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

https://www.mediafire.com/file/b431dfoa8mramfi/About+This+Hack.zip/file

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

I couldn't launch the app. you UpLoaded yesterday and nor this one above

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Interesting - I will implement your fix then, since you have tested it already. Will then push. Thanks

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Will keep you updated.

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

Yes but let me set this fix in my Repo (main branch)

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

The only thing I would change in your code is obtaining the unit - better to pull it from the first shell string to optimize time spent.

let unit = size[size.length-2]
extension String {

    var length: Int {
        return count
    }

    subscript (i: Int) -> String {
        return self[i ..< i + 1]
    }

    func substring(fromIndex: Int) -> String {
        return self[min(fromIndex, length) ..< length]
    }

    func substring(toIndex: Int) -> String {
        return self[0 ..< max(0, toIndex)]
    }

    subscript (r: Range<Int>) -> String {
        let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
                                            upper: min(length, max(0, r.upperBound))))
        let start = index(startIndex, offsetBy: range.lowerBound)
        let end = index(start, offsetBy: range.upperBound - range.lowerBound)
        return String(self[start ..< end])
    }
}

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

@MDNich
I've pushed this code (without your fix above) in HardwareCollector.swift in my Repo (main branch) so get and keep what you need

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Merged, thank you. I also adjusted slightly the notation with the optimization I mentioned.

@frogg, if you could test the release tag I'm about to attach here, if it works we can make it as finished.

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

Yes and the 2 last sent issues (#62 #63) seem to be same as #60 one

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Either compile from source with tag storage-test-1 https://github.com/0xCUB3/About-This-Hack/releases/tag/storage-test-1
or with the compiled binary below: https://www.mediafire.com/file/y2v7fimnb68d3lz/About+This+Hack.zip/file

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

@matxpa lets keep this one for the display, and I merged 62,63 > 60.

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Thanks for your help :)

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

With your About-This-Hack-storage-test-1 built with Xcode 14.2 (Monterey) (Xcode 15.0 Ventura or Sonoma debug can't work)

Capture d’écran 2023-10-10 à 17 15 25

I'll try with forced values TB and MB (MB for the fun)

Regards

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Ok looks good yes ?

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

sorry I don't have Xcode 12.5 like 0xCUB3, just Sonoma
Capture d’écran 2023-10-10 à 18 18 34

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

With forced size to "2.0 TB" and available to "216.47 GB"

Capture d’écran 2023-10-10 à 17 22 43

Just remove (unit)B and (unitA)B in returned array
return ["""
(name) ((devicelocation) (deviceprotocol))
(size) (unit)B ((available) (unitA)B Available - (percentfree)%)
""", String(1 - percent)]

and also var sizeTrimmed to let sizeTrimmed
.../About-This-Hack-storage-test-1/About This Hack/HardwareCollector.swift:126:13 Variable 'sizeTrimmed' was never mutated; consider changing to 'let' constant

Did you apply the first commit in my Repo (main branch) commit concerning SIP returned value when SIP is enabled

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

That's my bad - I wrote exactly what you wrote, but the size and available already include the unit. Fixed in this push.

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

https://www.mediafire.com/file/prqoarm95ppn0jr/About+This+Hack.zip/file @frogg

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

With the app. above

Capture d’écran 2023-10-10 à 17 36 05

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

@MDNich

"Did you apply the first commit in my Repo (main branch) commit concerning SIP returned value when SIP is enabled"

I apologize, yes you did, I can see it in the proj you sent and in the App. above

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

@0xCUB3 @MDNich @frogg

Hi all
This issue isn't fixed ?
Regards

from about-this-hack.

MDNich avatar MDNich commented on June 6, 2024

Waiting on @frogg to test before closing.

from about-this-hack.

matxpa avatar matxpa commented on June 6, 2024

Ok

from about-this-hack.

0xCUB3 avatar 0xCUB3 commented on June 6, 2024

@frogg you there?

from about-this-hack.

0xCUB3 avatar 0xCUB3 commented on June 6, 2024

closing issue because of inactivity; assuming fixed

from about-this-hack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.