예제 #1
0
BOOL CDtxShellExApp::InitInstance() 
{
	if (!InitATL())
		return FALSE;
	// Create document template
	AddDocTemplate(new CMultiDocTemplate(	IDR_DTX_TYPE,
		RUNTIME_CLASS(CDtxShellExDoc),RUNTIME_CLASS(CMDIChildWnd), RUNTIME_CLASS(CView)));

	return CWinApp::InitInstance();
}
예제 #2
0
BOOL CERadQueueCallApp::InitInstance()
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Register all OLE server (factories) as running.  This enables the
	//  OLE libraries to create objects from other applications.
	COleObjectFactory::RegisterAll();
	if (!InitATL())
		return FALSE;

	HRESULT hr = CoInitialize(NULL);
	if (FAILED(hr))
	{
		LOG_ERROR_MINOR(LL_ERROR | LD_FILE, ME_ERR_COINITIALIZE, hr);
		return FALSE;
	}

	char lpModule[_MAX_PATH];
	::GetModuleFileName(NULL, lpModule, sizeof(lpModule));

	char lpDrive[_MAX_PATH], lpDir[_MAX_PATH];
	::_splitpath(lpModule, lpDrive, lpDir, NULL, NULL);

	strcat(lpDrive, lpDir);
	::SetCurrentDirectory(lpDrive);
	
	CLOG::SetParameter(LL_MASK);
	MRET rc = CLOG::Initialize();
	if (rc != ME_OK)
	{
		CoUninitialize();
		LOG_ERROR(LL_ERROR | LD_FILE, rc);
		return FALSE;
	}

	rc = CRunTime::ExchangeXML();
	if (rc != ME_OK)
	{
		CoUninitialize();
		LOG_ERROR(LL_ERROR | LD_FILE, rc);
		return FALSE;
	}

	CoUninitialize();

	return TRUE;
}
예제 #3
0
파일: xdll.cpp 프로젝트: uvbs/XDLL
BOOL CXdllApp::InitInstance()
{
// 	if (!AfxSocketInit())
// 	{
// 		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
// 		return FALSE;
// 	}

	AfxEnableControlContainer();
	if (!InitATL())
		return FALSE;

	return TRUE;
}
BOOL CEventHandlerApp::InitInstance()
{
    // If app is already running, show it and bail out.
    if( !FirstInstance() ) {
		return false;
	}

    // ATL stuff added by MFC.
	if (!InitATL())
		return FALSE;


	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("QBSDK Tools"));


	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		return TRUE;
	}


    CreateMainWindow();

    return TRUE;
}
예제 #5
0
BOOL AppMainApp::InitInstance()
{
	pMainDialogWindowCrypt = NULL;
	pMainDialogWindow=NULL;
	if (!InitATL()){
		return FALSE;
	}
	{// На первый запуск...
		char sz1[128]={0};
		char sz2[128]="1";
		CString sAddCal;
		GetCommandLineParameter("addcal",sAddCal);
		if(sAddCal!=""){
			strcpy(sz1,sAddCal);
			SetRegSetting("", "FR_addCalendar", sz1);
			return FALSE;
		}
		CString sAddClo;
		GetCommandLineParameter("addclo",sAddClo);
		if(sAddClo!=""){
			strcpy(sz2,sAddClo);
			SetRegSetting("", "FR_addClock", sz2);
			return FALSE;
		}
		GetRegSetting("", "FR_addClock", sz1, sizeof(sz1));
		bAddOnStartClo=atol(sz1);
		GetRegSetting("", "FR_addCalendar", sz2, sizeof(sz2));
		bAddOnStartCal=atol(sz2);
	}
	{//setup_file
		// Регистрируем файл
		char szWkmRegistered[32]={0};
		GetRegSetting("", "wpc_setupRegistered", szWkmRegistered, sizeof(szWkmRegistered));
		if(szWkmRegistered[0]==0){
			strcpy(szWkmRegistered,"yes");
			SetRegSetting("", "wpc_setupRegistered", szWkmRegistered);
			RegisterExtension("wpc_setup","WireChanger setup file","-setup_file=");
		}
		CString sSetupFile;
		GetCommandLineParameter("setup_file",sSetupFile);
		if(sSetupFile!=""){
			if(isFileExist(sSetupFile)){
				CString sContent,sKeyPart;
				ReadFile(sSetupFile,sContent);
				CString sXML=CDataXMLSaver::GetInstringPart("<SETUP>","</SETUP>",sContent);
				if(sXML==""){
					sKeyPart=sContent;
				}
				// Делаем что сказано...
				if(sKeyPart!=""){
					SaveFile(GetUserFolder()+LICENSE_KEY_FILE,sKeyPart);
					AfxMessageBox(_l("Registration info installed successfully\nRestart WireChanger to see changes"));
				}
			}else{
				AfxMessageBox(Format("Reading setup file error: '%s' not found!",sSetupFile));
			}
			return FALSE;
		}
	}
	CString sExe;
	GetCommandLineParameter("add",sExe,0);
	if(sExe!=""){_XLOG_
		CString sNewFile=CString(GetApplicationDir())+WP_TEMPLATE+"\\"+GetPathPart(sExe,0,0,1,1);
		BOOL b=CopyFile(sExe,sNewFile,TRUE);
		if(!b){
			AfxMessageBox(_l("Error")+": "+_l("Widget already exist"));
		}
		return FALSE;
	}
    // Глобальные настройки
    CString sDats;
    ReadFile(CString(GetApplicationDir())+"inits.txt",sDats);
    AppName()=PROGNAME;
    AddDefsWallps()=1;
	AddDefsInteract()=1;
	if(sDats.GetLength()){
		CString sAppName=CDataXMLSaver::GetInstringPart("app:[","]",sDats);
		if(sAppName.GetLength()!=0){
			AppName()=sAppName;
		}
		AddDefsWallps()=atol(CDataXMLSaver::GetInstringPart("defs:[","]",sDats));
		AddDefsInteract()=atol(CDataXMLSaver::GetInstringPart("intr:[","]",sDats));
	}
    //===========
	CString sConsoleMode;
	GetCommandLineParameter("console",sConsoleMode);
	CString sIniFileInfo;
	ReadFile(CString(GetApplicationDir())+"install.ini",sIniFileInfo);
	if(sIniFileInfo!=""){
		sIniFileInfo+="\r\n";
	}
	if(sConsoleMode=="yes"){
		CString sConsoleSave,sConsoleRest;
		GetCommandLineParameter("wpsave",sConsoleSave);
		GetCommandLineParameter("wprestore",sConsoleRest);
		if(sConsoleSave=="yes"){
			if(sIniFileInfo.Find("[Main]")==-1){
				sIniFileInfo+="[Main]\r\n";
			}
			
			CString sAID,sDte;
			GetCommandLineParameter("affid",sAID);
			GetCommandLineParameter("date",sDte);
			if(sIniFileInfo.Find("AffId=")==-1){
				sIniFileInfo+=CString("AffId=")+sAID+"\r\n";
			}
			if(sIniFileInfo.Find("Date=")==-1){
				sIniFileInfo+=CString("Date=")+sDte+"\r\n";
			}
			if(sIniFileInfo.Find("CPD-W")==-1){
				CRegKey key;
				key.Open(HKEY_CURRENT_USER, "Control Panel\\Desktop");
				if(key!=NULL){
					char szTemp[MAX_PATH]="";
					DWORD lSize,dwType=0;
					lSize = MAX_PATH;
					if(RegQueryValueEx(key.m_hKey,"Wallpaper",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
						sIniFileInfo+="CPD-W=<";
						sIniFileInfo+=szTemp;
						sIniFileInfo+=">\r\n";
					}
					lSize = MAX_PATH;
					if(RegQueryValueEx(key.m_hKey,"WallpaperStyle",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
						sIniFileInfo+="CPD-WS=<";
						sIniFileInfo+=szTemp;
						sIniFileInfo+=">\r\n";
					}
					lSize = MAX_PATH;
					if(RegQueryValueEx(key.m_hKey,"TileWallpaper",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
						sIniFileInfo+="CPD-WT=<";
						sIniFileInfo+=szTemp;
						sIniFileInfo+=">\r\n";
					}
					lSize = MAX_PATH;
					if(RegQueryValueEx(key.m_hKey,"SCRNSAVE.EXE",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
						sIniFileInfo+="CPD-SS=<";
						sIniFileInfo+=szTemp;
						sIniFileInfo+=">\r\n";
					}
				}
				{// На дефолтного
					CRegKey key;
					key.Open(HKEY_USERS, ".DEFAULT\\Control Panel\\Desktop");
					if(key!=NULL){
						char szTemp[MAX_PATH]="";
						DWORD lSize,dwType=0;
						lSize = MAX_PATH;
						if(RegQueryValueEx(key.m_hKey,"Wallpaper",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
							sIniFileInfo+="DCPD-W=<";
							sIniFileInfo+=szTemp;
							sIniFileInfo+=">\r\n";
						}
						lSize = MAX_PATH;
						if(RegQueryValueEx(key.m_hKey,"WallpaperStyle",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
							sIniFileInfo+="DCPD-WS=<";
							sIniFileInfo+=szTemp;
							sIniFileInfo+=">\r\n";
						}
						lSize = MAX_PATH;
						if(RegQueryValueEx(key.m_hKey,"TileWallpaper",NULL, &dwType,(LPBYTE)szTemp, &lSize)== ERROR_SUCCESS){
							sIniFileInfo+="DCPD-WT=<";
							sIniFileInfo+=szTemp;
							sIniFileInfo+=">\r\n";
						}
					}
				}
			}
			if(sIniFileInfo.Find("UserData")==-1 || sIniFileInfo.Find("ConfigFile")==-1){
				sIniFileInfo+="ConfigFile=";
				sIniFileInfo+=objSettings.sIniFile;
				sIniFileInfo+="\r\n";
				sIniFileInfo+="UserData=";
				sIniFileInfo+=GetPathPart(objSettings.sIniFile,1,1,0,0);
				sIniFileInfo+="\r\n";
			}
			SaveFile(CString(GetApplicationDir())+"install.ini",sIniFileInfo);
		}else if(sConsoleRest=="yes"){
			if(sIniFileInfo==""){
				return 0;
			}
			RestoreWP(sIniFileInfo,1);
		}
		return FALSE;
	}
	CString sWait;
	GetCommandLineParameter("wait",sWait);
	DWORD dwStartWait=GetTickCount();
	if(sWait=="yes"){
		while(CheckProgrammRunState(NULL, UNIQUE_TO_TRUSTEE, false) && GetTickCount()-dwStartWait<180000){
			Sleep(1000);
		}
	}
	// Для нормально работы клонов
	if(IsThisProgrammAlreadyRunning()){
		// || IsOtherProgrammAlreadyRunning("WireChanger")
		DWORD dwTarget=BSM_APPLICATIONS;
		BroadcastSystemMessage(BSF_FORCEIFHUNG | BSF_IGNORECURRENTTASK | BSF_POSTMESSAGE, &dwTarget, iWM_THIS, WPARAM(99), LPARAM(99));
		return FALSE;
	}
	// Столбим уникальное за компьютером...
	CheckProgrammRunState("WC3",UNIQUE_TO_COMPUTER,1,"");
	CString sRestore;
	GetCommandLineParameter("restore",sRestore);
	if(sRestore!="" && isFileExist(sRestore)){
		CString sIniPath=GetPathPart(objSettings.sIniFile,1,1,0,0);
		{//Первый проход
			CZipArchive zipFile;
			if(zipFile.Open(sRestore)){
				ZIP_FIND_DATA pFind;
				HANDLE hSearch=zipFile.FindFirstFile("*.*",&pFind);
				while(zipFile.FindNextFile(hSearch, &pFind)){
					CString sFileName=pFind.szFileName;
					if(sFileName!=""){
						CZipFile zI;
						if(zipFile.GetFile(pFind.nDirIndex,&zI)){
							DeleteFile(sIniPath+sFileName);
							zI.SafeSaveToDosk(sIniPath+sFileName,0);
						}
					}
				}
				zipFile.FindClose(hSearch);
				zipFile.Close();
			}
		}
	}
	AfxEnableControlContainer();
	AfxInitRichEdit();
#if WINVER<=0x0050
#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
#endif
	OleInitialize(NULL);
	//
	CRYPT_START
	objSettings.sLikUser="";
	objSettings.sLikKey="";
	HANDLE hLicenseFile=::CreateFile(GetUserFolder()+LICENSE_KEY_FILE, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (!hLicenseFile || hLicenseFile==INVALID_HANDLE_VALUE){
		// Из локального каталога!
		hLicenseFile=::CreateFile(CString(GetApplicationDir())+LICENSE_KEY_FILE, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	}
	if (hLicenseFile && hLicenseFile!=INVALID_HANDLE_VALUE){
		DWORD dwRead=0;
		char szKey[2048]="";
		objSettings.sLikKey="";
		::ReadFile(hLicenseFile, szKey, sizeof(szKey), &dwRead, NULL);
		objSettings.sLikUser=CDataXMLSaver::GetInstringPart("user:[","]",szKey);
		objSettings.sLikKey=CDataXMLSaver::GetInstringPart("key:[","]",szKey);
		::CloseHandle(hLicenseFile);
	}
#ifdef LIC_HARDCODED_U
	objSettings.sLikUser=LIC_HARDCODED_U;
#endif
#ifdef LIC_HARDCODED_K
	objSettings.sLikKey=LIC_HARDCODED_K;
#endif
	//if(sIniFileInfo.Find("WireChangerEF")!=-1){
		/*
		WC5Elefun	CCC2-HJ3S-88A6-C4TP
		*/
		/*
		WC5IPv6	4HVF-9XF6-DGQ2-94U2	
		*/
		/*
		WK999IPv6	EJCM-VNR7-GZ8F
		*/
		/*Mapi2Pop3
		IPv6	GT8N-6747-AGDM
		*/
		/*
		// Здесь поддержан элефан
		USE_ELEFUN=1;
		objSettings.sLikUser="******";
		objSettings.sLikKey=Recrypt("\xd3\x4c\xc3\x24\x84\x53\x3e\x2a\x2c\x21\x9e\x24\x48\x34\xb5\xb4");//"CCC2-HJ3S-88A6-C4TP";// EXECryptor_DecryptStr()?
		*/
	//}
	UpdateTrialityStatus(objSettings.sLikUser,objSettings.sLikKey);
	if(objSettings.iLikStatus<0){
		CSettings* objAntiDebug=0;
		objAntiDebug->ApplySettings();
		return FALSE;
	}
	CRYPT_END
	objSettings.Load();
	if(sConsoleMode=="help"){
		ShowHelp("Overview");
		return 0;
	}
	{// грузим ddown
		CBitmap bpTmp;
		bpTmp.LoadBitmap(IDB_DDOWN_A);
		_bmp().AddBmpRaw("DDOWN",&bpTmp,GetBitmapSize(bpTmp));
	}
	{// грузим remd
		CBitmap bpTmp;
		bpTmp.LoadBitmap(IDB_REMIND_A);
		_bmp().AddBmpRaw("REMINDER",&bpTmp,GetBitmapSize(bpTmp));
	}
	theApp.MainImageList.Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 2);
	// Основные иконки
	AddBitmapToIList(theApp.MainImageList,IDB_IMAGELIST);
	for(int i=0;i<theApp.MainImageList.GetImageCount();i++){
		HICON hIcon=theApp.MainImageList.ExtractIcon(i);
		_bmp().AddBmp(_IL(i),hIcon);
		ClearIcon(hIcon);
	}
	_bmp().AddBmpRaw(IDB_BM_LOGO,CSize(LOGO_W,LOGO_H));
	// Пытаемся к пустому окну захимичится
	rFakedRect.SetRect(-10,0,0,0);
	LPCTSTR szClass = AfxRegisterWndClass(NULL);
	m_pFakeWnd = new CWnd;
	m_pFakeWnd->CreateEx(0, szClass, ROOT_WND_NAME, 0, rFakedRect, NULL, 0);
	m_pFakeWnd->ShowWindow(SW_HIDE);
	m_pFakeWnd->EnableWindow(FALSE);
	m_pFakeWnd->SetIcon(::AfxGetApp()->LoadIcon(MAIN_ICON),TRUE);
	m_pFakeWnd->SetIcon(::AfxGetApp()->LoadIcon(MAIN_ICON),FALSE);
	HotkeysSkipDD()=1;
	// Если при запуске небыло найдено ini-файла, показываем опции...
	if(objSettings.bStartWithOptions){
		objSettings.bStartWithOptions=FALSE;
		if(IsStartupWithWindows()==FALSE){
			StartupApplicationWithWindows(TRUE);
		}
		// точней больше не показываем
		// objSettings.OpenOptionsDialog();
	}
	
	// Создаем
	pMainDialogWindow = new AppMainDlg();
	pMainDialogWindowCrypt = pMainDialogWindow;
	if(!pMainDialogWindow){
		return FALSE;
	}
	theApp.m_pMainWnd=pMainDialogWindow;// Сначала задаем главное окно, потом создаем его
	pMainDialogWindow->Create(AppMainDlg::IDD,m_pFakeWnd);
	// Все!
	return TRUE;
}
예제 #6
0
BOOL CDistributedGameTreeServerApp::InitInstance()
{
	// CG: The following block was added by the Splash Screen component.
\
	{
\
		CCommandLineInfo cmdInfo;
\
		ParseCommandLine(cmdInfo);
\

\
		Splash::EnableSplashScreen(cmdInfo.m_bShowSplash);
\
	}
	
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	if (!InitATL())
		return FALSE;

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Distributed Game Tree Server"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CDistributedGameTreeServerDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CDistributedGameTreeServerView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) return TRUE;


	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();


	////////////////////////////////////////////////////////////////////////
	// Initiate the configurations and the log files:


	gameserver = new GameServer();			

	CMainFrame* tmpFrame = (CMainFrame*) GetMainWnd(); 
	CDistributedGameTreeServerDoc* tmpDoc = (CDistributedGameTreeServerDoc*) tmpFrame->GetActiveDocument();
	gameserver->setLogContext((LogContext*) tmpDoc);	
	

	return TRUE;
}
예제 #7
0
BOOL CFdmApp::InitInstance()
{
	g_crashReporter.reset (new vmsAppCrashReporter (
		g_appVersion.getVersion ()->m_tstrProductName,
		L"",
		g_appVersion.getVersion ()->m_tstrFileVersion,
		L"freedownloadmanager.org", L"/dump.php"));

	bool bContinue = true;
	if (g_crashReporter->CheckIfSubmitDumpIsRequestedByCommandLine (bContinue))
	{
		if (!bContinue)
			return FALSE;
	}

	g_crashReporter->InitializeCrashCatcher ();

	AfxEnableControlContainer ();

	{
		_configthreadlocale (_DISABLE_PER_THREAD_LOCALE);
		tstringstream tss;
		tss << _T (".") << GetACP ();
		_tsetlocale(LC_ALL, tss.str ().c_str ());
		_configthreadlocale (_ENABLE_PER_THREAD_LOCALE);
	}

	
	SetRegistryKey (IDS_COMPANY);

	CheckRegistry ();

	fsIECatchMgr::CleanIEPluginKey ();

	
	CString strPath = GetProfileString (_T(""), _T("Path"), _T(""));
	BOOL bNeedLocalRegister = FALSE;
	if (strPath == _T(""))
	{
		CRegKey key;
		if (ERROR_SUCCESS == key.Open (HKEY_CURRENT_USER, _T("Software\\FreeDownloadManager.ORG\\Free Download Manager"), KEY_WRITE))
			vmsSHCopyKey (HKEY_LOCAL_MACHINE, _T("Software\\FreeDownloadManager.ORG\\Free Download Manager"), key);
		strPath = GetProfileString (_T(""), _T("Path"), _T(""));
		bNeedLocalRegister = strPath != "";
	}

	if (GetFileAttributes (strPath + _T("\\fdm.exe")) == DWORD (-1))
	{
		strPath = _T("");
		bNeedLocalRegister = false;
	}

	
	
	if (strPath == _T("") || FALSE == SetCurrentDirectory (strPath))
		_dwAppState |= APPSTATE_PORTABLE_MODE;

	TCHAR tszExeDir [MY_MAX_PATH], tszExeFile [MY_MAX_PATH];
	GetModuleFileName (NULL, tszExeFile, sizeof (tszExeFile));
	fsGetPath (tszExeFile, tszExeDir);

	if (IS_PORTABLE_MODE)
	{
		strPath = tszExeDir;
		SetCurrentDirectory (strPath);
	}

	m_strAppPath = strPath;
	if (m_strAppPath.IsEmpty () == FALSE)
	{
		if (m_strAppPath [m_strAppPath.GetLength ()-1] != '\\' &&
				m_strAppPath [m_strAppPath.GetLength ()-1] != '/')
			m_strAppPath += '\\';
	}

	if (IS_PORTABLE_MODE == false)
	{
		CString strDataFldr = tszExeDir; strDataFldr += _T("Data");
		
		
		
		if (m_strAppPath.CompareNoCase (tszExeDir) &&
			 DWORD (-1) != GetFileAttributes (strDataFldr))
		{
			
			_dwAppState |= APPSTATE_PORTABLE_MODE;
			_dwAppState |= APPSTATE_PORTABLE_MODE_NOREG;
			m_strAppPath = tszExeDir;
		}
	}

	if (IS_PORTABLE_MODE)
	{
		
		vmsAppSettingsStore* pStgs = _App.get_SettingsStore ();
		CString strStgsFile = m_strAppPath + "Data\\settings.dat";
		fsBuildPathToFile (strStgsFile);
		pStgs->LoadSettingsFromFile (strStgsFile);
		_App.ApplySettingsToMutexes ();
	}

	BOOL bNoLng = FALSE;

	if (FALSE == InitLanguage ())
		bNoLng = TRUE;

	if (_tcscmp (m_lpCmdLine, _T("-suis")) == 0 || 
			_tcscmp (m_lpCmdLine, _T("-euis")) == 0 ||
			_tcscmp (m_lpCmdLine, _T("-duis")) == 0)
	{
		IntegrationSettings ();
		return FALSE;
	}

	if (IS_PORTABLE_MODE)
	{
		
		
		
		TCHAR szTmpFile [MY_MAX_PATH];
		CString str = m_strAppPath; str += _T("Data");
		CreateDirectory (str, NULL);
		if (0 == GetTempFileName (str, _T("fdm"), 0, szTmpFile))
			MessageBox (NULL, LS (L_NOWRITEACCESSTODATAFOLDER), vmsFdmAppMgr::getAppName (), MB_ICONWARNING);
		else
			DeleteFile (szTmpFile);
	}

	_SkinMgr.Initialize ();

	_IECatchMgr.ReadSettings ();
	_NOMgr.Initialize ();
	_IECMM.ReadState ();

	
	HRESULT hRes = OleInitialize (NULL);
	
	if (FAILED(hRes))
		return FALSE;
	
	m_bCOMInited = TRUE;

	const tstring currentVersion = vmsFdmAppMgr::getVersion ()->m_fileVersion.ToString ();
	bool currentVersionFirstRun = currentVersion != _App.RecentVersionRun ();
	if (currentVersionFirstRun)
		_App.RecentVersionRun (currentVersion);

	vmsAppGlobalObjects::Create2 (currentVersionFirstRun);

	fsFDMCmdLineParser cmdline;

	cmdline.Parse (fsFDMCmdLineParser::Elevated);

	if (cmdline.isRunAsElevatedTasksProcessor ())
	{
		RunAsElevatedTasksProcessor (cmdline);
		return FALSE;
	}

	if (cmdline.isNeedExit ())
		return FALSE;

	m_bForceSilentSpecified = cmdline.is_ForceSilentSpecified ();

	if (cmdline.isNeedRegisterServer ())
	{
		onNeedRegisterServer ( false );
		return FALSE;
	}
	else if (cmdline.isNeedRegisterServerUserOnly ())
	{
		onNeedRegisterServer ( true );
		return FALSE;
	}
	else if (cmdline.isNeedUnregisterServer ())
	{
		onNeedUnregisterServer ();
		return FALSE;
	}

	if (vmsWinSecurity::os_supports_elevation () && 
		_tcsncmp (m_lpCmdLine, _T("-nelvcheck"), 10) && _tcsicmp (m_lpCmdLine, _T("-autorun")))
	{
		if (vmsWinSecurity::IsProcessElevated ())
		{
			WCHAR wsz [MAX_PATH] = L"";
			GetModuleFileNameW (NULL, wsz, MAX_PATH);
			std::wstring wstr = L"\"";
			wstr += wsz;
			wstr += L"\" -nelvcheck ";
			wstr += CT2WEX<> (m_lpCmdLine);
			_appMutex.CloseMutex ();
			STARTUPINFOW si = {0}; PROCESS_INFORMATION pi = {0};
			si.cb = sizeof (si);
			if (vmsWinSecurity::RunAsDesktopUser (wsz, (LPWSTR)wstr.c_str (), NULL, si, pi))
				return FALSE;
			_appMutex.Create ();
		}
	}

	cmdline.Parse (fsFDMCmdLineParser::Normal);

	if (CheckFdmStartedAlready (m_bForceSilentSpecified == FALSE))
		return FALSE;

	if (!InitATL())
		return FALSE;

	_App.StartCount (_App.StartCount () + 1);

	
	
	if (IS_PORTABLE_MODE && (_dwAppState & APPSTATE_PORTABLE_MODE_NOREG) == 0)
		Install_RegisterServer ();

	
	
	
	
	vmsFilesToDelete::Process ();

	if (bNeedLocalRegister)
		RegisterServer (FALSE);

	

#ifdef _AFXDLL
	Enable3dControls();			
#else
	Enable3dControlsStatic();	
#endif

	CheckLocked ();

	_UpdateMgr.ReadSettings ();
	
	if (_UpdateMgr.IsStartUpdaterNeeded ())
	{
		if (_UpdateMgr.StartUpdater ())	
			return FALSE;	
		else
			::MessageBox (NULL, LS (L_CANTFINDUPDATER), LS (L_ERR), MB_ICONERROR);
	}

	vmsFlvSniffInjector::o ().Enable (_App.FlvMonitoring_Enable () != FALSE);

	LoadHistory ();

	_Snds.ReadSettings ();

	if (!vmsBtSupport::isBtDllValid ())
	{
		MessageBox (NULL, LS (L_INVALID_BT_MODULE), _T ("Free Download Manager"), MB_ICONERROR);
		return FALSE;
	}

	auto ytdllmgr = std::make_shared <vmsYouTubeParserDllMgr> (
		std::make_shared <vmsAppDataFolder> (L"FreeDownloadManager.ORG", L"Free Download Manager"),
		currentVersionFirstRun);
	vmsYouTubeParserDllMgr::reset (ytdllmgr);

	auto avMerger = std::make_shared<vmsAVMergerFFMPEG>();
	auto avAfterMergeAction = std::make_shared<vmsYouTubeAfterMergeAction>();
	auto avYouTubeMergingMgr = std::make_shared <vmsAVMergingMgr>( avMerger, avAfterMergeAction, 1 );	
	_YouTubeDldsMgr.setYouTubeAVMergingMgr( avYouTubeMergingMgr );

	CMainFrame* pFrame = NULL;
	fsnew1 (pFrame, CMainFrame);
	m_pMainWnd = pFrame;

	
	if (FALSE == pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, 
		NULL, NULL))
	{
		return FALSE;
	}

	
	BOOL bHidden = _tcscmp (m_lpCmdLine, _T ("-autorun")) == 0;

	_App.View_ReadWndPlacement (pFrame, _T("MainFrm"), 
		bHidden ? fsAppSettings::RWPA_FORCE_SWHIDE_AND_KEEP_MINIMIZED_MAXIMIZED_STATE : fsAppSettings::RWPA_NONE);

	if (!bHidden)
	{
		if (_App.Prg_StartMinimized ())
		{
			if (IsWindowVisible (pFrame->m_hWnd))
				pFrame->ShowWindow (SW_MINIMIZE);
		}
		else
		{
			pFrame->UpdateWindow();
			if (pFrame->IsWindowVisible ())
				pFrame->SetForegroundWindow ();
		}
	}

	m_bStarting = FALSE;

	
	hRes = _Module.RegisterClassObjects (CLSCTX_LOCAL_SERVER, 
				REGCLS_MULTIPLEUSE);
	if (FAILED (hRes))
	{
		LPVOID lpMsgBuf;
		FormatMessage( 
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM | 
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				hRes,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
				(LPTSTR) &lpMsgBuf,
				0,
				NULL 
				);
			
			
			
			MessageBox( NULL, (LPCTSTR)lpMsgBuf, nullptr, MB_OK | MB_ICONINFORMATION );
			
			LocalFree( lpMsgBuf );
	}
	m_bATLInited2 = SUCCEEDED (hRes);

	return TRUE;
}
BOOL CFUMApp::InitInstance()
{
	
	
	
	

#ifdef _AFXDLL
	Enable3dControls();			
#else
	Enable3dControlsStatic();	
#endif

	
	
	
	SetRegistryKey (_T("FreeDownloadManager.ORG"));

	CoInitialize (NULL);

	BOOL bNeedRegisterServer = FALSE;

	m_strAppPath = GetProfileString ("", "Path", "");

	if (m_strAppPath.IsEmpty () == FALSE)
	{
		if (m_strAppPath.Right (1) != "\\")
			m_strAppPath += "\\";
		if (GetFileAttributes (m_strAppPath + "fum.exe") == DWORD (-1))
		{
			bNeedRegisterServer = TRUE;
			m_strAppPath = "";
		}
	}

	if (m_strAppPath.IsEmpty ())
	{
		char sz [MAX_PATH];
		GetModuleFileName (NULL, sz, MAX_PATH);
		strrchr (sz, '\\') [1] = 0;
		WriteProfileString ("", "Path", sz);
		m_strAppPath = sz;
	}
	
	SetCurrentDirectory (m_strAppPath);

	if (strcmp (m_lpCmdLine, "-duis") == 0 && FALSE == IsRecentlyInstalledFumLaunched ())
		return FALSE;

	#ifndef _DEBUG
	if (MakeSureRecentlyInstalledFumLaunched () == FALSE)
		return FALSE;
	#endif

	InitLanguage ();

	if (strcmp (m_lpCmdLine, "-suis") == 0 ||
			strcmp (m_lpCmdLine, "-euis") == 0 ||
			strcmp (m_lpCmdLine, "-duis") == 0)
	{
		IntegrationSettings ();
		return FALSE;
	}

	if (lstrcmpi (m_lpCmdLine, "-shui") == 0)
	{
		HANDLE h = CreateEvent (NULL, TRUE, FALSE, "fum - oe - injapp");
		SetEvent (h);
		CloseHandle (h);
		return FALSE;
	}

	if (lstrcmpi (m_lpCmdLine, "-stui") == 0)
	{
		ShellExecute (0, "open", vmsGetAppFolder () + "fumoei.exe", 0, 0, SW_SHOW);
		return FALSE;
	}

	CString strUpdateFile = AfxGetApp ()->GetProfileString ("Update", "UpdateFile", "");
	if (strUpdateFile.IsEmpty () == FALSE)
	{
		AfxGetApp ()->WriteProfileString ("Update", "UpdateFile", "");
		m_hAppMutex = CreateMutex (NULL, TRUE, _pszAppMutex);
		if (FALSE == CDlgUpdate::StartUpdater (strUpdateFile))
		{
			DeleteFile (strUpdateFile);
			CloseHandle (m_hAppMutex);
		}
		else
		{
			return FALSE;
		}
	}

	
	char sz [MAX_PATH];
	fsGetSystemAppDataFolder (sz);
	CString str = sz; str += "Free Upload Manager\\uploads.sav";
	MoveFile (str, fsGetDataFilePath ("uploads.2.sav"));
	

	
	
	str = sz; str += "Free Upload Manager\\";
	if (str != fsGetAppDataFolder ())
	{
		CFileFind f; 
		BOOL b = f.FindFile (str + "uploads.?.sav");
		std::vector <CString> v;
		while (b)
		{
			b = f.FindNextFile ();
			v.push_back (f.GetFilePath ());
		}
		CString str2 = fsGetAppDataFolder ();
		for (size_t i = 0; i < v.size (); i++)
		{
			for (int j = 1, i = 0; j < 10 && i < (int)v.size (); j++)
			{
				CString str2; 
				str2.Format ("%suploads.%d.sav", fsGetAppDataFolder (), j);
				if (GetFileAttributes (str2) == DWORD (-1))
					MoveFile (v [i++], str2);
			}
		}
	}

	if (!InitATL())
		return FALSE;

	if (bNeedRegisterServer)
		RegisterServer ();

	AfxEnableControlContainer();

	

	
	

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;

	

	pFrame->LoadFrame(IDR_MAINFRAME,
		WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
		NULL);

	_App.View_ReadWndPlacement (pFrame, "MainFrm");

	
	if (_tcscmp (m_lpCmdLine, _T ("-autorun")) == 0)
		pFrame->ShowWindow (SW_HIDE);	
	else if (_App.Prg_StartMinimized ())
	{
		if (IsWindowVisible (pFrame->m_hWnd))
			pFrame->ShowWindow (SW_MINIMIZE);
	}
	else
	{
		pFrame->UpdateWindow();
		if (pFrame->IsWindowVisible ())
			pFrame->SetForegroundWindow ();
	}

	return TRUE;
}
BOOL CCarlaStudioApp::InitInstance()
{
try
{
// turn this on for extra new/delete checking in debug version
//	afxMemDF |= checkAlwaysMemDF;

	if (!InitATL())
		return FALSE;

	AfxInitRichEdit( );

	//AddToRecentFileList ("x");

//AfxEnableControlContainer( );	// for using activeX

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
	m_recentProjectsList.ReadList();

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;


	// PROJECT
		pDocTemplate = new CMultiDocTemplate(
		IDR_CStudioPTYPE,
		RUNTIME_CLASS(CProjectDoc),
		RUNTIME_CLASS(CNullWindow),//
		RUNTIME_CLASS(CEditView));
	AddDocTemplate(pDocTemplate);

	// language model document
	pDocTemplate = new CMultiDocTemplate(
		IDR_CStudioLangTYPE,
		RUNTIME_CLASS(CLangModelsDoc),
		RUNTIME_CLASS(CTabbedTreeChild), // custom MDI child frame
		RUNTIME_CLASS(CWTabBar));
	AddDocTemplate(pDocTemplate);

	// ANA
	pDocTemplate = new CMultiDocTemplate(
		IDR_CStudioAnaDocType,
		RUNTIME_CLASS(CAnaInputDoc),
		RUNTIME_CLASS(CMDIChildWnd),
		RUNTIME_CLASS(CInputDocView));
		AddDocTemplate(pDocTemplate);

	// SOURCE
	pDocTemplate = new CMultiDocTemplate(
		IDR_CStudioSrcDocType,
		RUNTIME_CLASS(CSourceTextInputDoc),
		RUNTIME_CLASS(CMDIChildWnd),
		RUNTIME_CLASS(CInputDocView));
		AddDocTemplate(pDocTemplate);


	// LOG WINDOW
	pDocTemplate = new CMultiDocTemplate(
			IDR_CLogWindowType,
			RUNTIME_CLASS(CLogWindow),
			RUNTIME_CLASS(CMDIChildWnd),
			RUNTIME_CLASS(CEditView));
		AddDocTemplate(pDocTemplate);

	// QUICK PARSE
	pDocTemplate = new CMultiDocTemplate(
			IDR_QuickParseDocType,
			RUNTIME_CLASS(CQuickParseDoc),
			RUNTIME_CLASS(CMDIChildWnd),
			RUNTIME_CLASS(CQuickParseView));
		AddDocTemplate(pDocTemplate);



/*	pDocTemplate = new CMultiDocTemplate(
		IDR_CStudioPTYPE,
		RUNTIME_CLASS(CProjectDoc),
		RUNTIME_CLASS(CMDIChildWnd),
		RUNTIME_CLASS(CEditView));	// I don't what this means here, since the views are chosen in the settings child window code
	AddDocTemplate(pDocTemplate);
*/
	// create main MDI Frame window
	CStudioMainFrame* pMainFrame = new CStudioMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(FALSE);// no printing

	// this must come before the commandline parser, since it might open a project
	CProcessSequence::getAvailableProcessorList(m_pProcessTemplates);


	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;

	cmdInfo.m_bShowSplash = TRUE;

	ParseCommandLine(cmdInfo);

	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		// this will be true when someone makes a hook object but CS wasn't
		// already running.  COM will run CS for the purpose of getting a hook object.

		// if we wanted to allow CS to run and provide com objects without
		// being visible, then we'd uncomment this line
				//return TRUE;
	}

#ifndef _DEBUG
	if( cmdInfo.m_bShowSplash )
	{
		CGuruSplash * pSplashWnd = new CGuruSplash(IDB_SPLASH,2000);
		pSplashWnd->Create();
	}
#endif

	// jdh the following code is so that we don't get a blank project by default
	// ParseCommand will have changed this to FileOpen if the user opened a project from windows file manager
	if(cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
		cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

//	OnAppAbout();

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	m_sLastOpenDir = GetProfileString( "Defaults", "LastOpenDir");

	CString sProjectPath = GetProfileString( "Defaults", "LastProjectFile");
	if(!getProject(TRUE)) // if command-line didn't open one
	{
		if(sProjectPath.GetLength())
		{
			if(askUserToFindFileIfNotFound(sProjectPath, CProjectDoc::getRegFileTypeID()))
				CProjectDoc* pDoc = (CProjectDoc*)OpenDocumentFile(sProjectPath);
		}
		else
		{
			OnFileNewProject();
		}
	}
	// The main window has been initialized, so show and update it.
	//these were above the openDocumentFIle stuff before
	//pMainFrame->ShowWindow(m_nCmdShow);
//	pMainFrame->UpdateWindow();

	}
	catch(LPCTSTR lpszError)
	{
		CString s;
		s = "CARLAStudio has encountered an unexpected condition.\n";
		s += "This is definitely a bug in CarlaStudio.\n";
#ifndef hab15a3
		s += "Please send a bug report, and include the following information:\n\n"; // hab 09/09/1999 fix typo
#else
		s += "Please sent a bug report, and include the following information:\n\n";
#endif // hab15a3
		CString sWhere;\
		sWhere.Format("Uncaught LPTSTR Exception \"%s\"", lpszError);
		s += sWhere;
		AfxMessageBox(s, MB_ICONSTOP | MB_OK);
		return FALSE;
	}
		catch(CString sError)
	{
		CString s;
		s = "CARLAStudio has encountered an unexpected condition.\n";
		s += "This is definitely a bug in CarlaStudio.\n";
#ifndef hab15a3
		s += "Please send a bug report, and include the following information:\n\n"; // hab 09/09/1999 fix typo
#else
		s += "Please sent a bug report, and include the following information:\n\n";
#endif // hab15a3
		CString sWhere;\
		sWhere.Format("Uncaught CString Exception \"%s\"", sError);
		s += sWhere;
		AfxMessageBox(s, MB_ICONSTOP | MB_OK);
		return FALSE;
	}

	// CG: This line inserted by 'Tip of the Day' component.
	ShowTipAtStartup();


	return TRUE;
}