Exemplo n.º 1
0
static DWORD WINAPI BeginConversion(LPVOID data)
{
	InternalThreadData* threadData = (InternalThreadData*) data;
	HANDLE conversionHandle = threadData->conversionHandle;
	CPath inputPath = threadData->inputPath;
	CPath outputPath = threadData->outputPath;
	bool isUrl = threadData->isUrl;
	ConversionActivityCallback fcn = threadData->activityCallback;
	void* userData = threadData->userData;
	LONGLONG contentLength = threadData->contentLength;
	wstring contentTitle = threadData->contentTitle;
	__int64 contentDuration = threadData->contentDuration;

	if (outputPath.GetExtension().MakeLower() == _T(".dvr-ms"))
		ConvertToDvrms(conversionHandle, CComBSTR(inputPath), CComBSTR(outputPath), isUrl, ActivityCallback, NULL, contentLength, CComBSTR(contentTitle.c_str()), contentDuration);

	if (outputPath.GetExtension().MakeLower() == _T(".wmv"))
		ConvertToWmv(conversionHandle, CComBSTR(inputPath), CComBSTR(outputPath), isUrl, ActivityCallback, NULL, contentLength, CComBSTR(contentTitle.c_str()), contentDuration);

	if (outputPath.GetExtension().MakeLower() == _T(".wtv"))
		ConvertToWtv(conversionHandle, CComBSTR(inputPath), CComBSTR(outputPath), isUrl, ActivityCallback, NULL, contentLength, CComBSTR(contentTitle.c_str()), contentDuration);

	_done = true;
	return 0;
}
Exemplo n.º 2
0
bool DvSaveFormatConverter::GetSaveFormat(const CStdString& sFileName, long& format)
{
	if(!m_bInitalised)
	{
		Initalise();
	}

	CPath path = sFileName;
	CStdString sExtension = path.GetExtension();
	sExtension = NormaliseExtension(sExtension);

	std::map<CStdString, long>::iterator iter;
	iter = m_FormatMap.find(sExtension);
	bool bFoundFormat = iter != m_FormatMap.end();
	if( bFoundFormat)
	{
		format = iter->second;
	}
	return bFoundFormat;
}
Exemplo n.º 3
0
LRESULT	CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    switch (wID)
    {
    case IDCANCEL:
        EndDialog(0);
        break;
    case IDC_BTN_CHOOSE_FILE:
    {
        g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory);

        CPath FileName;
        if (FileName.SelectFile(m_hWnd, CPath(CPath::MODULE_DIRECTORY), "Text file (*.txt)\0*.txt;\0All files (*.*)\0*.*\0", false))
        {
            if (FileName.GetExtension().length() == 0)
            {
                FileName.SetExtension("txt");
                SetDlgItemText(IDC_FILENAME, FileName);
            }
        }
        g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
    }
    break;
    case IDOK:
    {
        TCHAR FileName[MAX_PATH];
        int CurrentFormatSel = SendDlgItemMessage(IDC_FORMAT, CB_GETCURSEL, 0, 0);
        DumpFormat Format = (DumpFormat)SendDlgItemMessage(IDC_FORMAT, CB_GETITEMDATA, CurrentFormatSel, 0);
        DWORD StartPC = m_StartAddress.GetValue();
        DWORD EndPC = m_EndAddress.GetValue();
        DWORD DumpPC = m_PC.GetValue();
        GetDlgItemText(IDC_FILENAME, FileName, sizeof(FileName));
        if (strlen(FileName) == 0)
        {
            g_Notify->DisplayError("Please Choose target file");
            ::SetFocus(GetDlgItem(IDC_FILENAME));
            return false;
        }
        if (SendDlgItemMessage(IDC_USE_ALT_PC, BM_GETSTATE, 0, 0) != BST_CHECKED)
        {
            DumpPC = g_Reg->m_PROGRAM_COUNTER;
        }
        //disable buttons
        ::EnableWindow(GetDlgItem(IDC_E_START_ADDR), FALSE);
        ::EnableWindow(GetDlgItem(IDC_E_END_ADDR), FALSE);
        ::EnableWindow(GetDlgItem(IDC_E_ALT_PC), FALSE);
        ::EnableWindow(GetDlgItem(IDC_USE_ALT_PC), FALSE);
        ::EnableWindow(GetDlgItem(IDC_FILENAME), FALSE);
        ::EnableWindow(GetDlgItem(IDC_BTN_CHOOSE_FILE), FALSE);
        ::EnableWindow(GetDlgItem(IDC_FORMAT), FALSE);
        ::EnableWindow(GetDlgItem(IDOK), FALSE);
        ::EnableWindow(GetDlgItem(IDCANCEL), FALSE);
        g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory);
        if (!DumpMemory(FileName, Format, StartPC, EndPC, DumpPC))
        {
            //enable buttons
            g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
            return false;
        }
        g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
    }
    EndDialog(0);
    break;
    }
    return FALSE;
}
Exemplo n.º 4
0
int RunConverter( int argc, _TCHAR* * argv )
{
#ifdef _DEBUG
	// sleep a bit so we can have time to attach a debugger
	Tell(_T("Sleeping for %d seconds in debug mode."), startupTimeout / 1000);
	Sleep(startupTimeout);
#endif
	int ret = 0;
	wstring name;
	wstring title;
	HANDLE conversionHandle = NULL;

	po::options_description desc("Converts an MPEG-2 Program Stream to a DVR-MS, WMV, or WTV file.");
	po::positional_options_description pos;

	string input;
	string output;
	LONGLONG length;
	bool disableFileLogging;
	bool disableConsoleLogging;
	bool disableAllLogging;
	string interruptName;
	string interruptDirectory;
	string outputDirectory;
	string contentTitle;
	__int64 contentDuration = -1i64;

	desc.add_options()
		("help,?", "Display help message.")
		("input,i", po::value<string>(&input), "an MPEG2 input path. Can be a url.")
		("output,o", po::value<string>(&output), "output path.<type>. Where <type> can be one of \"dvr-ms\", \"wmv\", or \"wtv\"")
		("length,l", po::value<LONGLONG>(&length)->default_value(-1), "the length of the input content in bytes. Only required for a network path such as http." )
		("interrupt-name", po::value<string>(&interruptName), "the file name (without path or extension) of a file that will be created when conversion is to be interrupted.")
		("interrupt-directory", po::value<string>(&interruptDirectory), "the path for this app to look for an interrupt file. An interrupt file is the interrupt_file name with a .interrupt extension. The file itself can be empty.")
		("disable-file-logging", po::value<bool>(&disableFileLogging)->zero_tokens()->default_value(false), "indicates that logging to a file will be disabled.")
		("disable-console-logging", po::value<bool>(&disableConsoleLogging)->zero_tokens()->default_value(false), "indicates that logging to the console will be disabled.")
		("disable-all-logging", po::value<bool>(&disableAllLogging)->zero_tokens()->default_value(false), "indicates that all logging will be disabled.")
		("output-directory,d", po::value<string>(&outputDirectory), "the directory for this app to place conversion output. Only valid if output_path is omitted.")
		("content-title,t", po::value<string>(&contentTitle), "the Title that will be assigned to the output path.<type>.")
		("version,v", po::value<string>()->zero_tokens(), "prints the version of this app.")
		//("content-duration,d", po::value<__int64>(&contentDuration)->default_value(-1i64), "the duration of the input content in seconds." )
		;

	pos.add("input", 1);
	pos.add("output", 1);
	pos.add("length", 1);

	vector<string> args;

	for (int i = 1; i < argc; i++)
		args.push_back(WStringToString(argv[i]));

	po::variables_map variables;

	try
	{
		po::basic_parsed_options<char> oo = po::command_line_parser(args).
			options(desc).positional(pos).run();
		po::store(oo, variables);
		po::notify(variables);
	}
	catch (std::exception e)
	{
		Tell(_T("Invalid command line. Use --help to see options."));
		return -1;
	}

	if (!variables.count("input"))
	{
		bool display = false;
		wstring message;
		if (variables.count("version"))
		{
			message = _T("Version: ");
			message += MPEG2DVRMS_VERSION;
			display = true;
		}
		if (variables.count("help"))
		{
			message = _T("eh... help message not available yet. Hope you have the source!");
			display = true;
		}
		if (!display)
			message = _T("No input file was specified.");
		ret = 100;
		Tell(message);
	}
	else
	{
		try
		{
			//////////////////////////////////////////////////////////////////////////
			// command-line option handling

			LONGLONG contentLength = -1;

			if (variables.count("length"))
				contentLength = length;

			if (variables.count("interrupt-name"))
				name = StringToWString(interruptName);
			else
			{
				name = NewGuid();
				Tell(_T("Generated interrupt name is %s"), name.c_str());
			}

			if (variables.count("interrupt-directory"))
				_conversionFileStoragePath = StringToWString(interruptDirectory);

			if (variables.count("content-title"))
				title = StringToWString(contentTitle);
			else
				title = _T("");

#pragma region input output file handling
			wstring defaultExtension;

			if (IsVista())
				defaultExtension = _T(".dvr-ms");
			else
				defaultExtension = _T(".wtv");

			ATL_URL_SCHEME urlScheme;
			CUrl inputUrl;

			if (!inputUrl.CrackUrl(StringToWString(input).c_str()))
				urlScheme = ATL_URL_SCHEME_FILE;
			else
				urlScheme = inputUrl.GetScheme();

			if (urlScheme == -1)
				urlScheme = ATL_URL_SCHEME_FILE;

			wstring inputPath = StringToWString(input);
			CPath outputPath;

			if (urlScheme == ATL_URL_SCHEME_FILE)
			{
				CPath input = inputPath.c_str();

				if (input.IsFileSpec())
				{
					TCHAR szCurrentDirectory[MAX_PATH];
					if (!GetCurrentDirectory(MAX_PATH, szCurrentDirectory))
						throw CarverLab::Exception(GetLastError());
					wstring currentDirectory = (LPCTSTR)szCurrentDirectory;
					inputPath = currentDirectory + _T("\\") + inputPath.c_str();
					input = inputPath.c_str();
				}
				if (!input.FileExists())
					throw CarverLab::Exception(_T("MPEG2 input path does not exist."));

				if (!variables.count("output"))
					outputPath = inputPath.c_str();
				else
					outputPath = StringToWString(output).c_str();
			}
			else if (urlScheme == ATL_URL_SCHEME_HTTP ||
				urlScheme == ATL_URL_SCHEME_HTTPS)
			{
				if (!variables.count("output"))
				{
					wstring thefullpath;
					CString envString;
					envString.GetEnvironmentVariable(_T("PUBLIC"));
					thefullpath = envString;
					thefullpath += _T("\\Videos\\mpeg2dvrms-output");
					thefullpath += defaultExtension;
					outputPath = thefullpath.c_str();
				}
				else
					outputPath = StringToWString(output).c_str();
			}
			else
				throw CarverLab::Exception(_T("Only http or https URL schemes are supported."));

			bool isUrl = urlScheme != ATL_URL_SCHEME_FILE;

			CPath inPath = inputPath.c_str();

			if (outputPath.GetExtension().MakeLower() == inPath.GetExtension().MakeLower())
				outputPath.RenameExtension(defaultExtension.c_str());

			if (outputPath.GetExtension().MakeLower() == _T(".dvrms"))
			{
				outputPath.RemoveExtension();
				outputPath.AddExtension(_T(".dvr-ms"));
			}
#pragma endregion input output file handling

			//////////////////////////////////////////////////////////////////////////

			conversionHandle = CreateConversion(false, CComBSTR(name.c_str()));

			if (!conversionHandle)
				throw CarverLab::Exception();

			SetConsoleTitle(outputPath);

			Tell(_T("Press ENTER to interrupt and exit."));

			_done = false;
			HANDLE stdinput = GetStdHandle(STD_INPUT_HANDLE);

			std::auto_ptr<InternalThreadData> threadData(new InternalThreadData);
			threadData->activityCallback = ActivityCallback;
			threadData->contentLength = contentLength;
			threadData->conversionHandle = conversionHandle;
			threadData->inputPath = inPath;
			threadData->isUrl = isUrl;
			threadData->outputPath = outputPath;
			threadData->threadData = NULL;
			threadData->userData = NULL;
			threadData->contentTitle = StringToWString(contentTitle);
			threadData->contentDuration = contentDuration;

			_lastConvertedFilePath = outputPath;

			HANDLE thread = CreateThread(NULL, 0, BeginConversion, threadData.get(), 0, NULL);
			if (thread == NULL)
				throw CarverLab::Exception();

			bool shuttingDown = false;
			bool interruptSuccessful = false;	// will be true if the conversion is inactive after InterruptConversion is called

			while (!_done)
			{
				if (!shuttingDown && ((_kbhit() && _getch() == 13) || InterruptNow(name.c_str())))
				{
					shuttingDown = true;
					interruptSuccessful = InterruptConversion(conversionHandle, 30000);	// will wait 30 seconds for the conversion to die
				}

				Sleep(10);
			}

			if (!interruptSuccessful)
			{	// TODO: will need to kill this puppy in an unnice way... awwww
				Tell(_T("InterruptConversion was unsusccessful."));
			}
			// TODO: INFINITE? um... nope. this will need an intervention
			WaitForSingleObject(thread, INFINITE);

			CloseHandle(thread);
		}
		catch (CarverLab::Exception exception)
		{
			Tell(_T("*** Error: %s"), exception.GetErrorString());
			Tell(_T("Exiting..."));
			ret = exception.GetHRESULT();
		}
		catch (...)
		{
			DWORD errorCode = GetLastError();
			wstring error = Exception::GetLastErrorString(errorCode);
			Tell(_T("*** Unhandled Exception: %s"), error.c_str());
			Tell(_T("Exiting..."));
			ret = errorCode;
		}
		if (conversionHandle != NULL)
			CloseConversion(conversionHandle);
	}
#ifdef _DEBUG
	// sleep a bit so we can see any errors
	Tell(_T("Sleeping for %d seconds in debug mode."), sleepTimeout / 1000);
	Sleep(sleepTimeout);
#endif
	return ret;
}