diff --git a/main.go b/main.go index a7d4116..b363ef1 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "os/exec" @@ -154,11 +155,7 @@ func startProcessing() { g.Update() if anime.HasSubtitlesStream && outputFormat != "mkv" { - animeList[index].Status = Error - gui.ButtonLabel = "Start" - processing = false - logMessage("File "+anime.Name+" contains subtitles stream, output format must be MKV", false) - g.Update() + handleStartUpscalingError("", index, "File "+anime.Name+" contains subtitles stream, output format must be MKV", errors.New("")) return } @@ -167,11 +164,7 @@ func startProcessing() { workingDirectory, err := os.Getwd() if err != nil { - animeList[index].Status = Error - gui.ButtonLabel = "Start" - processing = false - g.Update() - handleSoftError("Getting working directory error:", err.Error()) + handleStartUpscalingError("", index, "Getting working directory error:", err) return } @@ -189,23 +182,13 @@ func startProcessing() { stderr, err := cmd.StderrPipe() if err != nil { - os.Remove(outputPath) - animeList[index].Status = Error - gui.ButtonLabel = "Start" - processing = false - g.Update() - handleSoftError("Creating pipe error:", err.Error()) + handleStartUpscalingError(outputPath, index, "Creating pipe error:", err) return } err = cmd.Start() if err != nil { - os.Remove(outputPath) - animeList[index].Status = Error - gui.ButtonLabel = "Start" - processing = false - g.Update() - handleSoftError("Starting ffmpeg process error:", err.Error()) + handleStartUpscalingError(outputPath, index, "Starting ffmpeg process error:", err) return } @@ -213,17 +196,12 @@ func startProcessing() { err = cmd.Wait() if err != nil { - os.Remove(outputPath) if cancelled { cancelled = false return } - animeList[index].Status = Error - gui.ButtonLabel = "Start" - processing = false - g.Update() - handleSoftError("FFMPEG Error:", err.Error()) + handleStartUpscalingError(outputPath, index, "FFMPEG Error:", err) handleSoftError("FFMPEG logs:", ffmpegLogs) return } diff --git a/utils.go b/utils.go index 1943ae9..7e066eb 100644 --- a/utils.go +++ b/utils.go @@ -119,3 +119,21 @@ func check(err error) { log.Fatal(err) } } + +func handleStartUpscalingError(outputPath string, animeIndex int, errorMessage string, err error) { + if outputPath != "" { + os.Remove(outputPath) + } + + animeList[animeIndex].Status = Error + gui.ButtonLabel = "Start" + processing = false + g.Update() + + if err.Error() != "" { + handleSoftError(errorMessage, err.Error()) + return + } + + logMessage("File "+animeList[animeIndex].Name+" contains subtitles stream, output format must be MKV", false) +}