BOOL BackupDB(CString dbPath, CString prefix, CDittoPopupWindow **popUpMsg)
{
	if ((*popUpMsg) == NULL)
	{
		CRect r;
		GetMonitorRect(0, r);
		*popUpMsg = new CDittoPopupWindow();
		(*popUpMsg)->Create(CRect(r.right - 400, r.bottom - 100, r.right - 10, r.bottom - 10), NULL);		
		::SetWindowPos((*popUpMsg)->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
		(*popUpMsg)->ShowWindow(SW_SHOW);
		(*popUpMsg)->UpdateText(_T("Backing up Ditto's Database"));
	}
	CString backup = GetFilePath(dbPath);

	CInternetUpdate update;

	long runningVersion = update.GetRunningVersion();
	CString versionString = update.GetVersionString(runningVersion);

	backup += GetFileName(dbPath) += _T("_") + prefix + _T("_") + versionString;
	backup.Replace(_T(".db"), _T(""));
	backup.Replace(_T("."), _T("_"));

	CString temp = backup;

	temp += _T(".db");

	int i = 1;
	while(FileExists(temp))
	{
		temp.Format(_T("%s_%d.db"), backup, i);
		i++;
	}

	backup = temp;

	BOOL ret = CopyFile(dbPath, backup, TRUE);

	if ((*popUpMsg) != NULL)
	{
		(*popUpMsg)->UpdateText(_T("Running Ditto database scripts"));
	}

	return ret;
}
Ejemplo n.º 2
0
BOOL CCP_MainApp::InitInstance()
{
	AfxEnableControlContainer();
	AfxOleInit();
	AfxInitRichEditEx();

	DittoCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	if(cmdInfo.m_strFileName.IsEmpty() == FALSE)
	{
		try
		{
			g_Opt.m_bEnableDebugLogging = g_Opt.GetEnableDebugLogging();

			CClip_ImportExport Clip;
			CppSQLite3DB db;
			db.open(cmdInfo.m_strFileName);

			CClip_ImportExport clip;
			if(clip.ImportFromSqliteDB(db, false, true))
			{
				ShowCommandLineError("Ditto", theApp.m_Language.GetString("Importing_Good", "Clip placed on clipboard"));
			}
			else
			{
				ShowCommandLineError("Ditto", theApp.m_Language.GetString("Error_Importing", "Error importing exported clip"));
			}
		}
		catch (CppSQLite3Exception& e)
		{
			ASSERT(FALSE);

			CString csError;
			csError.Format(_T("%s - Exception - %d - %s"), theApp.m_Language.GetString("Error_Parsing", "Error parsing exported clip"), e.errorCode(), e.errorMessage());
			ShowCommandLineError("Ditto", csError);
		}	

		return FALSE;
	}
	else if(cmdInfo.m_bConnect || cmdInfo.m_bDisconnect)
	{
		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
		if(hWnd)
			::SendMessage(hWnd, WM_SET_CONNECTED, cmdInfo.m_bConnect, cmdInfo.m_bDisconnect);

		return FALSE;
	}

	//if starting from a u3 device we will pass in -U3Start
	if(cmdInfo.m_bU3)
		g_Opt.m_bU3 = cmdInfo.m_bU3 ? TRUE : FALSE;

	g_Opt.LoadSettings();

	CInternetUpdate update;

	long lRunningVersion = update.GetRunningVersion();
	CString cs = update.GetVersionString(lRunningVersion);
	cs.Insert(0, _T("InitInstance  -  Running Version - "));
	Log(cs);

	CString csMutex("Ditto Is Now Running");
	if(g_Opt.m_bU3)
	{
		//If running from a U3 device then allow other ditto's to run
		//only prevent Ditto from running from the same device
		csMutex += " ";
		csMutex += GETENV(_T("U3_DEVICE_SERIAL"));
	}
	else if(g_Opt.GetIsPortableDitto())
	{
		csMutex += " ";
		csMutex += g_Opt.GetExeFileName();
	}

	m_hMutex = CreateMutex(NULL, FALSE, csMutex);
	DWORD dwError = GetLastError();
	if(dwError == ERROR_ALREADY_EXISTS)
	{
		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
		if(hWnd)
			::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);

		return TRUE;
	}

	CString csFile = CGetSetOptions::GetLanguageFile();
	if(csFile.GetLength() > 0 && !m_Language.LoadLanguageFile(csFile))
	{
		CString cs;
		cs.Format(_T("Error loading language file - %s - \n\n%s"), csFile, m_Language.m_csLastError);
		Log(cs);
	}

	//The first time we run Ditto on U3 show a web page about ditto
	if(g_Opt.m_bU3)
	{
		if(FileExists(CGetSetOptions::GetDBPath()) == FALSE)
		{
			CString csFile = CGetSetOptions::GetPath(PATH_HELP);
			csFile += "U3_Install.htm";
			CHyperLink::GotoURL(csFile, SW_SHOW);
		}
	}

	int nRet = CheckDBExists(CGetSetOptions::GetDBPath());
	if(nRet == FALSE)
	{
		AfxMessageBox(theApp.m_Language.GetString("Error_Opening_Database", "Error Opening Database."));
		return FALSE;
	}

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = m_pMainFrame = pFrame;

	// prevent no one having focus on startup
	TargetActiveWindow();

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

	// prevent no one having focus on startup
	ReleaseFocus();

	return TRUE;
}
Ejemplo n.º 3
0
BOOL CCP_MainApp::InitInstance()
{
	LoadLibrary(TEXT("riched20.dll"));

	AfxEnableControlContainer();
	AfxOleInit();
	AfxInitRichEditEx();
	afxAmbientActCtx = FALSE; 

	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

	DittoCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	//if starting from a u3 device we will pass in -U3Start
	if(cmdInfo.m_bU3)
		g_Opt.m_bU3 = cmdInfo.m_bU3 ? TRUE : FALSE;

	g_Opt.LoadSettings();

	if(cmdInfo.m_uacPID > 0)
	{
		Log(StrF(_T("Startup up ditto as admin to paste to admin windows, parent process id: %d"), cmdInfo.m_uacPID));

		CString mutex;
		mutex.Format(_T("DittoAdminPaste_%d"), cmdInfo.m_uacPID);
		m_adminPasteMutex = CreateMutex(NULL, FALSE, mutex);

		m_pUacPasteThread = new CUAC_Thread(cmdInfo.m_uacPID);
		m_pUacPasteThread->Start();
		m_pUacPasteThread->WaitForThreadToExit(INT_MAX);

		return FALSE;
	}

	if(cmdInfo.m_strFileName.IsEmpty() == FALSE)
	{
		try
		{
			g_Opt.m_bEnableDebugLogging = g_Opt.GetEnableDebugLogging();

			CClip_ImportExport Clip;
			CppSQLite3DB db;
			db.open(cmdInfo.m_strFileName);

			CClip_ImportExport clip;
			if(clip.ImportFromSqliteDB(db, false, true))
			{
				ShowCommandLineError("Ditto", theApp.m_Language.GetString("Importing_Good", "Clip placed on clipboard"));
			}
			else
			{
				ShowCommandLineError("Ditto", theApp.m_Language.GetString("Error_Importing", "Error importing exported clip"));
			}
		}
		catch (CppSQLite3Exception& e)
		{
			ASSERT(FALSE);

			CString csError;
			csError.Format(_T("%s - Exception - %d - %s"), theApp.m_Language.GetString("Error_Parsing", "Error parsing exported clip"), e.errorCode(), e.errorMessage());
			ShowCommandLineError("Ditto", csError);
		}	

		return FALSE;
	}
	else if(cmdInfo.m_bConnect || cmdInfo.m_bDisconnect)
	{
		//First get the saved hwnd and send it a message
		//If ditt is running then this will return 1, meening the running ditto process
		//handled this message
		//If it didn't handle the message(ditto is not running) then startup this processes of ditto 
		//disconnected from the clipboard
		LRESULT ret = 0;
		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
		if(hWnd)
		{
			ret = ::SendMessage(hWnd, WM_SET_CONNECTED, cmdInfo.m_bConnect, cmdInfo.m_bDisconnect);
		}

		//passed off to the running instance of ditto, exit this instance
		if(ret == 1)
		{
			return FALSE;
		}
		
		if(cmdInfo.m_bConnect)
		{
			m_connectOnStartup = TRUE;
		}
		else if(cmdInfo.m_bDisconnect)
		{
			m_connectOnStartup = FALSE;
		}
	}
	else if(cmdInfo.m_bOpenWindow || cmdInfo.m_bCloseWindow)
	{
		//First get the saved hwnd and send it a message
		//If ditt is running then this will return 1, meening the running ditto process
		//handled this message
		//If it didn't handle the message(ditto is not running) then startup this processes of ditto 
		//disconnected from the clipboard
		LRESULT ret = 0;
		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
		if(hWnd)
		{
			ret = ::SendMessage(hWnd, WM_OPEN_CLOSE_WINDWOW, cmdInfo.m_bOpenWindow, cmdInfo.m_bCloseWindow);
		}

		return FALSE;		
	}

	CInternetUpdate update;

	long lRunningVersion = update.GetRunningVersion();
	CString cs = update.GetVersionString(lRunningVersion);
	cs.Insert(0, _T("InitInstance  -  Running Version - "));
	Log(cs);

	CString csMutex("Ditto Is Now Running");
	if(g_Opt.m_bU3)
	{
		//If running from a U3 device then allow other ditto's to run
		//only prevent Ditto from running from the same device
		csMutex += " ";
		csMutex += GETENV(_T("U3_DEVICE_SERIAL"));
	}
	else if(g_Opt.GetIsPortableDitto())
	{
		csMutex += " ";
		csMutex += g_Opt.GetExeFileName();
	}

	m_hMutex = CreateMutex(NULL, FALSE, csMutex);
	DWORD dwError = GetLastError();
	if(dwError == ERROR_ALREADY_EXISTS)
	{
		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
		if(hWnd)
			::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);

		return TRUE;
	}

	CString csFile = CGetSetOptions::GetLanguageFile();
	if(m_Language.LoadLanguageFile(csFile) == false)
	{
		CString cs;
		cs.Format(_T("Error loading language file - %s - \n\n%s"), csFile, m_Language.m_csLastError);
		Log(cs);

		m_Language.LoadLanguageFile(_T("English.xml"));
	}

	//The first time we run Ditto on U3 show a web page about ditto
	if(g_Opt.m_bU3)
	{
		if(FileExists(CGetSetOptions::GetDBPath()) == FALSE)
		{
			CString csFile = CGetSetOptions::GetPath(PATH_HELP);
			csFile += "U3_Install.htm";
			CHyperLink::GotoURL(csFile, SW_SHOW);
		}
	}

	int nRet = CheckDBExists(CGetSetOptions::GetDBPath());
	if(nRet == FALSE)
	{
		AfxMessageBox(theApp.m_Language.GetString("Error_Opening_Database", "Error Opening Database."));
		return FALSE;
	}

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = m_pMainFrame = pFrame;

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

	return TRUE;
}