Use the new CLI parser class in a few more places.

This commit is contained in:
LoRd_MuldeR 2014-02-01 20:21:24 +01:00
parent b18d067d51
commit 2d7aa8f949
7 changed files with 33 additions and 129 deletions

View File

@ -46,6 +46,8 @@ s_parameters[] =
{ "skip-avisynth-check", 0, CLI_PARAM_SKIP_AVS_CHECK },
{ "skip-vapoursynth-check", 0, CLI_PARAM_SKIP_VPS_CHECK },
{ "force-cpu-no-64bit", 0, CLI_PARAM_FORCE_CPU_NO_X64 },
{ "force-cpu-no-64bit", 0, CLI_PARAM_FORCE_CPU_NO_SSE },
{ "force-cpu-no-64bit", 0, CLI_PARAM_FORCE_CPU_NO_INT },
{ "no-deadlock-detection", 0, CLI_PARAM_NO_DEADLOCK },
{ "console", 0, CLI_PARAM_DEBUG_CONSOLE },
{ "no-console", 0, CLI_PARAM_NO_DEBUG_CONSOLE },

View File

@ -37,10 +37,12 @@ static const int CLI_PARAM_SKIP_AVS_CHECK = 6;
static const int CLI_PARAM_SKIP_VPS_CHECK = 7;
static const int CLI_PARAM_SKIP_X264_CHECK = 8;
static const int CLI_PARAM_FORCE_CPU_NO_X64 = 9;
static const int CLI_PARAM_NO_DEADLOCK = 10;
static const int CLI_PARAM_DEBUG_CONSOLE = 11;
static const int CLI_PARAM_NO_DEBUG_CONSOLE = 12;
static const int CLI_PARAM_NO_GUI_STYLE = 13;
static const int CLI_PARAM_FORCE_CPU_NO_SSE = 10;
static const int CLI_PARAM_FORCE_CPU_NO_INT = 11;
static const int CLI_PARAM_NO_DEADLOCK = 12;
static const int CLI_PARAM_DEBUG_CONSOLE = 13;
static const int CLI_PARAM_NO_DEBUG_CONSOLE = 14;
static const int CLI_PARAM_NO_GUI_STYLE = 15;
///////////////////////////////////////////////////////////////////////////////
// CLI Parser

View File

@ -19,14 +19,7 @@
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
//x264 includes
#include "global.h"
#include "targetver.h"
//Version
#define ENABLE_X264_VERSION_INCLUDE
#include "version.h"
#undef ENABLE_X264_VERSION_INCLUDE
//Windows includes
#define NOMINMAX
@ -47,6 +40,15 @@
//VLD
#include <vld.h>
//x264 includes
#include "targetver.h"
#include "cli.h"
//Version
#define ENABLE_X264_VERSION_INCLUDE
#include "version.h"
#undef ENABLE_X264_VERSION_INCLUDE
//Qt includes
#include <QApplication>
#include <QMessageBox>
@ -656,89 +658,6 @@ void x264_init_console(const QStringList &argv)
{
bool enableConsole = x264_is_prerelease() || (X264_DEBUG);
if(_environ)
{
wchar_t *logfile = NULL;
size_t logfile_len = 0;
if(!_wdupenv_s(&logfile, &logfile_len, L"X264_LOGFILE"))
{
if(logfile && (logfile_len > 0))
{
FILE *temp = NULL;
if(!_wfopen_s(&temp, logfile, L"wb"))
{
fprintf(temp, "%c%c%c", char(0xEF), char(0xBB), char(0xBF));
g_x264_log_file = temp;
}
free(logfile);
}
}
}
if(!X264_DEBUG)
{
for(int i = 0; i < argv.count(); i++)
{
if(!argv.at(i).compare("--console", Qt::CaseInsensitive))
{
enableConsole = true;
}
else if(!argv.at(i).compare("--no-console", Qt::CaseInsensitive))
{
enableConsole = false;
}
}
}
if(enableConsole)
{
if(!g_x264_console_attached)
{
if(AllocConsole() != FALSE)
{
SetConsoleCtrlHandler(NULL, TRUE);
SetConsoleTitle(L"Simple x264 Launcher | Debug Console");
SetConsoleOutputCP(CP_UTF8);
g_x264_console_attached = true;
}
}
if(g_x264_console_attached)
{
//-------------------------------------------------------------------
//See: http://support.microsoft.com/default.aspx?scid=kb;en-us;105305
//-------------------------------------------------------------------
const int flags = _O_WRONLY | _O_U8TEXT;
int hCrtStdOut = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), flags);
int hCrtStdErr = _open_osfhandle((intptr_t) GetStdHandle(STD_ERROR_HANDLE), flags);
FILE *hfStdOut = (hCrtStdOut >= 0) ? _fdopen(hCrtStdOut, "wb") : NULL;
FILE *hfStdErr = (hCrtStdErr >= 0) ? _fdopen(hCrtStdErr, "wb") : NULL;
if(hfStdOut) { *stdout = *hfStdOut; std::cout.rdbuf(new std::filebuf(hfStdOut)); }
if(hfStdErr) { *stderr = *hfStdErr; std::cerr.rdbuf(new std::filebuf(hfStdErr)); }
}
HWND hwndConsole = GetConsoleWindow();
if((hwndConsole != NULL) && (hwndConsole != INVALID_HANDLE_VALUE))
{
HMENU hMenu = GetSystemMenu(hwndConsole, 0);
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
SetWindowLong(hwndConsole, GWL_STYLE, GetWindowLong(hwndConsole, GWL_STYLE) & (~WS_MAXIMIZEBOX) & (~WS_MINIMIZEBOX));
SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
}
}
}
/*
* Initialize the console
*/
void x264_init_console(int argc, char* argv[])
{
bool enableConsole = x264_is_prerelease() || (X264_DEBUG);
if(_environ)
{
wchar_t *logfile = NULL;
@ -760,17 +679,8 @@ void x264_init_console(int argc, char* argv[])
if(!X264_DEBUG)
{
for(int i = 0; i < argc; i++)
{
if(!_stricmp(argv[i], "--console"))
{
enableConsole = true;
}
else if(!_stricmp(argv[i], "--no-console"))
{
enableConsole = false;
}
}
if(CLIParser::checkFlag(CLI_PARAM_DEBUG_CONSOLE, argv)) enableConsole = true;
if(CLIParser::checkFlag(CLI_PARAM_NO_DEBUG_CONSOLE, argv)) enableConsole = false;
}
if(enableConsole)
@ -1108,17 +1018,11 @@ x264_cpu_t x264_detect_cpu_features(const QStringList &argv)
features.count = qBound(1UL, systemInfo.dwNumberOfProcessors, 64UL);
}
if(argv.count() > 0)
{
bool flag = false;
for(int i = 0; i < argv.count(); i++)
{
if(!argv[i].compare("--force-cpu-no-64bit", Qt::CaseInsensitive)) { flag = true; features.x64 = false; }
if(!argv[i].compare("--force-cpu-no-sse", Qt::CaseInsensitive)) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
if(!argv[i].compare("--force-cpu-no-intel", Qt::CaseInsensitive)) { flag = true; features.intel = false; }
}
if(CLIParser::checkFlag(CLI_PARAM_FORCE_CPU_NO_X64, argv)) { flag = true; features.x64 = false; }
if(CLIParser::checkFlag(CLI_PARAM_FORCE_CPU_NO_SSE, argv)) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
if(CLIParser::checkFlag(CLI_PARAM_FORCE_CPU_NO_INT, argv)) { flag = true; features.intel = false; }
if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n");
}
return features;
}
@ -1484,7 +1388,7 @@ bool x264_user_is_admin(void)
/*
* Initialize Qt framework
*/
bool x264_init_qt(int argc, char* argv[])
bool x264_init_qt(int &argc, char **argv)
{
static bool qt_initialized = false;
typedef BOOL (WINAPI *SetDllDirectoryProc)(WCHAR *lpPathName);

View File

@ -132,9 +132,9 @@ x264_cpu_t x264_detect_cpu_features(const QStringList &argv);
bool x264_enable_close_button(const QWidget *win, const bool bEnable);
void x264_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
void x264_finalization(void);
void x264_init_console(int argc, char* argv[]);
void x264_init_console(const QStringList &argv);
void x264_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
bool x264_init_qt(int argc, char* argv[]);
bool x264_init_qt(int &argc, char **argv);
bool x264_is_executable(const QString &path);
bool x264_is_prerelease(void);
const QString &x264_known_folder(x264_known_folder_t folder_id);

View File

@ -44,8 +44,11 @@ void handleMultipleInstances(const QStringList &args, IPC *ipc);
static int x264_main(int argc, char* argv[])
{
//Get CLI arguments
const QStringList &arguments = x264_arguments();
//Init console
x264_init_console(argc, argv);
x264_init_console(arguments);
//Print version info
qDebug("Simple x264 Launcher v%u.%02u.%u - use 64-Bit x264 with 32-Bit Avisynth", x264_version_major(), x264_version_minor(), x264_version_build());
@ -65,9 +68,6 @@ static int x264_main(int argc, char* argv[])
qWarning("---------------------------------------------------------\n");
}
//Get CLI arguments
const QStringList &arguments = x264_arguments();
//Detect CPU capabilities
const x264_cpu_t cpuFeatures = x264_detect_cpu_features(arguments);
qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, X264_BOOL(cpuFeatures.intel));
@ -110,7 +110,7 @@ static int x264_main(int argc, char* argv[])
WinSevenTaskbar::init();
//Set style
if(!qApp->arguments().contains("--no-style", Qt::CaseInsensitive))
if(!CLIParser::checkFlag(CLI_PARAM_NO_GUI_STYLE, arguments))
{
qApp->setStyle(new QPlastiqueStyle());
}
@ -170,8 +170,6 @@ void handleMultipleInstances(const QStringList &args, IPC *ipc)
case CLI_PARAM_NO_FORCE_ENQUEUE:
flags = (flags & (~IPC_FLAG_FORCE_ENQUEUE));
break;
default:
qWarning("Unknown command-line option!");
}
}

View File

@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2
#define VER_X264_MINOR 3
#define VER_X264_PATCH 0
#define VER_X264_BUILD 743
#define VER_X264_BUILD 744
#define VER_X264_MINIMUM_REV 2380
#define VER_X264_CURRENT_API 142

View File

@ -1531,8 +1531,6 @@ bool MainWindow::parseCommandLineArgs(void)
case CLI_PARAM_NO_FORCE_ENQUEUE:
flags = (flags & (~IPC_FLAG_FORCE_ENQUEUE));
break;
default:
qWarning("Unknown command-line option!");
}
}