- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# vsconv.cpp

    00001 /*
    00002  *      Copyright (C) 2003-2005 Gabest
    00003  *      http://www.gabest.org
    00004  *
    00005  *  This Program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2, or (at your option)
    00008  *  any later version.
    00009  *
    00010  *  This Program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00013  *  GNU General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with GNU Make; see the file COPYING.  If not, write to
    00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *  http://www.gnu.org/copyleft/gpl.html
    00019  *
    00020  */
    00021
    00022 // vsconv.cpp : Defines the class behaviors for the application.
    00023 //
    00024
    00025 #include "stdafx.h"
    00026 #include "vsconv.h"
    00027 #include "vsconvDlg.h"
    00028 #include "..\..\subtitles\VobSubFile.h"
    00029
    00030 #ifdef _DEBUG
    00031 #define new DEBUG_NEW
    00032 #endif
    00033
    00034
    00035 // CvsconvApp
    00036
    00037 BEGIN_MESSAGE_MAP(CvsconvApp, CWinApp)
    00038         ON_COMMAND(ID_HELP, CWinApp::OnHelp)
    00039 END_MESSAGE_MAP()
    00040
    00041
    00042 // CvsconvApp construction
    00043
    00044 CvsconvApp::CvsconvApp()
    00045 {
    00046         // TODO: add construction code here,
    00047         // Place all significant initialization in InitInstance
    00048 }
    00049
    00050
    00051 // The one and only CvsconvApp object
    00052
    00053 CvsconvApp theApp;
    00054
    00055
    00056 // CvsconvApp initialization
    00057
    00058 BOOL CvsconvApp::InitInstance()
    00059 {
    00060         // InitCommonControls() is required on Windows XP if an application
    00061         // manifest specifies use of ComCtl32.dll version 6 or later to enable
    00062         // visual styles.  Otherwise, any window creation will fail.
    00063         InitCommonControls();
    00064
    00065         CWinApp::InitInstance();
    00066
    00067         AfxEnableControlContainer();
    00068
    00069         // TODO
    00070 //      if(__argc > 1)
    00071         {
    00072                 CString in, out;
    00073                 CVobSubFile::SubFormat sf = CVobSubFile::None;
    00074                 int iLang = -1;
    00075                 bool fIgnoreForcedOnly = false;
    00076                 bool fForcedOnly = false;
    00077
    00078                 try
    00079                 {
    00080                         for(int i = 1; i < __argc; i++)
    00081                         {
    00082                                 if(__targv[i][0] == '-' || __targv[i][0] == '/')
    00083                                 {
    00084                                         CString sw(&__targv[i][1]);
    00085
    00086                                         if(sw == _T("f"))
    00087                                         {
    00088                                                 if(++i < __argc && __targv[i][0] != '-' && __targv[i][0] != '/')
    00089                                                 {
    00090                                                         CString fmt = CString(__targv[i]).MakeLower();
    00091
    00092                                                         if(fmt == _T("winsubmux"))
    00093                                                                 sf = CVobSubFile::WinSubMux;
    00094                                                         else if(fmt == _T("scenarist"))
    00095                                                                 sf = CVobSubFile::Scenarist;
    00096                                                         else if(fmt == _T("maestro"))
    00097                                                                 sf = CVobSubFile::Maestro;
    00098                                                         else
    00099                                                                 throw _T("Unrecognized conversion format");
    00100                                                 }
    00101                                                 else
    00102                                                         throw _T("No conversion format given");
    00103                                         }
    00104                                         else if(sw == _T("i"))
    00105                                         {
    00106                                                 if(++i < __argc && __targv[i][0] != '-' && __targv[i][0] != '/')
    00107                                                         in = __targv[i];
    00108                                                 else
    00109                                                         throw _T("Missing input file");
    00110                                         }
    00111                                         else if(sw == _T("o"))
    00112                                         {
    00113                                                 if(++i < __argc && __targv[i][0] != '-' && __targv[i][0] != '/')
    00114                                                         out = __targv[i];
    00115                                                 else
    00116                                                         throw _T("Missing output file");
    00117                                         }
    00118                                         else if(sw == _T("id"))
    00119                                         {
    00120                                                 if(++i < __argc && __targv[i][0] != '-' && __targv[i][0] != '/')
    00121                                                         iLang = _tcstol(__targv[i], NULL, 10);
    00122                                                 else
    00123                                                         throw _T("Missing stream id");
    00124                                         }
    00125                                         else if(sw == _T("ignoreforcedonly"))
    00126                                         {
    00127                                                 fIgnoreForcedOnly = true;
    00128                                         }
    00129                                         else if(sw == _T("forcedonly"))
    00130                                         {
    00131                                                 fForcedOnly = true;
    00132                                         }
    00133                                 }
    00134                         }
    00135
    00136                         if(!in.IsEmpty() && !out.IsEmpty() && sf != CVobSubFile::None)
    00137                         {
    00138                                 CVobSubFile vsf(NULL);
    00139
    00140                                 if(!vsf.Open(in))
    00141                                         throw _T("Can't open input");
    00142
    00143                                 if(iLang >= 0 && iLang < 32)
    00144                                         vsf.m_iLang = iLang;
    00145
    00146                                 if(fForcedOnly)
    00147                                         vsf.m_fOnlyShowForcedSubs = true;
    00148
    00149                                 if(fIgnoreForcedOnly)
    00150                                         vsf.m_fOnlyShowForcedSubs = false;
    00151
    00152                                 if(!vsf.Save(out, sf))
    00153                                         throw _T("Can't save output");
    00154
    00155                                 return FALSE;
    00156                         }
    00157                 }
    00158                 catch(LPCTSTR msg)
    00159                 {
    00160                         AfxMessageBox(CString(_T("Error: ")) + msg);
    00161                 }
    00162
    00163                 AfxMessageBox(
    00164                         _T("Usage: vsconv.exe <switches>\n\n")
    00165                         _T("-f \"format\" (winsubmux, scenarist, maestro)\n")
    00166                         _T("-i \"input\"\n")
    00167                         _T("-o \"output\"\n")
    00168                         _T("-id 0-31 (optional)\n")
    00169                         _T("-ignoreforcedonly (optional)\n")
    00170                         _T("-forcedonly (optional)\n")
    00171                         );
    00172
    00173                 return FALSE;
    00174         }
    00175
    00176         // TODO
    00177         return FALSE;
    00178
    00179
    00180         CvsconvDlg dlg;
    00181         m_pMainWnd = &dlg;
    00182         INT_PTR nResponse = dlg.DoModal();
    00183         if (nResponse == IDOK)
    00184         {
    00185                 // TODO: Place code here to handle when the dialog is
    00186                 //  dismissed with OK
    00187         }
    00188         else if (nResponse == IDCANCEL)
    00189         {
    00190                 // TODO: Place code here to handle when the dialog is
    00191                 //  dismissed with Cancel
    00192         }
    00193
    00194         // Since the dialog has been closed, return FALSE so that we exit the
    00195         //  application, rather than start the application's message pump.
    00196         return FALSE;
    00197 }