Example #1
0
USEFORM("..\..\..\..\tools\win32\krdevui\ConfMainFrameUnit.cpp", ConfMainFrame); /* TFrame: File Type */
//---------------------------------------------------------------------------
#ifdef TVP_SUPPORT_ERI
#	pragma link "../../../../Lib/liberina.lib"
#endif
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	// try starting the program!
	bool engine_init = false;
	try
	{
		if(TVPCheckProcessLog()) return 0; // sub-process for processing object hash map log


		TVPInitScriptEngine();
		engine_init = true;

		// banner
		TVPAddImportantLog(TJS_W("Program started on ") + TVPGetOSName() +
			TJS_W(" (") + TVPGetPlatformName() + TJS_W(")"));

		// TVPInitializeBaseSystems
		TVPInitializeBaseSystems();

		Application->Initialize();

		if(TVPCheckPrintDataPath()) return 0;
		if(TVPCheckCmdDescription()) return 0;
		if(TVPExecuteUserConfig()) return 0; // userconf

		TVPSystemInit();

		if(TVPCheckAbout()) return 0; // version information dialog box;

		Application->Title = "‹g—¢‹g—¢";
		Application->CreateForm(__classid(TTVPMainForm), &TVPMainForm);
		TVPLoadPluigins(); // load plugin module *.tpm
		if(TVPProjectDirSelected) TVPInitializeStartupScript();

		Application->Run();

		try
		{
			TVPSystemUninit();
		}
		catch(...)
		{
			// ignore errors
		}
	}
	catch (EAbort &e)
	{
		// nothing to do
	}
	catch (Exception &exception)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&exception);
	}
	catch (eTJSScriptError &e)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&Exception(e.GetMessage().AsAnsiString()));
	}
	catch (eTJS &e)
	{
		TVPOnError();
		if(!TVPSystemUninitCalled)
			Application->ShowException(&Exception(e.GetMessage().AsAnsiString()));
	}
	catch(...)
	{
		Application->ShowException(&Exception("Unknown error!"));
	}

	if(engine_init) TVPUninitScriptEngine();

#ifndef _DEBUG
	// delete application and exit forcely
	// this prevents ugly exception message on exit

	delete Application;
	ExitProcess(TVPTerminateCode);
#endif
	return TVPTerminateCode;
}
Example #2
0
bool tTVPApplication::StartApplication( int argc, char* argv[] ) {
	_set_se_translator(se_translator_function);

	ArgC = argc;
	ArgV = argv;
	for( int i = 0; i < argc; i++ ) {
		if(!strcmp(argv[i], "-@processohmlog")) {
			has_map_report_process_ = true;
		}
	}
	TVPTerminateCode = 0;

	CheckConsole();

	// try starting the program!
	bool engine_init = false;
	try {
		if(TVPCheckProcessLog()) return true; // sub-process for processing object hash map log

		TVPInitScriptEngine();
		engine_init = true;

		// banner
		TVPAddImportantLog( TVPFormatMessage(TVPProgramStartedOn, TVPGetOSName(), TVPGetPlatformName()) );

		// TVPInitializeBaseSystems
		TVPInitializeBaseSystems();

		Initialize();

		if(TVPCheckPrintDataPath()) return true;
		if(TVPExecuteUserConfig()) return true;
		
		image_load_thread_ = new tTVPAsyncImageLoader();

		TVPSystemInit();

		if(TVPCheckAbout()) return true; // version information dialog box;

		SetTitle( std::wstring(TVPKirikiri) );
		TVPSystemControl = new tTVPSystemControl();
#ifndef TVP_IGNORE_LOAD_TPM_PLUGIN
		TVPLoadPluigins(); // load plugin module *.tpm
#endif
		// Check digitizer
		CheckDigitizer();

		// start image load thread
		image_load_thread_->Resume();

		if(TVPProjectDirSelected) TVPInitializeStartupScript();

		Run();

		try {
			// image_load_thread_->ExitRequest();
			delete image_load_thread_;
			image_load_thread_ = NULL;
		} catch(...) {
			// ignore errors
		}
		try {
			TVPSystemUninit();
		} catch(...) {
			// ignore errors
		}
	} catch( const EAbort & ) {
		// nothing to do
	} catch( const Exception &exception ) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException(exception.what());
	} catch( const TJS::eTJSScriptError &e ) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException( e.GetMessage().c_str() );
	} catch( const TJS::eTJS &e) {
		TVPOnError();
		if(!TVPSystemUninitCalled)
			ShowException( e.GetMessage().c_str() );
	} catch( const std::exception &e ) {
		ShowException( ttstr(e.what()).c_str() );
	} catch( const char* e ) {
		ShowException( ttstr(e).c_str() );
	} catch( const wchar_t* e ) {
		ShowException( e );
	} catch( const SEHException& e ) {
		PEXCEPTION_RECORD rec = e.ExceptionPointers->ExceptionRecord;
		std::wstring text(SECodeToMessage(e.Code));
		ttstr result = TJSGetStackTraceString( 10 );
		PrintConsole( result.c_str(), result.length(), true );

		TVPDumpHWException();
		ShowException( text.c_str() );
	} catch(...) {
		ShowException( (const tjs_char*)TVPUnknownError );
	}

	if(engine_init) TVPUninitScriptEngine();

	if(TVPSystemControl) delete TVPSystemControl;
	TVPSystemControl = NULL;

	CloseConsole();

	return false;
}