vlmc.cpp 4.32 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlmc.cpp: VLMC launcher for unix
 *****************************************************************************
4
 * Copyright (C) 2008-2014 VideoLAN
5
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "config.h"

25
#include "Main/Core.h"
26 27
#include "Workflow/Types.h"
#include "Tools/VlmcDebug.h"
28
#include "Project/Project.h"
29 30

#include <QMetaType>
31
#include <QTextStream>
32
#include <QVariant>
33 34 35 36

#include <sys/wait.h>
#include <unistd.h>

37

38 39
int VLMCmain( int , char** );

40 41
#if defined(WITH_CRASHHANDLER) && defined(Q_OS_UNIX)

42
#ifdef WITH_GUI
43
    #include "Gui/project/GuiProjectManager.h"
44
    #ifdef WITH_CRASHHANDLER_GUI
45
        #include "Gui/widgets/CrashHandler.h"
46 47 48 49 50 51 52 53 54 55
    #endif
#else
    #include "ProjectManager.h"
#endif

void
signalHandler( int sig )
{
    signal( sig, SIG_DFL );

56
    Core::getInstance()->currentProject()->emergencyBackup();
57 58 59 60 61 62 63 64

    #ifdef WITH_CRASHHANDLER_GUI
        CrashHandler* ch = new CrashHandler( sig );
        ::exit( ch->exec() );
    #else
        ::exit( 1 );
    #endif
}
65 66
#endif

67
/**
68 69 70 71 72
 * Print version text
 */
void
version( void )
{
73
    QTextStream out( stdout );
74 75 76 77 78 79 80 81
    out << "VLMC-" << PROJECT_VERSION << " '" << CODENAME << "'\n"
        << "VideoLAN Movie Creator (VLMC) is a cross-platform, non-linear\n"
        << "video editing software.\n"
        << "Copyright (C) 2008-10 VideoLAN\n"
        << "This is free software; see the source for copying conditions. There is NO\n"
        << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
}

82
/**
83 84 85 86 87
 * Print usage text
 */
void
usage( QString const& appName )
{
88
    QTextStream out( stdout );
89 90 91
    out << "Usage: " << appName << " [options] [filename|URI]...\n"
        << "Options:\n"
        << "\t[--project|-p projectfile]\tload the given VLMC project\n"
92
        << "\t[--version]\tversion information\n"
93 94 95 96 97 98 99 100
        << "\t[--help|-?]\tthis text\n\n"
        << "\tFILES:\n"
        << "\t\tFiles specified on the command line should include \n"
        << "\t\tVLMC project files (.vlmc)\n";
}

int
main( int argc, char **argv )
101
{
102
    /* Check for command arguments */
103
    for( int i = 1; i < argc; i++ )
104 105 106
    {
        QString arg = argv[i];

107
        if( arg == "--help" || arg == "-?" )
108
        {
109
            ::usage( QString(argv[0]) );
110 111
            return 2;
        }
112
        else if( arg == "--version" )
113
        {
114
            ::version();
115 116 117 118
            return 2;
        }
    }

119 120
    #ifdef WITH_CRASHHANDLER
        while( true )
121
        {
122 123
            pid_t pid = fork();
            if( pid < 0 )
124
                vlmcFatal("Can't fork to launch VLMC. Exiting.");
125 126 127

            /* We're in the crash handler process */
            if( pid != 0 )
128
            {
129 130 131 132 133 134 135 136 137
                int status;

                wait( &status );
                if( WIFEXITED(status) )
                {
                    int ret = WEXITSTATUS( status );
                    if ( ret == 2 )
                        continue ;
                    else
138
                        return ret ;
139 140 141
                }
                else
                {
142
                    vlmcCritical() << "Unhandled crash.";
143
                    return 1;
144
                }
145
            }
146 147 148 149 150 151 152 153
            else /* We're actually in the program */
            {
                signal( SIGSEGV, signalHandler );
                signal( SIGFPE, signalHandler );
                signal( SIGABRT, signalHandler );
                signal( SIGILL, signalHandler );
                break; /* Run it */
            }
154
        }
155
    #endif
156 157

    return VLMCmain( argc, argv );
158
}