|
|
|
@ -7,11 +7,12 @@ import (
|
|
|
|
|
"io/fs"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
//"path/filepath"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
//"time"
|
|
|
|
|
|
|
|
|
|
"github.com/estebangarcia21/subprocess"
|
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
@ -65,6 +66,69 @@ func (a *App) GetProjects() []Project {
|
|
|
|
|
return projects
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Disk struct {
|
|
|
|
|
Name string
|
|
|
|
|
Free uint64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getFileCountAndSize(dir string) (int, int64, error) {
|
|
|
|
|
var fileCount int
|
|
|
|
|
var totalSize int64
|
|
|
|
|
|
|
|
|
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !info.IsDir() { // Проверяем, что это не каталог
|
|
|
|
|
fileCount++
|
|
|
|
|
totalSize += info.Size() // Добавляем размер файла
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileCount, totalSize, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) GetDownloads() string {
|
|
|
|
|
cnt, size, err := getFileCountAndSize("C:\\Users\\admin\\Downloads")
|
|
|
|
|
checkError("getDownloads", err)
|
|
|
|
|
info := fmt.Sprintf("%d(%d Mb)", cnt, size/1024/1024)
|
|
|
|
|
return info
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StartFarDownloads - запускает far
|
|
|
|
|
func (a *App) StartFarDownloads() string {
|
|
|
|
|
cmd := `far "D:\soft" "C:\Users\admin\Downloads"`
|
|
|
|
|
far := subprocess.New(cmd)
|
|
|
|
|
err := far.Exec()
|
|
|
|
|
if err != nil {
|
|
|
|
|
runtime.LogError(a.ctx, err.Error())
|
|
|
|
|
}
|
|
|
|
|
runtime.LogInfo(a.ctx, "команда выполнена успешно")
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) GetDisks() []Disk {
|
|
|
|
|
var disks = []Disk{}
|
|
|
|
|
var freeBytes, totalBytes, totalFreeBytes uint64
|
|
|
|
|
err := windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr("C:\\"), &freeBytes, &totalBytes, &totalFreeBytes)
|
|
|
|
|
checkError("free space c:", err)
|
|
|
|
|
free_C := freeBytes / 1024 / 1024 / 1024
|
|
|
|
|
disks = append(disks, Disk{Name: "C:", Free: free_C})
|
|
|
|
|
|
|
|
|
|
err = windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr("D:\\"), &freeBytes, &totalBytes, &totalFreeBytes)
|
|
|
|
|
checkError("free space d:", err)
|
|
|
|
|
free_D := freeBytes / 1024 / 1024 / 1024
|
|
|
|
|
disks = append(disks, Disk{Name: "D:", Free: free_D})
|
|
|
|
|
|
|
|
|
|
return disks
|
|
|
|
|
//fmt.Printf("Свободное место на диске: %dGB\n", freeGB)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Greet returns a greeting for the given name
|
|
|
|
|
func (a *App) Greet(name string) string {
|
|
|
|
|
return fmt.Sprintf("Hello %s, It's show time!", name)
|
|
|
|
@ -94,7 +158,7 @@ func (a *App) StartServer(s string) string {
|
|
|
|
|
return "starting server"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StartServer - запускает сервер на выполнение
|
|
|
|
|
// StartFar - запускает far
|
|
|
|
|
func (a *App) StartFar(s string) string {
|
|
|
|
|
runtime.LogInfo(a.ctx, s)
|
|
|
|
|
cmd := fmt.Sprintf("far \"%s\" \"%s\"", s, s)
|
|
|
|
|