Ticket #12334: 0001-Added-error-messages-when-converted-file-cannot-be-w.patch

File 0001-Added-error-messages-when-converted-file-cannot-be-w.patch, 3.3 KB (added by vivek-roy, 7 years ago)

I couldn't test it thoroughly because of the frequent crashes I was facing, but this should work.

  • src/apps/mediaconverter/MediaConverterApp.cpp

    From 3af91d33254686e02b27ac804cdff0cc5eb595e3 Mon Sep 17 00:00:00 2001
    From: Vivek Roy <vivekroy@outlook.com>
    Date: Wed, 8 Mar 2017 02:12:36 +0000
    Subject: [PATCH] Added error messages when converted file cannot be writen to
     destination
    
    ---
     src/apps/mediaconverter/MediaConverterApp.cpp    | 25 ++++++++++++++++++++++++
     src/apps/mediaconverter/MediaConverterWindow.cpp | 16 ++++++++++++++-
     2 files changed, 40 insertions(+), 1 deletion(-)
    
    diff --git a/src/apps/mediaconverter/MediaConverterApp.cpp b/src/apps/mediaconverter/MediaConverterApp.cpp
    index e3949d3..5fc41d0 100644
    a b MediaConverterApp::_CreateOutputFile(BDirectory directory,  
    204204
    205205    name.Append(outputFormat->file_extension);
    206206
     207    BEntry directoryEntry;
     208    directory.GetEntry(&directoryEntry);
     209    if (!directoryEntry.Exists()) {
     210        BAlert* alert = new BAlert(B_TRANSLATE("Error"),
     211            B_TRANSLATE("Selected directory not found. "
     212                "Defaulting to /boot/home"),
     213            B_TRANSLATE("OK"));
     214        alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
     215        alert->Go();
     216        directory.SetTo("/boot/home");
     217    }
     218
    207219    BEntry inEntry(ref);
    208220    BEntry outEntry;
    209221
    MediaConverterApp::_RunConvert()  
    318330
    319331
    320332            } else {
     333                srcIndex++;
     334                BString error(
     335                    B_TRANSLATE("Error converting '%filename'"));
     336                error.ReplaceAll("%filename", inRef.name);
     337                fWin->SetStatusMessage(error.String());
    321338                fWin->Unlock();
    322339                break;
    323340            }
    MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,  
    391408                        B_TRANSLATE("Audio quality not supported"));
    392409                    fWin->Unlock();
    393410                }
     411            } else {
     412                fWin->SetStatusMessage(
     413                    B_TRANSLATE("Error creating track."));
    394414            }
    395415
    396416        } else if (inFormat.IsVideo() && (videoCodec != NULL)) {
    MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,  
    465485                    fWin->SetVideoQualityLabel(videoQualitySupport);
    466486                    fWin->Unlock();
    467487                }
     488            } else {
     489                fWin->SetStatusMessage(
     490                    B_TRANSLATE("Error creating video."));
    468491            }
    469492        } else {
    470493            //  didn't do anything with the track
     494            fWin->SetStatusMessage(
     495                B_TRANSLATE("Input file not recognized as Audio or Video"));
    471496            inFile->ReleaseTrack(inTrack);
    472497        }
    473498    }
  • src/apps/mediaconverter/MediaConverterWindow.cpp

    diff --git a/src/apps/mediaconverter/MediaConverterWindow.cpp b/src/apps/mediaconverter/MediaConverterWindow.cpp
    index 7fee41f..7cf8336 100644
    a b  
    99
    1010#include <stdio.h>
    1111#include <string.h>
     12#include <unistd.h>
    1213
    1314#include <Alert.h>
    1415#include <Application.h>
    MediaConverterWindow::_CreateMenu()  
    10051006void
    10061007MediaConverterWindow::_SetOutputFolder(BEntry entry)
    10071008{
    1008     fOutputDir.SetTo(&entry);
     1009    BPath path;
     1010    entry.GetPath(&path);
     1011    if (access(path.Path(), W_OK) != -1) {
     1012        fOutputDir.SetTo(&entry);
     1013    } else {
     1014        BString errorString(B_TRANSLATE("Error writing to location: %strPath%."
     1015            " Defaulting to location: /boot/home"));
     1016        errorString.ReplaceFirst("%strPath%", path.Path());
     1017        BAlert* alert = new BAlert(B_TRANSLATE("Error"),
     1018            errorString.String(), B_TRANSLATE("OK"));
     1019        alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
     1020        alert->Go();
     1021        fOutputDir.SetTo("/boot/home");
     1022    }
    10091023    TruncateOutputFolderPath();
    10101024}