package main import ( "changeme/hardware" "context" "fmt" "io" "log" "os" "strings" "sync" ) // App struct type App struct { ctx context.Context hardwareManager *hardware.HardwareManager // For managing all the hardware wmiMutex sync.Mutex // Avoid some WMI operations at the same time projectInfo ProjectInfo // The project information structure projectSave string // The file name of the project // FOR TESTING PURPOSE ONLY ftdi *hardware.FTDIPeripheral } // NewApp creates a new App application struct func NewApp() *App { // Create a new hadware manager hardwareManager := hardware.NewHardwareManager() hardwareManager.RegisterDriver(hardware.NewMIDIDriver()) hardwareManager.RegisterDriver(hardware.NewFTDIDriver()) hardwareManager.RegisterDriver(hardware.NewOS2LDriver()) return &App{ hardwareManager: hardwareManager, projectSave: "", projectInfo: ProjectInfo{ PeripheralsInfo: make(map[string]hardware.PeripheralInfo), }, } } // startup is called when the app starts. The context is saved // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx err := a.hardwareManager.Start(ctx) if err != nil { log.Fatalf("Unable to start the device manager: %s", err) return } } func formatString(input string) string { // Convertir en minuscules lowerCaseString := strings.ToLower(input) // Remplacer les espaces par des underscores formattedString := strings.ReplaceAll(lowerCaseString, " ", "_") return formattedString } func copy(src, dst string) (int64, error) { sourceFileStat, err := os.Stat(src) if err != nil { return 0, err } if !sourceFileStat.Mode().IsRegular() { return 0, fmt.Errorf("%s is not a regular file", src) } source, err := os.Open(src) if err != nil { return 0, err } defer source.Close() destination, err := os.Create(dst) if err != nil { return 0, err } defer destination.Close() nBytes, err := io.Copy(destination, source) return nBytes, err }