Made it possible to change the path to FFmpeg and FFprobe.
This commit is contained in:
parent
d86c0d37af
commit
0d5cfab38d
36
src/convertor/repository.go
Normal file
36
src/convertor/repository.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package convertor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ffmpegGui/setting"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RepositoryContract interface {
|
||||||
|
GetPathFfmpeg() (string, error)
|
||||||
|
SavePathFfmpeg(code string) (setting.Setting, error)
|
||||||
|
GetPathFfprobe() (string, error)
|
||||||
|
SavePathFfprobe(code string) (setting.Setting, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
settingRepository setting.RepositoryContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(settingRepository setting.RepositoryContract) *Repository {
|
||||||
|
return &Repository{settingRepository: settingRepository}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) GetPathFfmpeg() (string, error) {
|
||||||
|
return r.settingRepository.GetValue("ffmpeg")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) SavePathFfmpeg(path string) (setting.Setting, error) {
|
||||||
|
return r.settingRepository.CreateOrUpdate("ffmpeg", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) GetPathFfprobe() (string, error) {
|
||||||
|
return r.settingRepository.GetValue("ffprobe")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Repository) SavePathFfprobe(path string) (setting.Setting, error) {
|
||||||
|
return r.settingRepository.CreateOrUpdate("ffprobe", path)
|
||||||
|
}
|
@ -18,7 +18,10 @@ type ViewContract interface {
|
|||||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
||||||
)
|
)
|
||||||
SelectFFPath(
|
SelectFFPath(
|
||||||
func(ffmpegPath string, ffprobePath string) error,
|
ffmpegPath string,
|
||||||
|
ffprobePath string,
|
||||||
|
save func(ffmpegPath string, ffprobePath string) error,
|
||||||
|
cancel func(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +12,18 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) {
|
func (v View) SelectFFPath(
|
||||||
|
currentPathFfmpeg string,
|
||||||
|
currentPathFfprobe string,
|
||||||
|
save func(ffmpegPath string, ffprobePath string) error,
|
||||||
|
cancel func(),
|
||||||
|
) {
|
||||||
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
||||||
errorMessage.TextSize = 16
|
errorMessage.TextSize = 16
|
||||||
errorMessage.TextStyle = fyne.TextStyle{Bold: true}
|
errorMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile()
|
ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile(currentPathFfmpeg)
|
||||||
ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile()
|
ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile(currentPathFfprobe)
|
||||||
|
|
||||||
link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{
|
link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -60,23 +65,28 @@ func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) erro
|
|||||||
MessageID: "save",
|
MessageID: "save",
|
||||||
}),
|
}),
|
||||||
OnSubmit: func() {
|
OnSubmit: func() {
|
||||||
err := save(string(*ffmpegPath), string(*ffprobePath))
|
err := save(*ffmpegPath, *ffprobePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorMessage.Text = err.Error()
|
errorMessage.Text = err.Error()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if cancel != nil {
|
||||||
|
form.OnCancel = cancel
|
||||||
|
form.CancelText = v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: "cancel",
|
||||||
|
})
|
||||||
|
}
|
||||||
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "selectFFPathTitle",
|
MessageID: "selectFFPathTitle",
|
||||||
})
|
})
|
||||||
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(form)))
|
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(form)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
|
func (v View) getButtonSelectFile(path string) (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
|
||||||
path := ""
|
|
||||||
filePath = &path
|
filePath = &path
|
||||||
|
|
||||||
buttonMessage = canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
buttonMessage = canvas.NewText(path, color.RGBA{49, 127, 114, 255})
|
||||||
buttonMessage.TextSize = 16
|
buttonMessage.TextSize = 16
|
||||||
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"ffmpegGui/convertor"
|
"ffmpegGui/convertor"
|
||||||
"ffmpegGui/helper"
|
"ffmpegGui/helper"
|
||||||
"ffmpegGui/localizer"
|
"ffmpegGui/localizer"
|
||||||
"ffmpegGui/setting"
|
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"io"
|
"io"
|
||||||
@ -17,26 +16,27 @@ import (
|
|||||||
|
|
||||||
type ConvertorHandlerContract interface {
|
type ConvertorHandlerContract interface {
|
||||||
MainConvertor()
|
MainConvertor()
|
||||||
|
FfPathSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConvertorHandler struct {
|
type ConvertorHandler struct {
|
||||||
convertorService convertor.ServiceContract
|
convertorService convertor.ServiceContract
|
||||||
convertorView convertor.ViewContract
|
convertorView convertor.ViewContract
|
||||||
settingRepository setting.RepositoryContract
|
convertorRepository convertor.RepositoryContract
|
||||||
localizerService localizer.ServiceContract
|
localizerService localizer.ServiceContract
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConvertorHandler(
|
func NewConvertorHandler(
|
||||||
convertorService convertor.ServiceContract,
|
convertorService convertor.ServiceContract,
|
||||||
convertorView convertor.ViewContract,
|
convertorView convertor.ViewContract,
|
||||||
settingRepository setting.RepositoryContract,
|
convertorRepository convertor.RepositoryContract,
|
||||||
localizerService localizer.ServiceContract,
|
localizerService localizer.ServiceContract,
|
||||||
) *ConvertorHandler {
|
) *ConvertorHandler {
|
||||||
return &ConvertorHandler{
|
return &ConvertorHandler{
|
||||||
convertorService: convertorService,
|
convertorService: convertorService,
|
||||||
convertorView: convertorView,
|
convertorView: convertorView,
|
||||||
settingRepository: settingRepository,
|
convertorRepository: convertorRepository,
|
||||||
localizerService: localizerService,
|
localizerService: localizerService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,13 @@ func (h ConvertorHandler) MainConvertor() {
|
|||||||
h.convertorView.Main(h.runConvert)
|
h.convertorView.Main(h.runConvert)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.convertorView.SelectFFPath(h.saveSettingFFPath)
|
h.convertorView.SelectFFPath("", "", h.saveSettingFFPath, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h ConvertorHandler) FfPathSelection() {
|
||||||
|
ffmpeg, _ := h.convertorRepository.GetPathFfmpeg()
|
||||||
|
ffprobe, _ := h.convertorRepository.GetPathFfprobe()
|
||||||
|
h.convertorView.SelectFFPath(ffmpeg, ffprobe, h.saveSettingFFPath, h.MainConvertor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
|
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
|
||||||
@ -84,10 +90,8 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
if ffprobeChecking == false {
|
if ffprobeChecking == false {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: item.FFmpeg}
|
_, _ = h.convertorRepository.SavePathFfmpeg(item.FFmpeg)
|
||||||
_, _ = h.settingRepository.Create(ffmpegEntity)
|
_, _ = h.convertorRepository.SavePathFfprobe(item.FFprobe)
|
||||||
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: item.FFprobe}
|
|
||||||
_, _ = h.settingRepository.Create(ffprobeEntity)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,10 +115,8 @@ func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath strin
|
|||||||
return errors.New(errorText)
|
return errors.New(errorText)
|
||||||
}
|
}
|
||||||
|
|
||||||
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath}
|
_, _ = h.convertorRepository.SavePathFfmpeg(ffmpegPath)
|
||||||
_, _ = h.settingRepository.Create(ffmpegEntity)
|
_, _ = h.convertorRepository.SavePathFfprobe(ffprobePath)
|
||||||
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
|
|
||||||
_, _ = h.settingRepository.Create(ffprobeEntity)
|
|
||||||
|
|
||||||
h.MainConvertor()
|
h.MainConvertor()
|
||||||
|
|
||||||
|
@ -51,9 +51,14 @@ func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
|
|||||||
}), h.LanguageSelection)
|
}), h.LanguageSelection)
|
||||||
h.menuItems.menuItem["changeLanguage"] = languageSelection
|
h.menuItems.menuItem["changeLanguage"] = languageSelection
|
||||||
|
|
||||||
|
ffPathSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: "changeFFPath",
|
||||||
|
}), h.convertorHandler.FfPathSelection)
|
||||||
|
h.menuItems.menuItem["changeFFPath"] = ffPathSelection
|
||||||
|
|
||||||
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "settings",
|
MessageID: "settings",
|
||||||
}), languageSelection, quit)
|
}), languageSelection, ffPathSelection, quit)
|
||||||
h.menuItems.menu["settings"] = settings
|
h.menuItems.menu["settings"] = settings
|
||||||
|
|
||||||
return fyne.NewMainMenu(settings)
|
return fyne.NewMainMenu(settings)
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||||
other = "Folder where it will be saved:"
|
other = "Folder where it will be saved:"
|
||||||
|
|
||||||
|
[cancel]
|
||||||
|
hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a"
|
||||||
|
other = "Cancel"
|
||||||
|
|
||||||
|
[changeFFPath]
|
||||||
|
hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491"
|
||||||
|
other = "FFmpeg and FFprobe"
|
||||||
|
|
||||||
[changeLanguage]
|
[changeLanguage]
|
||||||
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
other = "Change language"
|
other = "Change language"
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||||
other = "Файлды сақтауға арналған каталог:"
|
other = "Файлды сақтауға арналған каталог:"
|
||||||
|
|
||||||
|
[cancel]
|
||||||
|
hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a"
|
||||||
|
other = "Болдырмау"
|
||||||
|
|
||||||
|
[changeFFPath]
|
||||||
|
hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491"
|
||||||
|
other = "FFmpeg және FFprobe"
|
||||||
|
|
||||||
[changeLanguage]
|
[changeLanguage]
|
||||||
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
||||||
other = "Тілді өзгерту"
|
other = "Тілді өзгерту"
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
|
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
|
||||||
|
cancel = "Отмена"
|
||||||
|
changeFFPath = "FFmpeg и FFprobe"
|
||||||
changeLanguage = "Поменять язык"
|
changeLanguage = "Поменять язык"
|
||||||
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
||||||
choose = "выбрать"
|
choose = "выбрать"
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
[changeLanguage]
|
[changeFFPath]
|
||||||
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491"
|
||||||
other = "Change language"
|
other = "FFmpeg and FFprobe"
|
||||||
|
|
||||||
[exit]
|
|
||||||
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
|
||||||
other = "Exit"
|
|
||||||
|
|
||||||
[settings]
|
|
||||||
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
|
||||||
other = "Settings"
|
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
[changeLanguage]
|
[changeFFPath]
|
||||||
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
|
hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491"
|
||||||
other = "Тілді өзгерту"
|
other = "FFmpeg және FFprobe"
|
||||||
|
|
||||||
[exit]
|
|
||||||
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
|
|
||||||
other = "Шығу"
|
|
||||||
|
|
||||||
[settings]
|
|
||||||
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
|
||||||
other = "Параметрлер"
|
|
||||||
|
@ -62,13 +62,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
settingRepository := setting.NewRepository(db)
|
settingRepository := setting.NewRepository(db)
|
||||||
pathFFmpeg, err := settingRepository.GetValue("ffmpeg")
|
convertorRepository := convertor.NewRepository(settingRepository)
|
||||||
|
pathFFmpeg, err := convertorRepository.GetPathFfmpeg()
|
||||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pathFFprobe, err := settingRepository.GetValue("ffprobe")
|
pathFFprobe, err := convertorRepository.GetPathFfprobe()
|
||||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
@ -81,7 +82,7 @@ func main() {
|
|||||||
convertorView := convertor.NewView(w, localizerService)
|
convertorView := convertor.NewView(w, localizerService)
|
||||||
convertorService := convertor.NewService(ffPathUtilities)
|
convertorService := convertor.NewService(ffPathUtilities)
|
||||||
defer appCloseWithConvert(convertorService)
|
defer appCloseWithConvert(convertorService)
|
||||||
convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, settingRepository, localizerService)
|
convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, convertorRepository, localizerService)
|
||||||
|
|
||||||
localizerRepository := localizer.NewRepository(settingRepository)
|
localizerRepository := localizer.NewRepository(settingRepository)
|
||||||
mainMenu := handler.NewMenuHandler(convertorHandler, localizerService, localizerView, localizerRepository)
|
mainMenu := handler.NewMenuHandler(convertorHandler, localizerService, localizerView, localizerRepository)
|
||||||
|
Loading…
Reference in New Issue
Block a user