2024-01-14 16:31:07 +06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-18 01:39:20 +06:00
|
|
|
"errors"
|
2024-01-14 16:31:07 +06:00
|
|
|
"ffmpegGui/convertor"
|
|
|
|
myError "ffmpegGui/error"
|
|
|
|
"ffmpegGui/handler"
|
2024-01-18 01:39:20 +06:00
|
|
|
"ffmpegGui/migration"
|
|
|
|
"ffmpegGui/setting"
|
2024-01-14 16:31:07 +06:00
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/app"
|
2024-01-18 01:39:20 +06:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"os"
|
2024-01-14 16:31:07 +06:00
|
|
|
)
|
|
|
|
|
2024-01-18 20:23:23 +06:00
|
|
|
//const appVersion string = "0.1.0"
|
2024-01-14 16:31:07 +06:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
a := app.New()
|
|
|
|
w := a.NewWindow("GUI FFMpeg!")
|
2024-01-18 20:23:23 +06:00
|
|
|
w.Resize(fyne.Size{Width: 800, Height: 600})
|
2024-01-14 16:31:07 +06:00
|
|
|
|
|
|
|
errorView := myError.NewView(w)
|
|
|
|
|
2024-01-18 01:39:20 +06:00
|
|
|
if canCreateFile("data/database") != true {
|
2024-01-18 20:23:23 +06:00
|
|
|
errorView.PanicError(errors.New("не смогли создать файл 'database' в папке 'data'"))
|
2024-01-18 01:39:20 +06:00
|
|
|
w.ShowAndRun()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := gorm.Open(sqlite.Open("data/database"), &gorm.Config{})
|
|
|
|
if err != nil {
|
|
|
|
errorView.PanicError(err)
|
|
|
|
w.ShowAndRun()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer appClose(db)
|
|
|
|
|
|
|
|
err = migration.Run(db)
|
|
|
|
if err != nil {
|
|
|
|
errorView.PanicError(err)
|
|
|
|
w.ShowAndRun()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settingRepository := setting.NewRepository(db)
|
|
|
|
pathFFmpeg, err := settingRepository.GetValue("ffmpeg")
|
|
|
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
|
|
|
errorView.PanicError(err)
|
|
|
|
w.ShowAndRun()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pathFFprobe, err := settingRepository.GetValue("ffprobe")
|
|
|
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
|
|
|
errorView.PanicError(err)
|
|
|
|
w.ShowAndRun()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ffPathUtilities := convertor.FFPathUtilities{FFmpeg: pathFFmpeg, FFprobe: pathFFprobe}
|
2024-01-14 16:31:07 +06:00
|
|
|
|
|
|
|
convertorView := convertor.NewView(w)
|
2024-01-18 01:39:20 +06:00
|
|
|
settingView := setting.NewView(w)
|
|
|
|
convertorService := convertor.NewService(ffPathUtilities)
|
|
|
|
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, settingRepository)
|
2024-01-14 16:31:07 +06:00
|
|
|
|
|
|
|
mainHandler.GetConvertor()
|
|
|
|
|
|
|
|
w.ShowAndRun()
|
|
|
|
}
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
func appClose(db *gorm.DB) {
|
|
|
|
sqlDB, err := db.DB()
|
|
|
|
if err == nil {
|
|
|
|
_ = sqlDB.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func canCreateFile(path string) bool {
|
|
|
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_ = file.Close()
|
|
|
|
return true
|
|
|
|
}
|