Skip to content

Commit

Permalink
Fixed dehash file error not outputting correct pairs. added check dis…
Browse files Browse the repository at this point in the history
…k space.
  • Loading branch information
ethanperrine committed Jan 30, 2024
1 parent 993bffe commit 00eec14
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 46 deletions.
92 changes: 70 additions & 22 deletions Models/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package Models

import (
"GoIris/Models/Database"
"context"
"fmt"
"os"
"os/exec"
Expand All @@ -10,8 +11,8 @@ import (
"syscall"
"time"

"github.com/shirou/gopsutil/disk"
"golang.org/x/text/message"

)

func ClearConsole() {
Expand All @@ -27,13 +28,6 @@ func ClearConsole() {
}
}

func exit() {
fmt.Println("Performing cleanup...")
Database.SetPragmasForExit(DB)
fmt.Println("Exiting...")
os.Exit(0)
}

func SetupSignalHandler() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
Expand All @@ -44,25 +38,79 @@ func SetupSignalHandler() {
}()
}

func UpdateInsertConsoleTitle() {
func ConvertBytesToPretty(bytes int64) string {
p := message.NewPrinter(message.MatchLanguage("en"))

const (
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
TB = 1024 * GB
)

switch {
case bytes < KB:
return p.Sprintf("%d B", bytes)
case bytes < MB:
return p.Sprintf("%.2f KB", float64(bytes)/KB)
case bytes < GB:
return p.Sprintf("%.2f MB", float64(bytes)/MB)
case bytes < TB:
return p.Sprintf("%.2f GB", float64(bytes)/GB)
default:
return p.Sprintf("%.2f TB", float64(bytes)/TB)
}
}

func UpdateInsertConsoleTitle(ctx context.Context) {
p := message.NewPrinter(message.MatchLanguage("en"))
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return // Exit the function when context is cancelled
case <-ticker.C:
Database.Mutex.Lock()
totalInserts := Database.TotalInserts
Database.Mutex.Unlock()

for range time.Tick(2 * time.Second) {
Database.Mutex.Lock()
totalInserts := Database.TotalInserts
Database.Mutex.Unlock()
elapsedTime := time.Since(Database.StartTime)
var insertsPerSecond float64
if elapsedTime.Seconds() > 0 {
insertsPerSecond = float64(totalInserts) / elapsedTime.Seconds()
}

elapsedTime := time.Since(Database.StartTime)
var insertsPerSecond float64
if elapsedTime.Seconds() > 0 {
insertsPerSecond = float64(totalInserts) / elapsedTime.Seconds()
formattedElapsedTime := elapsedTime.Truncate(time.Second).String()
formattedTotalInserts := p.Sprintf("%d", totalInserts)
formattedInsertsPerSecond := p.Sprintf("%.2f", insertsPerSecond)

title := fmt.Sprintf("GoIris ~ Total Inserts: %s - Inserts/sec: %s - Elapsed Time: %s", formattedTotalInserts, formattedInsertsPerSecond, formattedElapsedTime)
fmt.Printf("\033]0;%s\007", title)
}
}
}

formattedElapsedTime := elapsedTime.Truncate(time.Second).String()
formattedTotalInserts := p.Sprintf("%d", totalInserts)
formattedInsertsPerSecond := p.Sprintf("%.2f", insertsPerSecond)
func CheckDiskSpace() uint64 {
dir, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

title := fmt.Sprintf("GoIris ~ Total Inserts: %s - Inserts/sec: %s - Elapsed Time: %s", formattedTotalInserts, formattedInsertsPerSecond, formattedElapsedTime)
fmt.Printf("\033]0;%s\007", title)
diskStat, err := disk.Usage(dir)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

return diskStat.Free
}

func exit() {
fmt.Println("Performing cleanup...")
Database.SetPragmasForExit(DB)
fmt.Println("Exiting...")
os.Exit(0)
}
35 changes: 35 additions & 0 deletions Models/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Models

import (
"bufio"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"fmt"
"os"
)

func CalculateFileHashSizes(file *os.File) (int, int, int, int, int) {
scanner := bufio.NewScanner(file)
lineCount := 0

for scanner.Scan() {
lineCount++
}

if err := scanner.Err(); err != nil {
fmt.Println("Error reading file:", err)
return 0, 0, 0, 0, 0
}

file.Seek(0, 0)

md4Size := lineCount * md5.Size // MD4 is roughly the same size as MD5
md5Size := lineCount * md5.Size
sha1Size := lineCount * sha1.Size
sha256Size := lineCount * sha256.Size
sha512Size := lineCount * sha512.Size

return md4Size, md5Size, sha1Size, sha256Size, sha512Size
}
3 changes: 2 additions & 1 deletion Models/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"

_ "modernc.org/sqlite"

)

var DB *sql.DB
var DB *sql.DB
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ require (
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
golang.org/x/text v0.14.0
)

require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2j
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
Expand All @@ -22,9 +24,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf h1:pCxn3BCfu8n8VUhYl4zS1BftoZoYY0J4qVF3dqAQ4aU=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand All @@ -41,6 +47,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
Loading

0 comments on commit 00eec14

Please sign in to comment.